iboot-http-client 1.0.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.
@@ -0,0 +1,65 @@
1
+ export declare const defaultLocale = "zh-CN";
2
+ export declare const setDefaultRequestHeader: (deviceId: string, website: CurWebsite) => void;
3
+ export declare const get: <T>(url: string, opts?: ClientGetParams) => Promise<ResultModel<T>>;
4
+ export declare const iGet: <T>(url: string, opts?: ClientGetParams) => Promise<T | undefined>;
5
+ export declare const post: <T>(url: string, opts?: ClientPostParams) => Promise<ResultModel<T>>;
6
+ export declare const iPost: <T>(url: string, opts?: ClientPostParams) => Promise<T | undefined>;
7
+ export declare const iPostSuccess: (url: string, opts?: ClientPostParams) => Promise<boolean>;
8
+ export declare const getHttpClientOpts: (request: Request) => HttpOpts;
9
+ export declare const getHttpOptsByHeaders: (cookie: IbootReadonlyCookies) => HttpOpts;
10
+ export declare const getHttpClientOptsByCookie: (cookie: IbootReadonlyCookies) => HttpOpts;
11
+ export declare class HttpClient {
12
+ private readonly baseUrl;
13
+ private readonly apiKey;
14
+ private readonly userType;
15
+ private readonly userFrom;
16
+ private readonly deviceId;
17
+ private readonly version;
18
+ private readonly lang;
19
+ private readonly websiteId?;
20
+ private readonly websiteNo?;
21
+ private readonly _isDebug;
22
+ constructor({ deviceId, lang, webId, webNo, userType }: Readonly<HttpOpts>);
23
+ isDebug(): boolean;
24
+ encrypt(data: string): string;
25
+ decrypt(data: string): string;
26
+ getDeviceId(): string;
27
+ private convertUrlParameter;
28
+ private sign;
29
+ private assemblyParameter;
30
+ private assemblyHeader;
31
+ private helloIboot;
32
+ private getApiUrl;
33
+ get<T>({ url, data, token }: Readonly<{
34
+ url: string;
35
+ data?: Record<string, any>;
36
+ token?: Readonly<HttpToken>;
37
+ }>): Promise<ResultModel<T>>;
38
+ csrf(): Promise<string | undefined>;
39
+ post<T>({ url, data, token }: Readonly<{
40
+ url: string;
41
+ data?: Record<string, any>;
42
+ token?: Readonly<HttpToken>;
43
+ }>): Promise<ResultModel<T>>;
44
+ stream({ url, data, token }: Readonly<{
45
+ url: string;
46
+ data?: Record<string, any>;
47
+ token?: Readonly<HttpToken>;
48
+ }>): Promise<Response>;
49
+ getUserInfo(cookies: IbootCookieStore): User | null;
50
+ getToken(cookies: IbootCookieStore): HttpToken;
51
+ getTokenByCookies: (cookies: IbootReadonlyCookies) => HttpToken;
52
+ setToken(data: User & {
53
+ token: string;
54
+ extFields: Record<string, any>;
55
+ }, response: {
56
+ cookies: IbootWritableCookie;
57
+ }): {
58
+ cookies: IbootWritableCookie;
59
+ };
60
+ cleanToken(response: {
61
+ cookies: IbootWritableCookie;
62
+ }): {
63
+ cookies: IbootWritableCookie;
64
+ };
65
+ }
@@ -0,0 +1,432 @@
1
+ declare type UIFormEntities<T = any> = { [k: string]: T; }
2
+ declare const ACCOUNT_TYPE: {
3
+ GENERAL : 0,
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
+ }
@@ -0,0 +1,30 @@
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
+ /**
9
+ * 生成指定长度的随机串
10
+ * @param {Object} len
11
+ */
12
+ 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
+ export declare const urlParamToJson: (urlQueryParams: string, exclude?: string[]) => Record<string, string>;
24
+ export declare const urlDecode: (value: string | null | undefined) => string;
25
+ /**
26
+ * 首字符大写
27
+ * @param str
28
+ * @returns
29
+ */
30
+ export declare const capitalizeFirstLetter: (str: string) => string;
package/dist/vite.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "iboot-http-client",
3
+ "private": false,
4
+ "version": "1.0.0",
5
+ "description": "A simple HTTP client library for making HTTP requests",
6
+ "type": "module",
7
+ "main": "./dist/iboot-http-client.cjs",
8
+ "module": "./dist/iboot-http-client.js",
9
+ "browser": "./dist/iboot-http-client.umd.js",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/iboot-http-client.js",
13
+ "require": "./dist/iboot-http-client.cjs"
14
+ }
15
+ },
16
+ "types": "./dist/types/index.d.ts",
17
+ "files": [
18
+ "dist/**/*"
19
+ ],
20
+ "scripts": {
21
+ "dev": "vite",
22
+ "build": "tsc && vite build",
23
+ "test": "vitest run",
24
+ "preview": "vite preview",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "keywords": [
28
+ "http",
29
+ "client",
30
+ "request",
31
+ "axios",
32
+ "fetch",
33
+ "api",
34
+ "rest"
35
+ ],
36
+ "author": "szygnet@qq.com",
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "@types/crypto-js": "^4.2.2",
40
+ "@types/node": "^25.0.3",
41
+ "js-md5": "^0.8.3",
42
+ "typescript": "~5.9.3",
43
+ "vite": "^7.2.4",
44
+ "vite-plugin-dts": "^4.5.4",
45
+ "vitest": "^1.0.0"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/rockychen2016/iboot-http-client.git"
50
+ },
51
+ "bugs": {
52
+ "url": "https://github.com/rockychen2016/iboot-http-client/issues"
53
+ },
54
+ "homepage": "https://github.com/rockychen2016/iboot-http-client#readme",
55
+ "dependencies": {
56
+ "crypto-js": "^4.2.0"
57
+ }
58
+ }