@corp-products/app-core 1.0.7 → 1.0.8

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 (132) hide show
  1. package/eslint.config.js +48 -0
  2. package/ng-package.json +7 -0
  3. package/package.json +20 -36
  4. package/project.json +29 -0
  5. package/{index.d.ts → src/index.ts} +10 -10
  6. package/src/lib/core/components/global-loader/global-loader.component.html +18 -0
  7. package/src/lib/core/components/global-loader/global-loader.component.scss +0 -0
  8. package/src/lib/core/components/global-loader/global-loader.component.spec.ts +24 -0
  9. package/src/lib/core/components/global-loader/global-loader.component.ts +16 -0
  10. package/{lib/core/components/index.d.ts → src/lib/core/components/index.ts} +1 -1
  11. package/src/lib/core/components/no-access/no-access.component.html +9 -0
  12. package/src/lib/core/components/no-access/no-access.component.ts +17 -0
  13. package/src/lib/core/core-config.ts +11 -0
  14. package/{lib/core/directives/index.d.ts → src/lib/core/directives/index.ts} +1 -1
  15. package/src/lib/core/directives/permissions.directive.ts +114 -0
  16. package/{lib/core/enums/index.d.ts → src/lib/core/enums/index.ts} +1 -1
  17. package/src/lib/core/enums/user-permissions.enum.ts +36 -0
  18. package/src/lib/core/guards/auth.guard.ts +17 -0
  19. package/{lib/core/guards/index.d.ts → src/lib/core/guards/index.ts} +2 -2
  20. package/src/lib/core/guards/permissions.guard.ts +17 -0
  21. package/src/lib/core/handlers/http-context-handler.ts +14 -0
  22. package/{lib/core/handlers/index.d.ts → src/lib/core/handlers/index.ts} +3 -3
  23. package/src/lib/core/handlers/storage-handler.ts +37 -0
  24. package/src/lib/core/handlers/stortage.ts +7 -0
  25. package/src/lib/core/interceptors/app-http-config.ts +8 -0
  26. package/src/lib/core/interceptors/base-http.interceptor.ts +45 -0
  27. package/src/lib/core/interceptors/global-http-error.interceptor.ts +21 -0
  28. package/{lib/core/interceptors/index.d.ts → src/lib/core/interceptors/index.ts} +3 -3
  29. package/src/lib/core/interfaces/index.ts +3 -0
  30. package/{lib/core/interfaces/jwt-token-decoded.interface.d.ts → src/lib/core/interfaces/jwt-token-decoded.interface.ts} +7 -7
  31. package/src/lib/core/interfaces/list-response.interface.ts +5 -0
  32. package/src/lib/core/interfaces/router-data.interface.ts +20 -0
  33. package/src/lib/core/interfaces/user-info.interface.ts +4 -0
  34. package/src/lib/core/interfaces/user-profile-data.ts +19 -0
  35. package/src/lib/core/services/auth.service.ts +63 -0
  36. package/src/lib/core/services/base-http-service/base-http-response.ts +14 -0
  37. package/src/lib/core/services/base-http-service/base-http-types.ts +42 -0
  38. package/src/lib/core/services/base-http-service/base-http-utils.ts +43 -0
  39. package/src/lib/core/services/base-http-service/base-http.service.ts +106 -0
  40. package/src/lib/core/services/base-http-service/http-context-handler.ts +9 -0
  41. package/{lib/core/services/base-http-service/index.d.ts → src/lib/core/services/base-http-service/index.ts} +4 -4
  42. package/src/lib/core/services/base-pagination-service/base-pagination.service.ts +59 -0
  43. package/{lib/core/services/base-pagination-service/index.d.ts → src/lib/core/services/base-pagination-service/index.ts} +3 -3
  44. package/src/lib/core/services/base-pagination-service/list-options.interface.ts +8 -0
  45. package/src/lib/core/services/base-pagination-service/pagination.ts +6 -0
  46. package/src/lib/core/services/enviroment.base.service.ts +16 -0
  47. package/src/lib/core/services/error-handler.service.ts +74 -0
  48. package/{lib/core/services/index.d.ts → src/lib/core/services/index.ts} +8 -8
  49. package/src/lib/core/services/jwt-decoder.service.ts +23 -0
  50. package/src/lib/core/services/loader.service.ts +32 -0
  51. package/src/lib/core/services/lov.service.ts +22 -0
  52. package/src/lib/core/services/permissions.service.ts +66 -0
  53. package/src/lib/core/services/toaster.service.ts +65 -0
  54. package/tsconfig.json +26 -0
  55. package/tsconfig.lib.json +11 -0
  56. package/tsconfig.lib.prod.json +9 -0
  57. package/esm2022/corp-products-app-core.mjs +0 -5
  58. package/esm2022/index.mjs +0 -11
  59. package/esm2022/lib/core/components/global-loader/global-loader.component.mjs +0 -20
  60. package/esm2022/lib/core/components/index.mjs +0 -2
  61. package/esm2022/lib/core/core-config.mjs +0 -3
  62. package/esm2022/lib/core/directives/index.mjs +0 -2
  63. package/esm2022/lib/core/directives/permissions.directive.mjs +0 -99
  64. package/esm2022/lib/core/enums/index.mjs +0 -2
  65. package/esm2022/lib/core/enums/user-permissions.enum.mjs +0 -38
  66. package/esm2022/lib/core/guards/auth.guard.mjs +0 -14
  67. package/esm2022/lib/core/guards/index.mjs +0 -3
  68. package/esm2022/lib/core/guards/permissions.guard.mjs +0 -16
  69. package/esm2022/lib/core/handlers/http-context-handler.mjs +0 -12
  70. package/esm2022/lib/core/handlers/index.mjs +0 -4
  71. package/esm2022/lib/core/handlers/storage-handler.mjs +0 -33
  72. package/esm2022/lib/core/handlers/stortage.mjs +0 -9
  73. package/esm2022/lib/core/interceptors/app-http-config.mjs +0 -9
  74. package/esm2022/lib/core/interceptors/base-http.interceptor.mjs +0 -46
  75. package/esm2022/lib/core/interceptors/global-http-error.interceptor.mjs +0 -17
  76. package/esm2022/lib/core/interceptors/index.mjs +0 -4
  77. package/esm2022/lib/core/interfaces/index.mjs +0 -4
  78. package/esm2022/lib/core/interfaces/jwt-token-decoded.interface.mjs +0 -2
  79. package/esm2022/lib/core/interfaces/list-response.interface.mjs +0 -2
  80. package/esm2022/lib/core/interfaces/router-data.interface.mjs +0 -2
  81. package/esm2022/lib/core/interfaces/user-info.interface.mjs +0 -2
  82. package/esm2022/lib/core/interfaces/user-profile-data.mjs +0 -2
  83. package/esm2022/lib/core/services/auth.service.mjs +0 -64
  84. package/esm2022/lib/core/services/base-http-service/base-http-response.mjs +0 -2
  85. package/esm2022/lib/core/services/base-http-service/base-http-types.mjs +0 -2
  86. package/esm2022/lib/core/services/base-http-service/base-http-utils.mjs +0 -32
  87. package/esm2022/lib/core/services/base-http-service/base-http.service.mjs +0 -79
  88. package/esm2022/lib/core/services/base-http-service/index.mjs +0 -5
  89. package/esm2022/lib/core/services/base-pagination-service/base-pagination.service.mjs +0 -49
  90. package/esm2022/lib/core/services/base-pagination-service/index.mjs +0 -4
  91. package/esm2022/lib/core/services/base-pagination-service/list-options.interface.mjs +0 -2
  92. package/esm2022/lib/core/services/base-pagination-service/pagination.mjs +0 -8
  93. package/esm2022/lib/core/services/error-handler.service.mjs +0 -76
  94. package/esm2022/lib/core/services/index.mjs +0 -9
  95. package/esm2022/lib/core/services/jwt-decoder.service.mjs +0 -25
  96. package/esm2022/lib/core/services/loader.service.mjs +0 -33
  97. package/esm2022/lib/core/services/lov.service.mjs +0 -26
  98. package/esm2022/lib/core/services/permissions.service.mjs +0 -64
  99. package/esm2022/lib/core/services/toaster.service.mjs +0 -67
  100. package/fesm2022/corp-products-app-core.mjs +0 -793
  101. package/fesm2022/corp-products-app-core.mjs.map +0 -1
  102. package/lib/core/components/global-loader/global-loader.component.d.ts +0 -9
  103. package/lib/core/core-config.d.ts +0 -9
  104. package/lib/core/directives/permissions.directive.d.ts +0 -31
  105. package/lib/core/enums/user-permissions.enum.d.ts +0 -35
  106. package/lib/core/guards/auth.guard.d.ts +0 -2
  107. package/lib/core/guards/permissions.guard.d.ts +0 -2
  108. package/lib/core/handlers/http-context-handler.d.ts +0 -7
  109. package/lib/core/handlers/storage-handler.d.ts +0 -16
  110. package/lib/core/handlers/stortage.d.ts +0 -7
  111. package/lib/core/interceptors/app-http-config.d.ts +0 -8
  112. package/lib/core/interceptors/base-http.interceptor.d.ts +0 -15
  113. package/lib/core/interceptors/global-http-error.interceptor.d.ts +0 -6
  114. package/lib/core/interfaces/index.d.ts +0 -3
  115. package/lib/core/interfaces/list-response.interface.d.ts +0 -5
  116. package/lib/core/interfaces/router-data.interface.d.ts +0 -17
  117. package/lib/core/interfaces/user-info.interface.d.ts +0 -4
  118. package/lib/core/interfaces/user-profile-data.d.ts +0 -16
  119. package/lib/core/services/auth.service.d.ts +0 -19
  120. package/lib/core/services/base-http-service/base-http-response.d.ts +0 -14
  121. package/lib/core/services/base-http-service/base-http-types.d.ts +0 -37
  122. package/lib/core/services/base-http-service/base-http-utils.d.ts +0 -6
  123. package/lib/core/services/base-http-service/base-http.service.d.ts +0 -22
  124. package/lib/core/services/base-pagination-service/base-pagination.service.d.ts +0 -21
  125. package/lib/core/services/base-pagination-service/list-options.interface.d.ts +0 -8
  126. package/lib/core/services/base-pagination-service/pagination.d.ts +0 -6
  127. package/lib/core/services/error-handler.service.d.ts +0 -12
  128. package/lib/core/services/jwt-decoder.service.d.ts +0 -11
  129. package/lib/core/services/loader.service.d.ts +0 -13
  130. package/lib/core/services/lov.service.d.ts +0 -9
  131. package/lib/core/services/permissions.service.d.ts +0 -20
  132. package/lib/core/services/toaster.service.d.ts +0 -15
@@ -0,0 +1,48 @@
1
+ const nx = require('@nx/eslint-plugin');
2
+ const baseConfig = require('../../eslint.config.js');
3
+
4
+ module.exports = [
5
+ ...baseConfig,
6
+ {
7
+ files: ['**/*.json'],
8
+ rules: {
9
+ '@nx/dependency-checks': [
10
+ 'error',
11
+ {
12
+ ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
13
+ },
14
+ ],
15
+ },
16
+ languageOptions: {
17
+ parser: require('jsonc-eslint-parser'),
18
+ },
19
+ },
20
+ ...nx.configs['flat/angular'],
21
+ ...nx.configs['flat/angular-template'],
22
+ {
23
+ files: ['**/*.ts'],
24
+ rules: {
25
+ '@angular-eslint/directive-selector': [
26
+ 'error',
27
+ {
28
+ type: 'attribute',
29
+ prefix: 'app',
30
+ style: 'camelCase',
31
+ },
32
+ ],
33
+ '@angular-eslint/component-selector': [
34
+ 'error',
35
+ {
36
+ type: 'element',
37
+ prefix: 'app',
38
+ style: 'kebab-case',
39
+ },
40
+ ],
41
+ },
42
+ },
43
+ {
44
+ files: ['**/*.html'],
45
+ // Override or add rules here
46
+ rules: {},
47
+ },
48
+ ];
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/libs/core",
4
+ "lib": {
5
+ "entryFile": "src/index.ts"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,36 +1,20 @@
1
- {
2
- "name": "@corp-products/app-core",
3
- "version": "1.0.7",
4
- "author": "shireen Omar",
5
- "description": "shared core services across our apps",
6
- "peerDependencies": {
7
- "@angular/common": "^18.2.0",
8
- "@angular/core": "^18.2.0",
9
- "primeng": "^17.6.0"
10
- },
11
- "keywords": [
12
- "angular",
13
- "library"
14
- ],
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "license": "MIT",
19
- "sideEffects": false,
20
- "module": "fesm2022/corp-products-app-core.mjs",
21
- "typings": "index.d.ts",
22
- "exports": {
23
- "./package.json": {
24
- "default": "./package.json"
25
- },
26
- ".": {
27
- "types": "./index.d.ts",
28
- "esm2022": "./esm2022/corp-products-app-core.mjs",
29
- "esm": "./esm2022/corp-products-app-core.mjs",
30
- "default": "./fesm2022/corp-products-app-core.mjs"
31
- }
32
- },
33
- "dependencies": {
34
- "tslib": "^2.3.0"
35
- }
36
- }
1
+ {
2
+ "name": "@corp-products/app-core",
3
+ "version": "1.0.8",
4
+ "author": "shireen Omar",
5
+ "description": "shared core services across our apps",
6
+ "peerDependencies": {
7
+ "@angular/common": "^18.2.0",
8
+ "@angular/core": "^18.2.0",
9
+ "primeng": "^17.6.0"
10
+ },
11
+ "keywords": [
12
+ "angular",
13
+ "library"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "license": "MIT",
19
+ "sideEffects": false
20
+ }
package/project.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "core",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/core/src",
5
+ "prefix": "",
6
+ "projectType": "library",
7
+ "tags": [],
8
+ "targets": {
9
+ "build": {
10
+ "executor": "@nx/angular:package",
11
+ "outputs": ["{workspaceRoot}/dist/{projectRoot}"],
12
+ "options": {
13
+ "project": "libs/core/ng-package.json"
14
+ },
15
+ "configurations": {
16
+ "production": {
17
+ "tsConfig": "libs/core/tsconfig.lib.prod.json"
18
+ },
19
+ "development": {
20
+ "tsConfig": "libs/core/tsconfig.lib.json"
21
+ }
22
+ },
23
+ "defaultConfiguration": "production"
24
+ },
25
+ "lint": {
26
+ "executor": "@nx/eslint:lint"
27
+ }
28
+ }
29
+ }
@@ -1,10 +1,10 @@
1
- export * from "./lib/core/services/base-pagination-service";
2
- export * from "./lib/core/components";
3
- export * from "./lib/core/services";
4
- export * from "./lib/core/interfaces";
5
- export * from "./lib/core/guards";
6
- export * from "./lib/core/interceptors";
7
- export * from "./lib/core/enums";
8
- export * from "./lib/core/directives";
9
- export * from "./lib/core/core-config";
10
- export * from "./lib/core/handlers";
1
+ export * from "./lib/core/services/base-pagination-service";
2
+ export * from "./lib/core/components";
3
+ export * from "./lib/core/services";
4
+ export * from "./lib/core/interfaces";
5
+ export * from "./lib/core/guards";
6
+ export * from "./lib/core/interceptors";
7
+ export * from "./lib/core/enums";
8
+ export * from "./lib/core/directives";
9
+ export * from "./lib/core/core-config";
10
+ export * from "./lib/core/handlers";
@@ -0,0 +1,18 @@
1
+ @if (loaderService.isLoading$ | async; as data) {
2
+ @if (data.show) {
3
+ <div
4
+ class="fixed inset-0 z-[1111] flex justify-center items-center"
5
+ [ngClass]="{
6
+ 'bg-white/75': data?.isSystemLoader,
7
+ 'absolute': !data?.isSystemLoader
8
+ }"
9
+ >
10
+ <div class="text-center flex flex-col gap-5 items-center">
11
+ <div
12
+ class="animate-spin inline-block w-12 h-12 border-[3px] border-current border-t-transparent text-gray-800 rounded-full">
13
+ </div>
14
+ <span>{{ 'loading' | translate }}</span>
15
+ </div>
16
+ </div>
17
+ }
18
+ }
@@ -0,0 +1,24 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { GlobalLoaderComponent } from 'libs/core/src/lib/core/components/global-loader/global-loader.component';
4
+
5
+ describe("LoaderComponent", () => {
6
+ let component: GlobalLoaderComponent;
7
+ let fixture: ComponentFixture<GlobalLoaderComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [GlobalLoaderComponent]
12
+ }).compileComponents();
13
+ });
14
+
15
+ beforeEach(() => {
16
+ fixture = TestBed.createComponent(GlobalLoaderComponent);
17
+ component = fixture.componentInstance;
18
+ fixture.detectChanges();
19
+ });
20
+
21
+ it("should create", () => {
22
+ expect(component).toBeTruthy();
23
+ });
24
+ });
@@ -0,0 +1,16 @@
1
+ import { AsyncPipe, NgClass } from '@angular/common';
2
+ import { Component, Input } from '@angular/core';
3
+ import {TranslatePipe} from "@ngx-translate/core";
4
+ import {LoaderService} from "../../services";
5
+
6
+ @Component({
7
+ selector: "global-loader",
8
+ templateUrl: "./global-loader.component.html",
9
+ styleUrls: ["./global-loader.component.scss"],
10
+ standalone: true,
11
+ imports: [AsyncPipe, NgClass, TranslatePipe]
12
+ })
13
+ export class GlobalLoaderComponent {
14
+ @Input() color: string;
15
+ constructor(public loaderService: LoaderService) {}
16
+ }
@@ -1 +1 @@
1
- export * from "./global-loader/global-loader.component";
1
+ export * from "./global-loader/global-loader.component";
@@ -0,0 +1,9 @@
1
+ <div class="flex items-center justify-center flex-col h-full gap-4 w-full">
2
+ <img [src]="imageSrc" alt="no-access" class="h-[300px]" />
3
+ <strong class="text-secondary font-size-22">{{ "oops" | translate }}</strong>
4
+ <p class="font-size-22 text-gray-500">{{ "do_not_have_permission" | translate }}</p>
5
+
6
+ <!-- @if (authService.isUserLoggedIn$ | async) {
7
+ <app-button (click)="router.navigate(['/'])" [title]="'home' | translate"/>
8
+ } -->
9
+ </div>
@@ -0,0 +1,17 @@
1
+ import { Component, inject } from "@angular/core";
2
+ import { Router } from "@angular/router";
3
+ import { AuthService } from "../../services/auth.service";
4
+ import { AsyncPipe } from "@angular/common";
5
+ import { TranslatePipe } from "@ngx-translate/core";
6
+
7
+ @Component({
8
+ selector: "app-no-access",
9
+ templateUrl: "./no-access.component.html",
10
+ imports: [AsyncPipe, TranslatePipe],
11
+ standalone: true
12
+ })
13
+ export class NoAccessComponent {
14
+ imageSrc: string = "assets/images/no-access.svg";
15
+ authService = inject(AuthService);
16
+ public router = inject(Router);
17
+ }
@@ -0,0 +1,11 @@
1
+ import { InjectionToken } from "@angular/core";
2
+
3
+ export interface CoreConfig {
4
+ apiPrefix: string;
5
+ production: boolean;
6
+ gatewayUrl: string;
7
+ loginUrl: string;
8
+ logoutEndpoint: string;
9
+ }
10
+
11
+ export const CORE_CONFIG = new InjectionToken<CoreConfig>("CoreConfig");
@@ -1 +1 @@
1
- export * from './permissions.directive';
1
+ export * from './permissions.directive';
@@ -0,0 +1,114 @@
1
+ import {
2
+ Directive,
3
+ Input,
4
+ OnDestroy,
5
+ OnInit,
6
+ TemplateRef,
7
+ ViewContainerRef,
8
+ } from '@angular/core';
9
+ import { PermissionsService } from '../services';
10
+ import { PermissionsActions, UserPermissionsEnum } from '../enums';
11
+ import { Subscription } from 'rxjs';
12
+
13
+ @Directive({
14
+ selector: '[hasPermissions]',
15
+ standalone: true
16
+ })
17
+ export class HasPermissionsDirective implements OnInit, OnDestroy {
18
+ private _actions: string[];
19
+ private _key: string;
20
+ private _newPermissions: string[];
21
+ private _isDomain: boolean;
22
+
23
+ private isViewCreated = false;
24
+ private subscription: Subscription;
25
+
26
+ constructor(
27
+ private permissionsService: PermissionsService,
28
+ private viewContainer: ViewContainerRef,
29
+ private templateRef: TemplateRef<unknown>
30
+ ) {}
31
+
32
+ /**
33
+ * make sure that the key value looks like the UserPermissionsEnum enum
34
+ * usage: *permissions="[PermissionsActions.EDIT]; key: LOOKUPS
35
+ */
36
+
37
+ @Input({ required: true }) set hasPermissions(actions: string[]) {
38
+ if (this.arraysChanged(this._actions, actions)) {
39
+ this._actions = actions;
40
+ this.updateView();
41
+ }
42
+ }
43
+
44
+ @Input({ required: true }) set hasPermissionsKey(key: string) {
45
+ if (this._key !== key) {
46
+ this._key = key;
47
+ this.updateView();
48
+ }
49
+ }
50
+
51
+ @Input() set hasPermissionsNewPermissions(newPermissions: string[]) {
52
+ if (this.arraysChanged(this._newPermissions, newPermissions)) {
53
+ this._newPermissions = newPermissions;
54
+ this.updateView();
55
+ }
56
+ }
57
+
58
+ @Input() set hasPermissionsIsDomain(isDomain: boolean) {
59
+ if (this._isDomain !== isDomain) {
60
+ this._isDomain = isDomain;
61
+ this.updateView();
62
+ }
63
+ }
64
+
65
+ ngOnInit(): void {
66
+ this.subscription = this.permissionsService.domainPermissions$.subscribe(() => {
67
+ if (this._isDomain) {
68
+ this.updateView();
69
+ }
70
+ });
71
+ }
72
+
73
+ ngOnDestroy(): void {
74
+ this.subscription?.unsubscribe();
75
+ }
76
+
77
+ private updateView() {
78
+ const canShow = this._actions.some(action => this.hasPermission(action));
79
+
80
+ if (canShow && !this.isViewCreated) {
81
+ this.viewContainer.createEmbeddedView(this.templateRef);
82
+ this.isViewCreated = true;
83
+ } else if (!canShow && this.isViewCreated) {
84
+ this.clearView();
85
+ }
86
+ }
87
+
88
+ private hasPermission(action: string): boolean {
89
+ if (this._isDomain) {
90
+ return this.permissionsService.checkDomainHasPermission(
91
+ this._key as UserPermissionsEnum,
92
+ action as PermissionsActions
93
+ );
94
+ }
95
+
96
+ return this.permissionsService.checkKeyHasPermission(
97
+ this._key as UserPermissionsEnum,
98
+ action as PermissionsActions,
99
+ this._newPermissions
100
+ );
101
+ }
102
+
103
+ private clearView() {
104
+ this.viewContainer.clear();
105
+ this.isViewCreated = false;
106
+ }
107
+
108
+ private arraysChanged(a?: string[], b?: string[]): boolean {
109
+ if (a === b) return false;
110
+ if (!a || !b) return true;
111
+ if (a.length !== b.length) return true;
112
+ return a.some((v, i) => v !== b[i]);
113
+ }
114
+ }
@@ -1 +1 @@
1
- export * from './user-permissions.enum';
1
+ export * from './user-permissions.enum';
@@ -0,0 +1,36 @@
1
+ export enum UserPermissionsEnum {
2
+ BOD = "BOD",
3
+ BOARD_COMMITTEES = "BOARD_COMMITTEES",
4
+ BOARD_MEETINGS = "BOARD_MEETINGS",
5
+ MEETING_INSIDE_THE_BOD = "MEETING_INSIDE_THE_BOD",
6
+ COMMITTEE = "COMMITTEE",
7
+ MEETING_INSIDE_THE_COMMITTEE = "MEETING_INSIDE_THE_COMMITTEE",
8
+ MEETING = "MEETING",
9
+ DECISION = "DECISION",
10
+ RECOMMENDATION = "RECOMMENDATION",
11
+ TASK = "TASK",
12
+ VOTING = "VOTING",
13
+ VOTING_SECRETARY_RESULTS = "VOTING_SECRETARY_RESULTS",
14
+ VOTING_RESULTS = "VOTING_RESULTS",
15
+ DRAFT_MOM = "DRAFT_MOM",
16
+ FINAL_MOM = "FINAL_MOM",
17
+ MOM = "MOM",
18
+ AGENDA = "AGENDA",
19
+ ATTENDEES = "ATTENDEES",
20
+ COMMENT = "COMMENT"
21
+ }
22
+
23
+ export enum PermissionsActions {
24
+ VIEW = "VIEW",
25
+ CREATE = "CREATE",
26
+ EDIT = "EDIT",
27
+ DELETE = "DELETE",
28
+ REORDER = "REORDER",
29
+ DOWNLOAD = "DOWNLOAD",
30
+ MARK = "MARK",
31
+ GENERATE = "GENERATE",
32
+ TERMINATE = "TERMINATE",
33
+ START = "START",
34
+ END = "END",
35
+ ACTIVATE = "ACTIVATE"
36
+ }
@@ -0,0 +1,17 @@
1
+ import { inject } from "@angular/core";
2
+ import { CanActivateFn } from "@angular/router";
3
+ import { AuthService } from "../services";
4
+ import { CORE_CONFIG, CoreConfig } from "../core-config";
5
+
6
+ export const authGuard: CanActivateFn = () => {
7
+ const appConfig = inject<CoreConfig>(CORE_CONFIG);
8
+ const authService = inject(AuthService);
9
+ const token: string | null = authService.getUserToken();
10
+
11
+ if (!token) {
12
+ window.location.href = appConfig.loginUrl;
13
+ return false;
14
+ }
15
+
16
+ return true;
17
+ };
@@ -1,2 +1,2 @@
1
- export * from './auth.guard';
2
- export * from './permissions.guard';
1
+ export * from './auth.guard';
2
+ export * from './permissions.guard';
@@ -0,0 +1,17 @@
1
+ import { inject } from "@angular/core";
2
+ import { CanActivateFn, Router } from "@angular/router";
3
+ import { PermissionsService } from "../services";
4
+ import { RoutePermissionsInfo } from "../interfaces";
5
+
6
+ export const permissionsGuard: CanActivateFn = (route) => {
7
+ const permissionsService = inject(PermissionsService);
8
+ const router = inject(Router);
9
+ const { key, action }: RoutePermissionsInfo = route.data["permissions"];
10
+
11
+ if (!route.data["permissions"] || (route.data["permissions"] && permissionsService.routeGuardChecker(key, action))) {
12
+ return true;
13
+ } else {
14
+ router.navigate(["no-access"]);
15
+ return false;
16
+ }
17
+ };
@@ -0,0 +1,14 @@
1
+ import { HttpContext, HttpContextToken } from "@angular/common/http";
2
+
3
+ export const IS_SYSTEM_LOADER = new HttpContextToken<boolean>(() => true); // set default loader
4
+ export const USE_API_PREFIX = new HttpContextToken<boolean>(() => true); // set default loader
5
+
6
+ export class HttpContextHandler {
7
+ static setLoaderType(isSystemLoader: boolean) {
8
+ return new HttpContext().set(IS_SYSTEM_LOADER, isSystemLoader);
9
+ }
10
+
11
+ static useApiPrefix(hasBaseSegment: boolean) {
12
+ return new HttpContext().set(USE_API_PREFIX, hasBaseSegment);
13
+ }
14
+ }
@@ -1,3 +1,3 @@
1
- export * from "./http-context-handler";
2
- export * from "./storage-handler";
3
- export * from "./stortage";
1
+ export * from "./http-context-handler";
2
+ export * from "./storage-handler";
3
+ export * from "./stortage";
@@ -0,0 +1,37 @@
1
+ // Important for global context
2
+ import { LocalStorageKeys, SessionStorageKeys, StorageEnum } from "./stortage";
3
+
4
+ const setLocalStorage = (key: string, value: string) => localStorage.setItem(key, value);
5
+ const getLocalStorage = (key: string) => localStorage.getItem(key);
6
+ const clearLocalStorage = () => localStorage.clear();
7
+ const setSessionStorage = (key: string, value: string) => sessionStorage.setItem(key, value);
8
+ const getSessionStorage = (key: string) => sessionStorage.getItem(key);
9
+ const clearSessionStorage = () => sessionStorage.clear();
10
+
11
+ export class StorageHandler {
12
+ public static local = {
13
+ set: (key: LocalStorageKeys, value: unknown) => this.setItem(key, value, setLocalStorage),
14
+ get: <T>(key: LocalStorageKeys) => this.getItem<T>(key, getLocalStorage),
15
+ clear: () => this.clearStorage(clearLocalStorage)
16
+ };
17
+ public static session = {
18
+ set: (key: SessionStorageKeys, value: unknown) => this.setItem(key, value, setSessionStorage),
19
+ get: <T>(key: SessionStorageKeys) => this.getItem<T>(key, getSessionStorage),
20
+ clear: () => this.clearStorage(clearSessionStorage)
21
+ };
22
+
23
+ private static setItem(key: StorageEnum, value: unknown, set: (key: string, value: string) => void): void {
24
+ if (!key) return;
25
+ set(key as string, typeof value === "string" ? value : JSON.stringify(value));
26
+ }
27
+
28
+ private static getItem<T>(key: StorageEnum, get: (key: string) => string | null, withParsing = false): T | null {
29
+ const data: string | null = get(key as string) ?? null;
30
+ if (data) return withParsing ? JSON.parse(data) : data;
31
+ return null;
32
+ }
33
+
34
+ private static clearStorage(clear: () => void): void {
35
+ clear();
36
+ }
37
+ }
@@ -0,0 +1,7 @@
1
+ export enum LocalStorageKeys {
2
+ LANGUAGE = "LANGUAGE",
3
+ TOKEN = "TOKEN"
4
+ }
5
+
6
+ export enum SessionStorageKeys {}
7
+ export type StorageEnum = SessionStorageKeys | LocalStorageKeys;
@@ -0,0 +1,8 @@
1
+ export const COMMON_BASE_URL = "common/api/v1";
2
+ export const APP_HTTP_CONFIG = {
3
+ BOARD_BASE_URL: "board-acl/private/v1",
4
+ MEETING_BASE_URL: "meeting-acl/private/v1",
5
+ IGATE_BASE_URL: COMMON_BASE_URL + "/igate-users",
6
+ LOV_BASE_URL: COMMON_BASE_URL + "/lov",
7
+ ATTACHMENT_BASE_URL: COMMON_BASE_URL + "/attachment"
8
+ };
@@ -0,0 +1,45 @@
1
+ import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http";
2
+ import { Inject, inject, Injectable } from "@angular/core";
3
+ import { finalize, Observable, tap } from "rxjs";
4
+ import { IS_SYSTEM_LOADER, USE_API_PREFIX } from "../handlers/http-context-handler";
5
+ import { AuthService } from "../services/auth.service";
6
+ import { LoaderService } from "../services/loader.service";
7
+ import { CORE_CONFIG, CoreConfig } from "../core-config";
8
+
9
+ @Injectable()
10
+ export class HttpBaseInterceptor implements HttpInterceptor {
11
+ authService = inject(AuthService);
12
+ loaderService = inject(LoaderService);
13
+
14
+ constructor(@Inject(CORE_CONFIG) protected appConfig: CoreConfig) {}
15
+
16
+ intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
17
+ const useApiPrefix = request.context.get(USE_API_PREFIX);
18
+ const URL = `${this.appConfig.gatewayUrl}${useApiPrefix ? this.appConfig.apiPrefix : ""}${request.url}`;
19
+ const token = this.authService.getUserToken();
20
+
21
+ // Handler header
22
+ request = request.clone({
23
+ url: URL,
24
+ setHeaders: {
25
+ Authorization: `Bearer ${token}`,
26
+ Language: "en",
27
+ ...request.headers
28
+ }
29
+ });
30
+
31
+ // Handle loader
32
+ const IS_SYSTEM_LOADER_CHECK = request.context.get(IS_SYSTEM_LOADER);
33
+ this.loaderService.setLoading(true, IS_SYSTEM_LOADER_CHECK, request.url);
34
+
35
+ return next.handle(request).pipe(
36
+ // Handler Token
37
+ tap((event) => {
38
+ // if (event instanceof HttpResponse && request.url.includes(User_Token)) {
39
+ // Set user token ..
40
+ // }
41
+ }),
42
+ finalize(() => this.loaderService.setLoading(false, IS_SYSTEM_LOADER_CHECK, request.url))
43
+ );
44
+ }
45
+ }
@@ -0,0 +1,21 @@
1
+ import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
2
+ import { Observable, retry, timer } from 'rxjs';
3
+
4
+ export class GlobalHttpErrorInterceptor implements HttpInterceptor {
5
+ // check if it is a server error to retry the request
6
+ shouldRetry(error: HttpErrorResponse) {
7
+ if (error.status >= 500) {
8
+ return timer(1000);
9
+ }
10
+ throw error;
11
+ }
12
+
13
+ intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
14
+ return next.handle(request).pipe(
15
+ retry({
16
+ count: 1,
17
+ delay: this.shouldRetry
18
+ })
19
+ );
20
+ }
21
+ }
@@ -1,3 +1,3 @@
1
- export * from "./app-http-config";
2
- export * from "./base-http.interceptor";
3
- export * from "./global-http-error.interceptor";
1
+ export * from "./app-http-config";
2
+ export * from "./base-http.interceptor";
3
+ export * from "./global-http-error.interceptor";
@@ -0,0 +1,3 @@
1
+ export * from "./router-data.interface"
2
+ export * from "./list-response.interface"
3
+ export * from "./user-info.interface"
@@ -1,7 +1,7 @@
1
- import { JwtPayload } from "jwt-decode";
2
- import { UserProfileData } from "./user-profile-data";
3
- export interface JWTDecoded extends JwtPayload {
4
- permissions: string[];
5
- role: string;
6
- profile: UserProfileData;
7
- }
1
+ import { JwtPayload } from "jwt-decode";
2
+ import { UserProfileData } from "./user-profile-data";
3
+ export interface JWTDecoded extends JwtPayload {
4
+ permissions: string[];
5
+ role: string;
6
+ profile: UserProfileData;
7
+ }
@@ -0,0 +1,5 @@
1
+ export interface ListResponse<T> {
2
+ data: T;
3
+ totalElements: number;
4
+ totalPages: number;
5
+ }