iboot-http-client 1.2.6 → 1.2.8
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 +8 -1
- package/dist/iboot-http-client.cjs.js.map +1 -1
- package/dist/iboot-http-client.es.js +1982 -288
- package/dist/iboot-http-client.es.js.map +1 -1
- package/dist/iboot-http-client.umd.js +8 -1
- package/dist/iboot-http-client.umd.js.map +1 -1
- package/dist/types/http-client.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/router-dapter/nextjs.d.ts +7 -0
- package/dist/types/router-dapter/nuxtjs.d.ts +7 -0
- package/dist/types/router.d.ts +34 -0
- package/dist/types/types/router.d.ts +60 -0
- package/package.json +17 -13
|
@@ -4,7 +4,7 @@ export declare const setClientRequestHeader: ({ deviceId, website }: Readonly<{
|
|
|
4
4
|
deviceId: string;
|
|
5
5
|
website?: CurWebsite;
|
|
6
6
|
}>, storage: IStorage) => void;
|
|
7
|
-
export declare const get: <T>(
|
|
7
|
+
export declare const get: <T>(urlName: string, opts?: ClientGetParams) => Promise<ResultModel<T>>;
|
|
8
8
|
export declare const post: <T>(url: string, opts?: ClientPostParams) => Promise<ResultModel<T>>;
|
|
9
9
|
export declare const iGet: <T>(url: string, opts?: ClientGetParams) => Promise<T | undefined>;
|
|
10
10
|
export declare const iPost: <T>(url: string, opts?: ClientPostParams) => Promise<T | undefined>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { FrameworkAdapter, RequestContext, ResponseContext } from '../types/router';
|
|
3
|
+
export declare class NextJsAdapter implements FrameworkAdapter {
|
|
4
|
+
parseRequest(request: NextRequest): Promise<RequestContext>;
|
|
5
|
+
createResponse(context: ResponseContext): NextResponse;
|
|
6
|
+
setCookie(response: ResponseContext, name: string, value: string, options?: any): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { H3Event } from 'h3';
|
|
2
|
+
import { FrameworkAdapter, RequestContext, ResponseContext } from '../types/router';
|
|
3
|
+
export declare class NuxtJsAdapter implements FrameworkAdapter {
|
|
4
|
+
parseRequest(event: H3Event): Promise<RequestContext>;
|
|
5
|
+
createResponse(context: ResponseContext): any;
|
|
6
|
+
setCookie(response: ResponseContext, name: string, value: string, options?: any): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ICookies, IStorage } from './types/http';
|
|
2
|
+
import { FrameworkAdapter, RequestContext, ResponseContext, RouteConfig } from './types/router';
|
|
3
|
+
export declare const CONTENT_TYPE_KEY = "Content-Type";
|
|
4
|
+
export declare const CONTENT_TYPE_MAP: {
|
|
5
|
+
applicationJson: string;
|
|
6
|
+
multipartFormData: string;
|
|
7
|
+
applicationXwwwFormUrlencoded: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class HTTPRouter {
|
|
10
|
+
private config;
|
|
11
|
+
private http;
|
|
12
|
+
private cookies;
|
|
13
|
+
private adapter;
|
|
14
|
+
constructor({ config, adapter, storage, cookies }: Readonly<{
|
|
15
|
+
config: RouteConfig;
|
|
16
|
+
/**
|
|
17
|
+
* 框架适配路由处理器
|
|
18
|
+
*/
|
|
19
|
+
adapter: FrameworkAdapter;
|
|
20
|
+
/**
|
|
21
|
+
* 这里的存取器应该使用Request.headers.get
|
|
22
|
+
*/
|
|
23
|
+
storage: IStorage;
|
|
24
|
+
/**
|
|
25
|
+
* 需要同时实现RequestCookies.get,及ResponseCookies.set
|
|
26
|
+
*/
|
|
27
|
+
cookies: ICookies;
|
|
28
|
+
}>);
|
|
29
|
+
handleRequest(rawRequest: any): Promise<any>;
|
|
30
|
+
private processRequest;
|
|
31
|
+
private createErrorResponse;
|
|
32
|
+
}
|
|
33
|
+
export { NextJsAdapter } from './router-dapter/nextjs';
|
|
34
|
+
export type { RequestContext, ResponseContext, RouteConfig };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ResultModel } from './http';
|
|
2
|
+
export type ContentType = 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded';
|
|
3
|
+
export interface RequestContext {
|
|
4
|
+
url: URL;
|
|
5
|
+
headers: Readonly<Headers>;
|
|
6
|
+
body?: Record<string, any>;
|
|
7
|
+
formData?: FormData;
|
|
8
|
+
cookies?: Record<string, string>;
|
|
9
|
+
clone(): Request;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface ResponseContext {
|
|
13
|
+
status: number;
|
|
14
|
+
headers: Record<string, string>;
|
|
15
|
+
cookies: Record<string, {
|
|
16
|
+
value: string;
|
|
17
|
+
options?: any;
|
|
18
|
+
}>;
|
|
19
|
+
body: ResultModel<any>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 路由处理适配器
|
|
23
|
+
* 不同框架集成请实成该适配器
|
|
24
|
+
* 注:本组件已实现NextJs、NuxtJs框架的路由处理
|
|
25
|
+
*/
|
|
26
|
+
export interface FrameworkAdapter {
|
|
27
|
+
/**
|
|
28
|
+
* 解析请求
|
|
29
|
+
* @param request
|
|
30
|
+
*/
|
|
31
|
+
parseRequest(request: any): Promise<RequestContext>;
|
|
32
|
+
/**
|
|
33
|
+
* 创建响应
|
|
34
|
+
* @param context
|
|
35
|
+
*/
|
|
36
|
+
createResponse(context: ResponseContext): any;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param response 设置cookies
|
|
40
|
+
* @param name
|
|
41
|
+
* @param value
|
|
42
|
+
* @param options
|
|
43
|
+
*/
|
|
44
|
+
setCookie(response: ResponseContext, name: string, value: string, options?: any): void;
|
|
45
|
+
}
|
|
46
|
+
export interface RouteConfig {
|
|
47
|
+
/**
|
|
48
|
+
* 设置API影射
|
|
49
|
+
*/
|
|
50
|
+
APIMAP: Record<string, string>;
|
|
51
|
+
/**
|
|
52
|
+
* 自定义处理成功输出
|
|
53
|
+
* @param param0
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
onHandlerSuccess?: ({ request, response }: Readonly<{
|
|
57
|
+
request: RequestContext;
|
|
58
|
+
response: ResponseContext;
|
|
59
|
+
}>) => void;
|
|
60
|
+
}
|
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
|
+
"version": "1.2.8",
|
|
5
5
|
"description": "iBoot.xin 相关应用的客户端Http封装",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/iboot-http-client.cjs.js",
|
|
@@ -37,14 +37,6 @@
|
|
|
37
37
|
],
|
|
38
38
|
"author": "rock.chen<szygnet@qq.com>",
|
|
39
39
|
"license": "MIT",
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@types/crypto-js": "^4.2.2",
|
|
42
|
-
"@types/node": "^25.0.3",
|
|
43
|
-
"typescript": "~5.9.3",
|
|
44
|
-
"vite": "^7.2.4",
|
|
45
|
-
"vite-plugin-dts": "^4.5.4",
|
|
46
|
-
"vitest": "^1.0.0"
|
|
47
|
-
},
|
|
48
40
|
"repository": {
|
|
49
41
|
"type": "git",
|
|
50
42
|
"url": "git+https://github.com/rockychen2016/iboot-http-client.git"
|
|
@@ -55,15 +47,27 @@
|
|
|
55
47
|
"homepage": "https://www.iboot.fun",
|
|
56
48
|
"dependencies": {
|
|
57
49
|
"crypto-js": "^4.2.0",
|
|
50
|
+
"h3": "^2.0.1-rc.8",
|
|
58
51
|
"js-md5": "^0.8.3",
|
|
52
|
+
"next-server-context": "^6.0.0",
|
|
59
53
|
"pino": "^10.1.0",
|
|
60
54
|
"pino-pretty": "^13.1.3"
|
|
61
55
|
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/crypto-js": "^4.2.2",
|
|
58
|
+
"@types/node": "^25.0.3",
|
|
59
|
+
"typescript": "~5.9.3",
|
|
60
|
+
"vite": "^7.2.4",
|
|
61
|
+
"vite-plugin-dts": "^4.5.4",
|
|
62
|
+
"vitest": "^1.0.0"
|
|
63
|
+
},
|
|
62
64
|
"peerDependencies": {
|
|
63
|
-
"crypto-js": "
|
|
64
|
-
"js-md5": "
|
|
65
|
-
"
|
|
66
|
-
"
|
|
65
|
+
"crypto-js": ">=4.2.0",
|
|
66
|
+
"js-md5": ">=0.8.3",
|
|
67
|
+
"next-server-context": ">=6.0.0",
|
|
68
|
+
"h3": ">=2.0.1-rc.8",
|
|
69
|
+
"pino": ">=10.1.0",
|
|
70
|
+
"pino-pretty": ">=13.1.3"
|
|
67
71
|
},
|
|
68
72
|
"peerDependenciesMeta": {
|
|
69
73
|
"pino-pretty": {
|