@faasjs/http 8.0.0-beta.6 → 8.0.0-beta.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/README.md +0 -1
- package/dist/index.cjs +364 -426
- package/dist/index.d.ts +149 -153
- package/dist/index.mjs +363 -424
- package/package.json +8 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,180 +1,176 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Logger } from
|
|
1
|
+
import { InvokeData, MountData, Next, Plugin, UseifyPlugin } from "@faasjs/func";
|
|
2
|
+
import { Logger } from "@faasjs/logger";
|
|
3
3
|
|
|
4
|
+
//#region src/session.d.ts
|
|
4
5
|
type SessionOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
key: string;
|
|
7
|
+
secret: string;
|
|
8
|
+
salt?: string;
|
|
9
|
+
signedSalt?: string;
|
|
10
|
+
keylen?: number;
|
|
11
|
+
iterations?: number;
|
|
12
|
+
digest?: string;
|
|
13
|
+
cipherName?: string;
|
|
13
14
|
};
|
|
14
15
|
type SessionContent = string | number | {
|
|
15
|
-
|
|
16
|
+
[key: string]: any;
|
|
16
17
|
} | null | undefined;
|
|
17
18
|
declare class Session<S extends Record<string, string> = any, C extends Record<string, string> = any> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
content: Record<string, string | number>;
|
|
20
|
+
readonly config: {
|
|
21
|
+
key: string;
|
|
22
|
+
secret: string;
|
|
23
|
+
salt: string;
|
|
24
|
+
signedSalt: string;
|
|
25
|
+
keylen: number;
|
|
26
|
+
iterations: number;
|
|
27
|
+
digest: string;
|
|
28
|
+
cipherName: string;
|
|
29
|
+
};
|
|
30
|
+
private readonly secret;
|
|
31
|
+
private readonly signedSecret;
|
|
32
|
+
private readonly cookie;
|
|
33
|
+
private changed?;
|
|
34
|
+
constructor(cookie: Cookie<C, S>, config: SessionOptions);
|
|
35
|
+
invoke(cookie?: string, logger?: Logger): void;
|
|
36
|
+
encode(text: SessionContent): string;
|
|
37
|
+
decode<TData = any>(text: string): TData | SessionContent;
|
|
38
|
+
read(key: string): string | number;
|
|
39
|
+
write(key: string, value?: string | number | null): Session<S, C>;
|
|
40
|
+
update(): Session<S, C>;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/cookie.d.ts
|
|
42
44
|
type CookieOptions = {
|
|
45
|
+
domain?: string;
|
|
46
|
+
path?: string;
|
|
47
|
+
expires?: number;
|
|
48
|
+
secure?: boolean;
|
|
49
|
+
httpOnly?: boolean;
|
|
50
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
51
|
+
session?: SessionOptions;
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
};
|
|
54
|
+
declare class Cookie<C extends Record<string, string> = any, S extends Record<string, string> = any> {
|
|
55
|
+
session: Session<S, C>;
|
|
56
|
+
content: Record<string, string>;
|
|
57
|
+
readonly config: {
|
|
58
|
+
domain?: string;
|
|
59
|
+
path: string;
|
|
60
|
+
expires: number;
|
|
61
|
+
secure: boolean;
|
|
62
|
+
httpOnly: boolean;
|
|
63
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
64
|
+
session: SessionOptions;
|
|
65
|
+
};
|
|
66
|
+
logger: Logger | undefined;
|
|
67
|
+
private setCookie;
|
|
68
|
+
constructor(config: CookieOptions, logger?: Logger);
|
|
69
|
+
invoke(cookie: string | undefined, logger: Logger): Cookie<C, S>;
|
|
70
|
+
read(key: string): any;
|
|
71
|
+
write(key: string, value: string | null | undefined, opts?: {
|
|
43
72
|
domain?: string;
|
|
44
73
|
path?: string;
|
|
45
|
-
expires?: number;
|
|
74
|
+
expires?: number | string;
|
|
46
75
|
secure?: boolean;
|
|
47
76
|
httpOnly?: boolean;
|
|
48
77
|
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
session: Session<S, C>;
|
|
54
|
-
content: Record<string, string>;
|
|
55
|
-
readonly config: {
|
|
56
|
-
domain?: string;
|
|
57
|
-
path: string;
|
|
58
|
-
expires: number;
|
|
59
|
-
secure: boolean;
|
|
60
|
-
httpOnly: boolean;
|
|
61
|
-
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
62
|
-
session: SessionOptions;
|
|
63
|
-
};
|
|
64
|
-
logger: Logger;
|
|
65
|
-
private setCookie;
|
|
66
|
-
constructor(config: CookieOptions, logger?: Logger);
|
|
67
|
-
invoke(cookie: string | undefined, logger: Logger): Cookie<C, S>;
|
|
68
|
-
read(key: string): any;
|
|
69
|
-
write(key: string, value: string, opts?: {
|
|
70
|
-
domain?: string;
|
|
71
|
-
path?: string;
|
|
72
|
-
expires?: number | string;
|
|
73
|
-
secure?: boolean;
|
|
74
|
-
httpOnly?: boolean;
|
|
75
|
-
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
76
|
-
}): Cookie<C, S>;
|
|
77
|
-
headers(): {
|
|
78
|
-
'Set-Cookie'?: string[];
|
|
79
|
-
};
|
|
78
|
+
}): Cookie<C, S>;
|
|
79
|
+
headers(): {
|
|
80
|
+
'Set-Cookie'?: string[];
|
|
81
|
+
};
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/index.d.ts
|
|
82
85
|
declare const ContentType: {
|
|
83
|
-
|
|
86
|
+
[key: string]: string;
|
|
84
87
|
};
|
|
85
88
|
type HttpConfig = {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
cookie?: CookieOptions;
|
|
98
|
-
};
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
name?: string;
|
|
91
|
+
config?: {
|
|
92
|
+
[key: string]: any; /** POST as default */
|
|
93
|
+
method?: 'BEGIN' | 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'PUT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'ANY';
|
|
94
|
+
timeout?: number; /** file relative path as default */
|
|
95
|
+
path?: string;
|
|
96
|
+
ignorePathPrefix?: string;
|
|
97
|
+
functionName?: string;
|
|
98
|
+
cookie?: CookieOptions;
|
|
99
|
+
};
|
|
99
100
|
};
|
|
100
101
|
type Response = {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
statusCode?: number;
|
|
103
|
+
headers?: {
|
|
104
|
+
[key: string]: string;
|
|
105
|
+
};
|
|
106
|
+
body?: string | ReadableStream;
|
|
107
|
+
message?: string;
|
|
107
108
|
};
|
|
108
109
|
declare class HttpError extends Error {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
readonly statusCode: number;
|
|
111
|
+
readonly message: string;
|
|
112
|
+
constructor({
|
|
113
|
+
statusCode,
|
|
114
|
+
message
|
|
115
|
+
}: {
|
|
116
|
+
statusCode?: number;
|
|
117
|
+
message: string;
|
|
118
|
+
});
|
|
115
119
|
}
|
|
116
120
|
declare class Http<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> implements Plugin {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
121
|
+
readonly type = "http";
|
|
122
|
+
readonly name: string;
|
|
123
|
+
headers: {
|
|
124
|
+
[key: string]: string;
|
|
125
|
+
};
|
|
126
|
+
body: any;
|
|
127
|
+
params: TParams;
|
|
128
|
+
cookie: Cookie<TCookie, TSession>;
|
|
129
|
+
session: Session<TSession, TCookie>;
|
|
130
|
+
config: HttpConfig;
|
|
131
|
+
private response;
|
|
132
|
+
constructor(config?: HttpConfig);
|
|
133
|
+
onMount(data: MountData, next: Next): Promise<void>;
|
|
134
|
+
onInvoke(data: InvokeData, next: Next): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* set header
|
|
137
|
+
* @param key {string} key
|
|
138
|
+
* @param value {string} value
|
|
139
|
+
*/
|
|
140
|
+
setHeader(key: string, value: string): Http<TParams, TCookie, TSession>;
|
|
141
|
+
/**
|
|
142
|
+
* set Content-Type
|
|
143
|
+
* @param type {string} 类型
|
|
144
|
+
* @param charset {string} 编码
|
|
145
|
+
*/
|
|
146
|
+
setContentType(type: string, charset?: string): Http<TParams, TCookie, TSession>;
|
|
147
|
+
/**
|
|
148
|
+
* set status code
|
|
149
|
+
* @param code {number} 状态码
|
|
150
|
+
*/
|
|
151
|
+
setStatusCode(code: number): Http<TParams, TCookie, TSession>;
|
|
152
|
+
/**
|
|
153
|
+
* set body
|
|
154
|
+
* @param body {*} 内容
|
|
155
|
+
*/
|
|
156
|
+
setBody(body: string): Http<TParams, TCookie, TSession>;
|
|
153
157
|
}
|
|
154
158
|
declare function useHttp<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any>(config?: HttpConfig): UseifyPlugin<Http<TParams, TCookie, TSession>>;
|
|
155
|
-
type HttpFuncHandler<TParams extends Record<string, any> = Record<string, any>, TCookie extends Record<string, string> = Record<string, string>, TSession extends Record<string, any> = Record<string, any>, TResult = any> = (data: InvokeData<{
|
|
156
|
-
[key: string]: any;
|
|
157
|
-
params?: TParams;
|
|
158
|
-
}> & {
|
|
159
|
-
params?: TParams;
|
|
160
|
-
cookie?: Cookie<TCookie, TSession>;
|
|
161
|
-
session?: Session<TSession, TCookie>;
|
|
162
|
-
}) => Promise<TResult>;
|
|
163
159
|
declare module '@faasjs/func' {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
160
|
+
interface FaasPluginEventMap {
|
|
161
|
+
http: {
|
|
162
|
+
headers?: Record<string, any>;
|
|
163
|
+
body?: any;
|
|
164
|
+
params?: Record<string, any>;
|
|
165
|
+
queryString?: Record<string, any>;
|
|
166
|
+
httpMethod?: string;
|
|
167
|
+
path?: string;
|
|
168
|
+
raw?: {
|
|
169
|
+
request?: unknown;
|
|
170
|
+
response?: unknown;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
}
|
|
178
174
|
}
|
|
179
|
-
|
|
180
|
-
export { ContentType, Cookie, type CookieOptions, Http,
|
|
175
|
+
//#endregion
|
|
176
|
+
export { ContentType, Cookie, type CookieOptions, Http, HttpConfig, HttpError, Response, Session, type SessionContent, type SessionOptions, useHttp };
|