@bool-ts/guard-sdk 1.1.0-beta.8 → 1.1.0-beta.9
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/constants/enums.d.ts +3 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/keys.d.ts +4 -0
- package/dist/decorators/actionGuard.decorator.d.ts +3 -0
- package/dist/decorators/authState.decorator.d.ts +1 -0
- package/dist/decorators/controllerGuard.decorator.d.ts +2 -0
- package/dist/decorators/index.d.ts +3 -0
- package/dist/definers/index.d.ts +1 -0
- package/dist/definers/policies.d.ts +5 -0
- package/dist/definers/resources.d.ts +8 -0
- package/dist/entities/@validators.d.ts +6 -0
- package/dist/entities/guard.d.ts +7 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/loader.d.ts +8 -0
- package/dist/index.d.ts +6 -0
- package/dist/instances/client.d.ts +50 -0
- package/dist/instances/index.d.ts +1 -0
- package/dist/interfaces/account.interface.d.ts +6 -0
- package/dist/interfaces/accountCredential.interface.d.ts +7 -0
- package/dist/interfaces/base.d.ts +3 -0
- package/dist/interfaces/client.interface.d.ts +53 -0
- package/dist/interfaces/index.d.ts +4 -0
- 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 +7 -0
- package/dist/ultils/functions/index.d.ts +1 -0
- package/dist/ultils/types/constructor.d.ts +1 -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 +14 -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 +2 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IContext, IGuard, THttpRouteModel } from "@bool-ts/core";
|
|
2
|
+
import type { IClient } from "../interfaces/client.interface";
|
|
3
|
+
export declare class Guard implements IGuard {
|
|
4
|
+
private readonly clientInstance;
|
|
5
|
+
constructor(clientInstance: IClient | undefined);
|
|
6
|
+
enforce(routeModel: THttpRouteModel, requestHeaders: Headers, context: IContext): Promise<boolean>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TClientCredential, TClientDefinition, TClientOptions } from "../interfaces/client.interface";
|
|
2
|
+
import { Client } from "../instances/client";
|
|
3
|
+
export type TLoaderParameters = {
|
|
4
|
+
credential: TClientCredential;
|
|
5
|
+
definition?: TClientDefinition;
|
|
6
|
+
options?: TClientOptions;
|
|
7
|
+
};
|
|
8
|
+
export declare const loader: ({ credential, definition, options }: TLoaderParameters) => Promise<[symbol, Client]>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { IClient, TClientCredential, TClientDefinition, TClientOptions } from "../interfaces/client.interface";
|
|
2
|
+
export declare class Client implements IClient {
|
|
3
|
+
#private;
|
|
4
|
+
private readonly params;
|
|
5
|
+
private token;
|
|
6
|
+
/**
|
|
7
|
+
* Initialize BoolGuard client instance
|
|
8
|
+
* @param configs
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
constructor(params: Readonly<{
|
|
12
|
+
credential: TClientCredential;
|
|
13
|
+
definition?: TClientDefinition;
|
|
14
|
+
options?: TClientOptions;
|
|
15
|
+
}>);
|
|
16
|
+
/**
|
|
17
|
+
* Sign JWT token with Ed25519 algorithm
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
signToken(): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Ping to BoolGuard service to check if the service is reachable
|
|
23
|
+
* This action should be done before any other actions.
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
ping(): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new plain account with custom account name
|
|
29
|
+
* @param args
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
createPlainAccount({ identity, password, metadata }: Parameters<IClient["createPlainAccount"]>[number]): ReturnType<IClient["createPlainAccount"]>;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new email account, this action will create email record and link to account
|
|
35
|
+
* with random account alias generated by system.
|
|
36
|
+
* @param args
|
|
37
|
+
*/
|
|
38
|
+
createEmailAccount({ identity, password, metadata }: Parameters<IClient["createEmailAccount"]>[number]): ReturnType<IClient["createEmailAccount"]>;
|
|
39
|
+
/**
|
|
40
|
+
* Authenticate an account with account name and password
|
|
41
|
+
* This action will return account info and JWT token if successful
|
|
42
|
+
* @param param0
|
|
43
|
+
*/
|
|
44
|
+
authenticate({ identity, password }: Parameters<IClient["authenticate"]>[number]): ReturnType<IClient["authenticate"]>;
|
|
45
|
+
/**
|
|
46
|
+
* Authenticate a token and return account info if token is valid
|
|
47
|
+
* @param param0
|
|
48
|
+
*/
|
|
49
|
+
verifyToken({ token }: Parameters<IClient["verifyToken"]>[number]): ReturnType<IClient["verifyToken"]>;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Client } from "./client";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { defineResources } from "../definers";
|
|
2
|
+
import type { IAccount, TDefaultAccountMetadata } from "./account.interface";
|
|
3
|
+
import type { IAccountCredential } from "./accountCredential.interface";
|
|
4
|
+
export type TClientCredential = Readonly<{
|
|
5
|
+
tenantId: string;
|
|
6
|
+
appId: string;
|
|
7
|
+
modeId: string;
|
|
8
|
+
secretKey: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type TClientDefinition = Readonly<{
|
|
11
|
+
resources: ReturnType<typeof defineResources>["resources"];
|
|
12
|
+
policies: ReturnType<ReturnType<typeof defineResources>["definePolicies"]>;
|
|
13
|
+
}>;
|
|
14
|
+
export type TClientOptions = Readonly<{
|
|
15
|
+
version?: 1;
|
|
16
|
+
logs?: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
export interface IClient<TAccountMetadata extends TDefaultAccountMetadata = TDefaultAccountMetadata> {
|
|
19
|
+
createPlainAccount(args: {
|
|
20
|
+
identity: string;
|
|
21
|
+
password: string;
|
|
22
|
+
metadata?: TAccountMetadata | null;
|
|
23
|
+
}): Promise<Readonly<{
|
|
24
|
+
account: IAccount<TAccountMetadata>;
|
|
25
|
+
credential: IAccountCredential;
|
|
26
|
+
}>>;
|
|
27
|
+
createEmailAccount(args: {
|
|
28
|
+
identity: string;
|
|
29
|
+
password: string | null;
|
|
30
|
+
metadata?: TAccountMetadata | null;
|
|
31
|
+
}): Promise<Readonly<{
|
|
32
|
+
account: IAccount<TAccountMetadata>;
|
|
33
|
+
credential: IAccountCredential;
|
|
34
|
+
}>>;
|
|
35
|
+
authenticate(args: {
|
|
36
|
+
identity: string;
|
|
37
|
+
password?: string | null;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
token: string;
|
|
40
|
+
account: IAccount<TAccountMetadata>;
|
|
41
|
+
credential: IAccountCredential;
|
|
42
|
+
}>;
|
|
43
|
+
verifyToken(args: {
|
|
44
|
+
token: string;
|
|
45
|
+
}): Promise<{
|
|
46
|
+
account: IAccount<TAccountMetadata>;
|
|
47
|
+
credential: IAccountCredential;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
export type TAuthState = {
|
|
51
|
+
account: IAccount;
|
|
52
|
+
credential: IAccountCredential;
|
|
53
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { IAccount } from "./account.interface";
|
|
2
|
+
export type { IAccountCredential } from "./accountCredential.interface";
|
|
3
|
+
export type { TApiResponse } from "./base";
|
|
4
|
+
export type { IClient, TAuthState, TClientCredential as TClientConfigs, TClientOptions } from "./client.interface";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TOptionalTupleUnorderedNonEmpty } from "../ultils/types";
|
|
2
|
+
import type { TResourceDefinition } from "./resources";
|
|
3
|
+
export type TActionGuardOptions<T extends readonly TResourceDefinition[]> = {
|
|
4
|
+
[R in T[number] as R["type"]]: {
|
|
5
|
+
resource: R["type"];
|
|
6
|
+
action: R["actions"][number] | TOptionalTupleUnorderedNonEmpty<R["actions"]>;
|
|
7
|
+
};
|
|
8
|
+
}[T[number]["type"]];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TResourceDefinition } from "./resources";
|
|
2
|
+
export type TPolicyDefinition<T extends readonly TResourceDefinition[] = readonly TResourceDefinition[]> = {
|
|
3
|
+
readonly alias: string;
|
|
4
|
+
readonly effect: "permit" | "deny";
|
|
5
|
+
readonly [key: string]: unknown;
|
|
6
|
+
} & {
|
|
7
|
+
[R in T[number] as R["type"]]: {
|
|
8
|
+
readonly resource: R["type"];
|
|
9
|
+
readonly action: R["actions"][number];
|
|
10
|
+
};
|
|
11
|
+
}[T[number]["type"]];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type DeepReadonly<T> = T extends (...args: any[]) => any ? T : T extends readonly any[] ? {
|
|
2
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
3
|
+
} : T extends object ? {
|
|
4
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
5
|
+
} : T;
|
|
6
|
+
export declare function deepFreeze<const T>(obj: T): DeepReadonly<T>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { deepFreeze } from "./deepFreeze";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TConstructor<T, K extends any[] = any[]> = new (...args: K) => T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type ValuesOfKey<Arr extends any[], K extends keyof any> = Arr extends [
|
|
2
|
+
infer Head,
|
|
3
|
+
...infer Tail
|
|
4
|
+
] ? Head extends Record<K, any> ? [Head[K], ...ValuesOfKey<Tail, K>] : ValuesOfKey<Tail, K> : [];
|
|
5
|
+
type Includes<Arr extends any[], V> = Arr extends [infer H, ...infer R] ? [V] extends [H] ? true : Includes<R, V> : false;
|
|
6
|
+
type HasDuplicate<Arr extends readonly any[], K extends keyof any> = Arr extends [infer Head, ...infer Tail] ? Head extends Record<K, any> ? Includes<ValuesOfKey<Tail, K>, Head[K]> extends true ? true : HasDuplicate<Tail, K> : HasDuplicate<Tail, K> : false;
|
|
7
|
+
export type TEnforceUnique<Arr extends readonly any[], K extends keyof Arr[number]> = HasDuplicate<Arr, K> extends true ? ["Duplicate key found"] : Arr;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ExtractTuple<T> = T extends readonly [...infer U] ? U : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TInArray<T, X> = T extends readonly [X, ...infer _Rest] ? true : T extends readonly [X] ? true : T extends readonly [infer _, ...infer Rest] ? TInArray<Rest, X> : false;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { TConstructor } from "./constructor";
|
|
2
|
+
export type { TEnforceUnique } from "./enforceUnique";
|
|
3
|
+
export type { TError } from "./error";
|
|
4
|
+
export type { ExtractTuple } from "./extractTuple";
|
|
5
|
+
export type { TInArray } from "./inArray";
|
|
6
|
+
export type { MergeTuple } from "./mergeTuple";
|
|
7
|
+
export type { TNonEmptyArray } from "./noneEmptyArray";
|
|
8
|
+
export type { TPartialTuple } from "./partialTuple";
|
|
9
|
+
export type { TPartialTupleUnordered as TOptionalTupleUnordered } from "./partialTupleUnordered";
|
|
10
|
+
export type { TOptionalTupleUnorderedNonEmpty } from "./partialTupleUnorderedNonEmpty";
|
|
11
|
+
export type { TPartialTupleNonEmpty } from "./partialTurpleNonEmpty";
|
|
12
|
+
export type { TPermutationTuple } from "./permutationTuple";
|
|
13
|
+
export type { TShuffleTuple } from "./shuffleTuple";
|
|
14
|
+
export type { TStrictPartial } from "./strictPartial";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TNonEmptyArray<T> = readonly [T, ...T[]];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TPartialTuple } from "./partialTuple";
|
|
2
|
+
import type { TPermutationTuple } from "./permutationTuple";
|
|
3
|
+
export type TPartialTupleUnordered<T extends readonly any[]> = TPartialTuple<T> extends infer S ? S extends readonly any[] ? TPermutationTuple<S[number]> : never : never;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TPartialTupleNonEmpty } from "./partialTurpleNonEmpty";
|
|
2
|
+
import type { TPermutationTuple } from "./permutationTuple";
|
|
3
|
+
export type TOptionalTupleUnorderedNonEmpty<T extends readonly any[]> = TPartialTupleNonEmpty<T> extends infer S ? S extends readonly any[] ? TPermutationTuple<S[number]> : never : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TPermutationTuple<T, K = T> = [T] extends [never] ? [] : T extends any ? [T, ...TPermutationTuple<Exclude<K, T>>] : never;
|
package/package.json
CHANGED
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"url": "git+https://github.com/BoolTS/guard-sdk.git"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "
|
|
44
|
+
"build": "bun run ./app.build.ts && tsc --emitDeclarationOnly",
|
|
45
45
|
"format": "prettier \"**/*.ts\" --write",
|
|
46
46
|
"test": "bun --hot run __test/index.ts"
|
|
47
47
|
},
|
|
48
48
|
"types": "./dist/index.d.ts",
|
|
49
|
-
"version": "1.1.0-beta.
|
|
49
|
+
"version": "1.1.0-beta.9"
|
|
50
50
|
}
|