@bigbinary/neeto-commons-frontend 1.0.10 → 2.0.2

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/initializers.js CHANGED
@@ -1,35 +1,19 @@
1
- 'use strict';
2
-
3
- var axios = require('axios');
4
- var ramda = require('ramda');
5
- var i18next = require('i18next');
6
- var dayjs = require('dayjs');
7
- var relativeTime = require('dayjs/plugin/relativeTime');
8
- var updateLocale = require('dayjs/plugin/updateLocale');
9
- var neetoui = require('@bigbinary/neetoui');
10
- var mixpanel = require('mixpanel-browser');
11
- var reactI18next = require('react-i18next');
12
-
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
-
15
- var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
16
- var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
17
- var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
18
- var relativeTime__default = /*#__PURE__*/_interopDefaultLegacy(relativeTime);
19
- var updateLocale__default = /*#__PURE__*/_interopDefaultLegacy(updateLocale);
20
- var mixpanel__default = /*#__PURE__*/_interopDefaultLegacy(mixpanel);
21
-
22
- var HEADERS_KEYS = {
23
- xAuthEmail: "X-Auth-Email",
24
- xAuthToken: "X-Auth-Token",
25
- xCsrfToken: "X-CSRF-TOKEN"
26
- };
1
+ import { curry, isNil, values, evolve, omit, modify, either, isEmpty, mergeDeepLeft } from 'ramda';
2
+ import { Toastr } from '@bigbinary/neetoui';
3
+ import axios from 'axios';
4
+ import i18next from 'i18next';
5
+ import mixpanel from 'mixpanel-browser';
6
+ import { initReactI18next } from 'react-i18next';
7
+
8
+ function _typeof(obj) {
9
+ "@babel/helpers - typeof";
27
10
 
28
- var resetAuthTokens = function resetAuthTokens() {
29
- ramda.values(HEADERS_KEYS).forEach(function (header) {
30
- delete axios__default["default"].defaults.headers[header];
31
- });
32
- };
11
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
12
+ return typeof obj;
13
+ } : function (obj) {
14
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
15
+ }, _typeof(obj);
16
+ }
33
17
 
34
18
  function _arrayWithHoles(arr) {
35
19
  if (Array.isArray(arr)) return arr;
@@ -92,16 +76,6 @@ function _slicedToArray(arr, i) {
92
76
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
93
77
  }
94
78
 
95
- function _typeof$1(obj) {
96
- "@babel/helpers - typeof";
97
-
98
- return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
99
- return typeof obj;
100
- } : function (obj) {
101
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
102
- }, _typeof$1(obj);
103
- }
104
-
105
79
  var snakeToCamelCase = function snakeToCamelCase(string) {
106
80
  return string.replace(/(_\w)/g, function (letter) {
107
81
  return letter[1].toUpperCase();
@@ -118,7 +92,7 @@ var transformObjectDeep = function transformObjectDeep(object, keyValueTransform
118
92
  return object.map(function (obj) {
119
93
  return transformObjectDeep(obj, keyValueTransformer);
120
94
  });
121
- } else if (object === null || _typeof$1(object) !== "object") {
95
+ } else if (object === null || _typeof(object) !== "object") {
122
96
  return object;
123
97
  }
124
98
 
@@ -136,7 +110,7 @@ var keysToCamelCase = function keysToCamelCase(object) {
136
110
  });
137
111
  };
138
112
  var deepFreezeObject = function deepFreezeObject(object) {
139
- if (object && _typeof$1(object) === "object" && !Object.isFrozen(object)) {
113
+ if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
140
114
  Object.keys(object).forEach(function (property) {
141
115
  return deepFreezeObject(object[property]);
142
116
  });
@@ -145,19 +119,29 @@ var deepFreezeObject = function deepFreezeObject(object) {
145
119
 
146
120
  return object;
147
121
  };
148
- var matches = ramda.curry(function (pattern, object) {
122
+ var matches = curry(function (pattern, object) {
123
+ var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
124
+
149
125
  if (object === pattern) return true;
150
- if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
151
- if (_typeof$1(pattern) !== "object") return false;
126
+ if (typeof pattern === "function" && pattern(object, __parent)) return true;
127
+ if (isNil(pattern) || isNil(object)) return false;
128
+ if (_typeof(pattern) !== "object") return false;
152
129
  return Object.entries(pattern).every(function (_ref3) {
153
130
  var _ref4 = _slicedToArray(_ref3, 2),
154
131
  key = _ref4[0],
155
132
  value = _ref4[1];
156
133
 
157
- return matches(value, object[key]);
134
+ return matches(value, object[key], __parent);
158
135
  });
159
136
  });
160
137
 
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
+
161
145
  function _defineProperty(obj, key, value) {
162
146
  if (key in obj) {
163
147
  Object.defineProperty(obj, key, {
@@ -173,510 +157,26 @@ function _defineProperty(obj, key, value) {
173
157
  return obj;
174
158
  }
175
159
 
176
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
177
-
178
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
179
- ramda.curry(function (id, array) {
180
- return array.filter(function (item) {
181
- return item.id !== id;
182
- });
183
- });
184
- ramda.curry(function (id, array) {
185
- return array.find(function (item) {
186
- return item.id === id;
187
- });
188
- });
189
- ramda.curry(function (id, newItem, array) {
190
- return array.map(function (item) {
191
- return item.id === id ? newItem : item;
192
- });
193
- });
194
- ramda.curry(function (id, modifier, array) {
195
- return array.map(function (item) {
196
- return item.id === id ? modifier(item) : item;
197
- });
198
- });
199
- ramda.curry(function (pattern, array) {
200
- return array.find(matches(pattern));
201
- });
202
- ramda.curry(function (pattern, array) {
203
- return array.filter(ramda.complement(matches(pattern)));
204
- });
205
- ramda.curry(function (pattern, newItem, array) {
206
- return array.map(function (item) {
207
- return matches(pattern, item) ? newItem : item;
208
- });
209
- });
210
- ramda.curry(function (pattern, modifier, array) {
211
- return array.map(function (item) {
212
- return matches(pattern, item) ? modifier(item) : item;
213
- });
214
- });
215
- ramda.curry(function (id, array) {
216
- return array.some(function (item) {
217
- return item.id === id;
218
- });
219
- });
220
- ramda.curry(function (pattern, array) {
221
- return array.some(matches(pattern));
222
- });
223
- ramda.curry(function (keyMap, objectArray) {
224
- return objectArray.map(function (object) {
225
- return _objectSpread(_objectSpread({}, object), ramda.fromPairs(ramda.toPairs(keyMap).map(function (_ref) {
226
- var _ref2 = _slicedToArray(_ref, 2),
227
- key = _ref2[0],
228
- value = _ref2[1];
229
-
230
- return [value, object[key]];
231
- })));
232
- });
233
- });
234
- ramda.curry(function (keyMap, objectArray) {
235
- return objectArray.map(function (object) {
236
- return _objectSpread(_objectSpread({}, ramda.omit(ramda.keys(keyMap), object)), ramda.fromPairs(ramda.toPairs(keyMap).map(function (_ref3) {
237
- var _ref4 = _slicedToArray(_ref3, 2),
238
- source = _ref4[0],
239
- destination = _ref4[1];
240
-
241
- return [destination, object[source]];
242
- })));
243
- });
244
- });
245
- ramda.curry(function (keyMap, objectArray) {
246
- var copyKeysSingleObject = function copyKeysSingleObject(object, keyMap) {
247
- var root = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
248
- return _objectSpread(_objectSpread({}, object), ramda.fromPairs(ramda.toPairs(keyMap).map(function (_ref5) {
249
- var _ref6 = _slicedToArray(_ref5, 2),
250
- destination = _ref6[0],
251
- source = _ref6[1];
252
-
253
- if (typeof source === "function") {
254
- return [destination, source(object[destination], root)];
255
- } else if (Array.isArray(source)) {
256
- return [destination, ramda.path(source, root)];
257
- } else if (_typeof$1(source) === "object") {
258
- return [destination, copyKeysSingleObject(object[destination], source, root)];
259
- }
260
-
261
- return [destination, object[source]];
262
- })));
263
- };
160
+ var HEADERS_KEYS = {
161
+ xAuthEmail: "X-Auth-Email",
162
+ xAuthToken: "X-Auth-Token",
163
+ xCsrfToken: "X-CSRF-TOKEN"
164
+ };
264
165
 
265
- return objectArray.map(function (object) {
266
- return copyKeysSingleObject(object, keyMap);
166
+ var resetAuthTokens = function resetAuthTokens() {
167
+ values(HEADERS_KEYS).forEach(function (header) {
168
+ delete axios.defaults.headers[header];
267
169
  });
268
- });
269
-
270
- var regeneratorRuntime$1 = {exports: {}};
271
-
272
- var _typeof = {exports: {}};
273
-
274
- (function (module) {
275
- function _typeof(obj) {
276
- "@babel/helpers - typeof";
277
-
278
- return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
279
- return typeof obj;
280
- } : function (obj) {
281
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
282
- }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
283
- }
284
-
285
- module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
286
- } (_typeof));
287
-
288
- (function (module) {
289
- var _typeof$1 = _typeof.exports["default"];
290
-
291
- function _regeneratorRuntime() {
292
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
293
-
294
- module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
295
- return exports;
296
- }, module.exports.__esModule = true, module.exports["default"] = module.exports;
297
- var exports = {},
298
- Op = Object.prototype,
299
- hasOwn = Op.hasOwnProperty,
300
- $Symbol = "function" == typeof Symbol ? Symbol : {},
301
- iteratorSymbol = $Symbol.iterator || "@@iterator",
302
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
303
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
304
-
305
- function define(obj, key, value) {
306
- return Object.defineProperty(obj, key, {
307
- value: value,
308
- enumerable: !0,
309
- configurable: !0,
310
- writable: !0
311
- }), obj[key];
312
- }
313
-
314
- try {
315
- define({}, "");
316
- } catch (err) {
317
- define = function define(obj, key, value) {
318
- return obj[key] = value;
319
- };
320
- }
321
-
322
- function wrap(innerFn, outerFn, self, tryLocsList) {
323
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
324
- generator = Object.create(protoGenerator.prototype),
325
- context = new Context(tryLocsList || []);
326
- return generator._invoke = function (innerFn, self, context) {
327
- var state = "suspendedStart";
328
- return function (method, arg) {
329
- if ("executing" === state) throw new Error("Generator is already running");
330
-
331
- if ("completed" === state) {
332
- if ("throw" === method) throw arg;
333
- return doneResult();
334
- }
335
-
336
- for (context.method = method, context.arg = arg;;) {
337
- var delegate = context.delegate;
338
-
339
- if (delegate) {
340
- var delegateResult = maybeInvokeDelegate(delegate, context);
341
-
342
- if (delegateResult) {
343
- if (delegateResult === ContinueSentinel) continue;
344
- return delegateResult;
345
- }
346
- }
347
-
348
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
349
- if ("suspendedStart" === state) throw state = "completed", context.arg;
350
- context.dispatchException(context.arg);
351
- } else "return" === context.method && context.abrupt("return", context.arg);
352
- state = "executing";
353
- var record = tryCatch(innerFn, self, context);
354
-
355
- if ("normal" === record.type) {
356
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
357
- return {
358
- value: record.arg,
359
- done: context.done
360
- };
361
- }
362
-
363
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
364
- }
365
- };
366
- }(innerFn, self, context), generator;
367
- }
368
-
369
- function tryCatch(fn, obj, arg) {
370
- try {
371
- return {
372
- type: "normal",
373
- arg: fn.call(obj, arg)
374
- };
375
- } catch (err) {
376
- return {
377
- type: "throw",
378
- arg: err
379
- };
380
- }
381
- }
382
-
383
- exports.wrap = wrap;
384
- var ContinueSentinel = {};
385
-
386
- function Generator() {}
387
-
388
- function GeneratorFunction() {}
389
-
390
- function GeneratorFunctionPrototype() {}
391
-
392
- var IteratorPrototype = {};
393
- define(IteratorPrototype, iteratorSymbol, function () {
394
- return this;
395
- });
396
- var getProto = Object.getPrototypeOf,
397
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
398
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
399
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
400
-
401
- function defineIteratorMethods(prototype) {
402
- ["next", "throw", "return"].forEach(function (method) {
403
- define(prototype, method, function (arg) {
404
- return this._invoke(method, arg);
405
- });
406
- });
407
- }
408
-
409
- function AsyncIterator(generator, PromiseImpl) {
410
- function invoke(method, arg, resolve, reject) {
411
- var record = tryCatch(generator[method], generator, arg);
412
-
413
- if ("throw" !== record.type) {
414
- var result = record.arg,
415
- value = result.value;
416
- return value && "object" == _typeof$1(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
417
- invoke("next", value, resolve, reject);
418
- }, function (err) {
419
- invoke("throw", err, resolve, reject);
420
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
421
- result.value = unwrapped, resolve(result);
422
- }, function (error) {
423
- return invoke("throw", error, resolve, reject);
424
- });
425
- }
426
-
427
- reject(record.arg);
428
- }
429
-
430
- var previousPromise;
431
-
432
- this._invoke = function (method, arg) {
433
- function callInvokeWithMethodAndArg() {
434
- return new PromiseImpl(function (resolve, reject) {
435
- invoke(method, arg, resolve, reject);
436
- });
437
- }
438
-
439
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
440
- };
441
- }
442
-
443
- function maybeInvokeDelegate(delegate, context) {
444
- var method = delegate.iterator[context.method];
445
-
446
- if (undefined === method) {
447
- if (context.delegate = null, "throw" === context.method) {
448
- if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
449
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
450
- }
451
-
452
- return ContinueSentinel;
453
- }
454
-
455
- var record = tryCatch(method, delegate.iterator, context.arg);
456
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
457
- var info = record.arg;
458
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
459
- }
460
-
461
- function pushTryEntry(locs) {
462
- var entry = {
463
- tryLoc: locs[0]
464
- };
465
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
466
- }
467
-
468
- function resetTryEntry(entry) {
469
- var record = entry.completion || {};
470
- record.type = "normal", delete record.arg, entry.completion = record;
471
- }
472
-
473
- function Context(tryLocsList) {
474
- this.tryEntries = [{
475
- tryLoc: "root"
476
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
477
- }
478
-
479
- function values(iterable) {
480
- if (iterable) {
481
- var iteratorMethod = iterable[iteratorSymbol];
482
- if (iteratorMethod) return iteratorMethod.call(iterable);
483
- if ("function" == typeof iterable.next) return iterable;
484
-
485
- if (!isNaN(iterable.length)) {
486
- var i = -1,
487
- next = function next() {
488
- for (; ++i < iterable.length;) {
489
- if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
490
- }
491
-
492
- return next.value = undefined, next.done = !0, next;
493
- };
494
-
495
- return next.next = next;
496
- }
497
- }
498
-
499
- return {
500
- next: doneResult
501
- };
502
- }
503
-
504
- function doneResult() {
505
- return {
506
- value: undefined,
507
- done: !0
508
- };
509
- }
510
-
511
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
512
- var ctor = "function" == typeof genFun && genFun.constructor;
513
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
514
- }, exports.mark = function (genFun) {
515
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
516
- }, exports.awrap = function (arg) {
517
- return {
518
- __await: arg
519
- };
520
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
521
- return this;
522
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
523
- void 0 === PromiseImpl && (PromiseImpl = Promise);
524
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
525
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
526
- return result.done ? result.value : iter.next();
527
- });
528
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
529
- return this;
530
- }), define(Gp, "toString", function () {
531
- return "[object Generator]";
532
- }), exports.keys = function (object) {
533
- var keys = [];
534
-
535
- for (var key in object) {
536
- keys.push(key);
537
- }
538
-
539
- return keys.reverse(), function next() {
540
- for (; keys.length;) {
541
- var key = keys.pop();
542
- if (key in object) return next.value = key, next.done = !1, next;
543
- }
544
-
545
- return next.done = !0, next;
546
- };
547
- }, exports.values = values, Context.prototype = {
548
- constructor: Context,
549
- reset: function reset(skipTempReset) {
550
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
551
- "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
552
- }
553
- },
554
- stop: function stop() {
555
- this.done = !0;
556
- var rootRecord = this.tryEntries[0].completion;
557
- if ("throw" === rootRecord.type) throw rootRecord.arg;
558
- return this.rval;
559
- },
560
- dispatchException: function dispatchException(exception) {
561
- if (this.done) throw exception;
562
- var context = this;
563
-
564
- function handle(loc, caught) {
565
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
566
- }
567
-
568
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
569
- var entry = this.tryEntries[i],
570
- record = entry.completion;
571
- if ("root" === entry.tryLoc) return handle("end");
572
-
573
- if (entry.tryLoc <= this.prev) {
574
- var hasCatch = hasOwn.call(entry, "catchLoc"),
575
- hasFinally = hasOwn.call(entry, "finallyLoc");
576
-
577
- if (hasCatch && hasFinally) {
578
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
579
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
580
- } else if (hasCatch) {
581
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
582
- } else {
583
- if (!hasFinally) throw new Error("try statement without catch or finally");
584
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
585
- }
586
- }
587
- }
588
- },
589
- abrupt: function abrupt(type, arg) {
590
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
591
- var entry = this.tryEntries[i];
592
-
593
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
594
- var finallyEntry = entry;
595
- break;
596
- }
597
- }
598
-
599
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
600
- var record = finallyEntry ? finallyEntry.completion : {};
601
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
602
- },
603
- complete: function complete(record, afterLoc) {
604
- if ("throw" === record.type) throw record.arg;
605
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
606
- },
607
- finish: function finish(finallyLoc) {
608
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
609
- var entry = this.tryEntries[i];
610
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
611
- }
612
- },
613
- "catch": function _catch(tryLoc) {
614
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
615
- var entry = this.tryEntries[i];
616
-
617
- if (entry.tryLoc === tryLoc) {
618
- var record = entry.completion;
619
-
620
- if ("throw" === record.type) {
621
- var thrown = record.arg;
622
- resetTryEntry(entry);
623
- }
624
-
625
- return thrown;
626
- }
627
- }
628
-
629
- throw new Error("illegal catch attempt");
630
- },
631
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
632
- return this.delegate = {
633
- iterator: values(iterable),
634
- resultName: resultName,
635
- nextLoc: nextLoc
636
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
637
- }
638
- }, exports;
639
- }
640
-
641
- module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
642
- } (regeneratorRuntime$1));
643
-
644
- // TODO(Babel 8): Remove this file.
645
-
646
- var runtime = regeneratorRuntime$1.exports();
647
-
648
- // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
649
- try {
650
- regeneratorRuntime = runtime;
651
- } catch (accidentalStrictMode) {
652
- if (typeof globalThis === "object") {
653
- globalThis.regeneratorRuntime = runtime;
654
- } else {
655
- Function("r", "regeneratorRuntime = r")(runtime);
656
- }
657
- }
658
-
659
- ramda.curry(function (func, event) {
660
- return func(event.target.value);
661
- });
662
-
663
- dayjs__default["default"].extend(relativeTime__default["default"]);
664
- dayjs__default["default"].extend(updateLocale__default["default"]);
665
-
666
- var _document$getElements, _document$getElements2;
667
- 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) || "{}"));
668
- deepFreezeObject(window.globalProps);
170
+ };
669
171
 
670
- var setAxiosDefaults = function setAxiosDefaults() {
671
- axios__default["default"].defaults.baseURL = "/";
672
- setAuthHeaders();
673
- registerIntercepts();
172
+ var shouldNot = function shouldNot(skip) {
173
+ return _typeof(skip) === "object" || !skip;
674
174
  };
675
175
 
676
176
  var setAuthHeaders = function setAuthHeaders() {
677
177
  var _globalProps$user, _globalProps$user2;
678
178
 
679
- axios__default["default"].defaults.headers = _defineProperty({
179
+ axios.defaults.headers = _defineProperty({
680
180
  Accept: "application/json",
681
181
  "Content-Type": "application/json"
682
182
  }, HEADERS_KEYS.xCsrfToken, document.querySelector('[name="csrf-token"]').getAttribute("content"));
@@ -684,78 +184,109 @@ var setAuthHeaders = function setAuthHeaders() {
684
184
  var email = (_globalProps$user2 = globalProps.user) === null || _globalProps$user2 === void 0 ? void 0 : _globalProps$user2.email;
685
185
 
686
186
  if (token && email) {
687
- axios__default["default"].defaults.headers[HEADERS_KEYS.xAuthEmail] = email;
688
- axios__default["default"].defaults.headers[HEADERS_KEYS.xAuthToken] = token;
187
+ axios.defaults.headers[HEADERS_KEYS.xAuthEmail] = email;
188
+ axios.defaults.headers[HEADERS_KEYS.xAuthToken] = token;
689
189
  }
190
+ }; // pipe function from ramda doesn't accept array of functions.
191
+ // We can't use spread operator too. So this is a workaround.
192
+
193
+
194
+ var createPipe = function createPipe(functions) {
195
+ return function (data) {
196
+ return functions.reduce(function (acc, fn) {
197
+ return fn(acc);
198
+ }, data);
199
+ };
690
200
  };
691
201
 
692
- var handleSuccessResponse = function handleSuccessResponse(response) {
693
- var _response$config = response.config,
694
- _response$config$tran = _response$config.transformResponseCase,
695
- transformResponseCase = _response$config$tran === void 0 ? true : _response$config$tran,
696
- _response$config$incl = _response$config.includeMetadataInResponse,
697
- includeMetadataInResponse = _response$config$incl === void 0 ? false : _response$config$incl,
698
- _response$config$show = _response$config.showToastr,
699
- showToastr = _response$config$show === void 0 ? true : _response$config$show;
202
+ var transformKeysToCamelCase = function transformKeysToCamelCase(response) {
203
+ var _response$config$tran = response.config.transformResponseCase,
204
+ transformResponseCase = _response$config$tran === void 0 ? true : _response$config$tran;
700
205
 
701
- if (response.data) {
702
- if (transformResponseCase) response.data = keysToCamelCase(response.data);
206
+ if (response.data && transformResponseCase) {
207
+ response.data = keysToCamelCase(response.data);
208
+ }
703
209
 
704
- if (showToastr && typeof response.data.notice === "string") {
705
- neetoui.Toastr.success(response.data.notice);
706
- }
210
+ return response;
211
+ };
212
+
213
+ var showSuccessToastr = function showSuccessToastr(response) {
214
+ var _response$config$show = response.config.showToastr,
215
+ showToastr = _response$config$show === void 0 ? true : _response$config$show;
216
+
217
+ if (showToastr && typeof response.data.notice === "string") {
218
+ Toastr.success(response.data.notice);
707
219
  }
708
220
 
221
+ return response;
222
+ };
223
+
224
+ var pullDataFromResponse = function pullDataFromResponse(response) {
225
+ var _response$config$incl = response.config.includeMetadataInResponse,
226
+ includeMetadataInResponse = _response$config$incl === void 0 ? false : _response$config$incl;
709
227
  return includeMetadataInResponse ? response : response.data;
710
228
  };
711
229
 
712
- var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse() {
230
+ var buildSuccessResponseHandler = function buildSuccessResponseHandler(skip) {
231
+ var interceptors = [];
232
+ if (!(skip !== null && skip !== void 0 && skip.transformCase)) interceptors.push(transformKeysToCamelCase);
233
+ if (!(skip !== null && skip !== void 0 && skip.showToastr)) interceptors.push(showSuccessToastr);
234
+ if (!(skip !== null && skip !== void 0 && skip.pullDataFromResponse)) interceptors.push(pullDataFromResponse);
235
+ return createPipe(interceptors);
236
+ };
237
+
238
+ var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(error) {
713
239
  resetAuthTokens();
714
240
  setTimeout(function () {
715
241
  var redirectTo = window.location.pathname === "/login" ? "/login" : "/login?redirect_uri=".concat(encodeURIComponent(window.location.href));
716
242
  window.location.href = redirectTo;
717
243
  }, 300);
244
+ return error;
718
245
  };
719
246
 
720
247
  var showErrorToastr = function showErrorToastr(error) {
721
- if (axios__default["default"].isCancel(error)) {
722
- neetoui.Toastr.error(i18next__default["default"].t("neetoCommons.toastr.error.requestCanceled"));
248
+ if (axios.isCancel(error)) {
249
+ Toastr.error(i18next.t("neetoCommons.toastr.error.requestCanceled"));
723
250
  } else if (error.message === "Network Error") {
724
- neetoui.Toastr.error(i18next__default["default"].t("neetoCommons.toastr.error.networkError"));
251
+ Toastr.error(i18next.t("neetoCommons.toastr.error.networkError"));
725
252
  } else {
726
- neetoui.Toastr.error(error);
253
+ Toastr.error(error);
727
254
  }
728
- };
729
255
 
730
- var handleErrorResponse = function handleErrorResponse(error) {
731
- var _error$response, _error$response2;
256
+ return error;
257
+ };
732
258
 
733
- var _error$config$showToa = error.config.showToastr,
734
- showToastr = _error$config$showToa === void 0 ? true : _error$config$showToa;
259
+ var redirect404 = function redirect404(error) {
260
+ var _error$response;
735
261
 
736
262
  if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 404) {
737
263
  window.location.href = "/page-not-found";
738
- } else if (((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) === 401) {
739
- handleUnauthorizedErrorResponse();
740
- } else if (showToastr) {
741
- showErrorToastr(error);
742
264
  }
743
265
 
744
- return Promise.reject(error);
266
+ return error;
267
+ };
268
+
269
+ var buildErrorResponseHandler = function buildErrorResponseHandler(skip) {
270
+ var interceptors = [];
271
+ if (!(skip !== null && skip !== void 0 && skip.redirectOn404)) interceptors.push(redirect404);
272
+ if (!(skip !== null && skip !== void 0 && skip.logoutOn401)) interceptors.push(handleUnauthorizedErrorResponse);
273
+ if (!(skip !== null && skip !== void 0 && skip.showToastr)) interceptors.push(showErrorToastr);
274
+ interceptors.push(Promise.reject);
275
+ return createPipe(interceptors);
745
276
  };
746
277
 
747
278
  var cleanupCredentialsForCrossOrigin = function cleanupCredentialsForCrossOrigin(request) {
748
279
  if (!request.url.includes("://")) return request;
749
280
  if (request.url.includes(window.location.hostname)) return request;
750
- return ramda.evolve({
751
- headers: ramda.omit(ramda.values(HEADERS_KEYS))
281
+ return evolve({
282
+ headers: omit(values(HEADERS_KEYS))
752
283
  })(request);
753
284
  };
754
285
 
755
286
  var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
756
287
  if (Array.isArray(object)) {
757
288
  return object.map(serializeKeysToSnakeCase);
758
- } else if (object === null || _typeof$1(object) !== "object") {
289
+ } else if (object === null || _typeof(object) !== "object") {
759
290
  return object;
760
291
  }
761
292
 
@@ -773,34 +304,54 @@ var transformDataToSnakeCase = function transformDataToSnakeCase(request) {
773
304
  var _request$transformReq = request.transformRequestCase,
774
305
  transformRequestCase = _request$transformReq === void 0 ? true : _request$transformReq;
775
306
  if (!transformRequestCase || !request.data) return request;
776
- return ramda.modify("data", serializeKeysToSnakeCase, request);
307
+ return modify("data", serializeKeysToSnakeCase, request);
777
308
  };
778
309
 
779
- var registerIntercepts = function registerIntercepts() {
780
- axios__default["default"].interceptors.request.use(ramda.pipe(cleanupCredentialsForCrossOrigin, transformDataToSnakeCase));
781
- axios__default["default"].interceptors.response.use(handleSuccessResponse, handleErrorResponse);
310
+ var addRequestInterceptors = function addRequestInterceptors(skip) {
311
+ if (!(skip !== null && skip !== void 0 && skip.cleanCredentialsForCrossOrigin)) {
312
+ axios.interceptors.request.use(cleanupCredentialsForCrossOrigin);
313
+ }
314
+
315
+ if (!(skip !== null && skip !== void 0 && skip.transformCase)) {
316
+ axios.interceptors.request.use(transformDataToSnakeCase);
317
+ }
782
318
  };
783
319
 
784
- setAxiosDefaults();
320
+ var addResponseInterceptors = function addResponseInterceptors(skip) {
321
+ axios.interceptors.response.use(buildSuccessResponseHandler(skip), buildErrorResponseHandler(skip));
322
+ };
785
323
 
786
- var isProduction = process.env.NODE_ENV === "production";
787
- var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
788
- var isUserLoggedIn = !ramda.either(ramda.isEmpty, ramda.isNil)(globalProps.user);
324
+ var registerIntercepts = function registerIntercepts(skip) {
325
+ if (shouldNot(skip === null || skip === void 0 ? void 0 : skip.request)) addRequestInterceptors(skip === null || skip === void 0 ? void 0 : skip.request);
326
+ if (shouldNot(skip === null || skip === void 0 ? void 0 : skip.response)) addResponseInterceptors(skip === null || skip === void 0 ? void 0 : skip.response);
327
+ };
789
328
 
790
- if (isProduction && isTokenPresent && isUserLoggedIn) {
791
- mixpanel__default["default"].init(process.env.MIXPANEL_TOKEN);
792
- mixpanel__default["default"].people.set({
793
- $email: globalProps.user.email,
794
- $fist_name: globalProps.user.firstName,
795
- $last_name: globalProps.user.lastName
796
- });
797
- mixpanel__default["default"].identify(globalProps.user.email);
798
- } else {
799
- /*
800
- We need to initialize mixpanel with a bogus token in development and test environment to
801
- prevent mixpanel library from throwing an error when we use mixpanel.track() method in react components.
802
- */
803
- mixpanel__default["default"].init("TEST_TOKEN");
329
+ function initializeAxios(skip) {
330
+ if (!(skip !== null && skip !== void 0 && skip.baseURL)) axios.defaults.baseURL = "/";
331
+ if (!(skip !== null && skip !== void 0 && skip.authHeaders)) setAuthHeaders();
332
+ if (shouldNot(skip === null || skip === void 0 ? void 0 : skip.interceptors)) registerIntercepts(skip === null || skip === void 0 ? void 0 : skip.interceptors);
333
+ }
334
+
335
+ function initializeMixPanel() {
336
+ var isProduction = process.env.NODE_ENV === "production";
337
+ var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
338
+ var isUserLoggedIn = !either(isEmpty, isNil)(globalProps.user);
339
+
340
+ if (isProduction && isTokenPresent && isUserLoggedIn) {
341
+ mixpanel.init(process.env.MIXPANEL_TOKEN || "");
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
+ }
804
355
  }
805
356
 
806
357
  var neetoCommons = {
@@ -843,8 +394,8 @@ var en = {
843
394
  };
844
395
 
845
396
  var initializeI18n = function initializeI18n(resources) {
846
- i18next__default["default"].use(reactI18next.initReactI18next).init({
847
- resources: ramda.mergeDeepLeft({
397
+ i18next.use(initReactI18next).init({
398
+ resources: mergeDeepLeft({
848
399
  en: {
849
400
  translation: en
850
401
  }
@@ -858,10 +409,23 @@ var initializeI18n = function initializeI18n(resources) {
858
409
  });
859
410
  };
860
411
 
861
- /* eslint-disable import/order */
412
+ var globalProps$1 = {};
862
413
  function initializeApplication(_ref) {
863
- var translationResources = _ref.translationResources;
864
- initializeI18n(translationResources);
414
+ var translationResources = _ref.translationResources,
415
+ skip = _ref.skip;
416
+
417
+ if (!(skip !== null && skip !== void 0 && skip.globalProps)) {
418
+ initializeGlobalProps();
419
+ globalProps$1 = window.globalProps;
420
+ }
421
+
422
+ if (!(skip !== null && skip !== void 0 && skip.mixpanel)) initializeMixPanel();
423
+
424
+ if (_typeof(skip === null || skip === void 0 ? void 0 : skip.axios) === "object" || !(skip !== null && skip !== void 0 && skip.axios)) {
425
+ initializeAxios(skip === null || skip === void 0 ? void 0 : skip.axios);
426
+ }
427
+
428
+ if (!(skip !== null && skip !== void 0 && skip.i18n)) initializeI18n(translationResources);
865
429
  }
866
430
 
867
- module.exports = initializeApplication;
431
+ export { initializeApplication as default, globalProps$1 as globalProps };