@aeriajs/http 0.0.60 → 0.0.61
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/routing.js +11 -16
- package/dist/routing.mjs +13 -18
- package/package.json +5 -5
package/dist/routing.js
CHANGED
|
@@ -10,20 +10,14 @@ const payload_js_1 = require("./payload.js");
|
|
|
10
10
|
const next_js_1 = require("./next.js");
|
|
11
11
|
const checkUnprocessable = (validationEither, context) => {
|
|
12
12
|
if ((0, common_1.isLeft)(validationEither)) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const validationError = (0, common_1.unwrapEither)(validationEither);
|
|
14
|
+
return context.error(types_1.HTTPStatus.UnprocessableContent, {
|
|
15
|
+
code: 'UNPROCESSABLE_ENTITY',
|
|
16
|
+
message: 'the provided payload is unprocessable',
|
|
17
|
+
details: validationError,
|
|
15
18
|
});
|
|
16
|
-
return validationEither;
|
|
17
19
|
}
|
|
18
20
|
};
|
|
19
|
-
const unsufficientRoles = (context) => {
|
|
20
|
-
context.response.writeHead(403, {
|
|
21
|
-
'content-type': 'application/json',
|
|
22
|
-
});
|
|
23
|
-
return {
|
|
24
|
-
error: types_1.ACErrors.AuthorizationError,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
21
|
const matches = (req, method, exp, options, config) => {
|
|
28
22
|
const base = config?.baseUrl && config.baseUrl !== '/'
|
|
29
23
|
? options.base
|
|
@@ -61,8 +55,7 @@ const registerRoute = async (context, method, exp, cb, contract, options = {}) =
|
|
|
61
55
|
});
|
|
62
56
|
}
|
|
63
57
|
catch (err) {
|
|
64
|
-
return context.error({
|
|
65
|
-
httpCode: 500,
|
|
58
|
+
return context.error(types_1.HTTPStatus.UnprocessableContent, {
|
|
66
59
|
code: 'INVALID_JSON',
|
|
67
60
|
message: 'Invalid JSON',
|
|
68
61
|
});
|
|
@@ -73,7 +66,10 @@ const registerRoute = async (context, method, exp, cb, contract, options = {}) =
|
|
|
73
66
|
if (contract.roles) {
|
|
74
67
|
const granted = (0, common_1.isGranted)(contract.roles, context.token);
|
|
75
68
|
if (!granted) {
|
|
76
|
-
return
|
|
69
|
+
return context.error(types_1.HTTPStatus.Unauthorized, {
|
|
70
|
+
code: types_1.ACError.AuthorizationError,
|
|
71
|
+
message: 'your roles dont grant access to this route',
|
|
72
|
+
});
|
|
77
73
|
}
|
|
78
74
|
}
|
|
79
75
|
if ('payload' in contract && contract.payload) {
|
|
@@ -199,8 +195,7 @@ const createRouter = (options = {}) => {
|
|
|
199
195
|
router.install = async (context, options) => {
|
|
200
196
|
const result = await routerPipe(undefined, context, options);
|
|
201
197
|
if (exhaust && (result === undefined || (0, next_js_1.isNext)(result))) {
|
|
202
|
-
return context.error({
|
|
203
|
-
httpCode: 404,
|
|
198
|
+
return context.error(types_1.HTTPStatus.NotFound, {
|
|
204
199
|
code: 'NOT_FOUND',
|
|
205
200
|
message: 'Not found',
|
|
206
201
|
});
|
package/dist/routing.mjs
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Stream } from "stream";
|
|
3
|
-
import {
|
|
4
|
-
import { pipe, isGranted, isLeft, deepMerge, error } from "@aeriajs/common";
|
|
3
|
+
import { ACError, HTTPStatus, REQUEST_METHODS } from "@aeriajs/types";
|
|
4
|
+
import { pipe, isGranted, isLeft, unwrapEither, deepMerge, error } from "@aeriajs/common";
|
|
5
5
|
import { validate } from "@aeriajs/validation";
|
|
6
6
|
import { getConfig } from "@aeriajs/entrypoint";
|
|
7
7
|
import { safeJson } from "./payload.mjs";
|
|
8
8
|
import { isNext } from "./next.mjs";
|
|
9
9
|
const checkUnprocessable = (validationEither, context) => {
|
|
10
10
|
if (isLeft(validationEither)) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const validationError = unwrapEither(validationEither);
|
|
12
|
+
return context.error(HTTPStatus.UnprocessableContent, {
|
|
13
|
+
code: "UNPROCESSABLE_ENTITY",
|
|
14
|
+
message: "the provided payload is unprocessable",
|
|
15
|
+
details: validationError
|
|
13
16
|
});
|
|
14
|
-
return validationEither;
|
|
15
17
|
}
|
|
16
18
|
};
|
|
17
|
-
const unsufficientRoles = (context) => {
|
|
18
|
-
context.response.writeHead(403, {
|
|
19
|
-
"content-type": "application/json"
|
|
20
|
-
});
|
|
21
|
-
return {
|
|
22
|
-
error: ACErrors.AuthorizationError
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
19
|
export const matches = (req, method, exp, options, config) => {
|
|
26
20
|
const base = config?.baseUrl && config.baseUrl !== "/" ? options.base ? `${config.baseUrl}${options.base}` : config.baseUrl : options.base ? options.base : "";
|
|
27
21
|
if (method && method !== req.method) {
|
|
@@ -59,8 +53,7 @@ export const registerRoute = async (context, method, exp, cb, contract, options
|
|
|
59
53
|
}
|
|
60
54
|
);
|
|
61
55
|
} catch (err) {
|
|
62
|
-
return context.error({
|
|
63
|
-
httpCode: 500,
|
|
56
|
+
return context.error(HTTPStatus.UnprocessableContent, {
|
|
64
57
|
code: "INVALID_JSON",
|
|
65
58
|
message: "Invalid JSON"
|
|
66
59
|
});
|
|
@@ -71,7 +64,10 @@ export const registerRoute = async (context, method, exp, cb, contract, options
|
|
|
71
64
|
if (contract.roles) {
|
|
72
65
|
const granted = isGranted(contract.roles, context.token);
|
|
73
66
|
if (!granted) {
|
|
74
|
-
return
|
|
67
|
+
return context.error(HTTPStatus.Unauthorized, {
|
|
68
|
+
code: ACError.AuthorizationError,
|
|
69
|
+
message: "your roles dont grant access to this route"
|
|
70
|
+
});
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
if ("payload" in contract && contract.payload) {
|
|
@@ -195,8 +191,7 @@ export const createRouter = (options = {}) => {
|
|
|
195
191
|
router.install = async (context, options2) => {
|
|
196
192
|
const result = await routerPipe(void 0, context, options2);
|
|
197
193
|
if (exhaust && (result === void 0 || isNext(result))) {
|
|
198
|
-
return context.error({
|
|
199
|
-
httpCode: 404,
|
|
194
|
+
return context.error(HTTPStatus.NotFound, {
|
|
200
195
|
code: "NOT_FOUND",
|
|
201
196
|
message: "Not found"
|
|
202
197
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"@aeriajs/validation": "link:../validation"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@aeriajs/common": "^0.0.
|
|
32
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
33
|
-
"@aeriajs/types": "^0.0.
|
|
34
|
-
"@aeriajs/validation": "^0.0.
|
|
31
|
+
"@aeriajs/common": "^0.0.53",
|
|
32
|
+
"@aeriajs/entrypoint": "^0.0.53",
|
|
33
|
+
"@aeriajs/types": "^0.0.50",
|
|
34
|
+
"@aeriajs/validation": "^0.0.56"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "echo skipping",
|