@bigbinary/neeto-commons-frontend 2.0.105 → 2.0.106
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/package.json +3 -2
- package/react-utils.cjs.js +109 -41
- package/react-utils.cjs.js.map +1 -1
- package/react-utils.d.ts +78 -11
- package/react-utils.js +108 -42
- package/react-utils.js.map +1 -1
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.106",
|
|
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>",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@babel/types": "^7.20.7",
|
|
79
79
|
"@bigbinary/babel-preset-neeto": "^1.0.3",
|
|
80
80
|
"@bigbinary/eslint-plugin-neeto": "^1.1.1",
|
|
81
|
-
"@bigbinary/neeto-commons-frontend": "2.0.
|
|
81
|
+
"@bigbinary/neeto-commons-frontend": "^2.0.104",
|
|
82
82
|
"@bigbinary/neeto-icons": "^1.9.15",
|
|
83
83
|
"@bigbinary/neeto-molecules": "^1.0.9",
|
|
84
84
|
"@bigbinary/neetoui": "^4.4.9",
|
|
@@ -137,6 +137,7 @@
|
|
|
137
137
|
"mixpanel-browser": "^2.45.0",
|
|
138
138
|
"mousetrap": "^1.6.5",
|
|
139
139
|
"mousetrap-global-bind": "^1.1.0",
|
|
140
|
+
"nock": "^13.3.2",
|
|
140
141
|
"platform": "1.3.6",
|
|
141
142
|
"postcss": "^8.4.17",
|
|
142
143
|
"postcss-import": "^15.0.0",
|
package/react-utils.cjs.js
CHANGED
|
@@ -10,6 +10,7 @@ var reactI18next = require('react-i18next');
|
|
|
10
10
|
var ErrorPage = require('@bigbinary/neeto-molecules/ErrorPage');
|
|
11
11
|
var reactRouterDom = require('react-router-dom');
|
|
12
12
|
var axios = require('axios');
|
|
13
|
+
var reactQuery = require('react-query');
|
|
13
14
|
var reactHelmet = require('react-helmet');
|
|
14
15
|
|
|
15
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -213,6 +214,112 @@ var PrivateRoute = function PrivateRoute(_ref) {
|
|
|
213
214
|
});
|
|
214
215
|
};
|
|
215
216
|
|
|
217
|
+
function _typeof$1(obj) {
|
|
218
|
+
"@babel/helpers - typeof";
|
|
219
|
+
|
|
220
|
+
return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
221
|
+
return typeof obj;
|
|
222
|
+
} : function (obj) {
|
|
223
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
224
|
+
}, _typeof$1(obj);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function _toPrimitive(input, hint) {
|
|
228
|
+
if (_typeof$1(input) !== "object" || input === null) return input;
|
|
229
|
+
var prim = input[Symbol.toPrimitive];
|
|
230
|
+
if (prim !== undefined) {
|
|
231
|
+
var res = prim.call(input, hint || "default");
|
|
232
|
+
if (_typeof$1(res) !== "object") return res;
|
|
233
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
234
|
+
}
|
|
235
|
+
return (hint === "string" ? String : Number)(input);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function _toPropertyKey(arg) {
|
|
239
|
+
var key = _toPrimitive(arg, "string");
|
|
240
|
+
return _typeof$1(key) === "symbol" ? key : String(key);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function _defineProperty(obj, key, value) {
|
|
244
|
+
key = _toPropertyKey(key);
|
|
245
|
+
if (key in obj) {
|
|
246
|
+
Object.defineProperty(obj, key, {
|
|
247
|
+
value: value,
|
|
248
|
+
enumerable: true,
|
|
249
|
+
configurable: true,
|
|
250
|
+
writable: true
|
|
251
|
+
});
|
|
252
|
+
} else {
|
|
253
|
+
obj[key] = value;
|
|
254
|
+
}
|
|
255
|
+
return obj;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
var fetch = function fetch() {
|
|
259
|
+
return axios__default["default"].get("/api/v1/neeto_apps");
|
|
260
|
+
};
|
|
261
|
+
var neetoAppsApi = {
|
|
262
|
+
fetch: fetch
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
var QUERY_KEYS = {
|
|
266
|
+
NEETO_APPS_LIST: "neeto-apps-list"
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
var QUERY_CACHE_NAME_SPACE = "queryCache";
|
|
270
|
+
var NEETO_APPS_LIST_STALE_TIME = 30 * 24 * 60 * 60 * 1000; // 30 days
|
|
271
|
+
|
|
272
|
+
function ownKeys$1(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; }
|
|
273
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
274
|
+
var localStorageQueryCache = {
|
|
275
|
+
set: function set(key, data) {
|
|
276
|
+
var cache = localStorageQueryCache.getAll();
|
|
277
|
+
var newCache = _objectSpread$1(_objectSpread$1({}, cache), {}, _defineProperty({}, key, {
|
|
278
|
+
data: data,
|
|
279
|
+
modifiedAt: Date.now()
|
|
280
|
+
}));
|
|
281
|
+
localStorage.setItem(QUERY_CACHE_NAME_SPACE, JSON.stringify(newCache));
|
|
282
|
+
},
|
|
283
|
+
getAll: function getAll() {
|
|
284
|
+
var cache = localStorage.getItem(QUERY_CACHE_NAME_SPACE);
|
|
285
|
+
if (!cache) return {};
|
|
286
|
+
return JSON.parse(cache);
|
|
287
|
+
},
|
|
288
|
+
get: function get(key) {
|
|
289
|
+
return localStorageQueryCache.getAll()[key];
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
var isOutdated = function isOutdated(localCache, staleTime) {
|
|
293
|
+
if (ramda.isNil(localCache)) return true;
|
|
294
|
+
if (ramda.isNil(staleTime)) return false;
|
|
295
|
+
return localCache.modifiedAt <= Date.now() - staleTime;
|
|
296
|
+
};
|
|
297
|
+
var usePersistedQuery = function usePersistedQuery(queryKey, fetch, options) {
|
|
298
|
+
var queryResult = reactQuery.useQuery(queryKey, fetch, options);
|
|
299
|
+
var localCache = localStorageQueryCache.get(queryKey);
|
|
300
|
+
React.useEffect(function () {
|
|
301
|
+
if (!queryResult.isSuccess) return;
|
|
302
|
+
localStorageQueryCache.set(queryKey, queryResult.data);
|
|
303
|
+
}, [queryKey, queryResult.data, queryResult.isSuccess]);
|
|
304
|
+
if (isOutdated(localCache, options === null || options === void 0 ? void 0 : options.staleTime)) {
|
|
305
|
+
return _objectSpread$1(_objectSpread$1({}, queryResult), {}, {
|
|
306
|
+
isFreshLoading: queryResult.isLoading
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return _objectSpread$1(_objectSpread$1({}, queryResult), {}, {
|
|
310
|
+
data: queryResult.data || localCache.data,
|
|
311
|
+
isFreshLoading: false
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
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; }
|
|
316
|
+
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; }
|
|
317
|
+
var useFetchNeetoApps = function useFetchNeetoApps(options) {
|
|
318
|
+
return usePersistedQuery(QUERY_KEYS.NEETO_APPS_LIST, neetoAppsApi.fetch, _objectSpread({
|
|
319
|
+
staleTime: NEETO_APPS_LIST_STALE_TIME
|
|
320
|
+
}, options));
|
|
321
|
+
};
|
|
322
|
+
|
|
216
323
|
function _arrayWithHoles(arr) {
|
|
217
324
|
if (Array.isArray(arr)) return arr;
|
|
218
325
|
}
|
|
@@ -3482,47 +3589,6 @@ var usePrevious = function usePrevious(value) {
|
|
|
3482
3589
|
return ref.current;
|
|
3483
3590
|
};
|
|
3484
3591
|
|
|
3485
|
-
function _typeof$1(obj) {
|
|
3486
|
-
"@babel/helpers - typeof";
|
|
3487
|
-
|
|
3488
|
-
return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
3489
|
-
return typeof obj;
|
|
3490
|
-
} : function (obj) {
|
|
3491
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
3492
|
-
}, _typeof$1(obj);
|
|
3493
|
-
}
|
|
3494
|
-
|
|
3495
|
-
function _toPrimitive(input, hint) {
|
|
3496
|
-
if (_typeof$1(input) !== "object" || input === null) return input;
|
|
3497
|
-
var prim = input[Symbol.toPrimitive];
|
|
3498
|
-
if (prim !== undefined) {
|
|
3499
|
-
var res = prim.call(input, hint || "default");
|
|
3500
|
-
if (_typeof$1(res) !== "object") return res;
|
|
3501
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
3502
|
-
}
|
|
3503
|
-
return (hint === "string" ? String : Number)(input);
|
|
3504
|
-
}
|
|
3505
|
-
|
|
3506
|
-
function _toPropertyKey(arg) {
|
|
3507
|
-
var key = _toPrimitive(arg, "string");
|
|
3508
|
-
return _typeof$1(key) === "symbol" ? key : String(key);
|
|
3509
|
-
}
|
|
3510
|
-
|
|
3511
|
-
function _defineProperty(obj, key, value) {
|
|
3512
|
-
key = _toPropertyKey(key);
|
|
3513
|
-
if (key in obj) {
|
|
3514
|
-
Object.defineProperty(obj, key, {
|
|
3515
|
-
value: value,
|
|
3516
|
-
enumerable: true,
|
|
3517
|
-
configurable: true,
|
|
3518
|
-
writable: true
|
|
3519
|
-
});
|
|
3520
|
-
} else {
|
|
3521
|
-
obj[key] = value;
|
|
3522
|
-
}
|
|
3523
|
-
return obj;
|
|
3524
|
-
}
|
|
3525
|
-
|
|
3526
3592
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3527
3593
|
try {
|
|
3528
3594
|
var info = gen[key](arg);
|
|
@@ -4754,6 +4820,7 @@ exports.registerBrowserNotifications = registerBrowserNotifications;
|
|
|
4754
4820
|
exports.useDebounce = useDebounce;
|
|
4755
4821
|
exports.useDisplayErrorPage = useDisplayErrorPage;
|
|
4756
4822
|
exports.useErrorDisplayStore = useErrorDisplayStore;
|
|
4823
|
+
exports.useFetchNeetoApps = useFetchNeetoApps;
|
|
4757
4824
|
exports.useFuncDebounce = useFuncDebounce;
|
|
4758
4825
|
exports.useHotKeys = useHotKeys;
|
|
4759
4826
|
exports.useIsElementVisibleInDom = useIsElementVisibleInDom;
|
|
@@ -4761,6 +4828,7 @@ exports.useKeyboardShortcutsPaneState = useKeyboardShortcutsPaneState;
|
|
|
4761
4828
|
exports.useLocalStorage = useLocalStorage;
|
|
4762
4829
|
exports.useNavigationCheckpoints = useNavigationCheckpoints;
|
|
4763
4830
|
exports.useOnClickOutside = useOnClickOutside;
|
|
4831
|
+
exports.usePersistedQuery = usePersistedQuery;
|
|
4764
4832
|
exports.usePrevious = usePrevious;
|
|
4765
4833
|
exports.useRegisterNavigationCheckpoint = useRegisterNavigationCheckpoint;
|
|
4766
4834
|
exports.useStateWithDependency = useStateWithDependency;
|