@aeriajs/common 0.0.51 → 0.0.53
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/error.d.ts +5 -5
- package/dist/error.js +4 -4
- package/dist/error.mjs +4 -4
- package/dist/isGranted.js +1 -1
- package/dist/isGranted.mjs +1 -1
- package/dist/schema.d.ts +2 -2
- package/package.json +2 -2
package/dist/error.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { EndpointError, RouteContext } from '@aeriajs/types';
|
|
2
|
-
export declare const error: (error:
|
|
3
|
-
readonly
|
|
4
|
-
readonly error:
|
|
1
|
+
import type { EndpointError, EndpointErrorContent, RouteContext } from '@aeriajs/types';
|
|
2
|
+
export declare const error: <TEndpointErrorContent extends EndpointErrorContent>(error: TEndpointErrorContent, context: Pick<RouteContext, 'response'>) => {
|
|
3
|
+
readonly _tag: "Error";
|
|
4
|
+
readonly error: TEndpointErrorContent;
|
|
5
5
|
};
|
|
6
|
-
export declare const isError: (object: any) => object is EndpointError
|
|
6
|
+
export declare const isError: (object: any) => object is EndpointError<any>;
|
package/dist/error.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isError = exports.error = void 0;
|
|
4
4
|
const error = (error, context) => {
|
|
5
|
-
const {
|
|
6
|
-
context.response.writeHead(
|
|
5
|
+
const { httpStatus = 500 } = error;
|
|
6
|
+
context.response.writeHead(httpStatus, {
|
|
7
7
|
'content-type': 'application/json',
|
|
8
8
|
});
|
|
9
9
|
return {
|
|
10
|
-
|
|
10
|
+
_tag: 'Error',
|
|
11
11
|
error,
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
exports.error = error;
|
|
15
15
|
const isError = (object) => {
|
|
16
|
-
return object
|
|
16
|
+
return object._tag === 'Error';
|
|
17
17
|
};
|
|
18
18
|
exports.isError = isError;
|
package/dist/error.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
export const error = (error2, context) => {
|
|
3
|
-
const {
|
|
4
|
-
context.response.writeHead(
|
|
3
|
+
const { httpStatus = 500 } = error2;
|
|
4
|
+
context.response.writeHead(httpStatus, {
|
|
5
5
|
"content-type": "application/json"
|
|
6
6
|
});
|
|
7
7
|
return {
|
|
8
|
-
|
|
8
|
+
_tag: "Error",
|
|
9
9
|
error: error2
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
export const isError = (object) => {
|
|
13
|
-
return object
|
|
13
|
+
return object._tag === "Error";
|
|
14
14
|
};
|
package/dist/isGranted.js
CHANGED
|
@@ -6,7 +6,7 @@ const isGranted = (condition, token) => {
|
|
|
6
6
|
if (Array.isArray(condition)) {
|
|
7
7
|
return token.authenticated
|
|
8
8
|
? (0, arraysIntersects_js_1.arraysIntersects)(token.roles, condition)
|
|
9
|
-
: condition.includes('
|
|
9
|
+
: condition.includes('unauthenticated');
|
|
10
10
|
}
|
|
11
11
|
switch (condition) {
|
|
12
12
|
case false: return false;
|
package/dist/isGranted.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { arraysIntersects } from "./arraysIntersects.mjs";
|
|
3
3
|
export const isGranted = (condition, token) => {
|
|
4
4
|
if (Array.isArray(condition)) {
|
|
5
|
-
return token.authenticated ? arraysIntersects(token.roles, condition) : condition.includes("
|
|
5
|
+
return token.authenticated ? arraysIntersects(token.roles, condition) : condition.includes("unauthenticated");
|
|
6
6
|
}
|
|
7
7
|
switch (condition) {
|
|
8
8
|
case false:
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Property, ObjectToSchema,
|
|
1
|
+
import type { Property, ObjectToSchema, EndpointErrorContent } from '@aeriajs/types';
|
|
2
2
|
export declare const fromLiteral: <const TObject, TRequired extends (keyof TObject & string)[]>(object: TObject, required?: TRequired) => ObjectToSchema<TObject, TRequired>;
|
|
3
3
|
export declare const leftSchema: <const TObject extends Property>(object: TObject) => {
|
|
4
4
|
readonly type: "object";
|
|
@@ -18,7 +18,7 @@ export declare const rightSchema: <const TObject extends Property>(object: TObje
|
|
|
18
18
|
readonly value: Property;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
export declare const endpointErrorSchema: (error:
|
|
21
|
+
export declare const endpointErrorSchema: (error: EndpointErrorContent) => {
|
|
22
22
|
readonly type: "object";
|
|
23
23
|
readonly properties: {
|
|
24
24
|
readonly httpCode: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"bson": "^6.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@aeriajs/types": "^0.0.
|
|
34
|
+
"@aeriajs/types": "^0.0.50",
|
|
35
35
|
"bson": "^6.5.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|