iboot-http-client 1.0.0 → 1.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/dist/iboot-http-client.cjs.js +1 -3
- package/dist/iboot-http-client.cjs.js.map +1 -1
- package/dist/iboot-http-client.es.js +107 -5637
- package/dist/iboot-http-client.es.js.map +1 -1
- package/dist/iboot-http-client.umd.js +1 -3
- package/dist/iboot-http-client.umd.js.map +1 -1
- package/dist/types/{HttpClient.d.ts → http-client.d.ts} +11 -7
- package/dist/types/index.d.ts +3 -432
- package/dist/types/types/http.d.ts +90 -0
- package/dist/types/types/user.d.ts +48 -0
- package/dist/types/utils.d.ts +1 -23
- package/package.json +12 -9
- package/README.en.md +0 -36
- package/dist/vite.svg +0 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ClientGetParams, ClientPostParams, CurWebsite, HttpClientOpts, HttpToken, IbootCookieStore, IbootReadonlyCookies, IbootWritableCookie, ResultModel } from './types/http';
|
|
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 setDefaultRequestHeader: (deviceId: string, website?: CurWebsite) => void;
|
|
3
7
|
export declare const get: <T>(url: string, opts?: ClientGetParams) => Promise<ResultModel<T>>;
|
|
4
8
|
export declare const iGet: <T>(url: string, opts?: ClientGetParams) => Promise<T | undefined>;
|
|
5
9
|
export declare const post: <T>(url: string, opts?: ClientPostParams) => Promise<ResultModel<T>>;
|
|
6
10
|
export declare const iPost: <T>(url: string, opts?: ClientPostParams) => Promise<T | undefined>;
|
|
7
11
|
export declare const iPostSuccess: (url: string, opts?: ClientPostParams) => Promise<boolean>;
|
|
8
|
-
export declare const getHttpClientOpts: (request: Request) =>
|
|
9
|
-
export declare const
|
|
10
|
-
export
|
|
11
|
-
export declare class HttpClient {
|
|
12
|
+
export declare const getHttpClientOpts: (request: Request) => HttpClientOpts;
|
|
13
|
+
export declare const getHttpClientOptsByCookie: (cookie: IbootReadonlyCookies) => HttpClientOpts;
|
|
14
|
+
export default class HttpClient {
|
|
12
15
|
private readonly baseUrl;
|
|
13
16
|
private readonly apiKey;
|
|
14
17
|
private readonly userType;
|
|
@@ -19,7 +22,8 @@ export declare class HttpClient {
|
|
|
19
22
|
private readonly websiteId?;
|
|
20
23
|
private readonly websiteNo?;
|
|
21
24
|
private readonly _isDebug;
|
|
22
|
-
|
|
25
|
+
private readonly logger;
|
|
26
|
+
constructor({ deviceId, lang, websiteId, websiteNo, userType }: Readonly<HttpClientOpts>);
|
|
23
27
|
isDebug(): boolean;
|
|
24
28
|
encrypt(data: string): string;
|
|
25
29
|
decrypt(data: string): string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,432 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
PHONE : 1,
|
|
5
|
-
EMAIL : 2
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
declare const USER_TYPE: {
|
|
9
|
-
TYPE_MGT : 0,
|
|
10
|
-
TYPE_C : 1,
|
|
11
|
-
TYPE_B : 2
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
declare const USER_FORM: {
|
|
15
|
-
FROM_WEB : 1,
|
|
16
|
-
FROM_PC : 2,
|
|
17
|
-
FROM_WX_MINI_PRO : 3,
|
|
18
|
-
FROM_WX_PLU : 4,
|
|
19
|
-
FROM_WX_E : 5,
|
|
20
|
-
FROM_APP : 6,
|
|
21
|
-
FROM_DEVICE : 7
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare const USER_SEX: {
|
|
25
|
-
unknown:0,
|
|
26
|
-
male:1,
|
|
27
|
-
female:2,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare type ACCOUNT_TYPE = typeof ACCOUNT_TYPE[keyof typeof ACCOUNT_TYPE];
|
|
31
|
-
declare type USER_TYPE = typeof USER_TYPE[keyof typeof USER_TYPE];
|
|
32
|
-
declare type USER_FORM = typeof USER_FORM[keyof typeof USER_FORM];
|
|
33
|
-
declare type USER_SEX = typeof USER_SEX[keyof typeof USER_SEX];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
declare interface User {
|
|
37
|
-
id: string,
|
|
38
|
-
status: 0 | 1
|
|
39
|
-
name: string,
|
|
40
|
-
sex: USER_SEX,
|
|
41
|
-
username: string,
|
|
42
|
-
phone?: string,
|
|
43
|
-
email?: string,
|
|
44
|
-
accountType: ACCOUNT_TYPE,
|
|
45
|
-
birthday?: string,
|
|
46
|
-
headImg?: string,
|
|
47
|
-
nickname?: string,
|
|
48
|
-
motto?: string,
|
|
49
|
-
enabled: boolean,
|
|
50
|
-
userType: USER_TYPE,
|
|
51
|
-
userFrom: USER_FORM,
|
|
52
|
-
needToReview: boolean,
|
|
53
|
-
socketOnline: boolean,
|
|
54
|
-
unionId?: string,
|
|
55
|
-
openId?: string,
|
|
56
|
-
wxPid?: string,
|
|
57
|
-
createTime: string,
|
|
58
|
-
lastLoginTime?: string,
|
|
59
|
-
lastLogoutTime?: string,
|
|
60
|
-
latitude?: number,
|
|
61
|
-
longitude?: number,
|
|
62
|
-
deviceId?: string,
|
|
63
|
-
tokenExpired?:number,
|
|
64
|
-
mustChangePwd?:boolean
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare type CurWebsite = {
|
|
68
|
-
websiteId?:string,
|
|
69
|
-
websiteNo?:string,
|
|
70
|
-
language:string,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
declare type CSRFToken = {
|
|
74
|
-
csrfToken: string,
|
|
75
|
-
csrfHeader: string,
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
declare interface Cookie {
|
|
79
|
-
name: string;
|
|
80
|
-
value: string;
|
|
81
|
-
path?: string;
|
|
82
|
-
httpOnly?: boolean;
|
|
83
|
-
secure?: boolean;
|
|
84
|
-
maxAge?: number;
|
|
85
|
-
expires?: Date;
|
|
86
|
-
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
87
|
-
domain?: string;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
declare interface IbootReadonlyCookies {
|
|
91
|
-
get(name: string): Cookie | undefined;
|
|
92
|
-
getAll(): Cookie[];
|
|
93
|
-
has(name: string): boolean;
|
|
94
|
-
[Symbol.iterator](): IterableIterator<Cookie>;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
declare interface IbootWritableCookie {
|
|
98
|
-
set(name: string, value: string, options?: Partial<Cookie>): void;
|
|
99
|
-
delete(name: string, options?: { path?: string; domain?: string }): void;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
declare interface IbootCookieStore {
|
|
103
|
-
get(name: string): Cookie | undefined;
|
|
104
|
-
getAll(): Cookie[];
|
|
105
|
-
has(name: string): boolean;
|
|
106
|
-
set(name: string, value: string, options?: Partial<Cookie>): void;
|
|
107
|
-
delete(name: string, options?: { path?: string; domain?: string }): void;
|
|
108
|
-
[Symbol.iterator](): IterableIterator<Cookie>;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
declare type HttpOpts = {
|
|
112
|
-
"deviceId"?: string,
|
|
113
|
-
"lang"?: string,
|
|
114
|
-
"webId"?: string,
|
|
115
|
-
"webNo"?: string,
|
|
116
|
-
"userType"?: USER_TYPE
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
declare type HttpToken = { username: string, token: string, utype: USER_TYPE, xcsrf?: CSRFToken };
|
|
120
|
-
|
|
121
|
-
declare interface ResultModel<T> {
|
|
122
|
-
code: number,
|
|
123
|
-
success: boolean,
|
|
124
|
-
msg?: string,
|
|
125
|
-
data?: T,
|
|
126
|
-
host?: string,
|
|
127
|
-
errorCode?: string
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
declare type ResultStream = ReadableStream<Uint8Array>
|
|
131
|
-
|
|
132
|
-
declare interface ClientGetParams {
|
|
133
|
-
data?: Record<string, string>,
|
|
134
|
-
useCache?: boolean,
|
|
135
|
-
heads?: Record<string, string>,
|
|
136
|
-
showError?: (error: string) => void
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
declare interface ClientPostParams {
|
|
140
|
-
data?: Record<string, string> | FormData | UIFormEntities,
|
|
141
|
-
heads?: Record<string, string>,
|
|
142
|
-
showError?: (error: string) => void,
|
|
143
|
-
showSuccess?:(msg:string)=>void
|
|
144
|
-
}
|
|
145
|
-
declare type UIFormEntities<T = any> = { [k: string]: T; }
|
|
146
|
-
declare const ACCOUNT_TYPE: {
|
|
147
|
-
GENERAL : 0,
|
|
148
|
-
PHONE : 1,
|
|
149
|
-
EMAIL : 2
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
declare const USER_TYPE: {
|
|
153
|
-
TYPE_MGT : 0,
|
|
154
|
-
TYPE_C : 1,
|
|
155
|
-
TYPE_B : 2
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
declare const USER_FORM: {
|
|
159
|
-
FROM_WEB : 1,
|
|
160
|
-
FROM_PC : 2,
|
|
161
|
-
FROM_WX_MINI_PRO : 3,
|
|
162
|
-
FROM_WX_PLU : 4,
|
|
163
|
-
FROM_WX_E : 5,
|
|
164
|
-
FROM_APP : 6,
|
|
165
|
-
FROM_DEVICE : 7
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
declare const USER_SEX: {
|
|
169
|
-
unknown:0,
|
|
170
|
-
male:1,
|
|
171
|
-
female:2,
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
declare type ACCOUNT_TYPE = typeof ACCOUNT_TYPE[keyof typeof ACCOUNT_TYPE];
|
|
175
|
-
declare type USER_TYPE = typeof USER_TYPE[keyof typeof USER_TYPE];
|
|
176
|
-
declare type USER_FORM = typeof USER_FORM[keyof typeof USER_FORM];
|
|
177
|
-
declare type USER_SEX = typeof USER_SEX[keyof typeof USER_SEX];
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
declare interface User {
|
|
181
|
-
id: string,
|
|
182
|
-
status: 0 | 1
|
|
183
|
-
name: string,
|
|
184
|
-
sex: USER_SEX,
|
|
185
|
-
username: string,
|
|
186
|
-
phone?: string,
|
|
187
|
-
email?: string,
|
|
188
|
-
accountType: ACCOUNT_TYPE,
|
|
189
|
-
birthday?: string,
|
|
190
|
-
headImg?: string,
|
|
191
|
-
nickname?: string,
|
|
192
|
-
motto?: string,
|
|
193
|
-
enabled: boolean,
|
|
194
|
-
userType: USER_TYPE,
|
|
195
|
-
userFrom: USER_FORM,
|
|
196
|
-
needToReview: boolean,
|
|
197
|
-
socketOnline: boolean,
|
|
198
|
-
unionId?: string,
|
|
199
|
-
openId?: string,
|
|
200
|
-
wxPid?: string,
|
|
201
|
-
createTime: string,
|
|
202
|
-
lastLoginTime?: string,
|
|
203
|
-
lastLogoutTime?: string,
|
|
204
|
-
latitude?: number,
|
|
205
|
-
longitude?: number,
|
|
206
|
-
deviceId?: string,
|
|
207
|
-
tokenExpired?:number,
|
|
208
|
-
mustChangePwd?:boolean
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
declare type CurWebsite = {
|
|
212
|
-
websiteId?:string,
|
|
213
|
-
websiteNo?:string,
|
|
214
|
-
language:string,
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
declare type CSRFToken = {
|
|
218
|
-
csrfToken: string,
|
|
219
|
-
csrfHeader: string,
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
declare interface Cookie {
|
|
223
|
-
name: string;
|
|
224
|
-
value: string;
|
|
225
|
-
path?: string;
|
|
226
|
-
httpOnly?: boolean;
|
|
227
|
-
secure?: boolean;
|
|
228
|
-
maxAge?: number;
|
|
229
|
-
expires?: Date;
|
|
230
|
-
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
231
|
-
domain?: string;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
declare interface IbootReadonlyCookies {
|
|
235
|
-
get(name: string): Cookie | undefined;
|
|
236
|
-
getAll(): Cookie[];
|
|
237
|
-
has(name: string): boolean;
|
|
238
|
-
[Symbol.iterator](): IterableIterator<Cookie>;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
declare interface IbootWritableCookie {
|
|
242
|
-
set(name: string, value: string, options?: Partial<Cookie>): void;
|
|
243
|
-
delete(name: string, options?: { path?: string; domain?: string }): void;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
declare interface IbootCookieStore {
|
|
247
|
-
get(name: string): Cookie | undefined;
|
|
248
|
-
getAll(): Cookie[];
|
|
249
|
-
has(name: string): boolean;
|
|
250
|
-
set(name: string, value: string, options?: Partial<Cookie>): void;
|
|
251
|
-
delete(name: string, options?: { path?: string; domain?: string }): void;
|
|
252
|
-
[Symbol.iterator](): IterableIterator<Cookie>;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
declare type HttpOpts = {
|
|
256
|
-
"deviceId"?: string,
|
|
257
|
-
"lang"?: string,
|
|
258
|
-
"webId"?: string,
|
|
259
|
-
"webNo"?: string,
|
|
260
|
-
"userType"?: USER_TYPE
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
declare type HttpToken = { username: string, token: string, utype: USER_TYPE, xcsrf?: CSRFToken };
|
|
264
|
-
|
|
265
|
-
declare interface ResultModel<T> {
|
|
266
|
-
code: number,
|
|
267
|
-
success: boolean,
|
|
268
|
-
msg?: string,
|
|
269
|
-
data?: T,
|
|
270
|
-
host?: string,
|
|
271
|
-
errorCode?: string
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
declare type ResultStream = ReadableStream<Uint8Array>
|
|
275
|
-
|
|
276
|
-
declare interface ClientGetParams {
|
|
277
|
-
data?: Record<string, string>,
|
|
278
|
-
useCache?: boolean,
|
|
279
|
-
heads?: Record<string, string>,
|
|
280
|
-
showError?: (error: string) => void
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
declare interface ClientPostParams {
|
|
284
|
-
data?: Record<string, string> | FormData | UIFormEntities,
|
|
285
|
-
heads?: Record<string, string>,
|
|
286
|
-
showError?: (error: string) => void,
|
|
287
|
-
showSuccess?:(msg:string)=>void
|
|
288
|
-
}
|
|
289
|
-
declare type UIFormEntities<T = any> = { [k: string]: T; }
|
|
290
|
-
declare const ACCOUNT_TYPE: {
|
|
291
|
-
GENERAL : 0,
|
|
292
|
-
PHONE : 1,
|
|
293
|
-
EMAIL : 2
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
declare const USER_TYPE: {
|
|
297
|
-
TYPE_MGT : 0,
|
|
298
|
-
TYPE_C : 1,
|
|
299
|
-
TYPE_B : 2
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
declare const USER_FORM: {
|
|
303
|
-
FROM_WEB : 1,
|
|
304
|
-
FROM_PC : 2,
|
|
305
|
-
FROM_WX_MINI_PRO : 3,
|
|
306
|
-
FROM_WX_PLU : 4,
|
|
307
|
-
FROM_WX_E : 5,
|
|
308
|
-
FROM_APP : 6,
|
|
309
|
-
FROM_DEVICE : 7
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
declare const USER_SEX: {
|
|
313
|
-
unknown:0,
|
|
314
|
-
male:1,
|
|
315
|
-
female:2,
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
declare type ACCOUNT_TYPE = typeof ACCOUNT_TYPE[keyof typeof ACCOUNT_TYPE];
|
|
319
|
-
declare type USER_TYPE = typeof USER_TYPE[keyof typeof USER_TYPE];
|
|
320
|
-
declare type USER_FORM = typeof USER_FORM[keyof typeof USER_FORM];
|
|
321
|
-
declare type USER_SEX = typeof USER_SEX[keyof typeof USER_SEX];
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
declare interface User {
|
|
325
|
-
id: string,
|
|
326
|
-
status: 0 | 1
|
|
327
|
-
name: string,
|
|
328
|
-
sex: USER_SEX,
|
|
329
|
-
username: string,
|
|
330
|
-
phone?: string,
|
|
331
|
-
email?: string,
|
|
332
|
-
accountType: ACCOUNT_TYPE,
|
|
333
|
-
birthday?: string,
|
|
334
|
-
headImg?: string,
|
|
335
|
-
nickname?: string,
|
|
336
|
-
motto?: string,
|
|
337
|
-
enabled: boolean,
|
|
338
|
-
userType: USER_TYPE,
|
|
339
|
-
userFrom: USER_FORM,
|
|
340
|
-
needToReview: boolean,
|
|
341
|
-
socketOnline: boolean,
|
|
342
|
-
unionId?: string,
|
|
343
|
-
openId?: string,
|
|
344
|
-
wxPid?: string,
|
|
345
|
-
createTime: string,
|
|
346
|
-
lastLoginTime?: string,
|
|
347
|
-
lastLogoutTime?: string,
|
|
348
|
-
latitude?: number,
|
|
349
|
-
longitude?: number,
|
|
350
|
-
deviceId?: string,
|
|
351
|
-
tokenExpired?:number,
|
|
352
|
-
mustChangePwd?:boolean
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
declare type CurWebsite = {
|
|
356
|
-
websiteId?:string,
|
|
357
|
-
websiteNo?:string,
|
|
358
|
-
language:string,
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
declare type CSRFToken = {
|
|
362
|
-
csrfToken: string,
|
|
363
|
-
csrfHeader: string,
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
declare interface Cookie {
|
|
367
|
-
name: string;
|
|
368
|
-
value: string;
|
|
369
|
-
path?: string;
|
|
370
|
-
httpOnly?: boolean;
|
|
371
|
-
secure?: boolean;
|
|
372
|
-
maxAge?: number;
|
|
373
|
-
expires?: Date;
|
|
374
|
-
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
375
|
-
domain?: string;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
declare interface IbootReadonlyCookies {
|
|
379
|
-
get(name: string): Cookie | undefined;
|
|
380
|
-
getAll(): Cookie[];
|
|
381
|
-
has(name: string): boolean;
|
|
382
|
-
[Symbol.iterator](): IterableIterator<Cookie>;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
declare interface IbootWritableCookie {
|
|
386
|
-
set(name: string, value: string, options?: Partial<Cookie>): void;
|
|
387
|
-
delete(name: string, options?: { path?: string; domain?: string }): void;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
declare interface IbootCookieStore {
|
|
391
|
-
get(name: string): Cookie | undefined;
|
|
392
|
-
getAll(): Cookie[];
|
|
393
|
-
has(name: string): boolean;
|
|
394
|
-
set(name: string, value: string, options?: Partial<Cookie>): void;
|
|
395
|
-
delete(name: string, options?: { path?: string; domain?: string }): void;
|
|
396
|
-
[Symbol.iterator](): IterableIterator<Cookie>;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
declare type HttpOpts = {
|
|
400
|
-
"deviceId"?: string,
|
|
401
|
-
"lang"?: string,
|
|
402
|
-
"webId"?: string,
|
|
403
|
-
"webNo"?: string,
|
|
404
|
-
"userType"?: USER_TYPE
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
declare type HttpToken = { username: string, token: string, utype: USER_TYPE, xcsrf?: CSRFToken };
|
|
408
|
-
|
|
409
|
-
declare interface ResultModel<T> {
|
|
410
|
-
code: number,
|
|
411
|
-
success: boolean,
|
|
412
|
-
msg?: string,
|
|
413
|
-
data?: T,
|
|
414
|
-
host?: string,
|
|
415
|
-
errorCode?: string
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
declare type ResultStream = ReadableStream<Uint8Array>
|
|
419
|
-
|
|
420
|
-
declare interface ClientGetParams {
|
|
421
|
-
data?: Record<string, string>,
|
|
422
|
-
useCache?: boolean,
|
|
423
|
-
heads?: Record<string, string>,
|
|
424
|
-
showError?: (error: string) => void
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
declare interface ClientPostParams {
|
|
428
|
-
data?: Record<string, string> | FormData | UIFormEntities,
|
|
429
|
-
heads?: Record<string, string>,
|
|
430
|
-
showError?: (error: string) => void,
|
|
431
|
-
showSuccess?:(msg:string)=>void
|
|
432
|
-
}
|
|
1
|
+
export * from './types/http';
|
|
2
|
+
export * from './types/user';
|
|
3
|
+
export * from './http-client';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { USER_TYPE } from './user';
|
|
2
|
+
export type UIFormEntities<T = any> = {
|
|
3
|
+
[k: string]: T;
|
|
4
|
+
};
|
|
5
|
+
export type CSRFToken = {
|
|
6
|
+
csrfToken: string;
|
|
7
|
+
csrfHeader: string;
|
|
8
|
+
};
|
|
9
|
+
export type HttpClientOpts = {
|
|
10
|
+
"deviceId"?: string;
|
|
11
|
+
"lang"?: string;
|
|
12
|
+
"websiteId"?: string;
|
|
13
|
+
"websiteNo"?: string;
|
|
14
|
+
"userType"?: USER_TYPE;
|
|
15
|
+
};
|
|
16
|
+
export type HttpHeaderNames = 'Device-Id' | 'Website-Id' | 'Website-No' | 'Lang';
|
|
17
|
+
export type HttpHeaders = {
|
|
18
|
+
"Device-Id"?: string;
|
|
19
|
+
"Website-Id"?: string;
|
|
20
|
+
"Website-No"?: string;
|
|
21
|
+
"Lang"?: string;
|
|
22
|
+
};
|
|
23
|
+
export type CookieNames = 'IBOOT_DEVICE_ID' | 'IBOOT_LOCALE' | 'IBOOT_WEBSITE_ID' | 'IBOOT_WEBSITE_NO' | 'token' | 'user';
|
|
24
|
+
export type HttpToken = {
|
|
25
|
+
username: string;
|
|
26
|
+
token: string;
|
|
27
|
+
utype: USER_TYPE;
|
|
28
|
+
xcsrf?: CSRFToken;
|
|
29
|
+
};
|
|
30
|
+
export type ResultStream = ReadableStream<Uint8Array>;
|
|
31
|
+
export type CurWebsite = {
|
|
32
|
+
websiteId?: string;
|
|
33
|
+
websiteNo?: string;
|
|
34
|
+
language: string;
|
|
35
|
+
};
|
|
36
|
+
export interface Cookie {
|
|
37
|
+
name: string;
|
|
38
|
+
value: string;
|
|
39
|
+
path?: string;
|
|
40
|
+
httpOnly?: boolean;
|
|
41
|
+
secure?: boolean;
|
|
42
|
+
maxAge?: number;
|
|
43
|
+
expires?: Date;
|
|
44
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
45
|
+
domain?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface IbootReadonlyCookies {
|
|
48
|
+
get(name: string): Cookie | undefined;
|
|
49
|
+
getAll(): Cookie[];
|
|
50
|
+
has(name: string): boolean;
|
|
51
|
+
[Symbol.iterator](): IterableIterator<Cookie>;
|
|
52
|
+
}
|
|
53
|
+
export interface IbootWritableCookie {
|
|
54
|
+
set(name: string, value: string, options?: Partial<Cookie>): void;
|
|
55
|
+
delete(name: string, options?: {
|
|
56
|
+
path?: string;
|
|
57
|
+
domain?: string;
|
|
58
|
+
}): void;
|
|
59
|
+
}
|
|
60
|
+
export interface IbootCookieStore {
|
|
61
|
+
get(name: string): Cookie | undefined;
|
|
62
|
+
getAll(): Cookie[];
|
|
63
|
+
has(name: string): boolean;
|
|
64
|
+
set(name: string, value: string, options?: Partial<Cookie>): void;
|
|
65
|
+
delete(name: string, options?: {
|
|
66
|
+
path?: string;
|
|
67
|
+
domain?: string;
|
|
68
|
+
}): void;
|
|
69
|
+
[Symbol.iterator](): IterableIterator<Cookie>;
|
|
70
|
+
}
|
|
71
|
+
export interface ResultModel<T> {
|
|
72
|
+
code: number;
|
|
73
|
+
success: boolean;
|
|
74
|
+
msg?: string;
|
|
75
|
+
data?: T;
|
|
76
|
+
host?: string;
|
|
77
|
+
errorCode?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface ClientGetParams {
|
|
80
|
+
data?: Record<string, string>;
|
|
81
|
+
useCache?: boolean;
|
|
82
|
+
heads?: Record<string, string>;
|
|
83
|
+
showError?: (error: string) => void;
|
|
84
|
+
}
|
|
85
|
+
export interface ClientPostParams {
|
|
86
|
+
data?: Record<string, string> | FormData | UIFormEntities;
|
|
87
|
+
heads?: Record<string, string>;
|
|
88
|
+
showError?: (error: string) => void;
|
|
89
|
+
showSuccess?: (msg: string) => void;
|
|
90
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const ACCOUNT_TYPE_MAP: {
|
|
2
|
+
GENERAL: number;
|
|
3
|
+
PHONE: number;
|
|
4
|
+
EMAIL: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const USER_TYPE_MAP: {
|
|
7
|
+
TYPE_MGT: number;
|
|
8
|
+
TYPE_C: number;
|
|
9
|
+
TYPE_B: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const USER_FORM_MAP: {
|
|
12
|
+
FROM_WEB: number;
|
|
13
|
+
FROM_PC: number;
|
|
14
|
+
FROM_WX_MINI_PRO: number;
|
|
15
|
+
FROM_WX_PLU: number;
|
|
16
|
+
FROM_WX_E: number;
|
|
17
|
+
FROM_APP: number;
|
|
18
|
+
FROM_DEVICE: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const USER_SEX_MAP: {
|
|
21
|
+
unknown: number;
|
|
22
|
+
male: number;
|
|
23
|
+
female: number;
|
|
24
|
+
};
|
|
25
|
+
export type ACCOUNT_TYPE = typeof ACCOUNT_TYPE_MAP[keyof typeof ACCOUNT_TYPE_MAP];
|
|
26
|
+
export type USER_TYPE = typeof USER_TYPE_MAP[keyof typeof USER_TYPE_MAP];
|
|
27
|
+
export type USER_FORM = typeof USER_FORM_MAP[keyof typeof USER_FORM_MAP];
|
|
28
|
+
export type USER_SEX = typeof USER_SEX_MAP[keyof typeof USER_SEX_MAP];
|
|
29
|
+
export interface User {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
username: string;
|
|
33
|
+
nickname: string;
|
|
34
|
+
sex: USER_SEX;
|
|
35
|
+
headImg: string;
|
|
36
|
+
lastLoginTime: string;
|
|
37
|
+
tokenExpired: string;
|
|
38
|
+
deviceId: string;
|
|
39
|
+
userType: USER_TYPE;
|
|
40
|
+
status: number;
|
|
41
|
+
accountType: number;
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
userFrom: USER_FORM;
|
|
44
|
+
needToReview: boolean;
|
|
45
|
+
socketOnline: boolean;
|
|
46
|
+
createTime: string;
|
|
47
|
+
mustChangePwd: boolean;
|
|
48
|
+
}
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
export declare const isArray: (obj: unknown) => boolean;
|
|
2
|
-
export declare const arrayIndexOf: <T>(arr: Array<T>, value: string | number, keyOrPredicate?: keyof T | ((item: T) => boolean)) => number;
|
|
3
|
-
export declare const removeArrayItem: <T>(arr: Array<T>, value: string | number, keyOrPredicate?: keyof T | ((item: T) => boolean)) => boolean;
|
|
4
|
-
export declare const strFormat: (str: string, ...args: string[]) => string;
|
|
5
|
-
export declare const strTrim: (str?: string) => string;
|
|
6
|
-
export declare const strLTrim: (str?: string) => string;
|
|
7
|
-
export declare const strRTrim: (str?: string) => string;
|
|
8
2
|
/**
|
|
9
3
|
* 生成指定长度的随机串
|
|
10
4
|
* @param {Object} len
|
|
11
5
|
*/
|
|
12
6
|
export declare const randomString: (len: number) => string;
|
|
13
|
-
/**
|
|
14
|
-
* 生成指定长度的uuid
|
|
15
|
-
* @param {Object} len
|
|
16
|
-
* @param {Object} radix 2,10,16进制
|
|
17
|
-
*/
|
|
18
|
-
export declare const uuidStr: (len: number, radix?: number) => string;
|
|
19
|
-
export declare const cleanHtml: (str?: string) => string;
|
|
20
|
-
export declare const simpleMarkdownToText: (markdown?: string) => string;
|
|
21
|
-
export declare const substring: (str: string, len: number) => string;
|
|
22
|
-
export declare const decrypt: (data: string, apikey: string) => string;
|
|
23
7
|
export declare const urlParamToJson: (urlQueryParams: string, exclude?: string[]) => Record<string, string>;
|
|
24
|
-
export declare const
|
|
25
|
-
/**
|
|
26
|
-
* 首字符大写
|
|
27
|
-
* @param str
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
30
|
-
export declare const capitalizeFirstLetter: (str: string) => string;
|
|
8
|
+
export declare const urlEncode: (value: string | null | undefined) => string;
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iboot-http-client",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "iBoot.xin 相关应用的客户端Http封装",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "./dist/iboot-http-client.cjs",
|
|
8
|
-
"module": "./dist/iboot-http-client.js",
|
|
7
|
+
"main": "./dist/iboot-http-client.cjs.js",
|
|
8
|
+
"module": "./dist/iboot-http-client.es.js",
|
|
9
9
|
"browser": "./dist/iboot-http-client.umd.js",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"import": "./dist/iboot-http-client.es.js",
|
|
14
|
+
"require": "./dist/iboot-http-client.cjs.js",
|
|
15
|
+
"default": "./dist/iboot-http-client.es.js"
|
|
14
16
|
}
|
|
15
17
|
},
|
|
16
18
|
"types": "./dist/types/index.d.ts",
|
|
@@ -20,6 +22,7 @@
|
|
|
20
22
|
"scripts": {
|
|
21
23
|
"dev": "vite",
|
|
22
24
|
"build": "tsc && vite build",
|
|
25
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist/types",
|
|
23
26
|
"test": "vitest run",
|
|
24
27
|
"preview": "vite preview",
|
|
25
28
|
"prepublishOnly": "npm run build"
|
|
@@ -28,7 +31,6 @@
|
|
|
28
31
|
"http",
|
|
29
32
|
"client",
|
|
30
33
|
"request",
|
|
31
|
-
"axios",
|
|
32
34
|
"fetch",
|
|
33
35
|
"api",
|
|
34
36
|
"rest"
|
|
@@ -38,7 +40,6 @@
|
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@types/crypto-js": "^4.2.2",
|
|
40
42
|
"@types/node": "^25.0.3",
|
|
41
|
-
"js-md5": "^0.8.3",
|
|
42
43
|
"typescript": "~5.9.3",
|
|
43
44
|
"vite": "^7.2.4",
|
|
44
45
|
"vite-plugin-dts": "^4.5.4",
|
|
@@ -53,6 +54,8 @@
|
|
|
53
54
|
},
|
|
54
55
|
"homepage": "https://github.com/rockychen2016/iboot-http-client#readme",
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"crypto-js": "^4.2.0"
|
|
57
|
+
"crypto-js": "^4.2.0",
|
|
58
|
+
"js-md5": "^0.8.3",
|
|
59
|
+
"pino": "^10.1.0"
|
|
57
60
|
}
|
|
58
61
|
}
|