@flusys/nestjs-shared 9.1.0 → 9.1.1
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/README.md +44 -0
- package/constants/permissions.d.ts +0 -2
- package/fesm/270.js +659 -0
- package/fesm/470.js +5 -40
- package/fesm/681.js +78 -2
- package/fesm/948.js +0 -1
- package/fesm/constants/index.js +0 -1
- package/fesm/guards/index.js +83 -42
- package/fesm/index.js +54 -539
- package/fesm/interceptors/index.js +0 -1
- package/fesm/interfaces/index.js +21 -3
- package/fesm/utils/index.js +131 -537
- package/guards/permission.guard.d.ts +0 -1
- package/interfaces/branch-hierarchy-resolver.interface.d.ts +10 -0
- package/interfaces/company-access-resolver.interface.d.ts +19 -0
- package/interfaces/email-adapter.interface.d.ts +27 -0
- package/interfaces/index.d.ts +3 -0
- package/modules/shared-permission-cache/shared-permission-cache.service.d.ts +6 -1
- package/package.json +3 -3
- package/utils/branch-hierarchy.util.d.ts +15 -0
- package/utils/index.d.ts +1 -0
- package/utils/permission-match.util.d.ts +18 -0
- package/utils/query-helpers.util.d.ts +6 -0
|
@@ -7,5 +7,4 @@ export declare class PermissionGuard implements CanActivate {
|
|
|
7
7
|
constructor(reflector: Reflector, permissionCacheService?: SharedPermissionCacheService | undefined);
|
|
8
8
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
9
9
|
private normalizeToLogicNode;
|
|
10
|
-
private evaluateLogicNode;
|
|
11
10
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IBranchHierarchyOptions } from '../utils/branch-hierarchy.util.js';
|
|
2
|
+
export declare const BRANCH_HIERARCHY_RESOLVER = "BRANCH_HIERARCHY_RESOLVER";
|
|
3
|
+
export interface IBranchHierarchyResolver {
|
|
4
|
+
getDescendantIds(branchIds: string | string[], options?: IBranchHierarchyOptions): Promise<string[]>;
|
|
5
|
+
getAncestorIds(branchId: string, options?: IBranchHierarchyOptions): Promise<string[]>;
|
|
6
|
+
isWithinBranch(branchId: string, ancestorId: string): Promise<boolean>;
|
|
7
|
+
getGrantedBranchIds(userId: string, companyId?: string): Promise<string[]>;
|
|
8
|
+
getGrantedDescendantIds(userId: string, branchIds: string | string[], options?: IBranchHierarchyOptions): Promise<string[]>;
|
|
9
|
+
hasBranchAccess(userId: string, branchId: string): Promise<boolean>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const COMPANY_ACCESS_RESOLVER = "COMPANY_ACCESS_RESOLVER";
|
|
2
|
+
export interface IAccessibleCompany {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IAccessibleBranch {
|
|
7
|
+
id: string;
|
|
8
|
+
companyId: string;
|
|
9
|
+
parentId: string | null;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IUserCompanyAccess {
|
|
13
|
+
companies: IAccessibleCompany[];
|
|
14
|
+
branches: IAccessibleBranch[];
|
|
15
|
+
}
|
|
16
|
+
export interface ICompanyAccessResolver {
|
|
17
|
+
getUserAccess(userId: string): Promise<IUserCompanyAccess>;
|
|
18
|
+
getCompanyMembers(companyId: string, branchIds?: string[]): Promise<string[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ILoggedUserInfo } from './logged-user-info.interface.js';
|
|
2
|
+
export declare const EMAIL_ADAPTER = "EMAIL_ADAPTER";
|
|
3
|
+
export interface IEmailAdapterRecipients {
|
|
4
|
+
to: string[];
|
|
5
|
+
cc?: string[];
|
|
6
|
+
bcc?: string[];
|
|
7
|
+
replyTo?: string;
|
|
8
|
+
emailConfigId?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IEmailAdapterContent extends IEmailAdapterRecipients {
|
|
11
|
+
subject: string;
|
|
12
|
+
html?: string;
|
|
13
|
+
text?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IEmailAdapterTemplate extends IEmailAdapterRecipients {
|
|
16
|
+
templateSlug: string;
|
|
17
|
+
variables?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface IEmailAdapterResult {
|
|
20
|
+
success: boolean;
|
|
21
|
+
messageId?: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface IEmailAdapter {
|
|
25
|
+
send(options: IEmailAdapterContent, user: ILoggedUserInfo | null): Promise<IEmailAdapterResult>;
|
|
26
|
+
sendTemplate(options: IEmailAdapterTemplate, user: ILoggedUserInfo | null): Promise<IEmailAdapterResult>;
|
|
27
|
+
}
|
package/interfaces/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from './ai-assistant-adapter.interface.js';
|
|
2
2
|
export * from './api.interface.js';
|
|
3
|
+
export * from './branch-hierarchy-resolver.interface.js';
|
|
4
|
+
export * from './company-access-resolver.interface.js';
|
|
3
5
|
export * from './datasource.interface.js';
|
|
6
|
+
export * from './email-adapter.interface.js';
|
|
4
7
|
export * from './event-bus.interface.js';
|
|
5
8
|
export * from './event-manager-adapter.interface.js';
|
|
6
9
|
export * from './identity.interface.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HybridCache } from '../../classes/hybrid-cache.class.js';
|
|
2
|
-
import type { PermissionGuardConfig } from '../../interfaces/index.js';
|
|
2
|
+
import type { ILogicNode, PermissionGuardConfig } from '../../interfaces/index.js';
|
|
3
3
|
import { type PermissionCacheKeyOptions } from '../../utils/permission-cache-key.util.js';
|
|
4
4
|
export declare class SharedPermissionCacheService {
|
|
5
5
|
private readonly cache?;
|
|
@@ -14,6 +14,11 @@ export declare class SharedPermissionCacheService {
|
|
|
14
14
|
companyId?: string | null;
|
|
15
15
|
branchId?: string | null;
|
|
16
16
|
} | null | undefined, requiredPermission: string): Promise<void>;
|
|
17
|
+
assertPermissionLogic(user: {
|
|
18
|
+
id?: string | null;
|
|
19
|
+
companyId?: string | null;
|
|
20
|
+
branchId?: string | null;
|
|
21
|
+
} | null | undefined, logic: ILogicNode): Promise<void>;
|
|
17
22
|
isCacheConfigured(): boolean;
|
|
18
23
|
matchPermission(userPermissions: string[], requiredPermission: string): boolean;
|
|
19
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flusys/nestjs-shared",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.1",
|
|
4
4
|
"description": "Common shared utilities for Flusys NestJS applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./fesm/index.js",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"class-transformer": "^0.5.1",
|
|
96
96
|
"class-validator": "^0.15.0",
|
|
97
97
|
"keyv": "^5.0.0",
|
|
98
|
-
"typeorm": "^0.3.
|
|
98
|
+
"typeorm": "^0.3.31",
|
|
99
99
|
"typeorm-naming-strategies": "^4.1.0",
|
|
100
100
|
"winston": "^3.0.0",
|
|
101
101
|
"winston-transport": "^4.9.0",
|
|
@@ -104,6 +104,6 @@
|
|
|
104
104
|
"rxjs": "^7.8.0"
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"@flusys/nestjs-core": "9.1.
|
|
107
|
+
"@flusys/nestjs-core": "9.1.1"
|
|
108
108
|
}
|
|
109
109
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface IBranchHierarchyNode {
|
|
2
|
+
id: string;
|
|
3
|
+
parentId?: string | null;
|
|
4
|
+
}
|
|
5
|
+
export interface IBranchHierarchyOptions {
|
|
6
|
+
includeSelf?: boolean;
|
|
7
|
+
maxDepth?: number;
|
|
8
|
+
}
|
|
9
|
+
type IdInput = string | null | undefined | ReadonlyArray<string | null | undefined>;
|
|
10
|
+
export declare function normalizeBranchIds(ids: IdInput): string[];
|
|
11
|
+
export declare function collectBranchDescendantIds(nodes: readonly IBranchHierarchyNode[], rootIds: IdInput, { includeSelf, maxDepth }?: IBranchHierarchyOptions): string[];
|
|
12
|
+
export declare function collectBranchAncestorIds(nodes: readonly IBranchHierarchyNode[], branchId: string | null | undefined, { includeSelf, maxDepth }?: IBranchHierarchyOptions): string[];
|
|
13
|
+
export declare function isBranchWithin(nodes: readonly IBranchHierarchyNode[], branchId: string | null | undefined, ancestorId: string | null | undefined): boolean;
|
|
14
|
+
export declare function getBranchPath<T extends IBranchHierarchyNode>(nodes: readonly T[], branchId: string | null | undefined): T[];
|
|
15
|
+
export {};
|
package/utils/index.d.ts
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
+
import { type IPermissionResolver, type IPermissionScope } from '../interfaces/permission-resolver.interface.js';
|
|
2
|
+
import { type ILogicNode } from '../interfaces/permission.interface.js';
|
|
3
|
+
import { type SharedPermissionCacheService } from '../modules/shared-permission-cache/shared-permission-cache.service.js';
|
|
1
4
|
export declare function matchesPermission(granted: readonly string[], required: string): boolean;
|
|
5
|
+
export interface IPermissionLogicResult {
|
|
6
|
+
passed: boolean;
|
|
7
|
+
missingPermissions: string[];
|
|
8
|
+
operator: 'AND' | 'OR';
|
|
9
|
+
}
|
|
10
|
+
export declare function evaluatePermissionLogic(node: ILogicNode, granted: readonly string[]): IPermissionLogicResult;
|
|
11
|
+
export declare function permissionLogicCodes(node: ILogicNode): string[];
|
|
12
|
+
export declare const MAX_PERMISSION_LOGIC_DEPTH = 5;
|
|
13
|
+
export declare const MAX_PERMISSION_LOGIC_CODES = 50;
|
|
14
|
+
export declare function permissionLogicProblem(value: unknown): 'invalid' | 'empty' | 'too_many' | null;
|
|
15
|
+
export interface IPermissionSources {
|
|
16
|
+
resolver?: IPermissionResolver;
|
|
17
|
+
cache?: SharedPermissionCacheService;
|
|
18
|
+
}
|
|
19
|
+
export declare function loadPermissionCodes(scope: IPermissionScope, sources: IPermissionSources): Promise<string[]>;
|
|
@@ -6,6 +6,12 @@ export interface ICompanyFilterConfig {
|
|
|
6
6
|
columnName?: string;
|
|
7
7
|
}
|
|
8
8
|
export declare function applyCompanyFilter<T extends ObjectLiteral>(query: SelectQueryBuilder<T>, config: ICompanyFilterConfig, user: ILoggedUserInfo | null | undefined): SelectQueryBuilder<T>;
|
|
9
|
+
export interface IBranchFilterConfig {
|
|
10
|
+
entityAlias: string;
|
|
11
|
+
columnName?: string;
|
|
12
|
+
includeUnassigned?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function applyBranchFilter<T extends ObjectLiteral>(query: SelectQueryBuilder<T>, config: IBranchFilterConfig, branchIds: ReadonlyArray<string | null | undefined>): SelectQueryBuilder<T>;
|
|
9
15
|
export declare function buildCompanyWhereCondition<T extends Record<string, unknown>>(baseWhere: T, isCompanyFeatureEnabled: boolean, user: ILoggedUserInfo | null | undefined): T & {
|
|
10
16
|
companyId?: string;
|
|
11
17
|
};
|