@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.
Files changed (45) hide show
  1. package/dist/constants/enums.d.ts +3 -0
  2. package/dist/constants/index.d.ts +2 -0
  3. package/dist/constants/keys.d.ts +4 -0
  4. package/dist/decorators/actionGuard.decorator.d.ts +3 -0
  5. package/dist/decorators/authState.decorator.d.ts +1 -0
  6. package/dist/decorators/controllerGuard.decorator.d.ts +2 -0
  7. package/dist/decorators/index.d.ts +3 -0
  8. package/dist/definers/index.d.ts +1 -0
  9. package/dist/definers/policies.d.ts +5 -0
  10. package/dist/definers/resources.d.ts +8 -0
  11. package/dist/entities/@validators.d.ts +6 -0
  12. package/dist/entities/guard.d.ts +7 -0
  13. package/dist/entities/index.d.ts +2 -0
  14. package/dist/entities/loader.d.ts +8 -0
  15. package/dist/index.d.ts +6 -0
  16. package/dist/instances/client.d.ts +50 -0
  17. package/dist/instances/index.d.ts +1 -0
  18. package/dist/interfaces/account.interface.d.ts +6 -0
  19. package/dist/interfaces/accountCredential.interface.d.ts +7 -0
  20. package/dist/interfaces/base.d.ts +3 -0
  21. package/dist/interfaces/client.interface.d.ts +53 -0
  22. package/dist/interfaces/index.d.ts +4 -0
  23. package/dist/types/actionGuard.d.ts +8 -0
  24. package/dist/types/controllerGuard.d.ts +6 -0
  25. package/dist/types/index.d.ts +3 -0
  26. package/dist/types/policies.d.ts +11 -0
  27. package/dist/types/resources.d.ts +6 -0
  28. package/dist/ultils/functions/deepFreeze.d.ts +7 -0
  29. package/dist/ultils/functions/index.d.ts +1 -0
  30. package/dist/ultils/types/constructor.d.ts +1 -0
  31. package/dist/ultils/types/enforceUnique.d.ts +8 -0
  32. package/dist/ultils/types/error.d.ts +3 -0
  33. package/dist/ultils/types/extractTuple.d.ts +1 -0
  34. package/dist/ultils/types/inArray.d.ts +1 -0
  35. package/dist/ultils/types/index.d.ts +14 -0
  36. package/dist/ultils/types/mergeTuple.d.ts +3 -0
  37. package/dist/ultils/types/noneEmptyArray.d.ts +1 -0
  38. package/dist/ultils/types/partialTuple.d.ts +4 -0
  39. package/dist/ultils/types/partialTupleUnordered.d.ts +3 -0
  40. package/dist/ultils/types/partialTupleUnorderedNonEmpty.d.ts +3 -0
  41. package/dist/ultils/types/partialTurpleNonEmpty.d.ts +2 -0
  42. package/dist/ultils/types/permutationTuple.d.ts +1 -0
  43. package/dist/ultils/types/shuffleTuple.d.ts +5 -0
  44. package/dist/ultils/types/strictPartial.d.ts +5 -0
  45. package/package.json +2 -2
@@ -0,0 +1,6 @@
1
+ export declare const headersSchema: import("zod/v4").ZodObject<{
2
+ authorization: import("zod/v4").ZodPipe<import("zod/v4").ZodString, import("zod/v4").ZodTransform<Readonly<{
3
+ schema: string;
4
+ token: string;
5
+ }>, string>>;
6
+ }, import("zod/v4/core").$strip>;
@@ -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,2 @@
1
+ export * from "./guard";
2
+ export * from "./loader";
@@ -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]>;
@@ -0,0 +1,6 @@
1
+ export type * from "./interfaces";
2
+ export * from "./constants";
3
+ export * from "./decorators";
4
+ export * from "./entities";
5
+ export * from "./instances";
6
+ export * from "./definers";
@@ -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,6 @@
1
+ export type TDefaultAccountMetadata = Record<string, string | number | Date | null | undefined>;
2
+ export interface IAccount<T = TDefaultAccountMetadata> {
3
+ uuid: string;
4
+ status: string;
5
+ metadata?: T | null;
6
+ }
@@ -0,0 +1,7 @@
1
+ export interface IAccountCredential {
2
+ uuid: string;
3
+ identity: string;
4
+ status: string;
5
+ type: string;
6
+ isVerified: boolean;
7
+ }
@@ -0,0 +1,3 @@
1
+ export type TApiResponse<T> = Readonly<{
2
+ data: Awaited<ReturnType<T extends (...args: any) => Promise<infer R> ? () => R : never>>;
3
+ }>;
@@ -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,6 @@
1
+ import type { TResourceDefinition } from "./resources";
2
+ export type TControllerGuardOptions<T extends readonly TResourceDefinition[]> = {
3
+ [R in T[number] as R["type"]]: {
4
+ resource: R["type"];
5
+ };
6
+ }[T[number]["type"]];
@@ -0,0 +1,3 @@
1
+ export * from "./actionGuard";
2
+ export * from "./policies";
3
+ export * from "./resources";
@@ -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,6 @@
1
+ import type { TNonEmptyArray } from "../ultils/types";
2
+ export type TResourceDefinition<T extends string = string, A extends TNonEmptyArray<string> = TNonEmptyArray<string>> = {
3
+ readonly type: T;
4
+ readonly actions: A;
5
+ readonly [key: string]: unknown;
6
+ };
@@ -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,3 @@
1
+ export type TError<Message extends string> = {
2
+ __error__: Message;
3
+ };
@@ -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,3 @@
1
+ export type MergeTuple<T extends readonly any[], U> = {
2
+ [K in keyof T]: T[K] & U;
3
+ };
@@ -0,0 +1 @@
1
+ export type TNonEmptyArray<T> = readonly [T, ...T[]];
@@ -0,0 +1,4 @@
1
+ export type TPartialTuple<T extends readonly any[]> = T extends readonly [
2
+ infer Head,
3
+ ...infer Tail
4
+ ] ? TPartialTuple<Tail> | [Head, ...TPartialTuple<Tail>] : [];
@@ -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,2 @@
1
+ import type { TPartialTuple } from "./partialTuple";
2
+ export type TPartialTupleNonEmpty<T extends readonly any[]> = T extends readonly [infer Head, ...infer Tail] ? [Head, ...TPartialTuple<Tail>] | TPartialTupleNonEmpty<Tail> : never;
@@ -0,0 +1 @@
1
+ export type TPermutationTuple<T, K = T> = [T] extends [never] ? [] : T extends any ? [T, ...TPermutationTuple<Exclude<K, T>>] : never;
@@ -0,0 +1,5 @@
1
+ type Values<T> = T[keyof T];
2
+ export type TShuffleTuple<U extends string | number> = [U] extends [never] ? [] : Values<{
3
+ [K in U]: [K, ...TShuffleTuple<Exclude<U, K>>];
4
+ }>;
5
+ export {};
@@ -0,0 +1,5 @@
1
+ export type TStrictPartial<T> = {
2
+ [K in keyof T]?: T[K];
3
+ } & {
4
+ [K in keyof T as K extends string ? never : never]: never;
5
+ };
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": "tsc --emitDeclarationOnly && bun run ./app.build.ts",
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.8"
49
+ "version": "1.1.0-beta.9"
50
50
  }