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

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,17 +6,96 @@ 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
43
  function isMurphyAvailable() {
10
- return typeof murphy !== 'undefined' && typeof murphy.error === 'function';
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;
11
92
  }
12
93
  function isDebugEnabled() {
13
- return typeof window !== 'undefined' && window.__I18N_DEBUG__ === true;
94
+ return true; // ALWAYS ENABLED FOR DEBUGGING
14
95
  }
15
96
  function debugLog(message, meta) {
16
- if (!isDebugEnabled() || typeof console === 'undefined') {
17
- return;
18
- }
19
- if (typeof console.log !== 'function') {
97
+ // ALWAYS LOG - debug flag removed
98
+ if (typeof console === 'undefined' || typeof console.log !== 'function') {
20
99
  return;
21
100
  }
22
101
  if (typeof meta === 'undefined') {
@@ -30,16 +109,116 @@ function sendToMurphy(type, key) {
30
109
  type,
31
110
  key
32
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] ═══════════════════════════════════════════');
33
156
  const error = new Error(`i18n ${type}: ${key}`);
34
157
  error.name = type;
35
- murphy.error(error, undefined, {
158
+ const murphyOptions = {
36
159
  customTags: {
37
160
  errorType: type,
38
161
  i18nKey: key,
39
162
  category: 'i18n'
40
163
  },
41
164
  preventClientGrouping: true
165
+ };
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()
42
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
+ 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
+ }
206
+ } 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
+ }
220
+ }
221
+ console.log('[i18n-debug] ═══════════════════════════════════════════');
43
222
  }
44
223
  function queuePendingError(dedupeKey, type, key) {
45
224
  if (pendingErrors.has(dedupeKey)) {
@@ -68,25 +247,43 @@ function queuePendingError(dedupeKey, type, key) {
68
247
  });
69
248
  }
70
249
  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
+ });
71
255
  if (!isMurphyAvailable()) {
72
256
  debugLog('flush skipped (murphy not available)', {
73
257
  pendingSize: pendingErrors.size
74
258
  });
259
+ console.log('[i18n-debug] Flush SKIPPED - Murphy not available');
75
260
  return;
76
261
  }
77
262
  if (pendingErrors.size === 0) {
78
263
  debugLog('flush skipped (no pending errors)');
264
+ console.log('[i18n-debug] Flush SKIPPED - No pending errors');
79
265
  return;
80
266
  }
81
267
  debugLog('flushing pending i18n errors', {
82
268
  pendingSize: pendingErrors.size
83
269
  });
270
+ console.log('[i18n-debug] FLUSHING pending errors:', {
271
+ count: pendingErrors.size,
272
+ errors: Array.from(pendingErrors.entries())
273
+ });
84
274
  let flushedCount = 0;
85
275
  for (const [dedupeKey, data] of pendingErrors) {
276
+ console.log('[i18n-debug] Processing pending error:', {
277
+ dedupeKey,
278
+ data,
279
+ alreadyReported: reportedKeys.has(dedupeKey)
280
+ });
86
281
  if (reportedKeys.has(dedupeKey)) {
282
+ console.log('[i18n-debug] Skipping already reported key:', dedupeKey);
87
283
  pendingErrors.delete(dedupeKey);
88
284
  continue;
89
285
  }
286
+ console.log('[i18n-debug] Sending pending error to Murphy:', dedupeKey);
90
287
  sendToMurphy(data.type, data.key);
91
288
  reportedKeys.add(dedupeKey);
92
289
  pendingErrors.delete(dedupeKey);
@@ -96,38 +293,69 @@ export function flushI18NErrors() {
96
293
  flushedCount,
97
294
  pendingRemaining: pendingErrors.size
98
295
  });
296
+ console.log('[i18n-debug] Flush COMPLETE:', {
297
+ flushedCount,
298
+ pendingRemaining: pendingErrors.size,
299
+ reportedKeysSize: reportedKeys.size
300
+ });
99
301
  }
100
302
  export function reportI18NError(type, key) {
101
303
  debugLog('reportI18NError called', {
102
304
  type,
103
305
  key
104
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
+ });
105
316
  const dedupeKey = `${type}:${key}`;
317
+ console.log('[i18n-debug] Deduplication check:', {
318
+ dedupeKey,
319
+ alreadyReported: reportedKeys.has(dedupeKey),
320
+ reportedKeysSet: Array.from(reportedKeys)
321
+ });
106
322
  if (reportedKeys.has(dedupeKey)) {
107
323
  debugLog('reported i18n error deduped', {
108
324
  type,
109
325
  key
110
326
  });
327
+ console.log('[i18n-debug] DEDUPED - EXITING reportI18NError');
111
328
  return;
112
329
  }
330
+ console.log('[i18n-debug] NOT deduped, proceeding with Murphy check');
113
331
  if (!isMurphyAvailable()) {
114
332
  debugLog('murphy not available, queueing i18n error', {
115
333
  type,
116
334
  key
117
335
  });
336
+ console.log('[i18n-debug] Murphy NOT available, queueing error');
118
337
  queuePendingError(dedupeKey, type, key);
119
338
  return;
120
339
  }
340
+ console.log('[i18n-debug] Murphy IS available, flushing pending errors');
121
341
  flushI18NErrors();
342
+ console.log('[i18n-debug] Post-flush deduplication check:', {
343
+ dedupeKey,
344
+ alreadyReported: reportedKeys.has(dedupeKey),
345
+ reportedKeysSet: Array.from(reportedKeys)
346
+ });
122
347
  if (reportedKeys.has(dedupeKey)) {
123
348
  debugLog('reported i18n error deduped after flush', {
124
349
  type,
125
350
  key
126
351
  });
352
+ console.log('[i18n-debug] DEDUPED AFTER FLUSH - EXITING reportI18NError');
127
353
  return;
128
354
  }
355
+ console.log('[i18n-debug] About to call sendToMurphy');
129
356
  sendToMurphy(type, key);
130
357
  reportedKeys.add(dedupeKey);
358
+ console.log('[i18n-debug] Added to reportedKeys, new size:', reportedKeys.size);
131
359
  }
132
360
  export function clearReportedKeys() {
133
361
  reportedKeys.clear();
package/es/utils/index.js CHANGED
@@ -234,17 +234,47 @@ 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
+ });
237
243
  if (typeof i18n === 'undefined') {
244
+ console.error('[i18n-debug] i18n object is UNDEFINED! Reporting error and returning fallback');
238
245
  reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
239
246
  return key => key;
240
247
  }
241
248
  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
+ });
242
256
  const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
243
257
  const finalKey = getMappedKey(key);
244
258
  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
+ });
245
266
  if (i18nStr === undefined) {
246
267
  const isNumeric = /^\d+$/.test(finalKey);
247
- reportI18NError(isNumeric ? I18N_ERROR_TYPES.NUMERIC_FALLBACK : I18N_ERROR_TYPES.MISSING_KEY, finalKey);
268
+ 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
+ reportI18NError(errorType, finalKey);
248
278
  return localizedValue || getFallbackText(finalKey);
249
279
  }
250
280
  i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
@@ -15,6 +15,7 @@ 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); }
18
19
  var I18N_ERROR_TYPES = exports.I18N_ERROR_TYPES = {
19
20
  UNDEFINED_OBJECT: 'I18N_UNDEFINED_OBJECT',
20
21
  MISSING_KEY: 'I18N_MISSING_KEY',
@@ -23,17 +24,96 @@ var I18N_ERROR_TYPES = exports.I18N_ERROR_TYPES = {
23
24
  var reportedKeys = new Set();
24
25
  var pendingErrors = new Map();
25
26
  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
61
  function isMurphyAvailable() {
27
- return typeof murphy !== 'undefined' && typeof murphy.error === 'function';
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;
28
110
  }
29
111
  function isDebugEnabled() {
30
- return typeof window !== 'undefined' && window.__I18N_DEBUG__ === true;
112
+ return true; // ALWAYS ENABLED FOR DEBUGGING
31
113
  }
32
114
  function debugLog(message, meta) {
33
- if (!isDebugEnabled() || typeof console === 'undefined') {
34
- return;
35
- }
36
- if (typeof console.log !== 'function') {
115
+ // ALWAYS LOG - debug flag removed
116
+ if (typeof console === 'undefined' || typeof console.log !== 'function') {
37
117
  return;
38
118
  }
39
119
  if (typeof meta === 'undefined') {
@@ -47,16 +127,119 @@ function sendToMurphy(type, key) {
47
127
  type: type,
48
128
  key: key
49
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] ═══════════════════════════════════════════');
50
174
  var error = new Error("i18n ".concat(type, ": ").concat(key));
51
175
  error.name = type;
52
- murphy.error(error, undefined, {
176
+ var murphyOptions = {
53
177
  customTags: {
54
178
  errorType: type,
55
179
  i18nKey: key,
56
180
  category: 'i18n'
57
181
  },
58
182
  preventClientGrouping: true
183
+ };
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()
59
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
+ 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
+ }
227
+ } 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
+ }
241
+ }
242
+ console.log('[i18n-debug] ═══════════════════════════════════════════');
60
243
  }
61
244
  function queuePendingError(dedupeKey, type, key) {
62
245
  if (pendingErrors.has(dedupeKey)) {
@@ -85,19 +268,30 @@ function queuePendingError(dedupeKey, type, key) {
85
268
  });
86
269
  }
87
270
  function flushI18NErrors() {
271
+ console.log('[i18n-debug] flushI18NErrors ENTRY:', {
272
+ pendingErrorsSize: pendingErrors.size,
273
+ pendingErrors: Array.from(pendingErrors.entries()),
274
+ reportedKeysSize: reportedKeys.size
275
+ });
88
276
  if (!isMurphyAvailable()) {
89
277
  debugLog('flush skipped (murphy not available)', {
90
278
  pendingSize: pendingErrors.size
91
279
  });
280
+ console.log('[i18n-debug] Flush SKIPPED - Murphy not available');
92
281
  return;
93
282
  }
94
283
  if (pendingErrors.size === 0) {
95
284
  debugLog('flush skipped (no pending errors)');
285
+ console.log('[i18n-debug] Flush SKIPPED - No pending errors');
96
286
  return;
97
287
  }
98
288
  debugLog('flushing pending i18n errors', {
99
289
  pendingSize: pendingErrors.size
100
290
  });
291
+ console.log('[i18n-debug] FLUSHING pending errors:', {
292
+ count: pendingErrors.size,
293
+ errors: Array.from(pendingErrors.entries())
294
+ });
101
295
  var flushedCount = 0;
102
296
  var _iterator = _createForOfIteratorHelper(pendingErrors),
103
297
  _step;
@@ -106,10 +300,17 @@ function flushI18NErrors() {
106
300
  var _step$value = _slicedToArray(_step.value, 2),
107
301
  dedupeKey = _step$value[0],
108
302
  data = _step$value[1];
303
+ console.log('[i18n-debug] Processing pending error:', {
304
+ dedupeKey: dedupeKey,
305
+ data: data,
306
+ alreadyReported: reportedKeys.has(dedupeKey)
307
+ });
109
308
  if (reportedKeys.has(dedupeKey)) {
309
+ console.log('[i18n-debug] Skipping already reported key:', dedupeKey);
110
310
  pendingErrors["delete"](dedupeKey);
111
311
  continue;
112
312
  }
313
+ console.log('[i18n-debug] Sending pending error to Murphy:', dedupeKey);
113
314
  sendToMurphy(data.type, data.key);
114
315
  reportedKeys.add(dedupeKey);
115
316
  pendingErrors["delete"](dedupeKey);
@@ -124,38 +325,69 @@ function flushI18NErrors() {
124
325
  flushedCount: flushedCount,
125
326
  pendingRemaining: pendingErrors.size
126
327
  });
328
+ console.log('[i18n-debug] Flush COMPLETE:', {
329
+ flushedCount: flushedCount,
330
+ pendingRemaining: pendingErrors.size,
331
+ reportedKeysSize: reportedKeys.size
332
+ });
127
333
  }
128
334
  function reportI18NError(type, key) {
129
335
  debugLog('reportI18NError called', {
130
336
  type: type,
131
337
  key: key
132
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
+ });
133
348
  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
+ });
134
354
  if (reportedKeys.has(dedupeKey)) {
135
355
  debugLog('reported i18n error deduped', {
136
356
  type: type,
137
357
  key: key
138
358
  });
359
+ console.log('[i18n-debug] DEDUPED - EXITING reportI18NError');
139
360
  return;
140
361
  }
362
+ console.log('[i18n-debug] NOT deduped, proceeding with Murphy check');
141
363
  if (!isMurphyAvailable()) {
142
364
  debugLog('murphy not available, queueing i18n error', {
143
365
  type: type,
144
366
  key: key
145
367
  });
368
+ console.log('[i18n-debug] Murphy NOT available, queueing error');
146
369
  queuePendingError(dedupeKey, type, key);
147
370
  return;
148
371
  }
372
+ console.log('[i18n-debug] Murphy IS available, flushing pending errors');
149
373
  flushI18NErrors();
374
+ console.log('[i18n-debug] Post-flush deduplication check:', {
375
+ dedupeKey: dedupeKey,
376
+ alreadyReported: reportedKeys.has(dedupeKey),
377
+ reportedKeysSet: Array.from(reportedKeys)
378
+ });
150
379
  if (reportedKeys.has(dedupeKey)) {
151
380
  debugLog('reported i18n error deduped after flush', {
152
381
  type: type,
153
382
  key: key
154
383
  });
384
+ console.log('[i18n-debug] DEDUPED AFTER FLUSH - EXITING reportI18NError');
155
385
  return;
156
386
  }
387
+ console.log('[i18n-debug] About to call sendToMurphy');
157
388
  sendToMurphy(type, key);
158
389
  reportedKeys.add(dedupeKey);
390
+ console.log('[i18n-debug] Added to reportedKeys, new size:', reportedKeys.size);
159
391
  }
160
392
  function clearReportedKeys() {
161
393
  reportedKeys.clear();
@@ -269,19 +269,49 @@ 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
+ });
272
278
  if (typeof i18n === 'undefined') {
279
+ console.error('[i18n-debug] i18n object is UNDEFINED! Reporting error and returning fallback');
273
280
  (0, _errorReporter.reportI18NError)(_errorReporter.I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
274
281
  return function (key) {
275
282
  return key;
276
283
  };
277
284
  }
278
285
  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
+ });
279
293
  var localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
280
294
  var finalKey = getMappedKey(key);
281
295
  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
+ });
282
303
  if (i18nStr === undefined) {
283
304
  var isNumeric = /^\d+$/.test(finalKey);
284
- (0, _errorReporter.reportI18NError)(isNumeric ? _errorReporter.I18N_ERROR_TYPES.NUMERIC_FALLBACK : _errorReporter.I18N_ERROR_TYPES.MISSING_KEY, finalKey);
305
+ 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
+ (0, _errorReporter.reportI18NError)(errorType, finalKey);
285
315
  return localizedValue || (0, _errorReporter.getFallbackText)(finalKey);
286
316
  }
287
317
  i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/i18n",
3
- "version": "1.0.0-beta.38-murphy",
3
+ "version": "1.0.0-beta.38-murphy-logs",
4
4
  "main": "lib/index",
5
5
  "module": "es/index.js",
6
6
  "jsnext:main": "es/index.js",
@@ -8,19 +8,102 @@ const reportedKeys = new Set();
8
8
  const pendingErrors = new Map();
9
9
  const MAX_PENDING_ERRORS = 100;
10
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
+ })();
46
+
11
47
  function isMurphyAvailable() {
12
- return typeof murphy !== 'undefined' && typeof murphy.error === 'function';
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;
13
98
  }
14
99
 
15
100
  function isDebugEnabled() {
16
- return typeof window !== 'undefined' && window.__I18N_DEBUG__ === true;
101
+ return true; // ALWAYS ENABLED FOR DEBUGGING
17
102
  }
18
103
 
19
104
  function debugLog(message, meta) {
20
- if (!isDebugEnabled() || typeof console === 'undefined') {
21
- return;
22
- }
23
- if (typeof console.log !== 'function') {
105
+ // ALWAYS LOG - debug flag removed
106
+ if (typeof console === 'undefined' || typeof console.log !== 'function') {
24
107
  return;
25
108
  }
26
109
  if (typeof meta === 'undefined') {
@@ -32,17 +115,122 @@ function debugLog(message, meta) {
32
115
 
33
116
  function sendToMurphy(type, key) {
34
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
+
35
164
  const error = new Error(`i18n ${type}: ${key}`);
36
165
  error.name = type;
37
166
 
38
- murphy.error(error, undefined, {
167
+ const murphyOptions = {
39
168
  customTags: {
40
169
  errorType: type,
41
170
  i18nKey: key,
42
171
  category: 'i18n'
43
172
  },
44
173
  preventClientGrouping: true
174
+ };
175
+
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()
45
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
+ 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
+ }
217
+ } 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
+ }
231
+ }
232
+
233
+ console.log('[i18n-debug] ═══════════════════════════════════════════');
46
234
  }
47
235
 
48
236
  function queuePendingError(dedupeKey, type, key) {
@@ -69,15 +257,23 @@ function queuePendingError(dedupeKey, type, key) {
69
257
  }
70
258
 
71
259
  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
+
72
266
  if (!isMurphyAvailable()) {
73
267
  debugLog('flush skipped (murphy not available)', {
74
268
  pendingSize: pendingErrors.size
75
269
  });
270
+ console.log('[i18n-debug] Flush SKIPPED - Murphy not available');
76
271
  return;
77
272
  }
78
273
 
79
274
  if (pendingErrors.size === 0) {
80
275
  debugLog('flush skipped (no pending errors)');
276
+ console.log('[i18n-debug] Flush SKIPPED - No pending errors');
81
277
  return;
82
278
  }
83
279
 
@@ -85,12 +281,26 @@ export function flushI18NErrors() {
85
281
  pendingSize: pendingErrors.size
86
282
  });
87
283
 
284
+ console.log('[i18n-debug] FLUSHING pending errors:', {
285
+ count: pendingErrors.size,
286
+ errors: Array.from(pendingErrors.entries())
287
+ });
288
+
88
289
  let flushedCount = 0;
89
290
  for (const [dedupeKey, data] of pendingErrors) {
291
+ console.log('[i18n-debug] Processing pending error:', {
292
+ dedupeKey,
293
+ data,
294
+ alreadyReported: reportedKeys.has(dedupeKey)
295
+ });
296
+
90
297
  if (reportedKeys.has(dedupeKey)) {
298
+ console.log('[i18n-debug] Skipping already reported key:', dedupeKey);
91
299
  pendingErrors.delete(dedupeKey);
92
300
  continue;
93
301
  }
302
+
303
+ console.log('[i18n-debug] Sending pending error to Murphy:', dedupeKey);
94
304
  sendToMurphy(data.type, data.key);
95
305
  reportedKeys.add(dedupeKey);
96
306
  pendingErrors.delete(dedupeKey);
@@ -101,30 +311,69 @@ export function flushI18NErrors() {
101
311
  flushedCount,
102
312
  pendingRemaining: pendingErrors.size
103
313
  });
314
+
315
+ console.log('[i18n-debug] Flush COMPLETE:', {
316
+ flushedCount,
317
+ pendingRemaining: pendingErrors.size,
318
+ reportedKeysSize: reportedKeys.size
319
+ });
104
320
  }
105
321
 
106
322
  export function reportI18NError(type, key) {
107
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
+
108
335
  const dedupeKey = `${type}:${key}`;
336
+
337
+ console.log('[i18n-debug] Deduplication check:', {
338
+ dedupeKey,
339
+ alreadyReported: reportedKeys.has(dedupeKey),
340
+ reportedKeysSet: Array.from(reportedKeys)
341
+ });
342
+
109
343
  if (reportedKeys.has(dedupeKey)) {
110
344
  debugLog('reported i18n error deduped', { type, key });
345
+ console.log('[i18n-debug] DEDUPED - EXITING reportI18NError');
111
346
  return;
112
347
  }
113
348
 
349
+ console.log('[i18n-debug] NOT deduped, proceeding with Murphy check');
350
+
114
351
  if (!isMurphyAvailable()) {
115
352
  debugLog('murphy not available, queueing i18n error', { type, key });
353
+ console.log('[i18n-debug] Murphy NOT available, queueing error');
116
354
  queuePendingError(dedupeKey, type, key);
117
355
  return;
118
356
  }
119
357
 
358
+ console.log('[i18n-debug] Murphy IS available, flushing pending errors');
120
359
  flushI18NErrors();
360
+
361
+ console.log('[i18n-debug] Post-flush deduplication check:', {
362
+ dedupeKey,
363
+ alreadyReported: reportedKeys.has(dedupeKey),
364
+ reportedKeysSet: Array.from(reportedKeys)
365
+ });
366
+
121
367
  if (reportedKeys.has(dedupeKey)) {
122
368
  debugLog('reported i18n error deduped after flush', { type, key });
369
+ console.log('[i18n-debug] DEDUPED AFTER FLUSH - EXITING reportI18NError');
123
370
  return;
124
371
  }
125
372
 
373
+ console.log('[i18n-debug] About to call sendToMurphy');
126
374
  sendToMurphy(type, key);
127
375
  reportedKeys.add(dedupeKey);
376
+ console.log('[i18n-debug] Added to reportedKeys, new size:', reportedKeys.size);
128
377
  }
129
378
  export function clearReportedKeys() {
130
379
  reportedKeys.clear();
@@ -290,20 +290,54 @@ 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
+
293
300
  if (typeof i18n === 'undefined') {
301
+ console.error('[i18n-debug] i18n object is UNDEFINED! Reporting error and returning fallback');
294
302
  reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
295
303
  return (key) => key;
296
304
  }
305
+
297
306
  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
+
298
315
  const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
299
316
  const finalKey = getMappedKey(key);
300
317
  let i18nStr = i18n[finalKey];
318
+
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
+
301
327
  if (i18nStr === undefined) {
302
328
  const isNumeric = /^\d+$/.test(finalKey);
303
- reportI18NError(
304
- isNumeric ? I18N_ERROR_TYPES.NUMERIC_FALLBACK : I18N_ERROR_TYPES.MISSING_KEY,
305
- finalKey
306
- );
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
+ });
339
+
340
+ reportI18NError(errorType, finalKey);
307
341
  return localizedValue || getFallbackText(finalKey);
308
342
  }
309
343
  i18nStr = replaceI18NValuesWithRegex(i18nStr, values);