@zohodesk/i18n 1.0.0-beta.40-murphy → 1.0.0-beta.41-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.
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, flushI18NErrors, clearReportedKeys, I18N_ERROR_TYPES } from "./utils/errorReporter";
2
+ export { reportI18NError, 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,105 +4,37 @@ 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
- let hasLoggedQueueUse = false;
10
- let hasLoggedFlushUse = false;
11
- function getDeskCustomError() {
12
- if (typeof window === 'undefined') {
13
- return null;
14
- }
15
- return typeof window._windowDeskCustomError === 'function' ? window._windowDeskCustomError : null;
16
- }
17
- function isReporterAvailable() {
18
- return Boolean(getDeskCustomError());
19
- }
20
- function sendToDesk(type, key) {
21
- const deskCustomError = getDeskCustomError();
22
- if (!deskCustomError) {
23
- console.log('[i18n] Murphy not available, skipping error report:', {
24
- type,
25
- key
26
- });
7
+ export function reportI18NError(type, key) {
8
+ const dedupeKey = `${type}:${key}`;
9
+ if (reportedKeys.has(dedupeKey)) {
10
+ console.log(`[i18n-reporter] SKIPPED (already reported): ${dedupeKey}`);
27
11
  return;
28
12
  }
29
13
  const errorMessage = `i18n ${type}: ${key}`;
30
- const errorDetails = {
31
- type,
32
- key,
33
- category: 'i18n'
34
- };
35
- const envData = {
14
+ const errorData = {
36
15
  errorType: type,
37
16
  i18nKey: key,
38
17
  category: 'i18n'
39
18
  };
40
19
  try {
41
- deskCustomError(errorDetails, errorMessage, envData);
42
- } catch (err) {
43
- console.log('[i18n] Error reporting to Murphy failed:', err);
44
- }
45
- }
46
- function queuePendingError(dedupeKey, type, key) {
47
- if (pendingErrors.has(dedupeKey)) {
48
- return;
49
- }
50
- if (!hasLoggedQueueUse && typeof console !== 'undefined') {
51
- console.log('[i18n] queued errors while murphy not available');
52
- hasLoggedQueueUse = true;
53
- }
54
- if (pendingErrors.size >= MAX_PENDING_ERRORS) {
55
- const oldestKey = pendingErrors.keys().next().value;
56
- pendingErrors.delete(oldestKey);
57
- }
58
- pendingErrors.set(dedupeKey, {
59
- type,
60
- key
61
- });
62
- }
63
- export function flushI18NErrors() {
64
- if (!isReporterAvailable()) {
65
- return;
66
- }
67
- if (pendingErrors.size === 0) {
68
- return;
69
- }
70
- if (!hasLoggedFlushUse && typeof console !== 'undefined') {
71
- console.log('[i18n] flushing queued errors', {
72
- count: pendingErrors.size
73
- });
74
- hasLoggedFlushUse = true;
75
- }
76
- for (const [dedupeKey, data] of pendingErrors) {
77
- if (reportedKeys.has(dedupeKey)) {
78
- pendingErrors.delete(dedupeKey);
79
- continue;
20
+ if (typeof window._windowDeskCustomError === 'function') {
21
+ console.log(`[i18n-reporter] Using DESK path (deskCustomError): ${dedupeKey}`);
22
+ window._windowDeskCustomError(errorData, errorMessage, errorData);
23
+ } else if (window.murphy) {
24
+ console.log(`[i18n-reporter] Using IM path (murphy direct): ${dedupeKey}`);
25
+ window.murphy.addCustomTracking(errorData);
26
+ const error = new Error(errorMessage);
27
+ error.name = type;
28
+ window.murphy.error(error);
29
+ } else {
30
+ console.log(`[i18n-reporter] SKIPPED (Murphy not loaded): ${dedupeKey}`);
31
+ return;
80
32
  }
81
- sendToDesk(data.type, data.key);
82
- reportedKeys.add(dedupeKey);
83
- pendingErrors.delete(dedupeKey);
84
- }
85
- }
86
- export function reportI18NError(type, key) {
87
- const dedupeKey = `${type}:${key}`;
88
- if (reportedKeys.has(dedupeKey)) {
89
- return;
90
- }
91
- if (!isReporterAvailable()) {
92
- queuePendingError(dedupeKey, type, key);
93
- return;
94
- }
95
- flushI18NErrors();
96
- if (reportedKeys.has(dedupeKey)) {
97
- return;
33
+ } catch (err) {
34
+ console.error(`[i18n-reporter] ERROR reporting: ${dedupeKey}`, err);
98
35
  }
99
- sendToDesk(type, key);
100
36
  reportedKeys.add(dedupeKey);
101
37
  }
102
- export function clearReportedKeys() {
103
- reportedKeys.clear();
104
- pendingErrors.clear();
105
- }
106
38
  export function getFallbackText(key) {
107
39
  const isNumeric = /^\d+$/.test(key);
108
40
  return isNumeric ? `text.unavailable.${key}` : key;
package/lib/index.js CHANGED
@@ -58,24 +58,12 @@ Object.defineProperty(exports, "UserTimeDiffFormat", {
58
58
  return _UserTimeDiffFormat["default"];
59
59
  }
60
60
  });
61
- Object.defineProperty(exports, "clearReportedKeys", {
62
- enumerable: true,
63
- get: function get() {
64
- return _errorReporter.clearReportedKeys;
65
- }
66
- });
67
61
  Object.defineProperty(exports, "dayi18n", {
68
62
  enumerable: true,
69
63
  get: function get() {
70
64
  return _utils.dayi18n;
71
65
  }
72
66
  });
73
- Object.defineProperty(exports, "flushI18NErrors", {
74
- enumerable: true,
75
- get: function get() {
76
- return _errorReporter.flushI18NErrors;
77
- }
78
- });
79
67
  Object.defineProperty(exports, "formatDate", {
80
68
  enumerable: true,
81
69
  get: function get() {
@@ -4,133 +4,45 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.I18N_ERROR_TYPES = void 0;
7
- exports.clearReportedKeys = clearReportedKeys;
8
- exports.flushI18NErrors = flushI18NErrors;
9
7
  exports.getFallbackText = getFallbackText;
10
8
  exports.reportI18NError = reportI18NError;
11
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
12
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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
- 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
- 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
9
  var I18N_ERROR_TYPES = exports.I18N_ERROR_TYPES = {
19
10
  UNDEFINED_OBJECT: 'I18N_UNDEFINED_OBJECT',
20
11
  MISSING_KEY: 'I18N_MISSING_KEY',
21
12
  NUMERIC_FALLBACK: 'I18N_NUMERIC_FALLBACK'
22
13
  };
23
14
  var reportedKeys = new Set();
24
- var pendingErrors = new Map();
25
- var MAX_PENDING_ERRORS = 100;
26
- var hasLoggedQueueUse = false;
27
- var hasLoggedFlushUse = false;
28
- function getDeskCustomError() {
29
- if (typeof window === 'undefined') {
30
- return null;
31
- }
32
- return typeof window._windowDeskCustomError === 'function' ? window._windowDeskCustomError : null;
33
- }
34
- function isReporterAvailable() {
35
- return Boolean(getDeskCustomError());
36
- }
37
- function sendToDesk(type, key) {
38
- var deskCustomError = getDeskCustomError();
39
- if (!deskCustomError) {
40
- console.log('[i18n] Murphy not available, skipping error report:', {
41
- type: type,
42
- key: key
43
- });
15
+ function reportI18NError(type, key) {
16
+ var dedupeKey = "".concat(type, ":").concat(key);
17
+ if (reportedKeys.has(dedupeKey)) {
18
+ console.log("[i18n-reporter] SKIPPED (already reported): ".concat(dedupeKey));
44
19
  return;
45
20
  }
46
21
  var errorMessage = "i18n ".concat(type, ": ").concat(key);
47
- var errorDetails = {
48
- type: type,
49
- key: key,
50
- category: 'i18n'
51
- };
52
- var envData = {
22
+ var errorData = {
53
23
  errorType: type,
54
24
  i18nKey: key,
55
25
  category: 'i18n'
56
26
  };
57
27
  try {
58
- deskCustomError(errorDetails, errorMessage, envData);
59
- } catch (err) {
60
- console.log('[i18n] Error reporting to Murphy failed:', err);
61
- }
62
- }
63
- function queuePendingError(dedupeKey, type, key) {
64
- if (pendingErrors.has(dedupeKey)) {
65
- return;
66
- }
67
- if (!hasLoggedQueueUse && typeof console !== 'undefined') {
68
- console.log('[i18n] queued errors while murphy not available');
69
- hasLoggedQueueUse = true;
70
- }
71
- if (pendingErrors.size >= MAX_PENDING_ERRORS) {
72
- var oldestKey = pendingErrors.keys().next().value;
73
- pendingErrors["delete"](oldestKey);
74
- }
75
- pendingErrors.set(dedupeKey, {
76
- type: type,
77
- key: key
78
- });
79
- }
80
- function flushI18NErrors() {
81
- if (!isReporterAvailable()) {
82
- return;
83
- }
84
- if (pendingErrors.size === 0) {
85
- return;
86
- }
87
- if (!hasLoggedFlushUse && typeof console !== 'undefined') {
88
- console.log('[i18n] flushing queued errors', {
89
- count: pendingErrors.size
90
- });
91
- hasLoggedFlushUse = true;
92
- }
93
- var _iterator = _createForOfIteratorHelper(pendingErrors),
94
- _step;
95
- try {
96
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
97
- var _step$value = _slicedToArray(_step.value, 2),
98
- dedupeKey = _step$value[0],
99
- data = _step$value[1];
100
- if (reportedKeys.has(dedupeKey)) {
101
- pendingErrors["delete"](dedupeKey);
102
- continue;
103
- }
104
- sendToDesk(data.type, data.key);
105
- reportedKeys.add(dedupeKey);
106
- pendingErrors["delete"](dedupeKey);
28
+ if (typeof window._windowDeskCustomError === 'function') {
29
+ console.log("[i18n-reporter] Using DESK path (deskCustomError): ".concat(dedupeKey));
30
+ window._windowDeskCustomError(errorData, errorMessage, errorData);
31
+ } else if (window.murphy) {
32
+ console.log("[i18n-reporter] Using IM path (murphy direct): ".concat(dedupeKey));
33
+ window.murphy.addCustomTracking(errorData);
34
+ var error = new Error(errorMessage);
35
+ error.name = type;
36
+ window.murphy.error(error);
37
+ } else {
38
+ console.log("[i18n-reporter] SKIPPED (Murphy not loaded): ".concat(dedupeKey));
39
+ return;
107
40
  }
108
41
  } catch (err) {
109
- _iterator.e(err);
110
- } finally {
111
- _iterator.f();
42
+ console.error("[i18n-reporter] ERROR reporting: ".concat(dedupeKey), err);
112
43
  }
113
- }
114
- function reportI18NError(type, key) {
115
- var dedupeKey = "".concat(type, ":").concat(key);
116
- if (reportedKeys.has(dedupeKey)) {
117
- return;
118
- }
119
- if (!isReporterAvailable()) {
120
- queuePendingError(dedupeKey, type, key);
121
- return;
122
- }
123
- flushI18NErrors();
124
- if (reportedKeys.has(dedupeKey)) {
125
- return;
126
- }
127
- sendToDesk(type, key);
128
44
  reportedKeys.add(dedupeKey);
129
45
  }
130
- function clearReportedKeys() {
131
- reportedKeys.clear();
132
- pendingErrors.clear();
133
- }
134
46
  function getFallbackText(key) {
135
47
  var isNumeric = /^\d+$/.test(key);
136
48
  return isNumeric ? "text.unavailable.".concat(key) : key;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/i18n",
3
- "version": "1.0.0-beta.40-murphy",
3
+ "version": "1.0.0-beta.41-murphy",
4
4
  "main": "lib/index",
5
5
  "module": "es/index.js",
6
6
  "jsnext:main": "es/index.js",
package/src/index.js CHANGED
@@ -23,8 +23,6 @@ export {
23
23
  } from './utils';
24
24
  export {
25
25
  reportI18NError,
26
- flushI18NErrors,
27
- clearReportedKeys,
28
26
  I18N_ERROR_TYPES
29
27
  } from './utils/errorReporter';
30
28
  import { getI18NValue as getI18NValue1 } from './utils';
@@ -5,124 +5,43 @@ export const I18N_ERROR_TYPES = {
5
5
  };
6
6
 
7
7
  const reportedKeys = new Set();
8
- const pendingErrors = new Map();
9
- const MAX_PENDING_ERRORS = 100;
10
- let hasLoggedQueueUse = false;
11
- let hasLoggedFlushUse = false;
12
8
 
13
- function getDeskCustomError() {
14
- if (typeof window === 'undefined') {
15
- return null;
16
- }
17
-
18
- return typeof window._windowDeskCustomError === 'function'
19
- ? window._windowDeskCustomError
20
- : null;
21
- }
22
-
23
- function isReporterAvailable() {
24
- return Boolean(getDeskCustomError());
25
- }
9
+ export function reportI18NError(type, key) {
10
+ const dedupeKey = `${type}:${key}`;
26
11
 
27
- function sendToDesk(type, key) {
28
- const deskCustomError = getDeskCustomError();
29
- if (!deskCustomError) {
30
- console.log('[i18n] Murphy not available, skipping error report:', { type, key });
12
+ if (reportedKeys.has(dedupeKey)) {
13
+ console.log(`[i18n-reporter] SKIPPED (already reported): ${dedupeKey}`);
31
14
  return;
32
15
  }
33
16
 
34
17
  const errorMessage = `i18n ${type}: ${key}`;
35
- const errorDetails = {
36
- type,
37
- key,
38
- category: 'i18n'
39
- };
40
- const envData = {
18
+ const errorData = {
41
19
  errorType: type,
42
20
  i18nKey: key,
43
21
  category: 'i18n'
44
22
  };
45
23
 
46
24
  try {
47
- deskCustomError(errorDetails, errorMessage, envData);
48
- } catch (err) {
49
- console.log('[i18n] Error reporting to Murphy failed:', err);
50
- }
51
- }
52
-
53
- function queuePendingError(dedupeKey, type, key) {
54
- if (pendingErrors.has(dedupeKey)) {
55
- return;
56
- }
57
-
58
- if (!hasLoggedQueueUse && typeof console !== 'undefined') {
59
- console.log('[i18n] queued errors while murphy not available');
60
- hasLoggedQueueUse = true;
61
- }
62
-
63
- if (pendingErrors.size >= MAX_PENDING_ERRORS) {
64
- const oldestKey = pendingErrors.keys().next().value;
65
- pendingErrors.delete(oldestKey);
66
- }
67
-
68
- pendingErrors.set(dedupeKey, { type, key });
69
- }
70
-
71
- export function flushI18NErrors() {
72
- if (!isReporterAvailable()) {
73
- return;
74
- }
75
-
76
- if (pendingErrors.size === 0) {
77
- return;
78
- }
79
-
80
- if (!hasLoggedFlushUse && typeof console !== 'undefined') {
81
- console.log('[i18n] flushing queued errors', {
82
- count: pendingErrors.size
83
- });
84
- hasLoggedFlushUse = true;
85
- }
86
-
87
- for (const [dedupeKey, data] of pendingErrors) {
88
- if (reportedKeys.has(dedupeKey)) {
89
- pendingErrors.delete(dedupeKey);
90
- continue;
25
+ if (typeof window._windowDeskCustomError === 'function') {
26
+ console.log(`[i18n-reporter] Using DESK path (deskCustomError): ${dedupeKey}`);
27
+ window._windowDeskCustomError(errorData, errorMessage, errorData);
28
+ } else if (window.murphy) {
29
+ console.log(`[i18n-reporter] Using IM path (murphy direct): ${dedupeKey}`);
30
+ window.murphy.addCustomTracking(errorData);
31
+ const error = new Error(errorMessage);
32
+ error.name = type;
33
+ window.murphy.error(error);
34
+ } else {
35
+ console.log(`[i18n-reporter] SKIPPED (Murphy not loaded): ${dedupeKey}`);
36
+ return;
91
37
  }
92
-
93
- sendToDesk(data.type, data.key);
94
- reportedKeys.add(dedupeKey);
95
- pendingErrors.delete(dedupeKey);
96
- }
97
- }
98
-
99
- export function reportI18NError(type, key) {
100
- const dedupeKey = `${type}:${key}`;
101
-
102
- if (reportedKeys.has(dedupeKey)) {
103
- return;
104
- }
105
-
106
- if (!isReporterAvailable()) {
107
- queuePendingError(dedupeKey, type, key);
108
- return;
109
- }
110
-
111
- flushI18NErrors();
112
-
113
- if (reportedKeys.has(dedupeKey)) {
114
- return;
38
+ } catch (err) {
39
+ console.error(`[i18n-reporter] ERROR reporting: ${dedupeKey}`, err);
115
40
  }
116
41
 
117
- sendToDesk(type, key);
118
42
  reportedKeys.add(dedupeKey);
119
43
  }
120
44
 
121
- export function clearReportedKeys() {
122
- reportedKeys.clear();
123
- pendingErrors.clear();
124
- }
125
-
126
45
  export function getFallbackText(key) {
127
46
  const isNumeric = /^\d+$/.test(key);
128
47
  return isNumeric ? `text.unavailable.${key}` : key;