@nano-lib/util 1.1.5 → 1.1.7

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/lib/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { parseTime, getTimeDistance, getDayRange } from './utils/date';
4
4
  import { addClass, removeClass, hasClass, toggleClass, noContextmenu, useRafThrottle } from './utils/element';
5
5
  import { encodeURIToParams, paramsToQueryString, queryStringToParams, errorCodeToString, YNToString, HNToString, valueToLabel, chargeToLabel, cascaderToLabel, multipleSelectToLabel, phoneToAsterisk, idNumberToAsterisk, firstLetterToUpperCase, firstLetterToLowerCase } from './utils/to';
6
6
  import { validHttp, validExternal, validString, validNumberStr, validEmptyObject, validURL, validPassword, validEmail, validIdNumber, validPhone, validTel } from './utils/valid';
7
- export { default as Request } from './utils/request/request';
7
+ export { default as Request } from './utils/request/index';
8
8
  export { default as NetworkManager } from './utils/request/network';
9
9
  export { default as TokenManager } from './utils/request/token';
10
10
  export { default as getRequestBaseUrl } from './utils/baseUrl';
@@ -1,4 +1,4 @@
1
- import { AnyObj } from '../../types';
1
+ import { AnyObj } from '.';
2
2
  import { AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios';
3
3
  export interface RequestOptions {
4
4
  showLoading?: boolean;
@@ -40,13 +40,12 @@ export interface PendingRequest {
40
40
  resolve: (value: any) => void;
41
41
  reject: (reason?: any) => void;
42
42
  }
43
- export interface ToastInstanceType<T = AnyObj> {
44
- show(message: string, type: 'success' | 'warning' | 'info' | 'error', options: T): void;
45
- success(message: string, options?: T): void;
46
- error(message: string, options?: T): void;
47
- warning(message: string, options?: T): void;
48
- info(message: string, options?: T): void;
49
- confirm(message: string, title: string, options: T): Promise<boolean>;
43
+ export interface ToastInstanceType<T extends string = string, U extends AnyObj = AnyObj> {
44
+ show(message: string, type: T, options: U): void;
45
+ success(message: string, options?: U): void;
46
+ error(message: string, options?: U): void;
47
+ warning(message: string, options?: U): void;
48
+ info(message: string, options?: U): void;
50
49
  clear(): void;
51
50
  }
52
51
  export interface LoadingOptions {
@@ -61,8 +60,8 @@ export interface LoadingInstanceType {
61
60
  forceHide(): void;
62
61
  isLoading(): boolean;
63
62
  }
64
- export interface RequestConstructorOptions extends RequestConfig {
65
- toastInstance: ToastInstanceType;
63
+ export interface RequestConstructorOptions<T extends string, U extends AnyObj> extends RequestConfig {
64
+ toastInstance: ToastInstanceType<T, U>;
66
65
  loadingInstance?: LoadingInstanceType;
67
66
  }
68
67
  export interface BaseResponse<T = any> {
@@ -1,4 +1,4 @@
1
- import { CustomInternalAxiosRequestConfig } from './types';
1
+ import { CustomInternalAxiosRequestConfig } from '../../types/request';
2
2
  export default class CancelManager {
3
3
  private pendingMap;
4
4
  private generateRequestKey;
@@ -1,5 +1,5 @@
1
1
  import { AxiosError } from 'axios';
2
- import { ToastInstanceType } from './types';
2
+ import { ToastInstanceType } from '../../types/request';
3
3
  export default class ErrorManager {
4
4
  private toastInstance;
5
5
  constructor(toastInstance: ToastInstanceType);
@@ -1,6 +1,7 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
- import { RequestConstructorOptions, RequestOptions, RequestParams } from './types';
3
- export default class Request {
2
+ import { AnyObj } from '../../types';
3
+ import { RequestConstructorOptions, RequestOptions, RequestParams } from '../../types/request';
4
+ export default class Request<ToastType extends string = string, ToastOptions extends AnyObj = AnyObj> {
4
5
  private axiosInstance;
5
6
  private errorInstance;
6
7
  private networkInstance;
@@ -11,7 +12,7 @@ export default class Request {
11
12
  private requestInstanceRequestOptions;
12
13
  private defaultRequestOptions;
13
14
  private defaultConfig;
14
- constructor(options: RequestConstructorOptions);
15
+ constructor(options: RequestConstructorOptions<ToastType, ToastOptions>);
15
16
  private setupNetworkListener;
16
17
  private setupInterceptors;
17
18
  private refreshTokenInBackend;
@@ -1,5 +1,5 @@
1
- import { NetworkStatus, PendingRequest, ToastInstanceType } from './types';
2
- export default class NetworkManager {
1
+ import { NetworkStatus, PendingRequest, ToastInstanceType } from '../../types/request';
2
+ export default class NetworkManage {
3
3
  private toastInstance;
4
4
  private status;
5
5
  private offlineQueue;
@@ -1,4 +1,4 @@
1
- import { PromiseResponse, TokenInfo } from './types';
1
+ import { PromiseResponse, TokenInfo } from '../../types/request';
2
2
  export default class TokenManager {
3
3
  private TOKEN_KEY;
4
4
  private REFRESH_TOKEN_KEY;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nano-lib/util",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Custom utility functions for the nano library",
5
5
  "author": "xylo",
6
6
  "license": "MIT",