@bool-ts/guard-sdk 1.0.2-beta.5 → 1.1.0-beta.10
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/decorators/actionGuard.decorator.d.ts +3 -1
- package/dist/decorators/controllerGuard.decorator.d.ts +2 -1
- package/dist/definers/index.d.ts +1 -0
- package/dist/definers/policies.d.ts +5 -0
- package/dist/definers/resources.d.ts +11 -0
- package/dist/entities/@validators.d.ts +6 -0
- package/dist/entities/guard.d.ts +7 -0
- package/dist/entities/index.d.ts +1 -2
- package/dist/entities/loader.d.ts +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +36 -17
- package/dist/index.js.map +44 -44
- package/dist/instances/client.d.ts +7 -4
- package/dist/interfaces/client.interface.d.ts +9 -4
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/types/actionGuard.d.ts +8 -0
- package/dist/types/controllerGuard.d.ts +6 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/policies.d.ts +11 -0
- package/dist/types/resources.d.ts +6 -0
- package/dist/ultils/functions/deepFreeze.d.ts +2 -0
- package/dist/ultils/functions/index.d.ts +1 -0
- package/dist/ultils/types/constructor.d.ts +1 -0
- package/dist/ultils/types/deepReadonly.d.ts +5 -0
- package/dist/ultils/types/enforceUnique.d.ts +8 -0
- package/dist/ultils/types/error.d.ts +3 -0
- package/dist/ultils/types/extractTuple.d.ts +1 -0
- package/dist/ultils/types/inArray.d.ts +1 -0
- package/dist/ultils/types/index.d.ts +15 -0
- package/dist/ultils/types/mergeTuple.d.ts +3 -0
- package/dist/ultils/types/noneEmptyArray.d.ts +1 -0
- package/dist/ultils/types/partialTuple.d.ts +4 -0
- package/dist/ultils/types/partialTupleUnordered.d.ts +3 -0
- package/dist/ultils/types/partialTupleUnorderedNonEmpty.d.ts +3 -0
- package/dist/ultils/types/partialTurpleNonEmpty.d.ts +2 -0
- package/dist/ultils/types/permutationTuple.d.ts +1 -0
- package/dist/ultils/types/shuffleTuple.d.ts +5 -0
- package/dist/ultils/types/strictPartial.d.ts +5 -0
- package/package.json +10 -10
- package/src/decorators/actionGuard.decorator.ts +19 -3
- package/src/decorators/controllerGuard.decorator.ts +7 -3
- package/src/definers/index.ts +1 -0
- package/src/definers/policies.ts +25 -0
- package/src/definers/resources.ts +76 -0
- package/src/entities/@validators.ts +22 -0
- package/src/entities/guard.ts +81 -0
- package/src/entities/index.ts +1 -2
- package/src/entities/loader.ts +17 -3
- package/src/index.ts +1 -0
- package/src/instances/client.ts +135 -57
- package/src/interfaces/account.interface.ts +4 -1
- package/src/interfaces/base.ts +5 -1
- package/src/interfaces/client.interface.ts +18 -8
- package/src/interfaces/index.ts +6 -1
- package/src/types/actionGuard.ts +11 -0
- package/src/types/controllerGuard.ts +8 -0
- package/src/types/index.ts +3 -0
- package/src/types/policies.ts +36 -0
- package/src/types/resources.ts +10 -0
- package/src/ultils/functions/deepFreeze.ts +13 -0
- package/src/ultils/functions/index.ts +1 -0
- package/src/ultils/types/constructor.ts +1 -0
- package/src/ultils/types/deepReadonly.ts +7 -0
- package/src/ultils/types/enforceUnique.ts +33 -0
- package/src/ultils/types/error.ts +1 -0
- package/src/ultils/types/extractTuple.ts +1 -0
- package/src/ultils/types/inArray.ts +7 -0
- package/src/ultils/types/index.ts +15 -0
- package/src/ultils/types/mergeTuple.ts +3 -0
- package/src/ultils/types/noneEmptyArray.ts +1 -0
- package/src/ultils/types/partialTuple.ts +6 -0
- package/src/ultils/types/partialTupleUnordered.ts +9 -0
- package/src/ultils/types/partialTupleUnorderedNonEmpty.ts +9 -0
- package/src/ultils/types/partialTurpleNonEmpty.ts +6 -0
- package/src/ultils/types/permutationTuple.ts +5 -0
- package/src/ultils/types/shuffleTuple.ts +7 -0
- package/src/ultils/types/strictPartial.ts +5 -0
- package/dist/entities/interceptor.d.ts +0 -5
- package/dist/entities/middleware.d.ts +0 -19
- package/src/entities/interceptor.ts +0 -47
- package/src/entities/middleware.ts +0 -73
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TPartialTupleNonEmpty } from "./partialTurpleNonEmpty";
|
|
2
|
+
import type { TPermutationTuple } from "./permutationTuple";
|
|
3
|
+
|
|
4
|
+
export type TOptionalTupleUnorderedNonEmpty<T extends readonly any[]> =
|
|
5
|
+
TPartialTupleNonEmpty<T> extends infer S
|
|
6
|
+
? S extends readonly any[]
|
|
7
|
+
? TPermutationTuple<S[number]>
|
|
8
|
+
: never
|
|
9
|
+
: never;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { IContext, IMiddleware } from "@bool-ts/core";
|
|
2
|
-
import type { IClient } from "../interfaces/client.interface";
|
|
3
|
-
/**
|
|
4
|
-
* Bool guard middleware for Bool Typescript framework
|
|
5
|
-
*/
|
|
6
|
-
export declare class Middleware implements IMiddleware {
|
|
7
|
-
private readonly clientInstance;
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param tenantAppModesService
|
|
11
|
-
*/
|
|
12
|
-
constructor(clientInstance: IClient);
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param context
|
|
16
|
-
* @param requestHeaders
|
|
17
|
-
*/
|
|
18
|
-
start(context: IContext, requestHeaders: Headers): Promise<ThisType<IContext>>;
|
|
19
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { IInterceptor, THttpRouteModel } from "@bool-ts/core";
|
|
2
|
-
import type { TAuthState } from "../interfaces/client.interface";
|
|
3
|
-
|
|
4
|
-
import { Interceptor as BoolInterceptor, HttpClientError, RouteModel } from "@bool-ts/core";
|
|
5
|
-
import { Keys } from "../constants";
|
|
6
|
-
import { AuthState } from "../decorators/authState.decorator";
|
|
7
|
-
|
|
8
|
-
@BoolInterceptor()
|
|
9
|
-
export class Interceptor implements IInterceptor {
|
|
10
|
-
open(
|
|
11
|
-
@RouteModel()
|
|
12
|
-
routeModel: THttpRouteModel,
|
|
13
|
-
@AuthState()
|
|
14
|
-
authState: TAuthState
|
|
15
|
-
) {
|
|
16
|
-
const actionMetadataKeys = Reflect.getOwnMetadataKeys(
|
|
17
|
-
routeModel.class.prototype,
|
|
18
|
-
routeModel.funcName
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
if (actionMetadataKeys.includes(Keys.authState)) {
|
|
22
|
-
if (!authState) {
|
|
23
|
-
throw new HttpClientError({
|
|
24
|
-
httpCode: 401,
|
|
25
|
-
message: "Unauthorized",
|
|
26
|
-
data: undefined
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const controllerMetadataKeys = Reflect.getOwnMetadataKeys(routeModel.class);
|
|
34
|
-
|
|
35
|
-
if (controllerMetadataKeys.includes(Keys.authState)) {
|
|
36
|
-
if (!authState) {
|
|
37
|
-
throw new HttpClientError({
|
|
38
|
-
httpCode: 401,
|
|
39
|
-
message: "Unauthorized",
|
|
40
|
-
data: undefined
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type { IContext, IMiddleware } from "@bool-ts/core";
|
|
2
|
-
import type { IClient, TAuthState } from "../interfaces/client.interface";
|
|
3
|
-
|
|
4
|
-
import { Middleware as BoolMiddleware, Context, Inject, RequestHeaders } from "@bool-ts/core";
|
|
5
|
-
import { object, string } from "zod/v4";
|
|
6
|
-
import { Keys } from "../constants";
|
|
7
|
-
|
|
8
|
-
const headersSchema = object({
|
|
9
|
-
authorization: string()
|
|
10
|
-
.startsWith("Bearer ")
|
|
11
|
-
.min(24)
|
|
12
|
-
.transform((value) => {
|
|
13
|
-
const [schema, token] = value.split(" ");
|
|
14
|
-
|
|
15
|
-
return Object.freeze({
|
|
16
|
-
schema,
|
|
17
|
-
token
|
|
18
|
-
});
|
|
19
|
-
})
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Bool guard middleware for Bool Typescript framework
|
|
24
|
-
*/
|
|
25
|
-
@BoolMiddleware()
|
|
26
|
-
export class Middleware implements IMiddleware {
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @param tenantAppModesService
|
|
30
|
-
*/
|
|
31
|
-
constructor(
|
|
32
|
-
@Inject(Keys.guardClient)
|
|
33
|
-
private readonly clientInstance: IClient
|
|
34
|
-
) {}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
* @param context
|
|
39
|
-
* @param requestHeaders
|
|
40
|
-
*/
|
|
41
|
-
async start(
|
|
42
|
-
@Context()
|
|
43
|
-
context: IContext,
|
|
44
|
-
@RequestHeaders()
|
|
45
|
-
requestHeaders: Headers
|
|
46
|
-
) {
|
|
47
|
-
const headersValidation = await headersSchema.safeParseAsync(requestHeaders.toJSON());
|
|
48
|
-
|
|
49
|
-
if (!headersValidation.success) {
|
|
50
|
-
return context.set(Keys.authState, undefined);
|
|
51
|
-
} else {
|
|
52
|
-
const {
|
|
53
|
-
authorization: { token }
|
|
54
|
-
} = headersValidation.data;
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const { account, credential } = await this.clientInstance.verifyToken({
|
|
58
|
-
token: token
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const authState: TAuthState = Object.freeze({
|
|
62
|
-
account: account,
|
|
63
|
-
credential: credential
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return context.set(Keys.authState, authState);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error(error);
|
|
69
|
-
return context.set(Keys.authState, undefined);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|