iboot-http-client 1.2.4 → 1.2.6

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,23 +1,6 @@
1
- import { ClientGetParams, ClientPostParams, CurWebsite, HttpClientOpts, HttpToken, ResultModel, ServerRequestOptions, ICookies, IStorage } from './types/http';
1
+ import { ClientGetParams, ClientPostParams, CurWebsite, ServerHttpOpts, HttpToken, ResultModel, ServerRequestOptions, ICookies, IStorage, ServerHttpOptsMin } from './types/http';
2
2
  import { User } from './types/user';
3
- export declare const DEFAULT_LOCALE = "zh-CN";
4
- export declare const DEVICE_ID_KEY = "_device_id_key";
5
- export declare const CURRENT_WEBSITE_KEY = "_current_website_key";
6
- export declare const COOKIE_NAMES: {
7
- IBOOT_DEVICE_ID: string;
8
- IBOOT_LANG: string;
9
- IBOOT_WEBSITE_ID: string;
10
- IBOOT_WEBSITE_NO: string;
11
- IBOOT_TOKEN: string;
12
- IBOOT_USER: string;
13
- };
14
- export declare const HEADER_NAMES: {
15
- DEVICE_ID: string;
16
- LANG: string;
17
- WEBSITE_ID: string;
18
- WEBSITE_NO: string;
19
- };
20
- export declare const setDefaultRequestHeader: ({ deviceId, website }: Readonly<{
3
+ export declare const setClientRequestHeader: ({ deviceId, website }: Readonly<{
21
4
  deviceId: string;
22
5
  website?: CurWebsite;
23
6
  }>, storage: IStorage) => void;
@@ -26,7 +9,10 @@ export declare const post: <T>(url: string, opts?: ClientPostParams) => Promise<
26
9
  export declare const iGet: <T>(url: string, opts?: ClientGetParams) => Promise<T | undefined>;
27
10
  export declare const iPost: <T>(url: string, opts?: ClientPostParams) => Promise<T | undefined>;
28
11
  export declare const iPostSuccess: (url: string, opts?: ClientPostParams) => Promise<boolean>;
29
- export declare const getHttpOpts: (storage: IStorage) => HttpClientOpts;
12
+ export declare const getServerHttpOpts: (storage: IStorage) => ServerHttpOptsMin;
13
+ export declare const setServerHttpHeaders: (storage: IStorage, opts: ServerHttpOptsMin) => void;
14
+ export declare const getServerHttpCookies: (cookies: ICookies) => ServerHttpOptsMin;
15
+ export declare const setServerHttpCookies: (cookies: ICookies, opts: ServerHttpOptsMin) => void;
30
16
  export declare const getLoginUser: (cookies: ICookies) => User | undefined;
31
17
  export declare const getToken: (cookies: ICookies) => HttpToken | undefined;
32
18
  export declare const setToken: (data: User & {
@@ -44,7 +30,7 @@ export declare class HttpClient {
44
30
  private readonly lang;
45
31
  private readonly websiteId?;
46
32
  private readonly websiteNo?;
47
- constructor(opts: Readonly<HttpClientOpts>);
33
+ constructor(opts: Readonly<ServerHttpOpts>);
48
34
  encrypt(data: string): string;
49
35
  decrypt(data: string): string;
50
36
  private convertUrlParameter;
@@ -6,7 +6,10 @@ export type CSRFToken = {
6
6
  csrfToken: string;
7
7
  csrfHeader: string;
8
8
  };
9
- export type HttpClientOpts = {
9
+ /**
10
+ * 服务端HttpClient构造函数形参
11
+ */
12
+ export type ServerHttpOpts = {
10
13
  "deviceId"?: string;
11
14
  "lang"?: string;
12
15
  "websiteId"?: string;
@@ -14,7 +17,11 @@ export type HttpClientOpts = {
14
17
  "userType"?: USER_TYPE;
15
18
  "helloURL"?: string;
16
19
  };
17
- export type HttpHeaders = {
20
+ export type ServerHttpOptsMin = Omit<ServerHttpOpts, 'userType' | 'helloURL'>;
21
+ /**
22
+ * 客户端HTTP请求请求头
23
+ */
24
+ export type ClientHttpHeaders = {
18
25
  "Device-Id"?: string;
19
26
  "Website-Id"?: string;
20
27
  "Website-No"?: string;
@@ -27,11 +34,17 @@ export type HttpToken = {
27
34
  xcsrf?: CSRFToken;
28
35
  };
29
36
  export type ResultStream = ReadableStream<Uint8Array>;
37
+ /**
38
+ * 当前访问网站形参
39
+ */
30
40
  export type CurWebsite = {
31
41
  websiteId?: string;
32
42
  websiteNo?: string;
33
43
  language: string;
34
44
  };
45
+ /**
46
+ * HTTP请求出参
47
+ */
35
48
  export interface ResultModel<T> {
36
49
  code: number;
37
50
  success: boolean;
@@ -41,6 +54,9 @@ export interface ResultModel<T> {
41
54
  errorCode?: string;
42
55
  headers?: Record<string, string>;
43
56
  }
57
+ /**
58
+ * 客户端GET形参
59
+ */
44
60
  export interface ClientGetParams {
45
61
  data?: Record<string, string>;
46
62
  useCache?: boolean;
@@ -48,6 +64,9 @@ export interface ClientGetParams {
48
64
  showError?: (error: string) => void;
49
65
  storage?: IStorage;
50
66
  }
67
+ /**
68
+ * 客户端POST形参
69
+ */
51
70
  export interface ClientPostParams {
52
71
  data?: Record<string, string> | FormData | UIFormEntities;
53
72
  headers?: Record<string, string>;
@@ -55,12 +74,18 @@ export interface ClientPostParams {
55
74
  showError?: (error: string) => void;
56
75
  showSuccess?: (msg: string) => void;
57
76
  }
77
+ /**
78
+ * 服务端HttpClient GET/POST 请求形参
79
+ */
58
80
  export type ServerRequestOptions = {
59
81
  url: string;
60
82
  data?: Record<string, any>;
61
83
  token?: Readonly<HttpToken>;
62
84
  cache?: RequestCache;
63
85
  };
86
+ /**
87
+ * ICookies存,取,删
88
+ */
64
89
  export interface ICookies {
65
90
  get?: (key: string) => string | null | undefined;
66
91
  set?: (key: string, value: string, opts?: {
@@ -68,6 +93,9 @@ export interface ICookies {
68
93
  }) => void;
69
94
  delete?: (key: string) => void;
70
95
  }
96
+ /**
97
+ * 存贮器
98
+ */
71
99
  export interface IStorage {
72
100
  get?: (key: string) => string | null | undefined;
73
101
  set?: (key: string, value: string) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "iboot-http-client",
3
3
  "private": false,
4
- "version": "1.2.4",
4
+ "version": "1.2.6",
5
5
  "description": "iBoot.xin 相关应用的客户端Http封装",
6
6
  "type": "module",
7
7
  "main": "./dist/iboot-http-client.cjs.js",