@aeriajs/http 0.0.52 → 0.0.54
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.d.ts +6 -6
- package/dist/routing.js +2 -6
- package/dist/routing.mjs +3 -6
- package/package.json +5 -5
package/dist/routing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RouteContext, GenericRequest, GenericResponse, RequestMethod, RouteUri, InferProperty, InferResponse, PackReferences, ContractWithRoles, ApiConfig } from '@aeriajs/types';
|
|
1
|
+
import type { RouteContext, GenericRequest, GenericResponse, RequestMethod, RouteUri, InferProperty, InferResponse, PackReferences, ContractWithRoles, ApiConfig, UserRole } from '@aeriajs/types';
|
|
2
2
|
export type RouterOptions = {
|
|
3
3
|
exhaust?: boolean;
|
|
4
4
|
base?: RouteUri;
|
|
@@ -8,7 +8,7 @@ export type Middleware = (context: RouteContext) => any;
|
|
|
8
8
|
export type RouteGroupOptions = {
|
|
9
9
|
base?: RouteUri;
|
|
10
10
|
};
|
|
11
|
-
type TypedContext<TContractWithRoles extends ContractWithRoles> = RouteContext<number extends keyof
|
|
11
|
+
type TypedContext<TContractWithRoles extends ContractWithRoles> = RouteContext<TContractWithRoles['roles'] extends infer AccessCondition ? number extends keyof AccessCondition ? AccessCondition[number] : AccessCondition extends true ? UserRole : AccessCondition extends false ? never : AccessCondition extends 'unauthenticated-only' ? 'guest' : AccessCondition extends 'unauthenticated' ? UserRole : null : never> & {
|
|
12
12
|
request: Omit<RouteContext['request'], 'payload' | 'query'> & {
|
|
13
13
|
payload: TContractWithRoles extends {
|
|
14
14
|
payload: infer Payload;
|
|
@@ -20,11 +20,11 @@ type TypedContext<TContractWithRoles extends ContractWithRoles> = RouteContext<n
|
|
|
20
20
|
};
|
|
21
21
|
export type ProxiedRouter<TRouter> = TRouter & Record<RequestMethod, <const TContractWithRoles extends ContractWithRoles, TCallback extends (TContractWithRoles extends {
|
|
22
22
|
response: infer Response;
|
|
23
|
-
} ? InferResponse<Response> : any) extends infer Response ? TContractWithRoles['roles'] extends
|
|
23
|
+
} ? InferResponse<Response> : any) extends infer Response ? TContractWithRoles['roles'] extends infer AccessCondition ? AccessCondition extends true ? (context: TypedContext<TContractWithRoles> & {
|
|
24
24
|
token: {
|
|
25
25
|
authenticated: true;
|
|
26
26
|
};
|
|
27
|
-
}) => Response :
|
|
27
|
+
}) => Response : (context: TypedContext<TContractWithRoles>) => Response : never : never>(exp: RouteUri, cb: TCallback, contract?: TContractWithRoles) => ReturnType<typeof registerRoute>>;
|
|
28
28
|
export declare const matches: <TRequest extends GenericRequest>(req: TRequest, method: RequestMethod | RequestMethod[] | null, exp: string | RegExp, options: RouterOptions, config?: ApiConfig) => {
|
|
29
29
|
fragments: string[];
|
|
30
30
|
} | undefined;
|
|
@@ -33,7 +33,7 @@ export declare const wrapRouteExecution: (res: GenericResponse, cb: () => any |
|
|
|
33
33
|
export declare const createRouter: (options?: Partial<RouterOptions>) => ProxiedRouter<{
|
|
34
34
|
route: <const TContractWithRoles extends ContractWithRoles, TCallback extends (TContractWithRoles extends {
|
|
35
35
|
response: infer Response;
|
|
36
|
-
} ? InferResponse<Response> : any) extends infer Response_1 ? TContractWithRoles["roles"] extends
|
|
36
|
+
} ? InferResponse<Response> : any) extends infer Response_1 ? TContractWithRoles["roles"] extends infer AccessCondition ? AccessCondition extends true ? (context: RouteContext<TContractWithRoles["roles"] extends infer AccessCondition_1 ? number extends keyof AccessCondition_1 ? AccessCondition_1[number] : AccessCondition_1 extends true ? any : AccessCondition_1 extends false ? never : AccessCondition_1 extends "unauthenticated-only" ? "guest" : AccessCondition_1 extends "unauthenticated" ? any : null : never> & {
|
|
37
37
|
request: Omit<GenericRequest, "payload" | "query"> & {
|
|
38
38
|
payload: TContractWithRoles extends {
|
|
39
39
|
payload: infer Payload;
|
|
@@ -46,7 +46,7 @@ export declare const createRouter: (options?: Partial<RouterOptions>) => Proxied
|
|
|
46
46
|
token: {
|
|
47
47
|
authenticated: true;
|
|
48
48
|
};
|
|
49
|
-
}) => Response_1 :
|
|
49
|
+
}) => Response_1 : (context: TypedContext<TContractWithRoles>) => Response_1 : never : never>(method: RequestMethod | RequestMethod[], exp: RouteUri, cb: TCallback, contract?: TContractWithRoles) => void;
|
|
50
50
|
routes: ((_: unknown, context: RouteContext, groupOptions?: RouteGroupOptions) => ReturnType<typeof registerRoute>)[];
|
|
51
51
|
routesMeta: RoutesMeta;
|
|
52
52
|
group: <TRouter extends {
|
package/dist/routing.js
CHANGED
|
@@ -71,12 +71,8 @@ const registerRoute = async (context, method, exp, cb, contract, options = {}) =
|
|
|
71
71
|
Object.assign(context.request, match);
|
|
72
72
|
if (contract) {
|
|
73
73
|
if (contract.roles) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return unsufficientRoles(context);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (!(0, common_1.arraysIntersects)(context.token.roles, contract.roles)) {
|
|
74
|
+
const granted = (0, common_1.isGranted)(contract.roles, context.token);
|
|
75
|
+
if (!granted) {
|
|
80
76
|
return unsufficientRoles(context);
|
|
81
77
|
}
|
|
82
78
|
}
|
package/dist/routing.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Stream } from "stream";
|
|
3
3
|
import { ACErrors, REQUEST_METHODS } from "@aeriajs/types";
|
|
4
|
-
import { pipe,
|
|
4
|
+
import { pipe, isGranted, left, isLeft, unwrapEither, deepMerge } from "@aeriajs/common";
|
|
5
5
|
import { validate } from "@aeriajs/validation";
|
|
6
6
|
import { getConfig } from "@aeriajs/entrypoint";
|
|
7
7
|
import { safeJson } from "./payload.mjs";
|
|
@@ -69,11 +69,8 @@ export const registerRoute = async (context, method, exp, cb, contract, options
|
|
|
69
69
|
Object.assign(context.request, match);
|
|
70
70
|
if (contract) {
|
|
71
71
|
if (contract.roles) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return unsufficientRoles(context);
|
|
75
|
-
}
|
|
76
|
-
} else if (!arraysIntersects(context.token.roles, contract.roles)) {
|
|
72
|
+
const granted = isGranted(contract.roles, context.token);
|
|
73
|
+
if (!granted) {
|
|
77
74
|
return unsufficientRoles(context);
|
|
78
75
|
}
|
|
79
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.54",
|
|
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.46",
|
|
32
|
+
"@aeriajs/entrypoint": "^0.0.46",
|
|
33
|
+
"@aeriajs/types": "^0.0.43",
|
|
34
|
+
"@aeriajs/validation": "^0.0.49"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "echo skipping",
|