@wooksjs/event-http 0.2.4 → 0.2.6
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/index.cjs +6 -6
- package/dist/index.d.ts +21 -19
- package/dist/index.mjs +6 -6
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -812,7 +812,7 @@ class WooksErrorRenderer extends BaseWooksResponseRenderer {
|
|
|
812
812
|
`<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
|
|
813
813
|
`<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
|
|
814
814
|
`<center><h4>${data.message}</h1></center><hr color="#666">` +
|
|
815
|
-
`<center style="color: #666;"> Wooks v${"0.2.
|
|
815
|
+
`<center style="color: #666;"> Wooks v${"0.2.6"} </center>` +
|
|
816
816
|
`${keys.length ? `<pre style="${preStyles}">${JSON.stringify(Object.assign(Object.assign({}, data), { statusCode: undefined, message: undefined, error: undefined }), null, ' ')}</pre>` : ''}` +
|
|
817
817
|
'</body></html>';
|
|
818
818
|
}
|
|
@@ -854,7 +854,7 @@ function escapeQuotes(s) {
|
|
|
854
854
|
return (typeof s === 'number' ? s : (s || '')).toString().replace(/[\""]/g, '\\"');
|
|
855
855
|
}
|
|
856
856
|
|
|
857
|
-
class
|
|
857
|
+
class HttpError extends Error {
|
|
858
858
|
constructor(code = 500, _body = '') {
|
|
859
859
|
super(typeof _body === 'string' ? _body : _body.message);
|
|
860
860
|
this.code = code;
|
|
@@ -887,11 +887,11 @@ errorRenderer = new WooksErrorRenderer()) {
|
|
|
887
887
|
if (data instanceof Error) {
|
|
888
888
|
const r = new BaseWooksResponse(errorRenderer);
|
|
889
889
|
let httpError;
|
|
890
|
-
if (data instanceof
|
|
890
|
+
if (data instanceof HttpError) {
|
|
891
891
|
httpError = data;
|
|
892
892
|
}
|
|
893
893
|
else {
|
|
894
|
-
httpError = new
|
|
894
|
+
httpError = new HttpError(500, data.message);
|
|
895
895
|
}
|
|
896
896
|
r.setBody(httpError.body);
|
|
897
897
|
return r;
|
|
@@ -982,7 +982,7 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
982
982
|
}
|
|
983
983
|
else {
|
|
984
984
|
// not found
|
|
985
|
-
this.respond(new
|
|
985
|
+
this.respond(new HttpError(404));
|
|
986
986
|
clearCtx();
|
|
987
987
|
}
|
|
988
988
|
});
|
|
@@ -1022,7 +1022,7 @@ function createHttpApp(opts, wooks) {
|
|
|
1022
1022
|
|
|
1023
1023
|
exports.BaseWooksResponse = BaseWooksResponse;
|
|
1024
1024
|
exports.BaseWooksResponseRenderer = BaseWooksResponseRenderer;
|
|
1025
|
-
exports.
|
|
1025
|
+
exports.HttpError = HttpError;
|
|
1026
1026
|
exports.WooksErrorRenderer = WooksErrorRenderer;
|
|
1027
1027
|
exports.WooksHttp = WooksHttp;
|
|
1028
1028
|
exports.WooksURLSearchParams = WooksURLSearchParams;
|
package/dist/index.d.ts
CHANGED
|
@@ -137,9 +137,19 @@ export declare enum EHttpStatusCode {
|
|
|
137
137
|
NetworkAuthenticationRequired = 511
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
export declare class HttpError<T extends TWooksErrorBody = TWooksErrorBody> extends Error {
|
|
141
|
+
protected code: THttpErrorCodes;
|
|
142
|
+
protected _body: string | T;
|
|
143
|
+
constructor(code?: THttpErrorCodes, _body?: string | T);
|
|
144
|
+
get body(): TWooksErrorBodyExt;
|
|
145
|
+
protected renderer?: WooksErrorRenderer;
|
|
146
|
+
attachRenderer(renderer: WooksErrorRenderer): void;
|
|
147
|
+
getRenderer(): WooksErrorRenderer | undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
140
150
|
export declare function renderCacheControl(data: TCacheControl): string;
|
|
141
151
|
|
|
142
|
-
declare type TAuthCache = {
|
|
152
|
+
export declare type TAuthCache = {
|
|
143
153
|
type: string | null;
|
|
144
154
|
credentials: string | null;
|
|
145
155
|
basicCredentials: {
|
|
@@ -160,7 +170,7 @@ export declare type TCacheControl = {
|
|
|
160
170
|
sMaxage?: number | TTimeMultiString;
|
|
161
171
|
};
|
|
162
172
|
|
|
163
|
-
declare interface TCookieAttributes {
|
|
173
|
+
export declare interface TCookieAttributes {
|
|
164
174
|
expires: Date | string | number;
|
|
165
175
|
maxAge: number | TTimeMultiString;
|
|
166
176
|
domain: string;
|
|
@@ -170,13 +180,15 @@ declare interface TCookieAttributes {
|
|
|
170
180
|
sameSite: boolean | 'Lax' | 'None' | 'Strict';
|
|
171
181
|
}
|
|
172
182
|
|
|
183
|
+
export declare type TCookieAttributesInput = Partial<TCookieAttributes>;
|
|
184
|
+
|
|
173
185
|
export declare type TCookieHook = ReturnType<typeof useSetCookie>;
|
|
174
186
|
|
|
175
187
|
export declare type THeaderHook = ReturnType<typeof useSetHeader>;
|
|
176
188
|
|
|
177
189
|
declare type THttpBadRequestCodes = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
|
|
178
190
|
|
|
179
|
-
declare interface THttpContextStore extends TGenericContextStore<THttpEvent> {
|
|
191
|
+
export declare interface THttpContextStore extends TGenericContextStore<THttpEvent> {
|
|
180
192
|
searchParams?: TSearchParamsCache;
|
|
181
193
|
cookies?: {
|
|
182
194
|
[name: string]: string | null;
|
|
@@ -202,18 +214,18 @@ declare interface THttpContextStore extends TGenericContextStore<THttpEvent> {
|
|
|
202
214
|
|
|
203
215
|
declare type THttpErrorCodes = THttpBadRequestCodes | THttpServerErrorCodes;
|
|
204
216
|
|
|
205
|
-
declare interface THttpEvent extends TGenericEvent, THttpEventData {
|
|
217
|
+
export declare interface THttpEvent extends TGenericEvent, THttpEventData {
|
|
206
218
|
type: 'HTTP';
|
|
207
219
|
}
|
|
208
220
|
|
|
209
|
-
declare interface THttpEventData {
|
|
221
|
+
export declare interface THttpEventData {
|
|
210
222
|
req: IncomingMessage;
|
|
211
223
|
res: ServerResponse;
|
|
212
224
|
}
|
|
213
225
|
|
|
214
226
|
declare type THttpServerErrorCodes = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
215
227
|
|
|
216
|
-
declare type TRequestCache = {
|
|
228
|
+
export declare type TRequestCache = {
|
|
217
229
|
rawBody: Promise<Buffer>;
|
|
218
230
|
parsed: unknown;
|
|
219
231
|
forwardedIp?: string;
|
|
@@ -224,14 +236,14 @@ declare type TRequestCache = {
|
|
|
224
236
|
};
|
|
225
237
|
};
|
|
226
238
|
|
|
227
|
-
declare type TSearchParamsCache = {
|
|
239
|
+
export declare type TSearchParamsCache = {
|
|
228
240
|
raw?: string;
|
|
229
241
|
urlSearchParams?: WooksURLSearchParams;
|
|
230
242
|
};
|
|
231
243
|
|
|
232
|
-
declare type TSetCookieData = {
|
|
244
|
+
export declare type TSetCookieData = {
|
|
233
245
|
value: string;
|
|
234
|
-
attrs:
|
|
246
|
+
attrs: TCookieAttributesInput;
|
|
235
247
|
};
|
|
236
248
|
|
|
237
249
|
export declare type TStatusHook = ReturnType<typeof useStatus>;
|
|
@@ -392,16 +404,6 @@ export declare function useStatus(): {
|
|
|
392
404
|
isDefined: boolean;
|
|
393
405
|
};
|
|
394
406
|
|
|
395
|
-
export declare class WooksError<T extends TWooksErrorBody = TWooksErrorBody> extends Error {
|
|
396
|
-
protected code: THttpErrorCodes;
|
|
397
|
-
protected _body: string | T;
|
|
398
|
-
constructor(code?: THttpErrorCodes, _body?: string | T);
|
|
399
|
-
get body(): TWooksErrorBodyExt;
|
|
400
|
-
protected renderer?: WooksErrorRenderer;
|
|
401
|
-
attachRenderer(renderer: WooksErrorRenderer): void;
|
|
402
|
-
getRenderer(): WooksErrorRenderer | undefined;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
407
|
export declare class WooksErrorRenderer extends BaseWooksResponseRenderer<TWooksErrorBodyExt> {
|
|
406
408
|
renderHtml(response: BaseWooksResponse<TWooksErrorBodyExt>): string;
|
|
407
409
|
renderText(response: BaseWooksResponse<TWooksErrorBodyExt>): string;
|
package/dist/index.mjs
CHANGED
|
@@ -810,7 +810,7 @@ class WooksErrorRenderer extends BaseWooksResponseRenderer {
|
|
|
810
810
|
`<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
|
|
811
811
|
`<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
|
|
812
812
|
`<center><h4>${data.message}</h1></center><hr color="#666">` +
|
|
813
|
-
`<center style="color: #666;"> Wooks v${"0.2.
|
|
813
|
+
`<center style="color: #666;"> Wooks v${"0.2.6"} </center>` +
|
|
814
814
|
`${keys.length ? `<pre style="${preStyles}">${JSON.stringify(Object.assign(Object.assign({}, data), { statusCode: undefined, message: undefined, error: undefined }), null, ' ')}</pre>` : ''}` +
|
|
815
815
|
'</body></html>';
|
|
816
816
|
}
|
|
@@ -852,7 +852,7 @@ function escapeQuotes(s) {
|
|
|
852
852
|
return (typeof s === 'number' ? s : (s || '')).toString().replace(/[\""]/g, '\\"');
|
|
853
853
|
}
|
|
854
854
|
|
|
855
|
-
class
|
|
855
|
+
class HttpError extends Error {
|
|
856
856
|
constructor(code = 500, _body = '') {
|
|
857
857
|
super(typeof _body === 'string' ? _body : _body.message);
|
|
858
858
|
this.code = code;
|
|
@@ -885,11 +885,11 @@ errorRenderer = new WooksErrorRenderer()) {
|
|
|
885
885
|
if (data instanceof Error) {
|
|
886
886
|
const r = new BaseWooksResponse(errorRenderer);
|
|
887
887
|
let httpError;
|
|
888
|
-
if (data instanceof
|
|
888
|
+
if (data instanceof HttpError) {
|
|
889
889
|
httpError = data;
|
|
890
890
|
}
|
|
891
891
|
else {
|
|
892
|
-
httpError = new
|
|
892
|
+
httpError = new HttpError(500, data.message);
|
|
893
893
|
}
|
|
894
894
|
r.setBody(httpError.body);
|
|
895
895
|
return r;
|
|
@@ -980,7 +980,7 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
980
980
|
}
|
|
981
981
|
else {
|
|
982
982
|
// not found
|
|
983
|
-
this.respond(new
|
|
983
|
+
this.respond(new HttpError(404));
|
|
984
984
|
clearCtx();
|
|
985
985
|
}
|
|
986
986
|
});
|
|
@@ -1018,4 +1018,4 @@ function createHttpApp(opts, wooks) {
|
|
|
1018
1018
|
return new WooksHttp(opts, wooks);
|
|
1019
1019
|
}
|
|
1020
1020
|
|
|
1021
|
-
export { BaseWooksResponse, BaseWooksResponseRenderer, EHttpStatusCode,
|
|
1021
|
+
export { BaseWooksResponse, BaseWooksResponseRenderer, EHttpStatusCode, HttpError, WooksErrorRenderer, WooksHttp, WooksURLSearchParams, createHttpApp, createHttpContext, createWooksResponder, renderCacheControl, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useSearchParams, useSetCacheControl, useSetCookie, useSetCookies, useSetHeader, useSetHeaders, useStatus };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-http",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "@wooksjs/event-http",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"wooks": "0.2.
|
|
35
|
-
"@wooksjs/event-core": "0.2.
|
|
34
|
+
"wooks": "0.2.6",
|
|
35
|
+
"@wooksjs/event-core": "0.2.6"
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/event-http#readme"
|
|
38
38
|
}
|