@bigbinary/neeto-commons-frontend 2.0.2 → 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 +1 -1
- package/initializers.cjs.js +86 -71
- package/initializers.js +86 -71
- package/package.json +2 -1
- package/pure.cjs.js +28 -11
- package/pure.d.ts +22 -20
- package/pure.js +28 -12
- package/react-utils.cjs.js +16 -18
- package/react-utils.d.ts +5 -10
- package/react-utils.js +16 -18
- package/utils.cjs.js +697 -0
- package/utils.d.ts +2 -0
- package/utils.js +698 -2
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.
|
|
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
|
package/initializers.cjs.js
CHANGED
|
@@ -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
|
|
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
|
}
|
|
@@ -119,6 +134,22 @@ var keysToCamelCase = function keysToCamelCase(object) {
|
|
|
119
134
|
return [snakeToCamelCase(key), value];
|
|
120
135
|
});
|
|
121
136
|
};
|
|
137
|
+
var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
|
|
138
|
+
if (Array.isArray(object)) {
|
|
139
|
+
return object.map(serializeKeysToSnakeCase);
|
|
140
|
+
} else if (object === null || _typeof(object) !== "object") {
|
|
141
|
+
return object;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return Object.fromEntries(Object.entries(object).map(function (_ref3) {
|
|
145
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
146
|
+
key = _ref4[0],
|
|
147
|
+
value = _ref4[1];
|
|
148
|
+
|
|
149
|
+
var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
|
|
150
|
+
return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
|
|
151
|
+
}));
|
|
152
|
+
};
|
|
122
153
|
var deepFreezeObject = function deepFreezeObject(object) {
|
|
123
154
|
if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
|
|
124
155
|
Object.keys(object).forEach(function (property) {
|
|
@@ -136,37 +167,15 @@ var matches = ramda.curry(function (pattern, object) {
|
|
|
136
167
|
if (typeof pattern === "function" && pattern(object, __parent)) return true;
|
|
137
168
|
if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
|
|
138
169
|
if (_typeof(pattern) !== "object") return false;
|
|
139
|
-
return Object.entries(pattern).every(function (
|
|
140
|
-
var
|
|
141
|
-
key =
|
|
142
|
-
value =
|
|
170
|
+
return Object.entries(pattern).every(function (_ref5) {
|
|
171
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
172
|
+
key = _ref6[0],
|
|
173
|
+
value = _ref6[1];
|
|
143
174
|
|
|
144
175
|
return matches(value, object[key], __parent);
|
|
145
176
|
});
|
|
146
177
|
});
|
|
147
178
|
|
|
148
|
-
function initializeGlobalProps() {
|
|
149
|
-
var _document$getElements, _document$getElements2;
|
|
150
|
-
|
|
151
|
-
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) || "{}"));
|
|
152
|
-
deepFreezeObject(window.globalProps);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function _defineProperty(obj, key, value) {
|
|
156
|
-
if (key in obj) {
|
|
157
|
-
Object.defineProperty(obj, key, {
|
|
158
|
-
value: value,
|
|
159
|
-
enumerable: true,
|
|
160
|
-
configurable: true,
|
|
161
|
-
writable: true
|
|
162
|
-
});
|
|
163
|
-
} else {
|
|
164
|
-
obj[key] = value;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return obj;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
179
|
var HEADERS_KEYS = {
|
|
171
180
|
xAuthEmail: "X-Auth-Email",
|
|
172
181
|
xAuthToken: "X-Auth-Token",
|
|
@@ -246,15 +255,28 @@ var buildSuccessResponseHandler = function buildSuccessResponseHandler(skip) {
|
|
|
246
255
|
};
|
|
247
256
|
|
|
248
257
|
var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(error) {
|
|
258
|
+
var _error$response;
|
|
259
|
+
|
|
260
|
+
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) !== 401) return error;
|
|
249
261
|
resetAuthTokens();
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
262
|
+
var _error$config$redirec = error.config.redirectOnError,
|
|
263
|
+
redirectOnError = _error$config$redirec === void 0 ? true : _error$config$redirec;
|
|
264
|
+
|
|
265
|
+
if (redirectOnError) {
|
|
266
|
+
setTimeout(function () {
|
|
267
|
+
var redirectTo = window.location.pathname === "/login" ? "/login" : "/login?redirect_uri=".concat(encodeURIComponent(window.location.href));
|
|
268
|
+
window.location.href = redirectTo;
|
|
269
|
+
}, 300);
|
|
270
|
+
}
|
|
271
|
+
|
|
254
272
|
return error;
|
|
255
273
|
};
|
|
256
274
|
|
|
257
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
|
+
|
|
258
280
|
if (axios__default["default"].isCancel(error)) {
|
|
259
281
|
neetoui.Toastr.error(i18next__default["default"].t("neetoCommons.toastr.error.requestCanceled"));
|
|
260
282
|
} else if (error.message === "Network Error") {
|
|
@@ -267,9 +289,12 @@ var showErrorToastr = function showErrorToastr(error) {
|
|
|
267
289
|
};
|
|
268
290
|
|
|
269
291
|
var redirect404 = function redirect404(error) {
|
|
270
|
-
var _error$
|
|
292
|
+
var _error$response2;
|
|
293
|
+
|
|
294
|
+
var _error$config$redirec2 = error.config.redirectOnError,
|
|
295
|
+
redirectOnError = _error$config$redirec2 === void 0 ? true : _error$config$redirec2;
|
|
271
296
|
|
|
272
|
-
if (((_error$
|
|
297
|
+
if (redirectOnError && ((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) === 404) {
|
|
273
298
|
window.location.href = "/page-not-found";
|
|
274
299
|
}
|
|
275
300
|
|
|
@@ -281,7 +306,7 @@ var buildErrorResponseHandler = function buildErrorResponseHandler(skip) {
|
|
|
281
306
|
if (!(skip !== null && skip !== void 0 && skip.redirectOn404)) interceptors.push(redirect404);
|
|
282
307
|
if (!(skip !== null && skip !== void 0 && skip.logoutOn401)) interceptors.push(handleUnauthorizedErrorResponse);
|
|
283
308
|
if (!(skip !== null && skip !== void 0 && skip.showToastr)) interceptors.push(showErrorToastr);
|
|
284
|
-
interceptors.push(Promise.reject);
|
|
309
|
+
interceptors.push(Promise.reject.bind(Promise));
|
|
285
310
|
return createPipe(interceptors);
|
|
286
311
|
};
|
|
287
312
|
|
|
@@ -293,23 +318,6 @@ var cleanupCredentialsForCrossOrigin = function cleanupCredentialsForCrossOrigin
|
|
|
293
318
|
})(request);
|
|
294
319
|
};
|
|
295
320
|
|
|
296
|
-
var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
|
|
297
|
-
if (Array.isArray(object)) {
|
|
298
|
-
return object.map(serializeKeysToSnakeCase);
|
|
299
|
-
} else if (object === null || _typeof(object) !== "object") {
|
|
300
|
-
return object;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return Object.fromEntries(Object.entries(object).map(function (_ref) {
|
|
304
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
305
|
-
key = _ref2[0],
|
|
306
|
-
value = _ref2[1];
|
|
307
|
-
|
|
308
|
-
var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
|
|
309
|
-
return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
|
|
310
|
-
}));
|
|
311
|
-
};
|
|
312
|
-
|
|
313
321
|
var transformDataToSnakeCase = function transformDataToSnakeCase(request) {
|
|
314
322
|
var _request$transformReq = request.transformRequestCase,
|
|
315
323
|
transformRequestCase = _request$transformReq === void 0 ? true : _request$transformReq;
|
|
@@ -342,26 +350,11 @@ function initializeAxios(skip) {
|
|
|
342
350
|
if (shouldNot(skip === null || skip === void 0 ? void 0 : skip.interceptors)) registerIntercepts(skip === null || skip === void 0 ? void 0 : skip.interceptors);
|
|
343
351
|
}
|
|
344
352
|
|
|
345
|
-
function
|
|
346
|
-
var
|
|
347
|
-
var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
|
|
348
|
-
var isUserLoggedIn = !ramda.either(ramda.isEmpty, ramda.isNil)(globalProps.user);
|
|
353
|
+
function initializeGlobalProps() {
|
|
354
|
+
var _document$getElements, _document$getElements2;
|
|
349
355
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
mixpanel__default["default"].people.set({
|
|
353
|
-
$email: globalProps.user.email,
|
|
354
|
-
$fist_name: globalProps.user.firstName,
|
|
355
|
-
$last_name: globalProps.user.lastName
|
|
356
|
-
});
|
|
357
|
-
mixpanel__default["default"].identify(globalProps.user.email);
|
|
358
|
-
} else {
|
|
359
|
-
/*
|
|
360
|
-
We need to initialize mixpanel with a bogus token in development and test environment to
|
|
361
|
-
prevent mixpanel library from throwing an error when we use mixpanel.track() method in react components.
|
|
362
|
-
*/
|
|
363
|
-
mixpanel__default["default"].init("TEST_TOKEN");
|
|
364
|
-
}
|
|
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);
|
|
365
358
|
}
|
|
366
359
|
|
|
367
360
|
var neetoCommons = {
|
|
@@ -419,6 +412,28 @@ var initializeI18n = function initializeI18n(resources) {
|
|
|
419
412
|
});
|
|
420
413
|
};
|
|
421
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
|
+
|
|
422
437
|
exports.globalProps = {};
|
|
423
438
|
function initializeApplication(_ref) {
|
|
424
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
|
|
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
|
}
|
|
@@ -109,6 +124,22 @@ var keysToCamelCase = function keysToCamelCase(object) {
|
|
|
109
124
|
return [snakeToCamelCase(key), value];
|
|
110
125
|
});
|
|
111
126
|
};
|
|
127
|
+
var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
|
|
128
|
+
if (Array.isArray(object)) {
|
|
129
|
+
return object.map(serializeKeysToSnakeCase);
|
|
130
|
+
} else if (object === null || _typeof(object) !== "object") {
|
|
131
|
+
return object;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return Object.fromEntries(Object.entries(object).map(function (_ref3) {
|
|
135
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
136
|
+
key = _ref4[0],
|
|
137
|
+
value = _ref4[1];
|
|
138
|
+
|
|
139
|
+
var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
|
|
140
|
+
return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
|
|
141
|
+
}));
|
|
142
|
+
};
|
|
112
143
|
var deepFreezeObject = function deepFreezeObject(object) {
|
|
113
144
|
if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
|
|
114
145
|
Object.keys(object).forEach(function (property) {
|
|
@@ -126,37 +157,15 @@ var matches = curry(function (pattern, object) {
|
|
|
126
157
|
if (typeof pattern === "function" && pattern(object, __parent)) return true;
|
|
127
158
|
if (isNil(pattern) || isNil(object)) return false;
|
|
128
159
|
if (_typeof(pattern) !== "object") return false;
|
|
129
|
-
return Object.entries(pattern).every(function (
|
|
130
|
-
var
|
|
131
|
-
key =
|
|
132
|
-
value =
|
|
160
|
+
return Object.entries(pattern).every(function (_ref5) {
|
|
161
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
162
|
+
key = _ref6[0],
|
|
163
|
+
value = _ref6[1];
|
|
133
164
|
|
|
134
165
|
return matches(value, object[key], __parent);
|
|
135
166
|
});
|
|
136
167
|
});
|
|
137
168
|
|
|
138
|
-
function initializeGlobalProps() {
|
|
139
|
-
var _document$getElements, _document$getElements2;
|
|
140
|
-
|
|
141
|
-
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) || "{}"));
|
|
142
|
-
deepFreezeObject(window.globalProps);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function _defineProperty(obj, key, value) {
|
|
146
|
-
if (key in obj) {
|
|
147
|
-
Object.defineProperty(obj, key, {
|
|
148
|
-
value: value,
|
|
149
|
-
enumerable: true,
|
|
150
|
-
configurable: true,
|
|
151
|
-
writable: true
|
|
152
|
-
});
|
|
153
|
-
} else {
|
|
154
|
-
obj[key] = value;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return obj;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
169
|
var HEADERS_KEYS = {
|
|
161
170
|
xAuthEmail: "X-Auth-Email",
|
|
162
171
|
xAuthToken: "X-Auth-Token",
|
|
@@ -236,15 +245,28 @@ var buildSuccessResponseHandler = function buildSuccessResponseHandler(skip) {
|
|
|
236
245
|
};
|
|
237
246
|
|
|
238
247
|
var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(error) {
|
|
248
|
+
var _error$response;
|
|
249
|
+
|
|
250
|
+
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) !== 401) return error;
|
|
239
251
|
resetAuthTokens();
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
252
|
+
var _error$config$redirec = error.config.redirectOnError,
|
|
253
|
+
redirectOnError = _error$config$redirec === void 0 ? true : _error$config$redirec;
|
|
254
|
+
|
|
255
|
+
if (redirectOnError) {
|
|
256
|
+
setTimeout(function () {
|
|
257
|
+
var redirectTo = window.location.pathname === "/login" ? "/login" : "/login?redirect_uri=".concat(encodeURIComponent(window.location.href));
|
|
258
|
+
window.location.href = redirectTo;
|
|
259
|
+
}, 300);
|
|
260
|
+
}
|
|
261
|
+
|
|
244
262
|
return error;
|
|
245
263
|
};
|
|
246
264
|
|
|
247
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
|
+
|
|
248
270
|
if (axios.isCancel(error)) {
|
|
249
271
|
Toastr.error(i18next.t("neetoCommons.toastr.error.requestCanceled"));
|
|
250
272
|
} else if (error.message === "Network Error") {
|
|
@@ -257,9 +279,12 @@ var showErrorToastr = function showErrorToastr(error) {
|
|
|
257
279
|
};
|
|
258
280
|
|
|
259
281
|
var redirect404 = function redirect404(error) {
|
|
260
|
-
var _error$
|
|
282
|
+
var _error$response2;
|
|
261
283
|
|
|
262
|
-
|
|
284
|
+
var _error$config$redirec2 = error.config.redirectOnError,
|
|
285
|
+
redirectOnError = _error$config$redirec2 === void 0 ? true : _error$config$redirec2;
|
|
286
|
+
|
|
287
|
+
if (redirectOnError && ((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) === 404) {
|
|
263
288
|
window.location.href = "/page-not-found";
|
|
264
289
|
}
|
|
265
290
|
|
|
@@ -271,7 +296,7 @@ var buildErrorResponseHandler = function buildErrorResponseHandler(skip) {
|
|
|
271
296
|
if (!(skip !== null && skip !== void 0 && skip.redirectOn404)) interceptors.push(redirect404);
|
|
272
297
|
if (!(skip !== null && skip !== void 0 && skip.logoutOn401)) interceptors.push(handleUnauthorizedErrorResponse);
|
|
273
298
|
if (!(skip !== null && skip !== void 0 && skip.showToastr)) interceptors.push(showErrorToastr);
|
|
274
|
-
interceptors.push(Promise.reject);
|
|
299
|
+
interceptors.push(Promise.reject.bind(Promise));
|
|
275
300
|
return createPipe(interceptors);
|
|
276
301
|
};
|
|
277
302
|
|
|
@@ -283,23 +308,6 @@ var cleanupCredentialsForCrossOrigin = function cleanupCredentialsForCrossOrigin
|
|
|
283
308
|
})(request);
|
|
284
309
|
};
|
|
285
310
|
|
|
286
|
-
var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
|
|
287
|
-
if (Array.isArray(object)) {
|
|
288
|
-
return object.map(serializeKeysToSnakeCase);
|
|
289
|
-
} else if (object === null || _typeof(object) !== "object") {
|
|
290
|
-
return object;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return Object.fromEntries(Object.entries(object).map(function (_ref) {
|
|
294
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
295
|
-
key = _ref2[0],
|
|
296
|
-
value = _ref2[1];
|
|
297
|
-
|
|
298
|
-
var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
|
|
299
|
-
return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
|
|
300
|
-
}));
|
|
301
|
-
};
|
|
302
|
-
|
|
303
311
|
var transformDataToSnakeCase = function transformDataToSnakeCase(request) {
|
|
304
312
|
var _request$transformReq = request.transformRequestCase,
|
|
305
313
|
transformRequestCase = _request$transformReq === void 0 ? true : _request$transformReq;
|
|
@@ -332,26 +340,11 @@ function initializeAxios(skip) {
|
|
|
332
340
|
if (shouldNot(skip === null || skip === void 0 ? void 0 : skip.interceptors)) registerIntercepts(skip === null || skip === void 0 ? void 0 : skip.interceptors);
|
|
333
341
|
}
|
|
334
342
|
|
|
335
|
-
function
|
|
336
|
-
var
|
|
337
|
-
var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
|
|
338
|
-
var isUserLoggedIn = !either(isEmpty, isNil)(globalProps.user);
|
|
343
|
+
function initializeGlobalProps() {
|
|
344
|
+
var _document$getElements, _document$getElements2;
|
|
339
345
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
mixpanel.people.set({
|
|
343
|
-
$email: globalProps.user.email,
|
|
344
|
-
$fist_name: globalProps.user.firstName,
|
|
345
|
-
$last_name: globalProps.user.lastName
|
|
346
|
-
});
|
|
347
|
-
mixpanel.identify(globalProps.user.email);
|
|
348
|
-
} else {
|
|
349
|
-
/*
|
|
350
|
-
We need to initialize mixpanel with a bogus token in development and test environment to
|
|
351
|
-
prevent mixpanel library from throwing an error when we use mixpanel.track() method in react components.
|
|
352
|
-
*/
|
|
353
|
-
mixpanel.init("TEST_TOKEN");
|
|
354
|
-
}
|
|
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);
|
|
355
348
|
}
|
|
356
349
|
|
|
357
350
|
var neetoCommons = {
|
|
@@ -409,6 +402,28 @@ var initializeI18n = function initializeI18n(resources) {
|
|
|
409
402
|
});
|
|
410
403
|
};
|
|
411
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
|
+
|
|
412
427
|
var globalProps$1 = {};
|
|
413
428
|
function initializeApplication(_ref) {
|
|
414
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.
|
|
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>",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"lint-staged": "^12.3.7",
|
|
82
82
|
"mixpanel-browser": "^2.45.0",
|
|
83
83
|
"prettier": "^2.6.2",
|
|
84
|
+
"query-string": "^7.1.1",
|
|
84
85
|
"ramda": "^0.28.0",
|
|
85
86
|
"react": "^17.0.2",
|
|
86
87
|
"react-dom": "17.0.2",
|
package/pure.cjs.js
CHANGED
|
@@ -133,6 +133,22 @@ var keysToSnakeCase = function keysToSnakeCase(object) {
|
|
|
133
133
|
return [camelToSnakeCase(key), value];
|
|
134
134
|
});
|
|
135
135
|
};
|
|
136
|
+
var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
|
|
137
|
+
if (Array.isArray(object)) {
|
|
138
|
+
return object.map(serializeKeysToSnakeCase);
|
|
139
|
+
} else if (object === null || _typeof(object) !== "object") {
|
|
140
|
+
return object;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return Object.fromEntries(Object.entries(object).map(function (_ref3) {
|
|
144
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
145
|
+
key = _ref4[0],
|
|
146
|
+
value = _ref4[1];
|
|
147
|
+
|
|
148
|
+
var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
|
|
149
|
+
return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
|
|
150
|
+
}));
|
|
151
|
+
};
|
|
136
152
|
var deepFreezeObject = function deepFreezeObject(object) {
|
|
137
153
|
if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
|
|
138
154
|
Object.keys(object).forEach(function (property) {
|
|
@@ -150,25 +166,25 @@ var matches = ramda.curry(function (pattern, object) {
|
|
|
150
166
|
if (typeof pattern === "function" && pattern(object, __parent)) return true;
|
|
151
167
|
if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
|
|
152
168
|
if (_typeof(pattern) !== "object") return false;
|
|
153
|
-
return Object.entries(pattern).every(function (
|
|
154
|
-
var
|
|
155
|
-
key =
|
|
156
|
-
value =
|
|
169
|
+
return Object.entries(pattern).every(function (_ref5) {
|
|
170
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
171
|
+
key = _ref6[0],
|
|
172
|
+
value = _ref6[1];
|
|
157
173
|
|
|
158
174
|
return matches(value, object[key], __parent);
|
|
159
175
|
});
|
|
160
176
|
});
|
|
161
177
|
var filterNonNull = function filterNonNull(object) {
|
|
162
|
-
return Object.fromEntries(Object.entries(object).filter(function (
|
|
163
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
164
|
-
v = _ref6[1];
|
|
165
|
-
|
|
166
|
-
return !ramda.isNil(v);
|
|
167
|
-
}).map(function (_ref7) {
|
|
178
|
+
return Object.fromEntries(Object.entries(object).filter(function (_ref7) {
|
|
168
179
|
var _ref8 = _slicedToArray(_ref7, 2),
|
|
169
|
-
k = _ref8[0],
|
|
170
180
|
v = _ref8[1];
|
|
171
181
|
|
|
182
|
+
return !ramda.isNil(v);
|
|
183
|
+
}).map(function (_ref9) {
|
|
184
|
+
var _ref10 = _slicedToArray(_ref9, 2),
|
|
185
|
+
k = _ref10[0],
|
|
186
|
+
v = _ref10[1];
|
|
187
|
+
|
|
172
188
|
return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
|
|
173
189
|
}));
|
|
174
190
|
};
|
|
@@ -385,6 +401,7 @@ exports.removeById = removeById;
|
|
|
385
401
|
exports.renameKeys = renameKeys;
|
|
386
402
|
exports.replaceBy = replaceBy;
|
|
387
403
|
exports.replaceById = replaceById;
|
|
404
|
+
exports.serializeKeysToSnakeCase = serializeKeysToSnakeCase;
|
|
388
405
|
exports.slugify = slugify;
|
|
389
406
|
exports.snakeToCamelCase = snakeToCamelCase;
|
|
390
407
|
exports.toLabelAndValue = toLabelAndValue;
|
package/pure.d.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
| boolean
|
|
7
|
-
|
|
|
8
|
-
|
|
|
9
|
-
|
|
10
|
-
type MatchPattern<Obj = any, Parent = Obj> =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
@@ -168,6 +169,7 @@ export function replaceBy(pattern: MatchPattern): <T>(entityArray: T[]) => T[];
|
|
|
168
169
|
export function replaceById<T>(id: any, entityArray: T[]): T[];
|
|
169
170
|
export function replaceById(id: any): <T>(entityArray: T[]) => T[];
|
|
170
171
|
|
|
172
|
+
export function serializeKeysToSnakeCase(object: object): object;
|
|
171
173
|
export function slugify(string: string): string;
|
|
172
174
|
export function snakeToCamelCase(string: string): string;
|
|
173
175
|
export function toLabelAndValue(string: string): {
|