@faasjs/http 5.0.0-beta.1 → 5.0.0-beta.3
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/package.json +6 -6
- package/dist/index.d.cts +0 -185
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/http",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": {
|
|
12
|
-
"types": "./dist/index.d.
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
13
|
"default": "./dist/index.mjs"
|
|
14
14
|
},
|
|
15
15
|
"require": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@faasjs/func": "5.0.0-beta.
|
|
39
|
-
"@faasjs/logger": "5.0.0-beta.
|
|
38
|
+
"@faasjs/func": "5.0.0-beta.3",
|
|
39
|
+
"@faasjs/logger": "5.0.0-beta.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@faasjs/func": "5.0.0-beta.
|
|
43
|
-
"@faasjs/logger": "5.0.0-beta.
|
|
42
|
+
"@faasjs/func": "5.0.0-beta.3",
|
|
43
|
+
"@faasjs/logger": "5.0.0-beta.3"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=22.0.0",
|
package/dist/index.d.cts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import * as _faasjs_func from '@faasjs/func';
|
|
2
|
-
import { Plugin, MountData, Next, InvokeData, UseifyPlugin } from '@faasjs/func';
|
|
3
|
-
import { Logger } from '@faasjs/logger';
|
|
4
|
-
|
|
5
|
-
type SessionOptions = {
|
|
6
|
-
key: string;
|
|
7
|
-
secret: string;
|
|
8
|
-
salt?: string;
|
|
9
|
-
signedSalt?: string;
|
|
10
|
-
keylen?: number;
|
|
11
|
-
iterations?: number;
|
|
12
|
-
digest?: string;
|
|
13
|
-
cipherName?: string;
|
|
14
|
-
};
|
|
15
|
-
type SessionContent = string | number | {
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
} | null | undefined;
|
|
18
|
-
declare class Session<S extends Record<string, string> = any, C extends Record<string, string> = any> {
|
|
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>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type CookieOptions = {
|
|
44
|
-
domain?: string;
|
|
45
|
-
path?: string;
|
|
46
|
-
expires?: number;
|
|
47
|
-
secure?: boolean;
|
|
48
|
-
httpOnly?: boolean;
|
|
49
|
-
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
50
|
-
session?: SessionOptions;
|
|
51
|
-
[key: string]: any;
|
|
52
|
-
};
|
|
53
|
-
declare class Cookie<C extends Record<string, string> = any, S extends Record<string, string> = any> {
|
|
54
|
-
session: Session<S, C>;
|
|
55
|
-
content: Record<string, string>;
|
|
56
|
-
readonly config: {
|
|
57
|
-
domain?: string;
|
|
58
|
-
path: string;
|
|
59
|
-
expires: number;
|
|
60
|
-
secure: boolean;
|
|
61
|
-
httpOnly: boolean;
|
|
62
|
-
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
63
|
-
session: SessionOptions;
|
|
64
|
-
};
|
|
65
|
-
logger: Logger;
|
|
66
|
-
private setCookie;
|
|
67
|
-
constructor(config: CookieOptions, logger?: Logger);
|
|
68
|
-
invoke(cookie: string | undefined, logger: Logger): Cookie<C, S>;
|
|
69
|
-
read(key: string): any;
|
|
70
|
-
write(key: string, value: string, opts?: {
|
|
71
|
-
domain?: string;
|
|
72
|
-
path?: string;
|
|
73
|
-
expires?: number | string;
|
|
74
|
-
secure?: boolean;
|
|
75
|
-
httpOnly?: boolean;
|
|
76
|
-
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
77
|
-
}): Cookie<C, S>;
|
|
78
|
-
headers(): {
|
|
79
|
-
'Set-Cookie'?: string[];
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
declare const ContentType: {
|
|
84
|
-
[key: string]: string;
|
|
85
|
-
};
|
|
86
|
-
type HttpConfig = {
|
|
87
|
-
[key: string]: any;
|
|
88
|
-
name?: string;
|
|
89
|
-
config?: {
|
|
90
|
-
[key: string]: any;
|
|
91
|
-
/** POST as default */
|
|
92
|
-
method?: 'BEGIN' | 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'PUT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'ANY';
|
|
93
|
-
timeout?: number;
|
|
94
|
-
/** file relative path as default */
|
|
95
|
-
path?: string;
|
|
96
|
-
ignorePathPrefix?: string;
|
|
97
|
-
functionName?: string;
|
|
98
|
-
cookie?: CookieOptions;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
type Response = {
|
|
102
|
-
statusCode?: number;
|
|
103
|
-
headers?: {
|
|
104
|
-
[key: string]: string;
|
|
105
|
-
};
|
|
106
|
-
body?: string;
|
|
107
|
-
message?: string;
|
|
108
|
-
};
|
|
109
|
-
declare class HttpError extends Error {
|
|
110
|
-
readonly statusCode: number;
|
|
111
|
-
readonly message: string;
|
|
112
|
-
constructor({ statusCode, message, }: {
|
|
113
|
-
statusCode?: number;
|
|
114
|
-
message: string;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
declare class Http<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> implements Plugin {
|
|
118
|
-
readonly type = "http";
|
|
119
|
-
readonly name: string;
|
|
120
|
-
headers: {
|
|
121
|
-
[key: string]: string;
|
|
122
|
-
};
|
|
123
|
-
body: any;
|
|
124
|
-
params: TParams;
|
|
125
|
-
cookie: Cookie<TCookie, TSession>;
|
|
126
|
-
session: Session<TSession, TCookie>;
|
|
127
|
-
config: HttpConfig;
|
|
128
|
-
private response?;
|
|
129
|
-
constructor(config?: HttpConfig);
|
|
130
|
-
onMount(data: MountData, next: Next): Promise<void>;
|
|
131
|
-
onInvoke(data: InvokeData, next: Next): Promise<void>;
|
|
132
|
-
/**
|
|
133
|
-
* set header
|
|
134
|
-
* @param key {string} key
|
|
135
|
-
* @param value {string} value
|
|
136
|
-
*/
|
|
137
|
-
setHeader(key: string, value: string): Http<TParams, TCookie, TSession>;
|
|
138
|
-
/**
|
|
139
|
-
* set Content-Type
|
|
140
|
-
* @param type {string} 类型
|
|
141
|
-
* @param charset {string} 编码
|
|
142
|
-
*/
|
|
143
|
-
setContentType(type: string, charset?: string): Http<TParams, TCookie, TSession>;
|
|
144
|
-
/**
|
|
145
|
-
* set status code
|
|
146
|
-
* @param code {number} 状态码
|
|
147
|
-
*/
|
|
148
|
-
setStatusCode(code: number): Http<TParams, TCookie, TSession>;
|
|
149
|
-
/**
|
|
150
|
-
* set body
|
|
151
|
-
* @param body {*} 内容
|
|
152
|
-
*/
|
|
153
|
-
setBody(body: string): Http<TParams, TCookie, TSession>;
|
|
154
|
-
}
|
|
155
|
-
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>>;
|
|
156
|
-
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<{
|
|
157
|
-
[key: string]: any;
|
|
158
|
-
params?: TParams;
|
|
159
|
-
}> & {
|
|
160
|
-
params?: TParams;
|
|
161
|
-
cookie?: Cookie<TCookie, TSession>;
|
|
162
|
-
session?: Session<TSession, TCookie>;
|
|
163
|
-
}) => Promise<TResult>;
|
|
164
|
-
/**
|
|
165
|
-
* A hook to create an HTTP function with specified handler and configuration.
|
|
166
|
-
*
|
|
167
|
-
* @template TParams - The type of the parameters object.
|
|
168
|
-
* @template TCookie - The type of the cookies object.
|
|
169
|
-
* @template TSession - The type of the session object.
|
|
170
|
-
* @template TResult - The type of the result.
|
|
171
|
-
*
|
|
172
|
-
* @param {() => HttpFuncHandler<TParams, TCookie, TSession, TResult>} handler - The function handler to be used.
|
|
173
|
-
* @param {Object} [config] - Optional configuration object.
|
|
174
|
-
* @param {HttpConfig} [config.http] - Optional HTTP configuration.
|
|
175
|
-
*
|
|
176
|
-
* @returns {Function} The created HTTP function.
|
|
177
|
-
*/
|
|
178
|
-
declare function useHttpFunc<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>(handler: () => HttpFuncHandler<TParams, TCookie, TSession, TResult>, config?: {
|
|
179
|
-
http?: HttpConfig;
|
|
180
|
-
}): _faasjs_func.Func<{
|
|
181
|
-
[key: string]: any;
|
|
182
|
-
params?: TParams;
|
|
183
|
-
}, any, TResult>;
|
|
184
|
-
|
|
185
|
-
export { ContentType, Cookie, type CookieOptions, Http, type HttpConfig, HttpError, type HttpFuncHandler, type Response, Session, type SessionOptions, useHttp, useHttpFunc };
|