@qlibs/utils 1.7.4 → 1.8.0

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.
@@ -1,8 +1,8 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  export declare function injectAxiosInstance(axiosInstance: AxiosInstance, headers: 'application/json' | 'multipart/form-data' | string | {
3
3
  contentType: 'application/json' | 'multipart/form-data' | string;
4
- 'x-platform'?: 'cms' | 'web' | 'mobile';
5
- 'x-device-id': string;
6
- 'x-device-name': string;
7
- 'x-app-version': string;
4
+ 'X-Platform'?: 'cms' | 'web' | 'mobile';
5
+ 'X-Device-Id': string;
6
+ 'X-Device-Name': string;
7
+ 'X-App-Version': string;
8
8
  }, Modal: any): AxiosInstance;
@@ -2,13 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.injectAxiosInstance = injectAxiosInstance;
4
4
  const auth_1 = require("./auth");
5
+ const browser_1 = require("./browser");
5
6
  function injectAxiosInstance(axiosInstance, headers, Modal) {
6
7
  axiosInstance.interceptors.request.use(async (config) => {
7
- config.headers['Content-Type'] = (typeof headers === 'object' ? headers.contentType : headers) || 'application/json';
8
- config.headers['x-platform'] = headers['x-platform'] || 'cms';
9
- config.headers['x-device-id'] = headers['x-device-id'];
10
- config.headers['x-device-name'] = headers['x-device-name'];
11
- config.headers['x-app-version'] = headers['x-app-version'];
8
+ if (typeof headers === 'object') {
9
+ config.headers['Content-Type'] =
10
+ headers.contentType || 'application/json';
11
+ config.headers['X-Platform'] = headers['X-Platform'] || 'cms';
12
+ config.headers['X-Device-Id'] = headers['X-Device-Id'];
13
+ config.headers['X-Device-Name'] = headers['X-Device-Name'];
14
+ config.headers['X-App-Version'] = headers['X-App-Version'];
15
+ }
16
+ else {
17
+ config.headers['Content-Type'] =
18
+ headers || 'application/json';
19
+ config.headers['X-Platform'] = 'cms';
20
+ config.headers['X-Device-Id'] = (0, browser_1.getBrowserId)();
21
+ config.headers['X-Device-Name'] = (0, browser_1.getBrowserName)();
22
+ config.headers['X-App-Version'] = '0.0.0';
23
+ }
12
24
  config.headers['Authorization'] = 'Bearer ' + (0, auth_1.getToken)();
13
25
  return config;
14
26
  }, (error) => {
@@ -0,0 +1,2 @@
1
+ export declare function getBrowserName(): string;
2
+ export declare function getBrowserId(): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getBrowserName = getBrowserName;
7
+ exports.getBrowserId = getBrowserId;
8
+ const ets_fingerprintjs_1 = require("ets-fingerprintjs");
9
+ const bowser_1 = __importDefault(require("bowser"));
10
+ function getBrowserName() {
11
+ const browser = bowser_1.default.getParser(window.navigator.userAgent);
12
+ return `${browser.getBrowserName()} ${browser.getBrowserVersion()} on ${browser.getOSName()} ${browser.getOSVersion()}`;
13
+ }
14
+ function getBrowserId() {
15
+ return ets_fingerprintjs_1.uid.toString();
16
+ }
@@ -1,14 +1,16 @@
1
- export * from './auth';
2
- export * from './axios';
3
- export * from './datetime';
4
- export * from './errorHandler';
5
- export * from './formRules';
6
- export * from './generateQueryString';
7
- export * from './image';
8
- export * from './name';
9
- export * from './number';
10
- export * from './order';
11
- export * from './pagination';
12
- export * from './price';
13
- export * from './text';
14
- export * from './formHandler';
1
+ export * from "./auth";
2
+ export * from "./axios";
3
+ export * from "./datetime";
4
+ export * from "./errorHandler";
5
+ export * from "./formRules";
6
+ export * from "./generateQueryString";
7
+ export * from "./image";
8
+ export * from "./name";
9
+ export * from "./number";
10
+ export * from "./order";
11
+ export * from "./pagination";
12
+ export * from "./price";
13
+ export * from "./text";
14
+ export * from "./formHandler";
15
+ export * from "./browser";
16
+ export * from "./passwordExpiry";
@@ -28,3 +28,5 @@ __exportStar(require("./pagination"), exports);
28
28
  __exportStar(require("./price"), exports);
29
29
  __exportStar(require("./text"), exports);
30
30
  __exportStar(require("./formHandler"), exports);
31
+ __exportStar(require("./browser"), exports);
32
+ __exportStar(require("./passwordExpiry"), exports);
@@ -0,0 +1,5 @@
1
+ export declare const savePasswordExpiry: (expiryDate: Date, isExpired: boolean) => void;
2
+ export declare const getPasswordExpiry: () => {
3
+ passwordExpiredAt: Date;
4
+ isPasswordExpired: boolean;
5
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPasswordExpiry = exports.savePasswordExpiry = void 0;
4
+ const exp = "passwordExpiry";
5
+ const expiredAt = "passwordExpiredAt";
6
+ const expiredStatus = "isPasswordExpired";
7
+ const savePasswordExpiry = (expiryDate, isExpired) => {
8
+ const data = {
9
+ [expiredAt]: expiryDate,
10
+ [expiredStatus]: isExpired,
11
+ };
12
+ localStorage.setItem(exp, JSON.stringify(data));
13
+ };
14
+ exports.savePasswordExpiry = savePasswordExpiry;
15
+ const getPasswordExpiry = () => {
16
+ const data = localStorage.getItem(exp);
17
+ if (data) {
18
+ const parsedData = JSON.parse(data);
19
+ return {
20
+ [expiredAt]: new Date(parsedData[expiredAt]),
21
+ [expiredStatus]: Boolean(parsedData[expiredStatus]),
22
+ };
23
+ }
24
+ return null;
25
+ };
26
+ exports.getPasswordExpiry = getPasswordExpiry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlibs/utils",
3
- "version": "1.7.4",
3
+ "version": "1.8.0",
4
4
  "description": "",
5
5
  "author": "QBIT Developer",
6
6
  "license": "MIT",
@@ -26,6 +26,8 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "axios": "^1.7.9",
29
+ "bowser": "^2.11.0",
30
+ "ets-fingerprintjs": "^1.8.0",
29
31
  "husky": "^8.0.3",
30
32
  "image-blob-reduce": "^4.1.0",
31
33
  "immutability-helper": "^3.1.1",