@bigbinary/neeto-commons-frontend 2.0.4 → 2.0.5

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/README.md CHANGED
@@ -7,7 +7,7 @@ The commons frontend library for Neeto Applications.
7
7
  Install from npm:
8
8
 
9
9
  ```bash
10
- yarn add "@bigbinary/neeto-commons-frontend@2.0.4"
10
+ yarn add "@bigbinary/neeto-commons-frontend@2.0.5"
11
11
  ```
12
12
 
13
13
  This package relies on the host project's tailwind configuration. So add
@@ -2,12 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var ramda = require('ramda');
6
5
  var neetoui = require('@bigbinary/neetoui');
7
6
  var axios = require('axios');
8
7
  var i18next = require('i18next');
9
- var mixpanel = require('mixpanel-browser');
8
+ var ramda = require('ramda');
10
9
  var reactI18next = require('react-i18next');
10
+ var mixpanel = require('mixpanel-browser');
11
11
 
12
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
13
 
@@ -25,6 +25,21 @@ function _typeof(obj) {
25
25
  }, _typeof(obj);
26
26
  }
27
27
 
28
+ function _defineProperty(obj, key, value) {
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else {
37
+ obj[key] = value;
38
+ }
39
+
40
+ return obj;
41
+ }
42
+
28
43
  function _arrayWithHoles(arr) {
29
44
  if (Array.isArray(arr)) return arr;
30
45
  }
@@ -161,28 +176,6 @@ var matches = ramda.curry(function (pattern, object) {
161
176
  });
162
177
  });
163
178
 
164
- function initializeGlobalProps() {
165
- var _document$getElements, _document$getElements2;
166
-
167
- window.globalProps = keysToCamelCase(JSON.parse(((_document$getElements = document.getElementsByClassName("root-container")[0]) === null || _document$getElements === void 0 ? void 0 : (_document$getElements2 = _document$getElements.dataset) === null || _document$getElements2 === void 0 ? void 0 : _document$getElements2.reactProps) || "{}"));
168
- deepFreezeObject(window.globalProps);
169
- }
170
-
171
- function _defineProperty(obj, key, value) {
172
- if (key in obj) {
173
- Object.defineProperty(obj, key, {
174
- value: value,
175
- enumerable: true,
176
- configurable: true,
177
- writable: true
178
- });
179
- } else {
180
- obj[key] = value;
181
- }
182
-
183
- return obj;
184
- }
185
-
186
179
  var HEADERS_KEYS = {
187
180
  xAuthEmail: "X-Auth-Email",
188
181
  xAuthToken: "X-Auth-Token",
@@ -280,6 +273,10 @@ var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(e
280
273
  };
281
274
 
282
275
  var showErrorToastr = function showErrorToastr(error) {
276
+ var _error$config$showToa = error.config.showToastr,
277
+ showToastr = _error$config$showToa === void 0 ? true : _error$config$showToa;
278
+ if (!showToastr) return error;
279
+
283
280
  if (axios__default["default"].isCancel(error)) {
284
281
  neetoui.Toastr.error(i18next__default["default"].t("neetoCommons.toastr.error.requestCanceled"));
285
282
  } else if (error.message === "Network Error") {
@@ -353,26 +350,11 @@ function initializeAxios(skip) {
353
350
  if (shouldNot(skip === null || skip === void 0 ? void 0 : skip.interceptors)) registerIntercepts(skip === null || skip === void 0 ? void 0 : skip.interceptors);
354
351
  }
355
352
 
356
- function initializeMixPanel() {
357
- var isProduction = process.env.NODE_ENV === "production";
358
- var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
359
- var isUserLoggedIn = !ramda.either(ramda.isEmpty, ramda.isNil)(globalProps.user);
353
+ function initializeGlobalProps() {
354
+ var _document$getElements, _document$getElements2;
360
355
 
361
- if (isProduction && isTokenPresent && isUserLoggedIn) {
362
- mixpanel__default["default"].init(process.env.MIXPANEL_TOKEN || "");
363
- mixpanel__default["default"].people.set({
364
- $email: globalProps.user.email,
365
- $fist_name: globalProps.user.firstName,
366
- $last_name: globalProps.user.lastName
367
- });
368
- mixpanel__default["default"].identify(globalProps.user.email);
369
- } else {
370
- /*
371
- We need to initialize mixpanel with a bogus token in development and test environment to
372
- prevent mixpanel library from throwing an error when we use mixpanel.track() method in react components.
373
- */
374
- mixpanel__default["default"].init("TEST_TOKEN");
375
- }
356
+ window.globalProps = keysToCamelCase(JSON.parse(((_document$getElements = document.getElementsByClassName("root-container")[0]) === null || _document$getElements === void 0 ? void 0 : (_document$getElements2 = _document$getElements.dataset) === null || _document$getElements2 === void 0 ? void 0 : _document$getElements2.reactProps) || "{}"));
357
+ deepFreezeObject(window.globalProps);
376
358
  }
377
359
 
378
360
  var neetoCommons = {
@@ -430,6 +412,28 @@ var initializeI18n = function initializeI18n(resources) {
430
412
  });
431
413
  };
432
414
 
415
+ function initializeMixPanel() {
416
+ var isProduction = process.env.NODE_ENV === "production";
417
+ var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
418
+ var isUserLoggedIn = !ramda.either(ramda.isEmpty, ramda.isNil)(globalProps.user);
419
+
420
+ if (isProduction && isTokenPresent && isUserLoggedIn) {
421
+ mixpanel__default["default"].init(process.env.MIXPANEL_TOKEN || "");
422
+ mixpanel__default["default"].people.set({
423
+ $email: globalProps.user.email,
424
+ $fist_name: globalProps.user.firstName,
425
+ $last_name: globalProps.user.lastName
426
+ });
427
+ mixpanel__default["default"].identify(globalProps.user.email);
428
+ } else {
429
+ /*
430
+ We need to initialize mixpanel with a bogus token in development and test environment to
431
+ prevent mixpanel library from throwing an error when we use mixpanel.track() method in react components.
432
+ */
433
+ mixpanel__default["default"].init("TEST_TOKEN");
434
+ }
435
+ }
436
+
433
437
  exports.globalProps = {};
434
438
  function initializeApplication(_ref) {
435
439
  var translationResources = _ref.translationResources,
package/initializers.js CHANGED
@@ -1,9 +1,9 @@
1
- import { curry, isNil, values, evolve, omit, modify, either, isEmpty, mergeDeepLeft } from 'ramda';
2
1
  import { Toastr } from '@bigbinary/neetoui';
3
2
  import axios from 'axios';
4
3
  import i18next from 'i18next';
5
- import mixpanel from 'mixpanel-browser';
4
+ import { curry, isNil, values, evolve, omit, modify, mergeDeepLeft, either, isEmpty } from 'ramda';
6
5
  import { initReactI18next } from 'react-i18next';
6
+ import mixpanel from 'mixpanel-browser';
7
7
 
8
8
  function _typeof(obj) {
9
9
  "@babel/helpers - typeof";
@@ -15,6 +15,21 @@ function _typeof(obj) {
15
15
  }, _typeof(obj);
16
16
  }
17
17
 
18
+ function _defineProperty(obj, key, value) {
19
+ if (key in obj) {
20
+ Object.defineProperty(obj, key, {
21
+ value: value,
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true
25
+ });
26
+ } else {
27
+ obj[key] = value;
28
+ }
29
+
30
+ return obj;
31
+ }
32
+
18
33
  function _arrayWithHoles(arr) {
19
34
  if (Array.isArray(arr)) return arr;
20
35
  }
@@ -151,28 +166,6 @@ var matches = curry(function (pattern, object) {
151
166
  });
152
167
  });
153
168
 
154
- function initializeGlobalProps() {
155
- var _document$getElements, _document$getElements2;
156
-
157
- window.globalProps = keysToCamelCase(JSON.parse(((_document$getElements = document.getElementsByClassName("root-container")[0]) === null || _document$getElements === void 0 ? void 0 : (_document$getElements2 = _document$getElements.dataset) === null || _document$getElements2 === void 0 ? void 0 : _document$getElements2.reactProps) || "{}"));
158
- deepFreezeObject(window.globalProps);
159
- }
160
-
161
- function _defineProperty(obj, key, value) {
162
- if (key in obj) {
163
- Object.defineProperty(obj, key, {
164
- value: value,
165
- enumerable: true,
166
- configurable: true,
167
- writable: true
168
- });
169
- } else {
170
- obj[key] = value;
171
- }
172
-
173
- return obj;
174
- }
175
-
176
169
  var HEADERS_KEYS = {
177
170
  xAuthEmail: "X-Auth-Email",
178
171
  xAuthToken: "X-Auth-Token",
@@ -270,6 +263,10 @@ var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(e
270
263
  };
271
264
 
272
265
  var showErrorToastr = function showErrorToastr(error) {
266
+ var _error$config$showToa = error.config.showToastr,
267
+ showToastr = _error$config$showToa === void 0 ? true : _error$config$showToa;
268
+ if (!showToastr) return error;
269
+
273
270
  if (axios.isCancel(error)) {
274
271
  Toastr.error(i18next.t("neetoCommons.toastr.error.requestCanceled"));
275
272
  } else if (error.message === "Network Error") {
@@ -343,26 +340,11 @@ function initializeAxios(skip) {
343
340
  if (shouldNot(skip === null || skip === void 0 ? void 0 : skip.interceptors)) registerIntercepts(skip === null || skip === void 0 ? void 0 : skip.interceptors);
344
341
  }
345
342
 
346
- function initializeMixPanel() {
347
- var isProduction = process.env.NODE_ENV === "production";
348
- var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
349
- var isUserLoggedIn = !either(isEmpty, isNil)(globalProps.user);
343
+ function initializeGlobalProps() {
344
+ var _document$getElements, _document$getElements2;
350
345
 
351
- if (isProduction && isTokenPresent && isUserLoggedIn) {
352
- mixpanel.init(process.env.MIXPANEL_TOKEN || "");
353
- mixpanel.people.set({
354
- $email: globalProps.user.email,
355
- $fist_name: globalProps.user.firstName,
356
- $last_name: globalProps.user.lastName
357
- });
358
- mixpanel.identify(globalProps.user.email);
359
- } else {
360
- /*
361
- We need to initialize mixpanel with a bogus token in development and test environment to
362
- prevent mixpanel library from throwing an error when we use mixpanel.track() method in react components.
363
- */
364
- mixpanel.init("TEST_TOKEN");
365
- }
346
+ window.globalProps = keysToCamelCase(JSON.parse(((_document$getElements = document.getElementsByClassName("root-container")[0]) === null || _document$getElements === void 0 ? void 0 : (_document$getElements2 = _document$getElements.dataset) === null || _document$getElements2 === void 0 ? void 0 : _document$getElements2.reactProps) || "{}"));
347
+ deepFreezeObject(window.globalProps);
366
348
  }
367
349
 
368
350
  var neetoCommons = {
@@ -420,6 +402,28 @@ var initializeI18n = function initializeI18n(resources) {
420
402
  });
421
403
  };
422
404
 
405
+ function initializeMixPanel() {
406
+ var isProduction = process.env.NODE_ENV === "production";
407
+ var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
408
+ var isUserLoggedIn = !either(isEmpty, isNil)(globalProps.user);
409
+
410
+ if (isProduction && isTokenPresent && isUserLoggedIn) {
411
+ mixpanel.init(process.env.MIXPANEL_TOKEN || "");
412
+ mixpanel.people.set({
413
+ $email: globalProps.user.email,
414
+ $fist_name: globalProps.user.firstName,
415
+ $last_name: globalProps.user.lastName
416
+ });
417
+ mixpanel.identify(globalProps.user.email);
418
+ } else {
419
+ /*
420
+ We need to initialize mixpanel with a bogus token in development and test environment to
421
+ prevent mixpanel library from throwing an error when we use mixpanel.track() method in react components.
422
+ */
423
+ mixpanel.init("TEST_TOKEN");
424
+ }
425
+ }
426
+
423
427
  var globalProps$1 = {};
424
428
  function initializeApplication(_ref) {
425
429
  var translationResources = _ref.translationResources,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
5
5
  "repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
package/pure.d.ts CHANGED
@@ -1,23 +1,24 @@
1
- export type ObjectAndPrimitives =
2
- | object
3
- | symbol
4
- | string
5
- | number
6
- | boolean
7
- | null
8
- | undefined;
9
-
10
- type MatchPattern<Obj = any, Parent = Obj> = {
11
- [key in keyof Partial<Obj>]:
12
- | ((object: Obj[key], parent: Parent) => boolean)
13
- | MatchPattern<Obj[key], Parent>
14
- | ObjectAndPrimitives;
15
- } & {
16
- [key: string | number | symbol]:
17
- | ((object: any, parent: Parent) => boolean)
18
- | MatchPattern<any, Parent>
19
- | ObjectAndPrimitives;
20
- };
1
+ export type Primitives = symbol | string | number | boolean | null | undefined;
2
+ export type ObjectAndPrimitives = Primitives | object;
3
+ type KeyType = string | number | symbol;
4
+
5
+ type Matchable<Obj, Parent, key extends keyof Obj> =
6
+ | ((object: Obj[key], parent: Parent) => boolean)
7
+ | MatchPattern<Obj[key], Parent>
8
+ | Primitives;
9
+
10
+ type MatchPattern<Obj = any, Parent = Obj> = Obj extends any[]
11
+ ?
12
+ | Matchable<Obj, Parent, number>[]
13
+ | { [key: number]: Matchable<Obj, Parent, number> }
14
+ : Obj extends Primitives
15
+ ? Obj
16
+ :
17
+ | {
18
+ [key in keyof Partial<Obj>]: Matchable<Obj, Parent, key>;
19
+ } & {
20
+ [key: KeyType]: Matchable<any, Parent, KeyType>;
21
+ };
21
22
 
22
23
  export function camelToSnakeCase(string: string): string;
23
24
  export function capitalize(string: string): string;
@@ -74,20 +74,6 @@ var SvgFallbackComponent = function SvgFallbackComponent(props) {
74
74
  })));
75
75
  };
76
76
 
77
- react.Honeybadger.beforeNotify(function (notice) {
78
- return !/ResizeObserver/.test(notice.message);
79
- });
80
- var honeybadger = react.Honeybadger.configure({
81
- apiKey: globalProps.honeybadgerApiKey,
82
- environment: globalProps.nodeEnv,
83
- revision: globalProps.honeybadgerRevision,
84
- developmentEnvironments: ["development", "test"],
85
- enableUncaught: true,
86
- async: true,
87
- breadcrumbsEnabled: true,
88
- projectRoot: "webpack:///./"
89
- });
90
-
91
77
  var FallbackComponent = function FallbackComponent() {
92
78
  var _useTranslation = reactI18next.useTranslation(),
93
79
  t = _useTranslation.t;
@@ -114,7 +100,7 @@ var FallbackComponent = function FallbackComponent() {
114
100
  style: "primary",
115
101
  size: "large",
116
102
  onClick: function onClick() {
117
- return window.location.reload(false);
103
+ return window.location.reload();
118
104
  },
119
105
  label: t("neetoCommons.fallbackComponent.reload")
120
106
  }))));
@@ -124,6 +110,19 @@ var HoneybadgerErrorBoundary = function HoneybadgerErrorBoundary(_ref) {
124
110
  var children = _ref.children,
125
111
  _ref$ErrorComponent = _ref.ErrorComponent,
126
112
  ErrorComponent = _ref$ErrorComponent === void 0 ? FallbackComponent : _ref$ErrorComponent;
113
+ react.Honeybadger.beforeNotify(function (notice) {
114
+ return !/ResizeObserver/.test(notice.message);
115
+ });
116
+ var honeybadger = react.Honeybadger.configure({
117
+ apiKey: globalProps.honeybadgerApiKey,
118
+ environment: globalProps.nodeEnv,
119
+ revision: globalProps.honeybadgerRevision,
120
+ developmentEnvironments: ["development", "test"],
121
+ enableUncaught: true,
122
+ async: true,
123
+ breadcrumbsEnabled: true,
124
+ projectRoot: "webpack:///./"
125
+ });
127
126
  return /*#__PURE__*/React__default["default"].createElement(react.HoneybadgerErrorBoundary, {
128
127
  honeybadger: honeybadger,
129
128
  ErrorComponent: ErrorComponent
package/react-utils.d.ts CHANGED
@@ -1,22 +1,17 @@
1
1
  import { AvatarProps } from "@bigbinary/neetoui";
2
- import {
3
- LinkType,
4
- NavLinkItemType,
5
- SidebarProps,
6
- } from "@bigbinary/neetoui/layouts";
2
+ import { LinkType, NavLinkItemType } from "@bigbinary/neetoui/layouts";
7
3
  import React from "react";
4
+ import { RouteProps } from "react-router-dom";
8
5
  import { ObjectAndPrimitives } from "./pure";
9
6
 
10
7
  export const HoneybadgerErrorBoundary: React.FC<{
11
- ErrorComponent?: React.ReactNode;
8
+ ErrorComponent?: React.ReactNode | React.ComponentType<any>;
12
9
  }>;
13
- export function PrivateRoute<Component extends JSX.Element>(
10
+ export function PrivateRoute(
14
11
  props: {
15
- component: Component;
16
12
  condition: boolean;
17
- path: string;
18
13
  redirectRoute: string;
19
- } & { [key in keyof Component]: Component[key] }
14
+ } & RouteProps
20
15
  ): JSX.Element;
21
16
  export const Sidebar: React.FC<{
22
17
  navLinks: NavLinkItemType[];
package/react-utils.js CHANGED
@@ -45,20 +45,6 @@ var SvgFallbackComponent = function SvgFallbackComponent(props) {
45
45
  })));
46
46
  };
47
47
 
48
- Honeybadger.beforeNotify(function (notice) {
49
- return !/ResizeObserver/.test(notice.message);
50
- });
51
- var honeybadger = Honeybadger.configure({
52
- apiKey: globalProps.honeybadgerApiKey,
53
- environment: globalProps.nodeEnv,
54
- revision: globalProps.honeybadgerRevision,
55
- developmentEnvironments: ["development", "test"],
56
- enableUncaught: true,
57
- async: true,
58
- breadcrumbsEnabled: true,
59
- projectRoot: "webpack:///./"
60
- });
61
-
62
48
  var FallbackComponent = function FallbackComponent() {
63
49
  var _useTranslation = useTranslation(),
64
50
  t = _useTranslation.t;
@@ -85,7 +71,7 @@ var FallbackComponent = function FallbackComponent() {
85
71
  style: "primary",
86
72
  size: "large",
87
73
  onClick: function onClick() {
88
- return window.location.reload(false);
74
+ return window.location.reload();
89
75
  },
90
76
  label: t("neetoCommons.fallbackComponent.reload")
91
77
  }))));
@@ -95,6 +81,19 @@ var HoneybadgerErrorBoundary = function HoneybadgerErrorBoundary(_ref) {
95
81
  var children = _ref.children,
96
82
  _ref$ErrorComponent = _ref.ErrorComponent,
97
83
  ErrorComponent = _ref$ErrorComponent === void 0 ? FallbackComponent : _ref$ErrorComponent;
84
+ Honeybadger.beforeNotify(function (notice) {
85
+ return !/ResizeObserver/.test(notice.message);
86
+ });
87
+ var honeybadger = Honeybadger.configure({
88
+ apiKey: globalProps.honeybadgerApiKey,
89
+ environment: globalProps.nodeEnv,
90
+ revision: globalProps.honeybadgerRevision,
91
+ developmentEnvironments: ["development", "test"],
92
+ enableUncaught: true,
93
+ async: true,
94
+ breadcrumbsEnabled: true,
95
+ projectRoot: "webpack:///./"
96
+ });
98
97
  return /*#__PURE__*/React__default.createElement(HoneybadgerErrorBoundary$1, {
99
98
  honeybadger: honeybadger,
100
99
  ErrorComponent: ErrorComponent