@zohodesk/i18n 1.0.0-beta.38-murphy-logs → 1.0.0-beta.39-murphy

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.
@@ -6,153 +6,12 @@ export const I18N_ERROR_TYPES = {
6
6
  const reportedKeys = new Set();
7
7
  const pendingErrors = new Map();
8
8
  const MAX_PENDING_ERRORS = 100;
9
-
10
- // STARTUP DIAGNOSTIC - Run once when module loads
11
- (function runStartupDiagnostic() {
12
- console.log('╔═══════════════════════════════════════════════════════════╗');
13
- console.log('║ i18n ERROR REPORTER - STARTUP DIAGNOSTIC ║');
14
- console.log('╚═══════════════════════════════════════════════════════════╝');
15
- const diagnostic = {
16
- moduleLoadTime: new Date().toISOString(),
17
- environment: {
18
- hasWindow: typeof window !== 'undefined',
19
- windowLocation: typeof window !== 'undefined' ? window.location.href : 'no window',
20
- isIframe: typeof window !== 'undefined' ? window.self !== window.top : 'unknown',
21
- userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : 'unknown'
22
- },
23
- murphy: {
24
- exists: typeof murphy !== 'undefined',
25
- hasErrorMethod: typeof murphy !== 'undefined' && typeof murphy.error === 'function',
26
- type: typeof murphy,
27
- methods: typeof murphy !== 'undefined' ? Object.keys(murphy) : 'murphy not defined'
28
- },
29
- zohoIM: {
30
- exists: typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined',
31
- hasMurphyConfig: typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined' && typeof window.ZOHOIM.murphyConfig !== 'undefined',
32
- murphyConfig: typeof window !== 'undefined' && window.ZOHOIM ? window.ZOHOIM.murphyConfig : 'ZOHOIM not available'
33
- },
34
- state: {
35
- reportedKeysCount: reportedKeys.size,
36
- pendingErrorsCount: pendingErrors.size,
37
- maxPendingErrors: MAX_PENDING_ERRORS
38
- }
39
- };
40
- console.log('[i18n-debug] STARTUP DIAGNOSTIC:', diagnostic);
41
- console.log('╚═══════════════════════════════════════════════════════════╝');
42
- })();
9
+ let hasLoggedQueueUse = false;
10
+ let hasLoggedFlushUse = false;
43
11
  function isMurphyAvailable() {
44
- const available = typeof murphy !== 'undefined' && typeof murphy.error === 'function';
45
-
46
- // COMPREHENSIVE MURPHY INSPECTION
47
- const murphyDetails = {
48
- murphyExists: typeof murphy !== 'undefined',
49
- murphyErrorExists: typeof murphy !== 'undefined' && typeof murphy.error === 'function',
50
- available,
51
- murphyType: typeof murphy,
52
- windowLocation: typeof window !== 'undefined' ? window.location.href : 'no window',
53
- isIframe: typeof window !== 'undefined' ? window.self !== window.top : 'no window'
54
- };
55
- if (typeof murphy !== 'undefined') {
56
- // Log all Murphy methods
57
- murphyDetails.murphyMethods = Object.keys(murphy);
58
-
59
- // Log Murphy config if accessible
60
- if (typeof murphy.config === 'object') {
61
- murphyDetails.murphyConfig = murphy.config;
62
- }
63
-
64
- // Log Murphy app info if accessible
65
- if (typeof murphy.appKey !== 'undefined') {
66
- murphyDetails.murphyAppKey = murphy.appKey;
67
- }
68
-
69
- // Try to get Murphy internal state
70
- try {
71
- murphyDetails.murphyState = {
72
- installed: typeof murphy.installed !== 'undefined' ? murphy.installed : 'unknown',
73
- version: typeof murphy.version !== 'undefined' ? murphy.version : 'unknown'
74
- };
75
- } catch (e) {
76
- murphyDetails.murphyStateError = e.message;
77
- }
78
- }
79
-
80
- // Log window.ZOHOIM Murphy config
81
- if (typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined') {
82
- murphyDetails.windowZOHOIM = {
83
- exists: true,
84
- hasMurphyConfig: typeof window.ZOHOIM.murphyConfig !== 'undefined',
85
- murphyConfig: window.ZOHOIM.murphyConfig
86
- };
87
- } else {
88
- murphyDetails.windowZOHOIM = 'not available';
89
- }
90
- console.log('[i18n-debug] Murphy availability check:', murphyDetails);
91
- return available;
92
- }
93
- function isDebugEnabled() {
94
- return true; // ALWAYS ENABLED FOR DEBUGGING
95
- }
96
- function debugLog(message, meta) {
97
- // ALWAYS LOG - debug flag removed
98
- if (typeof console === 'undefined' || typeof console.log !== 'function') {
99
- return;
100
- }
101
- if (typeof meta === 'undefined') {
102
- console.log(`[i18n] ${message}`);
103
- } else {
104
- console.log(`[i18n] ${message}`, meta);
105
- }
12
+ return typeof murphy !== 'undefined' && typeof murphy.error === 'function';
106
13
  }
107
14
  function sendToMurphy(type, key) {
108
- debugLog('reporting i18n error', {
109
- type,
110
- key
111
- });
112
-
113
- // COMPREHENSIVE MURPHY STATE INSPECTION
114
- const murphyInspection = {
115
- murphyType: typeof murphy,
116
- murphyErrorType: typeof murphy.error,
117
- murphyMethods: typeof murphy === 'object' ? Object.keys(murphy) : 'not an object',
118
- timestamp: new Date().toISOString(),
119
- url: typeof window !== 'undefined' ? window.location.href : 'no window'
120
- };
121
-
122
- // Get Murphy internal config
123
- if (typeof murphy !== 'undefined') {
124
- try {
125
- murphyInspection.murphyInternalConfig = {
126
- config: murphy.config || 'no config property',
127
- appKey: murphy.appKey || 'no appKey property',
128
- authKey: murphy.authKey || 'no authKey property',
129
- appDomain: murphy.appDomain || 'no appDomain property',
130
- endpoint: murphy.endpoint || 'no endpoint property',
131
- url: murphy.url || 'no url property'
132
- };
133
- } catch (e) {
134
- murphyInspection.murphyConfigError = e.message;
135
- }
136
- }
137
-
138
- // Get window.ZOHOIM config
139
- if (typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined') {
140
- murphyInspection.windowZOHOIM = {
141
- exists: true,
142
- murphyConfig: window.ZOHOIM.murphyConfig || 'no murphyConfig',
143
- getUserInfo: typeof window.ZOHOIM.getUserInfo === 'function' ? window.ZOHOIM.getUserInfo() : 'no getUserInfo',
144
- getServiceOrgInfo: typeof window.ZOHOIM.getServiceOrgInfo === 'function' ? window.ZOHOIM.getServiceOrgInfo() : 'no getServiceOrgInfo'
145
- };
146
- }
147
-
148
- // Get global murphy config if available
149
- if (typeof window !== 'undefined' && typeof window.murphyConfig !== 'undefined') {
150
- murphyInspection.globalMurphyConfig = window.murphyConfig;
151
- }
152
- console.log('[i18n-debug] ═══════════════════════════════════════════');
153
- console.log('[i18n-debug] MURPHY STATE BEFORE ERROR CALL:');
154
- console.log('[i18n-debug]', murphyInspection);
155
- console.log('[i18n-debug] ═══════════════════════════════════════════');
156
15
  const error = new Error(`i18n ${type}: ${key}`);
157
16
  error.name = type;
158
17
  const murphyOptions = {
@@ -163,204 +22,71 @@ function sendToMurphy(type, key) {
163
22
  },
164
23
  preventClientGrouping: true
165
24
  };
166
- console.log('[i18n-debug] murphy.error() CALL PARAMETERS:', {
167
- errorMessage: error.message,
168
- errorName: error.name,
169
- errorStack: error.stack,
170
- options: murphyOptions,
171
- timestamp: new Date().toISOString()
172
- });
173
-
174
- // Intercept network requests to see Murphy API calls
175
- const originalFetch = typeof window !== 'undefined' ? window.fetch : null;
176
- const originalXHR = typeof window !== 'undefined' ? window.XMLHttpRequest : null;
177
- let networkCallDetected = false;
178
-
179
- // Monitor fetch calls
180
- if (originalFetch && typeof window !== 'undefined') {
181
- window.fetch = function (...args) {
182
- console.log('[i18n-debug] 🌐 FETCH CALL DETECTED (possibly from Murphy):', {
183
- url: args[0],
184
- options: args[1],
185
- timestamp: new Date().toISOString()
186
- });
187
- networkCallDetected = true;
188
- return originalFetch.apply(this, args);
189
- };
190
- }
191
25
  try {
192
- console.log('[i18n-debug] ▶ CALLING murphy.error() NOW...');
193
- const result = murphy.error(error, undefined, murphyOptions);
194
- console.log('[i18n-debug] ✅ murphy.error() COMPLETED:', {
195
- result,
196
- resultType: typeof result,
197
- success: true,
198
- networkCallDetected,
199
- timestamp: new Date().toISOString()
200
- });
201
-
202
- // Check if Murphy queued the error
203
- if (typeof murphy.getQueuedErrors === 'function') {
204
- console.log('[i18n-debug] Murphy queued errors:', murphy.getQueuedErrors());
205
- }
26
+ murphy.error(error, undefined, murphyOptions);
206
27
  } catch (err) {
207
- console.error('[i18n-debug] murphy.error() FAILED:', {
208
- error: err.message,
209
- stack: err.stack,
210
- timestamp: new Date().toISOString()
211
- });
212
- } finally {
213
- // Restore original fetch
214
- if (originalFetch && typeof window !== 'undefined') {
215
- setTimeout(() => {
216
- window.fetch = originalFetch;
217
- console.log('[i18n-debug] Network call detected:', networkCallDetected);
218
- }, 100);
219
- }
28
+ // Avoid throwing from error reporting
220
29
  }
221
- console.log('[i18n-debug] ═══════════════════════════════════════════');
222
30
  }
223
31
  function queuePendingError(dedupeKey, type, key) {
224
32
  if (pendingErrors.has(dedupeKey)) {
225
- debugLog('pending i18n error deduped', {
226
- type,
227
- key
228
- });
229
33
  return;
230
34
  }
35
+ if (!hasLoggedQueueUse && typeof console !== 'undefined') {
36
+ console.log('[i18n] queued errors while murphy not available');
37
+ hasLoggedQueueUse = true;
38
+ }
231
39
  if (pendingErrors.size >= MAX_PENDING_ERRORS) {
232
40
  const oldestKey = pendingErrors.keys().next().value;
233
41
  pendingErrors.delete(oldestKey);
234
- debugLog('pending i18n error dropped (queue full)', {
235
- droppedKey: oldestKey,
236
- pendingSize: pendingErrors.size
237
- });
238
42
  }
239
43
  pendingErrors.set(dedupeKey, {
240
44
  type,
241
45
  key
242
46
  });
243
- debugLog('queued i18n error (murphy not ready)', {
244
- type,
245
- key,
246
- pendingSize: pendingErrors.size
247
- });
248
47
  }
249
48
  export function flushI18NErrors() {
250
- console.log('[i18n-debug] flushI18NErrors ENTRY:', {
251
- pendingErrorsSize: pendingErrors.size,
252
- pendingErrors: Array.from(pendingErrors.entries()),
253
- reportedKeysSize: reportedKeys.size
254
- });
255
49
  if (!isMurphyAvailable()) {
256
- debugLog('flush skipped (murphy not available)', {
257
- pendingSize: pendingErrors.size
258
- });
259
- console.log('[i18n-debug] Flush SKIPPED - Murphy not available');
260
50
  return;
261
51
  }
262
52
  if (pendingErrors.size === 0) {
263
- debugLog('flush skipped (no pending errors)');
264
- console.log('[i18n-debug] Flush SKIPPED - No pending errors');
265
53
  return;
266
54
  }
267
- debugLog('flushing pending i18n errors', {
268
- pendingSize: pendingErrors.size
269
- });
270
- console.log('[i18n-debug] FLUSHING pending errors:', {
271
- count: pendingErrors.size,
272
- errors: Array.from(pendingErrors.entries())
273
- });
274
- let flushedCount = 0;
275
- for (const [dedupeKey, data] of pendingErrors) {
276
- console.log('[i18n-debug] Processing pending error:', {
277
- dedupeKey,
278
- data,
279
- alreadyReported: reportedKeys.has(dedupeKey)
55
+ if (!hasLoggedFlushUse && typeof console !== 'undefined') {
56
+ console.log('[i18n] flushing queued errors', {
57
+ count: pendingErrors.size
280
58
  });
59
+ hasLoggedFlushUse = true;
60
+ }
61
+ for (const [dedupeKey, data] of pendingErrors) {
281
62
  if (reportedKeys.has(dedupeKey)) {
282
- console.log('[i18n-debug] Skipping already reported key:', dedupeKey);
283
63
  pendingErrors.delete(dedupeKey);
284
64
  continue;
285
65
  }
286
- console.log('[i18n-debug] Sending pending error to Murphy:', dedupeKey);
287
66
  sendToMurphy(data.type, data.key);
288
67
  reportedKeys.add(dedupeKey);
289
68
  pendingErrors.delete(dedupeKey);
290
- flushedCount += 1;
291
69
  }
292
- debugLog('flush complete', {
293
- flushedCount,
294
- pendingRemaining: pendingErrors.size
295
- });
296
- console.log('[i18n-debug] Flush COMPLETE:', {
297
- flushedCount,
298
- pendingRemaining: pendingErrors.size,
299
- reportedKeysSize: reportedKeys.size
300
- });
301
70
  }
302
71
  export function reportI18NError(type, key) {
303
- debugLog('reportI18NError called', {
304
- type,
305
- key
306
- });
307
- console.log('[i18n-debug] reportI18NError ENTRY:', {
308
- type,
309
- key,
310
- url: typeof window !== 'undefined' ? window.location.href : 'no window',
311
- timestamp: new Date().toISOString(),
312
- reportedKeysSize: reportedKeys.size,
313
- reportedKeys: Array.from(reportedKeys),
314
- pendingErrorsSize: pendingErrors.size
315
- });
316
72
  const dedupeKey = `${type}:${key}`;
317
- console.log('[i18n-debug] Deduplication check:', {
318
- dedupeKey,
319
- alreadyReported: reportedKeys.has(dedupeKey),
320
- reportedKeysSet: Array.from(reportedKeys)
321
- });
322
73
  if (reportedKeys.has(dedupeKey)) {
323
- debugLog('reported i18n error deduped', {
324
- type,
325
- key
326
- });
327
- console.log('[i18n-debug] DEDUPED - EXITING reportI18NError');
328
74
  return;
329
75
  }
330
- console.log('[i18n-debug] NOT deduped, proceeding with Murphy check');
331
76
  if (!isMurphyAvailable()) {
332
- debugLog('murphy not available, queueing i18n error', {
333
- type,
334
- key
335
- });
336
- console.log('[i18n-debug] Murphy NOT available, queueing error');
337
77
  queuePendingError(dedupeKey, type, key);
338
78
  return;
339
79
  }
340
- console.log('[i18n-debug] Murphy IS available, flushing pending errors');
341
80
  flushI18NErrors();
342
- console.log('[i18n-debug] Post-flush deduplication check:', {
343
- dedupeKey,
344
- alreadyReported: reportedKeys.has(dedupeKey),
345
- reportedKeysSet: Array.from(reportedKeys)
346
- });
347
81
  if (reportedKeys.has(dedupeKey)) {
348
- debugLog('reported i18n error deduped after flush', {
349
- type,
350
- key
351
- });
352
- console.log('[i18n-debug] DEDUPED AFTER FLUSH - EXITING reportI18NError');
353
82
  return;
354
83
  }
355
- console.log('[i18n-debug] About to call sendToMurphy');
356
84
  sendToMurphy(type, key);
357
85
  reportedKeys.add(dedupeKey);
358
- console.log('[i18n-debug] Added to reportedKeys, new size:', reportedKeys.size);
359
86
  }
360
87
  export function clearReportedKeys() {
361
88
  reportedKeys.clear();
362
89
  pendingErrors.clear();
363
- debugLog('cleared reported and pending i18n errors');
364
90
  }
365
91
  export function getFallbackText(key) {
366
92
  const isNumeric = /^\d+$/.test(key);
package/es/utils/index.js CHANGED
@@ -234,46 +234,17 @@ export function getLocalizedValue({
234
234
  return localizedValue || null;
235
235
  }
236
236
  export function getI18NValue(i18n) {
237
- console.log('[i18n-debug] getI18NValue called:', {
238
- i18nType: typeof i18n,
239
- i18nIsDefined: typeof i18n !== 'undefined',
240
- i18nKeysCount: typeof i18n === 'object' ? Object.keys(i18n).length : 0,
241
- url: typeof window !== 'undefined' ? window.location.href : 'no window'
242
- });
243
237
  if (typeof i18n === 'undefined') {
244
- console.error('[i18n-debug] i18n object is UNDEFINED! Reporting error and returning fallback');
245
238
  reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
246
239
  return key => key;
247
240
  }
248
241
  return (key, values, localizedProps) => {
249
- console.log('[i18n-debug] getI18NValue lookup:', {
250
- key,
251
- values,
252
- localizedProps,
253
- mappedKey: getMappedKey(key),
254
- hasLocalizedValue: localizedProps ? !!getLocalizedValue(localizedProps) : !!localizedStringData[key]
255
- });
256
242
  const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
257
243
  const finalKey = getMappedKey(key);
258
244
  let i18nStr = i18n[finalKey];
259
- console.log('[i18n-debug] i18n lookup result:', {
260
- originalKey: key,
261
- finalKey,
262
- found: i18nStr !== undefined,
263
- i18nStrValue: i18nStr,
264
- willFallback: i18nStr === undefined
265
- });
266
245
  if (i18nStr === undefined) {
267
246
  const isNumeric = /^\d+$/.test(finalKey);
268
247
  const errorType = isNumeric ? I18N_ERROR_TYPES.NUMERIC_FALLBACK : I18N_ERROR_TYPES.MISSING_KEY;
269
- console.warn('[i18n-debug] MISSING KEY detected!', {
270
- finalKey,
271
- isNumeric,
272
- errorType,
273
- fallbackText: getFallbackText(finalKey),
274
- aboutToCallReportI18NError: true,
275
- timestamp: new Date().toISOString()
276
- });
277
248
  reportI18NError(errorType, finalKey);
278
249
  return localizedValue || getFallbackText(finalKey);
279
250
  }
@@ -15,7 +15,6 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
15
15
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
16
16
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
17
17
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
18
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
19
18
  var I18N_ERROR_TYPES = exports.I18N_ERROR_TYPES = {
20
19
  UNDEFINED_OBJECT: 'I18N_UNDEFINED_OBJECT',
21
20
  MISSING_KEY: 'I18N_MISSING_KEY',
@@ -24,153 +23,12 @@ var I18N_ERROR_TYPES = exports.I18N_ERROR_TYPES = {
24
23
  var reportedKeys = new Set();
25
24
  var pendingErrors = new Map();
26
25
  var MAX_PENDING_ERRORS = 100;
27
-
28
- // STARTUP DIAGNOSTIC - Run once when module loads
29
- (function runStartupDiagnostic() {
30
- console.log('╔═══════════════════════════════════════════════════════════╗');
31
- console.log('║ i18n ERROR REPORTER - STARTUP DIAGNOSTIC ║');
32
- console.log('╚═══════════════════════════════════════════════════════════╝');
33
- var diagnostic = {
34
- moduleLoadTime: new Date().toISOString(),
35
- environment: {
36
- hasWindow: typeof window !== 'undefined',
37
- windowLocation: typeof window !== 'undefined' ? window.location.href : 'no window',
38
- isIframe: typeof window !== 'undefined' ? window.self !== window.top : 'unknown',
39
- userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : 'unknown'
40
- },
41
- murphy: {
42
- exists: typeof murphy !== 'undefined',
43
- hasErrorMethod: typeof murphy !== 'undefined' && typeof murphy.error === 'function',
44
- type: typeof murphy === "undefined" ? "undefined" : _typeof(murphy),
45
- methods: typeof murphy !== 'undefined' ? Object.keys(murphy) : 'murphy not defined'
46
- },
47
- zohoIM: {
48
- exists: typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined',
49
- hasMurphyConfig: typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined' && typeof window.ZOHOIM.murphyConfig !== 'undefined',
50
- murphyConfig: typeof window !== 'undefined' && window.ZOHOIM ? window.ZOHOIM.murphyConfig : 'ZOHOIM not available'
51
- },
52
- state: {
53
- reportedKeysCount: reportedKeys.size,
54
- pendingErrorsCount: pendingErrors.size,
55
- maxPendingErrors: MAX_PENDING_ERRORS
56
- }
57
- };
58
- console.log('[i18n-debug] STARTUP DIAGNOSTIC:', diagnostic);
59
- console.log('╚═══════════════════════════════════════════════════════════╝');
60
- })();
26
+ var hasLoggedQueueUse = false;
27
+ var hasLoggedFlushUse = false;
61
28
  function isMurphyAvailable() {
62
- var available = typeof murphy !== 'undefined' && typeof murphy.error === 'function';
63
-
64
- // COMPREHENSIVE MURPHY INSPECTION
65
- var murphyDetails = {
66
- murphyExists: typeof murphy !== 'undefined',
67
- murphyErrorExists: typeof murphy !== 'undefined' && typeof murphy.error === 'function',
68
- available: available,
69
- murphyType: typeof murphy === "undefined" ? "undefined" : _typeof(murphy),
70
- windowLocation: typeof window !== 'undefined' ? window.location.href : 'no window',
71
- isIframe: typeof window !== 'undefined' ? window.self !== window.top : 'no window'
72
- };
73
- if (typeof murphy !== 'undefined') {
74
- // Log all Murphy methods
75
- murphyDetails.murphyMethods = Object.keys(murphy);
76
-
77
- // Log Murphy config if accessible
78
- if (_typeof(murphy.config) === 'object') {
79
- murphyDetails.murphyConfig = murphy.config;
80
- }
81
-
82
- // Log Murphy app info if accessible
83
- if (typeof murphy.appKey !== 'undefined') {
84
- murphyDetails.murphyAppKey = murphy.appKey;
85
- }
86
-
87
- // Try to get Murphy internal state
88
- try {
89
- murphyDetails.murphyState = {
90
- installed: typeof murphy.installed !== 'undefined' ? murphy.installed : 'unknown',
91
- version: typeof murphy.version !== 'undefined' ? murphy.version : 'unknown'
92
- };
93
- } catch (e) {
94
- murphyDetails.murphyStateError = e.message;
95
- }
96
- }
97
-
98
- // Log window.ZOHOIM Murphy config
99
- if (typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined') {
100
- murphyDetails.windowZOHOIM = {
101
- exists: true,
102
- hasMurphyConfig: typeof window.ZOHOIM.murphyConfig !== 'undefined',
103
- murphyConfig: window.ZOHOIM.murphyConfig
104
- };
105
- } else {
106
- murphyDetails.windowZOHOIM = 'not available';
107
- }
108
- console.log('[i18n-debug] Murphy availability check:', murphyDetails);
109
- return available;
110
- }
111
- function isDebugEnabled() {
112
- return true; // ALWAYS ENABLED FOR DEBUGGING
113
- }
114
- function debugLog(message, meta) {
115
- // ALWAYS LOG - debug flag removed
116
- if (typeof console === 'undefined' || typeof console.log !== 'function') {
117
- return;
118
- }
119
- if (typeof meta === 'undefined') {
120
- console.log("[i18n] ".concat(message));
121
- } else {
122
- console.log("[i18n] ".concat(message), meta);
123
- }
29
+ return typeof murphy !== 'undefined' && typeof murphy.error === 'function';
124
30
  }
125
31
  function sendToMurphy(type, key) {
126
- debugLog('reporting i18n error', {
127
- type: type,
128
- key: key
129
- });
130
-
131
- // COMPREHENSIVE MURPHY STATE INSPECTION
132
- var murphyInspection = {
133
- murphyType: typeof murphy === "undefined" ? "undefined" : _typeof(murphy),
134
- murphyErrorType: _typeof(murphy.error),
135
- murphyMethods: (typeof murphy === "undefined" ? "undefined" : _typeof(murphy)) === 'object' ? Object.keys(murphy) : 'not an object',
136
- timestamp: new Date().toISOString(),
137
- url: typeof window !== 'undefined' ? window.location.href : 'no window'
138
- };
139
-
140
- // Get Murphy internal config
141
- if (typeof murphy !== 'undefined') {
142
- try {
143
- murphyInspection.murphyInternalConfig = {
144
- config: murphy.config || 'no config property',
145
- appKey: murphy.appKey || 'no appKey property',
146
- authKey: murphy.authKey || 'no authKey property',
147
- appDomain: murphy.appDomain || 'no appDomain property',
148
- endpoint: murphy.endpoint || 'no endpoint property',
149
- url: murphy.url || 'no url property'
150
- };
151
- } catch (e) {
152
- murphyInspection.murphyConfigError = e.message;
153
- }
154
- }
155
-
156
- // Get window.ZOHOIM config
157
- if (typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined') {
158
- murphyInspection.windowZOHOIM = {
159
- exists: true,
160
- murphyConfig: window.ZOHOIM.murphyConfig || 'no murphyConfig',
161
- getUserInfo: typeof window.ZOHOIM.getUserInfo === 'function' ? window.ZOHOIM.getUserInfo() : 'no getUserInfo',
162
- getServiceOrgInfo: typeof window.ZOHOIM.getServiceOrgInfo === 'function' ? window.ZOHOIM.getServiceOrgInfo() : 'no getServiceOrgInfo'
163
- };
164
- }
165
-
166
- // Get global murphy config if available
167
- if (typeof window !== 'undefined' && typeof window.murphyConfig !== 'undefined') {
168
- murphyInspection.globalMurphyConfig = window.murphyConfig;
169
- }
170
- console.log('[i18n-debug] ═══════════════════════════════════════════');
171
- console.log('[i18n-debug] MURPHY STATE BEFORE ERROR CALL:');
172
- console.log('[i18n-debug]', murphyInspection);
173
- console.log('[i18n-debug] ═══════════════════════════════════════════');
174
32
  var error = new Error("i18n ".concat(type, ": ").concat(key));
175
33
  error.name = type;
176
34
  var murphyOptions = {
@@ -181,118 +39,42 @@ function sendToMurphy(type, key) {
181
39
  },
182
40
  preventClientGrouping: true
183
41
  };
184
- console.log('[i18n-debug] murphy.error() CALL PARAMETERS:', {
185
- errorMessage: error.message,
186
- errorName: error.name,
187
- errorStack: error.stack,
188
- options: murphyOptions,
189
- timestamp: new Date().toISOString()
190
- });
191
-
192
- // Intercept network requests to see Murphy API calls
193
- var originalFetch = typeof window !== 'undefined' ? window.fetch : null;
194
- var originalXHR = typeof window !== 'undefined' ? window.XMLHttpRequest : null;
195
- var networkCallDetected = false;
196
-
197
- // Monitor fetch calls
198
- if (originalFetch && typeof window !== 'undefined') {
199
- window.fetch = function () {
200
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
201
- args[_key] = arguments[_key];
202
- }
203
- console.log('[i18n-debug] 🌐 FETCH CALL DETECTED (possibly from Murphy):', {
204
- url: args[0],
205
- options: args[1],
206
- timestamp: new Date().toISOString()
207
- });
208
- networkCallDetected = true;
209
- return originalFetch.apply(this, args);
210
- };
211
- }
212
42
  try {
213
- console.log('[i18n-debug] ▶ CALLING murphy.error() NOW...');
214
- var result = murphy.error(error, undefined, murphyOptions);
215
- console.log('[i18n-debug] ✅ murphy.error() COMPLETED:', {
216
- result: result,
217
- resultType: _typeof(result),
218
- success: true,
219
- networkCallDetected: networkCallDetected,
220
- timestamp: new Date().toISOString()
221
- });
222
-
223
- // Check if Murphy queued the error
224
- if (typeof murphy.getQueuedErrors === 'function') {
225
- console.log('[i18n-debug] Murphy queued errors:', murphy.getQueuedErrors());
226
- }
43
+ murphy.error(error, undefined, murphyOptions);
227
44
  } catch (err) {
228
- console.error('[i18n-debug] murphy.error() FAILED:', {
229
- error: err.message,
230
- stack: err.stack,
231
- timestamp: new Date().toISOString()
232
- });
233
- } finally {
234
- // Restore original fetch
235
- if (originalFetch && typeof window !== 'undefined') {
236
- setTimeout(function () {
237
- window.fetch = originalFetch;
238
- console.log('[i18n-debug] Network call detected:', networkCallDetected);
239
- }, 100);
240
- }
45
+ // Avoid throwing from error reporting
241
46
  }
242
- console.log('[i18n-debug] ═══════════════════════════════════════════');
243
47
  }
244
48
  function queuePendingError(dedupeKey, type, key) {
245
49
  if (pendingErrors.has(dedupeKey)) {
246
- debugLog('pending i18n error deduped', {
247
- type: type,
248
- key: key
249
- });
250
50
  return;
251
51
  }
52
+ if (!hasLoggedQueueUse && typeof console !== 'undefined') {
53
+ console.log('[i18n] queued errors while murphy not available');
54
+ hasLoggedQueueUse = true;
55
+ }
252
56
  if (pendingErrors.size >= MAX_PENDING_ERRORS) {
253
57
  var oldestKey = pendingErrors.keys().next().value;
254
58
  pendingErrors["delete"](oldestKey);
255
- debugLog('pending i18n error dropped (queue full)', {
256
- droppedKey: oldestKey,
257
- pendingSize: pendingErrors.size
258
- });
259
59
  }
260
60
  pendingErrors.set(dedupeKey, {
261
61
  type: type,
262
62
  key: key
263
63
  });
264
- debugLog('queued i18n error (murphy not ready)', {
265
- type: type,
266
- key: key,
267
- pendingSize: pendingErrors.size
268
- });
269
64
  }
270
65
  function flushI18NErrors() {
271
- console.log('[i18n-debug] flushI18NErrors ENTRY:', {
272
- pendingErrorsSize: pendingErrors.size,
273
- pendingErrors: Array.from(pendingErrors.entries()),
274
- reportedKeysSize: reportedKeys.size
275
- });
276
66
  if (!isMurphyAvailable()) {
277
- debugLog('flush skipped (murphy not available)', {
278
- pendingSize: pendingErrors.size
279
- });
280
- console.log('[i18n-debug] Flush SKIPPED - Murphy not available');
281
67
  return;
282
68
  }
283
69
  if (pendingErrors.size === 0) {
284
- debugLog('flush skipped (no pending errors)');
285
- console.log('[i18n-debug] Flush SKIPPED - No pending errors');
286
70
  return;
287
71
  }
288
- debugLog('flushing pending i18n errors', {
289
- pendingSize: pendingErrors.size
290
- });
291
- console.log('[i18n-debug] FLUSHING pending errors:', {
292
- count: pendingErrors.size,
293
- errors: Array.from(pendingErrors.entries())
294
- });
295
- var flushedCount = 0;
72
+ if (!hasLoggedFlushUse && typeof console !== 'undefined') {
73
+ console.log('[i18n] flushing queued errors', {
74
+ count: pendingErrors.size
75
+ });
76
+ hasLoggedFlushUse = true;
77
+ }
296
78
  var _iterator = _createForOfIteratorHelper(pendingErrors),
297
79
  _step;
298
80
  try {
@@ -300,99 +82,39 @@ function flushI18NErrors() {
300
82
  var _step$value = _slicedToArray(_step.value, 2),
301
83
  dedupeKey = _step$value[0],
302
84
  data = _step$value[1];
303
- console.log('[i18n-debug] Processing pending error:', {
304
- dedupeKey: dedupeKey,
305
- data: data,
306
- alreadyReported: reportedKeys.has(dedupeKey)
307
- });
308
85
  if (reportedKeys.has(dedupeKey)) {
309
- console.log('[i18n-debug] Skipping already reported key:', dedupeKey);
310
86
  pendingErrors["delete"](dedupeKey);
311
87
  continue;
312
88
  }
313
- console.log('[i18n-debug] Sending pending error to Murphy:', dedupeKey);
314
89
  sendToMurphy(data.type, data.key);
315
90
  reportedKeys.add(dedupeKey);
316
91
  pendingErrors["delete"](dedupeKey);
317
- flushedCount += 1;
318
92
  }
319
93
  } catch (err) {
320
94
  _iterator.e(err);
321
95
  } finally {
322
96
  _iterator.f();
323
97
  }
324
- debugLog('flush complete', {
325
- flushedCount: flushedCount,
326
- pendingRemaining: pendingErrors.size
327
- });
328
- console.log('[i18n-debug] Flush COMPLETE:', {
329
- flushedCount: flushedCount,
330
- pendingRemaining: pendingErrors.size,
331
- reportedKeysSize: reportedKeys.size
332
- });
333
98
  }
334
99
  function reportI18NError(type, key) {
335
- debugLog('reportI18NError called', {
336
- type: type,
337
- key: key
338
- });
339
- console.log('[i18n-debug] reportI18NError ENTRY:', {
340
- type: type,
341
- key: key,
342
- url: typeof window !== 'undefined' ? window.location.href : 'no window',
343
- timestamp: new Date().toISOString(),
344
- reportedKeysSize: reportedKeys.size,
345
- reportedKeys: Array.from(reportedKeys),
346
- pendingErrorsSize: pendingErrors.size
347
- });
348
100
  var dedupeKey = "".concat(type, ":").concat(key);
349
- console.log('[i18n-debug] Deduplication check:', {
350
- dedupeKey: dedupeKey,
351
- alreadyReported: reportedKeys.has(dedupeKey),
352
- reportedKeysSet: Array.from(reportedKeys)
353
- });
354
101
  if (reportedKeys.has(dedupeKey)) {
355
- debugLog('reported i18n error deduped', {
356
- type: type,
357
- key: key
358
- });
359
- console.log('[i18n-debug] DEDUPED - EXITING reportI18NError');
360
102
  return;
361
103
  }
362
- console.log('[i18n-debug] NOT deduped, proceeding with Murphy check');
363
104
  if (!isMurphyAvailable()) {
364
- debugLog('murphy not available, queueing i18n error', {
365
- type: type,
366
- key: key
367
- });
368
- console.log('[i18n-debug] Murphy NOT available, queueing error');
369
105
  queuePendingError(dedupeKey, type, key);
370
106
  return;
371
107
  }
372
- console.log('[i18n-debug] Murphy IS available, flushing pending errors');
373
108
  flushI18NErrors();
374
- console.log('[i18n-debug] Post-flush deduplication check:', {
375
- dedupeKey: dedupeKey,
376
- alreadyReported: reportedKeys.has(dedupeKey),
377
- reportedKeysSet: Array.from(reportedKeys)
378
- });
379
109
  if (reportedKeys.has(dedupeKey)) {
380
- debugLog('reported i18n error deduped after flush', {
381
- type: type,
382
- key: key
383
- });
384
- console.log('[i18n-debug] DEDUPED AFTER FLUSH - EXITING reportI18NError');
385
110
  return;
386
111
  }
387
- console.log('[i18n-debug] About to call sendToMurphy');
388
112
  sendToMurphy(type, key);
389
113
  reportedKeys.add(dedupeKey);
390
- console.log('[i18n-debug] Added to reportedKeys, new size:', reportedKeys.size);
391
114
  }
392
115
  function clearReportedKeys() {
393
116
  reportedKeys.clear();
394
117
  pendingErrors.clear();
395
- debugLog('cleared reported and pending i18n errors');
396
118
  }
397
119
  function getFallbackText(key) {
398
120
  var isNumeric = /^\d+$/.test(key);
@@ -269,48 +269,19 @@ function getLocalizedValue() {
269
269
  return localizedValue || null;
270
270
  }
271
271
  function getI18NValue(i18n) {
272
- console.log('[i18n-debug] getI18NValue called:', {
273
- i18nType: _typeof(i18n),
274
- i18nIsDefined: typeof i18n !== 'undefined',
275
- i18nKeysCount: _typeof(i18n) === 'object' ? Object.keys(i18n).length : 0,
276
- url: typeof window !== 'undefined' ? window.location.href : 'no window'
277
- });
278
272
  if (typeof i18n === 'undefined') {
279
- console.error('[i18n-debug] i18n object is UNDEFINED! Reporting error and returning fallback');
280
273
  (0, _errorReporter.reportI18NError)(_errorReporter.I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
281
274
  return function (key) {
282
275
  return key;
283
276
  };
284
277
  }
285
278
  return function (key, values, localizedProps) {
286
- console.log('[i18n-debug] getI18NValue lookup:', {
287
- key: key,
288
- values: values,
289
- localizedProps: localizedProps,
290
- mappedKey: getMappedKey(key),
291
- hasLocalizedValue: localizedProps ? !!getLocalizedValue(localizedProps) : !!localizedStringData[key]
292
- });
293
279
  var localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
294
280
  var finalKey = getMappedKey(key);
295
281
  var i18nStr = i18n[finalKey];
296
- console.log('[i18n-debug] i18n lookup result:', {
297
- originalKey: key,
298
- finalKey: finalKey,
299
- found: i18nStr !== undefined,
300
- i18nStrValue: i18nStr,
301
- willFallback: i18nStr === undefined
302
- });
303
282
  if (i18nStr === undefined) {
304
283
  var isNumeric = /^\d+$/.test(finalKey);
305
284
  var errorType = isNumeric ? _errorReporter.I18N_ERROR_TYPES.NUMERIC_FALLBACK : _errorReporter.I18N_ERROR_TYPES.MISSING_KEY;
306
- console.warn('[i18n-debug] MISSING KEY detected!', {
307
- finalKey: finalKey,
308
- isNumeric: isNumeric,
309
- errorType: errorType,
310
- fallbackText: (0, _errorReporter.getFallbackText)(finalKey),
311
- aboutToCallReportI18NError: true,
312
- timestamp: new Date().toISOString()
313
- });
314
285
  (0, _errorReporter.reportI18NError)(errorType, finalKey);
315
286
  return localizedValue || (0, _errorReporter.getFallbackText)(finalKey);
316
287
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/i18n",
3
- "version": "1.0.0-beta.38-murphy-logs",
3
+ "version": "1.0.0-beta.39-murphy",
4
4
  "main": "lib/index",
5
5
  "module": "es/index.js",
6
6
  "jsnext:main": "es/index.js",
@@ -7,160 +7,14 @@ export const I18N_ERROR_TYPES = {
7
7
  const reportedKeys = new Set();
8
8
  const pendingErrors = new Map();
9
9
  const MAX_PENDING_ERRORS = 100;
10
-
11
- // STARTUP DIAGNOSTIC - Run once when module loads
12
- (function runStartupDiagnostic() {
13
- console.log('╔═══════════════════════════════════════════════════════════╗');
14
- console.log('║ i18n ERROR REPORTER - STARTUP DIAGNOSTIC ║');
15
- console.log('╚═══════════════════════════════════════════════════════════╝');
16
-
17
- const diagnostic = {
18
- moduleLoadTime: new Date().toISOString(),
19
- environment: {
20
- hasWindow: typeof window !== 'undefined',
21
- windowLocation: typeof window !== 'undefined' ? window.location.href : 'no window',
22
- isIframe: typeof window !== 'undefined' ? window.self !== window.top : 'unknown',
23
- userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : 'unknown'
24
- },
25
- murphy: {
26
- exists: typeof murphy !== 'undefined',
27
- hasErrorMethod: typeof murphy !== 'undefined' && typeof murphy.error === 'function',
28
- type: typeof murphy,
29
- methods: typeof murphy !== 'undefined' ? Object.keys(murphy) : 'murphy not defined'
30
- },
31
- zohoIM: {
32
- exists: typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined',
33
- hasMurphyConfig: typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined' && typeof window.ZOHOIM.murphyConfig !== 'undefined',
34
- murphyConfig: typeof window !== 'undefined' && window.ZOHOIM ? window.ZOHOIM.murphyConfig : 'ZOHOIM not available'
35
- },
36
- state: {
37
- reportedKeysCount: reportedKeys.size,
38
- pendingErrorsCount: pendingErrors.size,
39
- maxPendingErrors: MAX_PENDING_ERRORS
40
- }
41
- };
42
-
43
- console.log('[i18n-debug] STARTUP DIAGNOSTIC:', diagnostic);
44
- console.log('╚═══════════════════════════════════════════════════════════╝');
45
- })();
10
+ let hasLoggedQueueUse = false;
11
+ let hasLoggedFlushUse = false;
46
12
 
47
13
  function isMurphyAvailable() {
48
- const available = typeof murphy !== 'undefined' && typeof murphy.error === 'function';
49
-
50
- // COMPREHENSIVE MURPHY INSPECTION
51
- const murphyDetails = {
52
- murphyExists: typeof murphy !== 'undefined',
53
- murphyErrorExists: typeof murphy !== 'undefined' && typeof murphy.error === 'function',
54
- available,
55
- murphyType: typeof murphy,
56
- windowLocation: typeof window !== 'undefined' ? window.location.href : 'no window',
57
- isIframe: typeof window !== 'undefined' ? window.self !== window.top : 'no window'
58
- };
59
-
60
- if (typeof murphy !== 'undefined') {
61
- // Log all Murphy methods
62
- murphyDetails.murphyMethods = Object.keys(murphy);
63
-
64
- // Log Murphy config if accessible
65
- if (typeof murphy.config === 'object') {
66
- murphyDetails.murphyConfig = murphy.config;
67
- }
68
-
69
- // Log Murphy app info if accessible
70
- if (typeof murphy.appKey !== 'undefined') {
71
- murphyDetails.murphyAppKey = murphy.appKey;
72
- }
73
-
74
- // Try to get Murphy internal state
75
- try {
76
- murphyDetails.murphyState = {
77
- installed: typeof murphy.installed !== 'undefined' ? murphy.installed : 'unknown',
78
- version: typeof murphy.version !== 'undefined' ? murphy.version : 'unknown'
79
- };
80
- } catch (e) {
81
- murphyDetails.murphyStateError = e.message;
82
- }
83
- }
84
-
85
- // Log window.ZOHOIM Murphy config
86
- if (typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined') {
87
- murphyDetails.windowZOHOIM = {
88
- exists: true,
89
- hasMurphyConfig: typeof window.ZOHOIM.murphyConfig !== 'undefined',
90
- murphyConfig: window.ZOHOIM.murphyConfig
91
- };
92
- } else {
93
- murphyDetails.windowZOHOIM = 'not available';
94
- }
95
-
96
- console.log('[i18n-debug] Murphy availability check:', murphyDetails);
97
- return available;
98
- }
99
-
100
- function isDebugEnabled() {
101
- return true; // ALWAYS ENABLED FOR DEBUGGING
102
- }
103
-
104
- function debugLog(message, meta) {
105
- // ALWAYS LOG - debug flag removed
106
- if (typeof console === 'undefined' || typeof console.log !== 'function') {
107
- return;
108
- }
109
- if (typeof meta === 'undefined') {
110
- console.log(`[i18n] ${message}`);
111
- } else {
112
- console.log(`[i18n] ${message}`, meta);
113
- }
14
+ return typeof murphy !== 'undefined' && typeof murphy.error === 'function';
114
15
  }
115
16
 
116
17
  function sendToMurphy(type, key) {
117
- debugLog('reporting i18n error', { type, key });
118
-
119
- // COMPREHENSIVE MURPHY STATE INSPECTION
120
- const murphyInspection = {
121
- murphyType: typeof murphy,
122
- murphyErrorType: typeof murphy.error,
123
- murphyMethods: typeof murphy === 'object' ? Object.keys(murphy) : 'not an object',
124
- timestamp: new Date().toISOString(),
125
- url: typeof window !== 'undefined' ? window.location.href : 'no window'
126
- };
127
-
128
- // Get Murphy internal config
129
- if (typeof murphy !== 'undefined') {
130
- try {
131
- murphyInspection.murphyInternalConfig = {
132
- config: murphy.config || 'no config property',
133
- appKey: murphy.appKey || 'no appKey property',
134
- authKey: murphy.authKey || 'no authKey property',
135
- appDomain: murphy.appDomain || 'no appDomain property',
136
- endpoint: murphy.endpoint || 'no endpoint property',
137
- url: murphy.url || 'no url property'
138
- };
139
- } catch (e) {
140
- murphyInspection.murphyConfigError = e.message;
141
- }
142
- }
143
-
144
- // Get window.ZOHOIM config
145
- if (typeof window !== 'undefined' && typeof window.ZOHOIM !== 'undefined') {
146
- murphyInspection.windowZOHOIM = {
147
- exists: true,
148
- murphyConfig: window.ZOHOIM.murphyConfig || 'no murphyConfig',
149
- getUserInfo: typeof window.ZOHOIM.getUserInfo === 'function' ? window.ZOHOIM.getUserInfo() : 'no getUserInfo',
150
- getServiceOrgInfo: typeof window.ZOHOIM.getServiceOrgInfo === 'function' ? window.ZOHOIM.getServiceOrgInfo() : 'no getServiceOrgInfo'
151
- };
152
- }
153
-
154
- // Get global murphy config if available
155
- if (typeof window !== 'undefined' && typeof window.murphyConfig !== 'undefined') {
156
- murphyInspection.globalMurphyConfig = window.murphyConfig;
157
- }
158
-
159
- console.log('[i18n-debug] ═══════════════════════════════════════════');
160
- console.log('[i18n-debug] MURPHY STATE BEFORE ERROR CALL:');
161
- console.log('[i18n-debug]', murphyInspection);
162
- console.log('[i18n-debug] ═══════════════════════════════════════════');
163
-
164
18
  const error = new Error(`i18n ${type}: ${key}`);
165
19
  error.name = type;
166
20
 
@@ -173,212 +27,84 @@ function sendToMurphy(type, key) {
173
27
  preventClientGrouping: true
174
28
  };
175
29
 
176
- console.log('[i18n-debug] murphy.error() CALL PARAMETERS:', {
177
- errorMessage: error.message,
178
- errorName: error.name,
179
- errorStack: error.stack,
180
- options: murphyOptions,
181
- timestamp: new Date().toISOString()
182
- });
183
-
184
- // Intercept network requests to see Murphy API calls
185
- const originalFetch = typeof window !== 'undefined' ? window.fetch : null;
186
- const originalXHR = typeof window !== 'undefined' ? window.XMLHttpRequest : null;
187
- let networkCallDetected = false;
188
-
189
- // Monitor fetch calls
190
- if (originalFetch && typeof window !== 'undefined') {
191
- window.fetch = function(...args) {
192
- console.log('[i18n-debug] 🌐 FETCH CALL DETECTED (possibly from Murphy):', {
193
- url: args[0],
194
- options: args[1],
195
- timestamp: new Date().toISOString()
196
- });
197
- networkCallDetected = true;
198
- return originalFetch.apply(this, args);
199
- };
200
- }
201
-
202
30
  try {
203
- console.log('[i18n-debug] ▶ CALLING murphy.error() NOW...');
204
- const result = murphy.error(error, undefined, murphyOptions);
205
- console.log('[i18n-debug] ✅ murphy.error() COMPLETED:', {
206
- result,
207
- resultType: typeof result,
208
- success: true,
209
- networkCallDetected,
210
- timestamp: new Date().toISOString()
211
- });
212
-
213
- // Check if Murphy queued the error
214
- if (typeof murphy.getQueuedErrors === 'function') {
215
- console.log('[i18n-debug] Murphy queued errors:', murphy.getQueuedErrors());
216
- }
31
+ murphy.error(error, undefined, murphyOptions);
217
32
  } catch (err) {
218
- console.error('[i18n-debug] murphy.error() FAILED:', {
219
- error: err.message,
220
- stack: err.stack,
221
- timestamp: new Date().toISOString()
222
- });
223
- } finally {
224
- // Restore original fetch
225
- if (originalFetch && typeof window !== 'undefined') {
226
- setTimeout(() => {
227
- window.fetch = originalFetch;
228
- console.log('[i18n-debug] Network call detected:', networkCallDetected);
229
- }, 100);
230
- }
33
+ // Avoid throwing from error reporting
231
34
  }
232
-
233
- console.log('[i18n-debug] ═══════════════════════════════════════════');
234
35
  }
235
36
 
236
37
  function queuePendingError(dedupeKey, type, key) {
237
38
  if (pendingErrors.has(dedupeKey)) {
238
- debugLog('pending i18n error deduped', { type, key });
239
39
  return;
240
40
  }
241
41
 
42
+ if (!hasLoggedQueueUse && typeof console !== 'undefined') {
43
+ console.log('[i18n] queued errors while murphy not available');
44
+ hasLoggedQueueUse = true;
45
+ }
46
+
242
47
  if (pendingErrors.size >= MAX_PENDING_ERRORS) {
243
48
  const oldestKey = pendingErrors.keys().next().value;
244
49
  pendingErrors.delete(oldestKey);
245
- debugLog('pending i18n error dropped (queue full)', {
246
- droppedKey: oldestKey,
247
- pendingSize: pendingErrors.size
248
- });
249
50
  }
250
51
 
251
52
  pendingErrors.set(dedupeKey, { type, key });
252
- debugLog('queued i18n error (murphy not ready)', {
253
- type,
254
- key,
255
- pendingSize: pendingErrors.size
256
- });
257
53
  }
258
54
 
259
55
  export function flushI18NErrors() {
260
- console.log('[i18n-debug] flushI18NErrors ENTRY:', {
261
- pendingErrorsSize: pendingErrors.size,
262
- pendingErrors: Array.from(pendingErrors.entries()),
263
- reportedKeysSize: reportedKeys.size
264
- });
265
-
266
56
  if (!isMurphyAvailable()) {
267
- debugLog('flush skipped (murphy not available)', {
268
- pendingSize: pendingErrors.size
269
- });
270
- console.log('[i18n-debug] Flush SKIPPED - Murphy not available');
271
57
  return;
272
58
  }
273
59
 
274
60
  if (pendingErrors.size === 0) {
275
- debugLog('flush skipped (no pending errors)');
276
- console.log('[i18n-debug] Flush SKIPPED - No pending errors');
277
61
  return;
278
62
  }
279
63
 
280
- debugLog('flushing pending i18n errors', {
281
- pendingSize: pendingErrors.size
282
- });
283
-
284
- console.log('[i18n-debug] FLUSHING pending errors:', {
285
- count: pendingErrors.size,
286
- errors: Array.from(pendingErrors.entries())
287
- });
288
-
289
- let flushedCount = 0;
290
- for (const [dedupeKey, data] of pendingErrors) {
291
- console.log('[i18n-debug] Processing pending error:', {
292
- dedupeKey,
293
- data,
294
- alreadyReported: reportedKeys.has(dedupeKey)
64
+ if (!hasLoggedFlushUse && typeof console !== 'undefined') {
65
+ console.log('[i18n] flushing queued errors', {
66
+ count: pendingErrors.size
295
67
  });
68
+ hasLoggedFlushUse = true;
69
+ }
296
70
 
71
+ for (const [dedupeKey, data] of pendingErrors) {
297
72
  if (reportedKeys.has(dedupeKey)) {
298
- console.log('[i18n-debug] Skipping already reported key:', dedupeKey);
299
73
  pendingErrors.delete(dedupeKey);
300
74
  continue;
301
75
  }
302
76
 
303
- console.log('[i18n-debug] Sending pending error to Murphy:', dedupeKey);
304
77
  sendToMurphy(data.type, data.key);
305
78
  reportedKeys.add(dedupeKey);
306
79
  pendingErrors.delete(dedupeKey);
307
- flushedCount += 1;
308
80
  }
309
-
310
- debugLog('flush complete', {
311
- flushedCount,
312
- pendingRemaining: pendingErrors.size
313
- });
314
-
315
- console.log('[i18n-debug] Flush COMPLETE:', {
316
- flushedCount,
317
- pendingRemaining: pendingErrors.size,
318
- reportedKeysSize: reportedKeys.size
319
- });
320
81
  }
321
82
 
322
83
  export function reportI18NError(type, key) {
323
- debugLog('reportI18NError called', { type, key });
324
-
325
- console.log('[i18n-debug] reportI18NError ENTRY:', {
326
- type,
327
- key,
328
- url: typeof window !== 'undefined' ? window.location.href : 'no window',
329
- timestamp: new Date().toISOString(),
330
- reportedKeysSize: reportedKeys.size,
331
- reportedKeys: Array.from(reportedKeys),
332
- pendingErrorsSize: pendingErrors.size
333
- });
334
-
335
84
  const dedupeKey = `${type}:${key}`;
336
85
 
337
- console.log('[i18n-debug] Deduplication check:', {
338
- dedupeKey,
339
- alreadyReported: reportedKeys.has(dedupeKey),
340
- reportedKeysSet: Array.from(reportedKeys)
341
- });
342
-
343
86
  if (reportedKeys.has(dedupeKey)) {
344
- debugLog('reported i18n error deduped', { type, key });
345
- console.log('[i18n-debug] DEDUPED - EXITING reportI18NError');
346
87
  return;
347
88
  }
348
89
 
349
- console.log('[i18n-debug] NOT deduped, proceeding with Murphy check');
350
-
351
90
  if (!isMurphyAvailable()) {
352
- debugLog('murphy not available, queueing i18n error', { type, key });
353
- console.log('[i18n-debug] Murphy NOT available, queueing error');
354
91
  queuePendingError(dedupeKey, type, key);
355
92
  return;
356
93
  }
357
94
 
358
- console.log('[i18n-debug] Murphy IS available, flushing pending errors');
359
95
  flushI18NErrors();
360
96
 
361
- console.log('[i18n-debug] Post-flush deduplication check:', {
362
- dedupeKey,
363
- alreadyReported: reportedKeys.has(dedupeKey),
364
- reportedKeysSet: Array.from(reportedKeys)
365
- });
366
-
367
97
  if (reportedKeys.has(dedupeKey)) {
368
- debugLog('reported i18n error deduped after flush', { type, key });
369
- console.log('[i18n-debug] DEDUPED AFTER FLUSH - EXITING reportI18NError');
370
98
  return;
371
99
  }
372
100
 
373
- console.log('[i18n-debug] About to call sendToMurphy');
374
101
  sendToMurphy(type, key);
375
102
  reportedKeys.add(dedupeKey);
376
- console.log('[i18n-debug] Added to reportedKeys, new size:', reportedKeys.size);
377
103
  }
104
+
378
105
  export function clearReportedKeys() {
379
106
  reportedKeys.clear();
380
107
  pendingErrors.clear();
381
- debugLog('cleared reported and pending i18n errors');
382
108
  }
383
109
 
384
110
  export function getFallbackText(key) {
@@ -290,52 +290,23 @@ export function getLocalizedValue({
290
290
  return localizedValue || null
291
291
  }
292
292
  export function getI18NValue(i18n) {
293
- console.log('[i18n-debug] getI18NValue called:', {
294
- i18nType: typeof i18n,
295
- i18nIsDefined: typeof i18n !== 'undefined',
296
- i18nKeysCount: typeof i18n === 'object' ? Object.keys(i18n).length : 0,
297
- url: typeof window !== 'undefined' ? window.location.href : 'no window'
298
- });
299
-
300
293
  if (typeof i18n === 'undefined') {
301
- console.error('[i18n-debug] i18n object is UNDEFINED! Reporting error and returning fallback');
302
294
  reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
303
295
  return (key) => key;
304
296
  }
305
297
 
306
298
  return (key, values, localizedProps) => {
307
- console.log('[i18n-debug] getI18NValue lookup:', {
308
- key,
309
- values,
310
- localizedProps,
311
- mappedKey: getMappedKey(key),
312
- hasLocalizedValue: localizedProps ? !!getLocalizedValue(localizedProps) : !!localizedStringData[key]
313
- });
314
-
315
- const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
299
+ const localizedValue = localizedProps
300
+ ? getLocalizedValue(localizedProps)
301
+ : localizedStringData[key];
316
302
  const finalKey = getMappedKey(key);
317
303
  let i18nStr = i18n[finalKey];
318
304
 
319
- console.log('[i18n-debug] i18n lookup result:', {
320
- originalKey: key,
321
- finalKey,
322
- found: i18nStr !== undefined,
323
- i18nStrValue: i18nStr,
324
- willFallback: i18nStr === undefined
325
- });
326
-
327
305
  if (i18nStr === undefined) {
328
306
  const isNumeric = /^\d+$/.test(finalKey);
329
- const errorType = isNumeric ? I18N_ERROR_TYPES.NUMERIC_FALLBACK : I18N_ERROR_TYPES.MISSING_KEY;
330
-
331
- console.warn('[i18n-debug] MISSING KEY detected!', {
332
- finalKey,
333
- isNumeric,
334
- errorType,
335
- fallbackText: getFallbackText(finalKey),
336
- aboutToCallReportI18NError: true,
337
- timestamp: new Date().toISOString()
338
- });
307
+ const errorType = isNumeric
308
+ ? I18N_ERROR_TYPES.NUMERIC_FALLBACK
309
+ : I18N_ERROR_TYPES.MISSING_KEY;
339
310
 
340
311
  reportI18NError(errorType, finalKey);
341
312
  return localizedValue || getFallbackText(finalKey);