@zohodesk/i18n 1.0.0-beta.37-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.
package/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { formatDate, pad, replaceI18NValuesWithRegex, unescapeUnicode, getValues, getI18NInfo, isToday, isYesterday, isTomorrow, isWithinAWeek, isTwoWeeksOrMore, userDateFormat, getDiffObj, getLyears, getSuffix, getDatePatternWithoutYear, setLocalizedData, setI18NKeyMapping, dayi18n, monthi18n, timei18n } from "./utils";
2
- export { reportI18NError, clearReportedKeys, I18N_ERROR_TYPES } from "./utils/errorReporter";
2
+ export { reportI18NError, flushI18NErrors, clearReportedKeys, I18N_ERROR_TYPES } from "./utils/errorReporter";
3
3
  import { getI18NValue as getI18NValue1 } from "./utils";
4
4
  export { I18NContext } from "./I18NContext";
5
5
  export { default as I18NProvider, i18NProviderUtils } from "./components/I18NProvider";
@@ -4,30 +4,363 @@ export const I18N_ERROR_TYPES = {
4
4
  NUMERIC_FALLBACK: 'I18N_NUMERIC_FALLBACK'
5
5
  };
6
6
  const reportedKeys = new Set();
7
+ const pendingErrors = new Map();
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
+ })();
7
43
  function isMurphyAvailable() {
8
- 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;
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
+ }
106
+ }
107
+ 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
+ const error = new Error(`i18n ${type}: ${key}`);
157
+ error.name = type;
158
+ const murphyOptions = {
159
+ customTags: {
160
+ errorType: type,
161
+ i18nKey: key,
162
+ category: 'i18n'
163
+ },
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()
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] ═══════════════════════════════════════════');
222
+ }
223
+ function queuePendingError(dedupeKey, type, key) {
224
+ if (pendingErrors.has(dedupeKey)) {
225
+ debugLog('pending i18n error deduped', {
226
+ type,
227
+ key
228
+ });
229
+ return;
230
+ }
231
+ if (pendingErrors.size >= MAX_PENDING_ERRORS) {
232
+ const oldestKey = pendingErrors.keys().next().value;
233
+ pendingErrors.delete(oldestKey);
234
+ debugLog('pending i18n error dropped (queue full)', {
235
+ droppedKey: oldestKey,
236
+ pendingSize: pendingErrors.size
237
+ });
238
+ }
239
+ pendingErrors.set(dedupeKey, {
240
+ type,
241
+ key
242
+ });
243
+ debugLog('queued i18n error (murphy not ready)', {
244
+ type,
245
+ key,
246
+ pendingSize: pendingErrors.size
247
+ });
248
+ }
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
+ });
255
+ 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
+ return;
261
+ }
262
+ if (pendingErrors.size === 0) {
263
+ debugLog('flush skipped (no pending errors)');
264
+ console.log('[i18n-debug] Flush SKIPPED - No pending errors');
265
+ return;
266
+ }
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)
280
+ });
281
+ if (reportedKeys.has(dedupeKey)) {
282
+ console.log('[i18n-debug] Skipping already reported key:', dedupeKey);
283
+ pendingErrors.delete(dedupeKey);
284
+ continue;
285
+ }
286
+ console.log('[i18n-debug] Sending pending error to Murphy:', dedupeKey);
287
+ sendToMurphy(data.type, data.key);
288
+ reportedKeys.add(dedupeKey);
289
+ pendingErrors.delete(dedupeKey);
290
+ flushedCount += 1;
291
+ }
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
+ });
9
301
  }
10
302
  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
+ });
11
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
+ });
12
322
  if (reportedKeys.has(dedupeKey)) {
323
+ debugLog('reported i18n error deduped', {
324
+ type,
325
+ key
326
+ });
327
+ console.log('[i18n-debug] DEDUPED - EXITING reportI18NError');
13
328
  return;
14
329
  }
15
- reportedKeys.add(dedupeKey);
16
- if (isMurphyAvailable()) {
17
- const error = new Error(`i18n ${type}: ${key}`);
18
- error.name = type;
19
- murphy.error(error, undefined, {
20
- customTags: {
21
- errorType: type,
22
- i18nKey: key,
23
- category: 'i18n'
24
- },
25
- preventClientGrouping: true
330
+ console.log('[i18n-debug] NOT deduped, proceeding with Murphy check');
331
+ if (!isMurphyAvailable()) {
332
+ debugLog('murphy not available, queueing i18n error', {
333
+ type,
334
+ key
26
335
  });
336
+ console.log('[i18n-debug] Murphy NOT available, queueing error');
337
+ queuePendingError(dedupeKey, type, key);
338
+ return;
27
339
  }
340
+ console.log('[i18n-debug] Murphy IS available, flushing pending errors');
341
+ flushI18NErrors();
342
+ console.log('[i18n-debug] Post-flush deduplication check:', {
343
+ dedupeKey,
344
+ alreadyReported: reportedKeys.has(dedupeKey),
345
+ reportedKeysSet: Array.from(reportedKeys)
346
+ });
347
+ 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
+ return;
354
+ }
355
+ console.log('[i18n-debug] About to call sendToMurphy');
356
+ sendToMurphy(type, key);
357
+ reportedKeys.add(dedupeKey);
358
+ console.log('[i18n-debug] Added to reportedKeys, new size:', reportedKeys.size);
28
359
  }
29
360
  export function clearReportedKeys() {
30
361
  reportedKeys.clear();
362
+ pendingErrors.clear();
363
+ debugLog('cleared reported and pending i18n errors');
31
364
  }
32
365
  export function getFallbackText(key) {
33
366
  const isNumeric = /^\d+$/.test(key);
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);
package/lib/index.js CHANGED
@@ -70,6 +70,12 @@ Object.defineProperty(exports, "dayi18n", {
70
70
  return _utils.dayi18n;
71
71
  }
72
72
  });
73
+ Object.defineProperty(exports, "flushI18NErrors", {
74
+ enumerable: true,
75
+ get: function get() {
76
+ return _errorReporter.flushI18NErrors;
77
+ }
78
+ });
73
79
  Object.defineProperty(exports, "formatDate", {
74
80
  enumerable: true,
75
81
  get: function get() {