@techextensor/tab-core-utility 2.1.7 → 2.1.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 (177) hide show
  1. package/esm2022/index.mjs +64 -0
  2. package/esm2022/lib/tab-core-utility/app/constants/api-constants.mjs +33 -0
  3. package/esm2022/lib/tab-core-utility/app/constants/common.mjs +25 -0
  4. package/esm2022/lib/tab-core-utility/app/constants/error-messages.mjs +13 -0
  5. package/esm2022/lib/tab-core-utility/app/constants/storage-constants.mjs +16 -0
  6. package/esm2022/lib/tab-core-utility/app/crud/tab-delete.service.mjs +145 -0
  7. package/esm2022/lib/tab-core-utility/app/crud/tab-get.service.mjs +131 -0
  8. package/esm2022/lib/tab-core-utility/app/crud/tab-insert.service.mjs +77 -0
  9. package/esm2022/lib/tab-core-utility/app/crud/tab-update.service.mjs +105 -0
  10. package/esm2022/lib/tab-core-utility/app/crud/tab-workflow.service.mjs +43 -0
  11. package/esm2022/lib/tab-core-utility/app/enums/controllers.enum.mjs +26 -0
  12. package/esm2022/lib/tab-core-utility/app/enums/dsq.enum.mjs +48 -0
  13. package/esm2022/lib/tab-core-utility/app/enums/permission.enum.mjs +20 -0
  14. package/esm2022/lib/tab-core-utility/app/enums/query.enum.mjs +14 -0
  15. package/esm2022/lib/tab-core-utility/app/enums/workflow.enum.mjs +37 -0
  16. package/esm2022/lib/tab-core-utility/app/helpers/common/app.helpers.mjs +68 -0
  17. package/esm2022/lib/tab-core-utility/app/helpers/common/dsq.helpers.mjs +70 -0
  18. package/esm2022/lib/tab-core-utility/app/helpers/common/req-res.helpers.mjs +64 -0
  19. package/esm2022/lib/tab-core-utility/app/helpers/common/where-clause.helpers.mjs +208 -0
  20. package/esm2022/lib/tab-core-utility/app/helpers/screen/forms.helpers.mjs +38 -0
  21. package/esm2022/lib/tab-core-utility/app/helpers/screen/grid-column-data.helpers.mjs +78 -0
  22. package/esm2022/lib/tab-core-utility/app/helpers/screen/grid.helpers.mjs +112 -0
  23. package/esm2022/lib/tab-core-utility/app/helpers/screen/media-upload.helpers.mjs +77 -0
  24. package/esm2022/lib/tab-core-utility/app/helpers/screen/plugin.helpers.mjs +55 -0
  25. package/esm2022/lib/tab-core-utility/app/helpers/screen/screen.helpers.mjs +26 -0
  26. package/esm2022/lib/tab-core-utility/app/interfaces/auth.interface.mjs +2 -0
  27. package/esm2022/lib/tab-core-utility/app/interfaces/common-api.interface.mjs +2 -0
  28. package/esm2022/lib/tab-core-utility/app/interfaces/grid.interface.mjs +3 -0
  29. package/esm2022/lib/tab-core-utility/app/interfaces/orgInfo.interface.mjs +2 -0
  30. package/esm2022/lib/tab-core-utility/app/interfaces/schema.interface.mjs +2 -0
  31. package/esm2022/lib/tab-core-utility/app/interfaces/user.interface.mjs +2 -0
  32. package/esm2022/lib/tab-core-utility/app/models/api-query.class.mjs +47 -0
  33. package/esm2022/lib/tab-core-utility/app/models/app-object.class.mjs +30 -0
  34. package/esm2022/lib/tab-core-utility/app/models/common.class.mjs +12 -0
  35. package/esm2022/lib/tab-core-utility/app/models/data-source-queries.class.mjs +31 -0
  36. package/esm2022/lib/tab-core-utility/app/utils/filter.util.mjs +75 -0
  37. package/esm2022/lib/tab-core-utility/app/utils/form-builder.util.mjs +39 -0
  38. package/esm2022/lib/tab-core-utility/app/utils/json.util.mjs +138 -0
  39. package/esm2022/lib/tab-core-utility/app/utils/operators.util.mjs +129 -0
  40. package/esm2022/lib/tab-core-utility/app/utils/req-res.util.mjs +168 -0
  41. package/esm2022/lib/tab-core-utility/app/utils/tab-app.util.mjs +99 -0
  42. package/esm2022/lib/tab-core-utility/auth/auth.service.mjs +74 -0
  43. package/esm2022/lib/tab-core-utility/auth/idb-storage.service.mjs +69 -0
  44. package/esm2022/lib/tab-core-utility/auth/local-storage.service.mjs +52 -0
  45. package/esm2022/lib/tab-core-utility/auth/session-storage.service.mjs +52 -0
  46. package/esm2022/lib/tab-core-utility/core/error-handler/error-handler-interceptor.service.mjs +26 -0
  47. package/esm2022/lib/tab-core-utility/core/error-handler/error-handler.store.mjs +21 -0
  48. package/esm2022/lib/tab-core-utility/core/error-handler/models/error-handler.state.mjs +5 -0
  49. package/esm2022/lib/tab-core-utility/core/http-client/api-url.token.mjs +4 -0
  50. package/esm2022/lib/tab-core-utility/core/http-client/api.service.mjs +99 -0
  51. package/esm2022/lib/tab-core-utility/core/util/auth.utils.mjs +21 -0
  52. package/esm2022/lib/tab-core-utility/store/auth.store.mjs +43 -0
  53. package/esm2022/lib/tab-core-utility/store/orginfo.store.mjs +42 -0
  54. package/esm2022/lib/tab-core-utility/store/schema.store.mjs +68 -0
  55. package/esm2022/techextensor-tab-core-utility.mjs +5 -0
  56. package/{src/index.ts → index.d.ts} +53 -77
  57. package/lib/tab-core-utility/app/constants/api-constants.d.ts +30 -0
  58. package/lib/tab-core-utility/app/constants/common.d.ts +8 -0
  59. package/lib/tab-core-utility/app/constants/error-messages.d.ts +6 -0
  60. package/lib/tab-core-utility/app/constants/storage-constants.d.ts +15 -0
  61. package/lib/tab-core-utility/app/crud/tab-delete.service.d.ts +51 -0
  62. package/lib/tab-core-utility/app/crud/tab-get.service.d.ts +58 -0
  63. package/lib/tab-core-utility/app/crud/tab-insert.service.d.ts +37 -0
  64. package/lib/tab-core-utility/app/crud/tab-update.service.d.ts +14 -0
  65. package/lib/tab-core-utility/app/crud/tab-workflow.service.d.ts +20 -0
  66. package/lib/tab-core-utility/app/enums/controllers.enum.d.ts +24 -0
  67. package/lib/tab-core-utility/app/enums/dsq.enum.d.ts +42 -0
  68. package/lib/tab-core-utility/app/enums/permission.enum.d.ts +16 -0
  69. package/lib/tab-core-utility/app/enums/query.enum.d.ts +11 -0
  70. package/lib/tab-core-utility/app/enums/workflow.enum.d.ts +30 -0
  71. package/lib/tab-core-utility/app/helpers/common/app.helpers.d.ts +31 -0
  72. package/lib/tab-core-utility/app/helpers/common/dsq.helpers.d.ts +32 -0
  73. package/lib/tab-core-utility/app/helpers/common/req-res.helpers.d.ts +62 -0
  74. package/lib/tab-core-utility/app/helpers/common/where-clause.helpers.d.ts +82 -0
  75. package/lib/tab-core-utility/app/helpers/screen/forms.helpers.d.ts +11 -0
  76. package/lib/tab-core-utility/app/helpers/screen/grid-column-data.helpers.d.ts +33 -0
  77. package/lib/tab-core-utility/app/helpers/screen/grid.helpers.d.ts +63 -0
  78. package/lib/tab-core-utility/app/helpers/screen/media-upload.helpers.d.ts +38 -0
  79. package/lib/tab-core-utility/app/helpers/screen/plugin.helpers.d.ts +25 -0
  80. package/lib/tab-core-utility/app/helpers/screen/screen.helpers.d.ts +11 -0
  81. package/{src/lib/tab-core-utility/app/interfaces/auth.interface.ts → lib/tab-core-utility/app/interfaces/auth.interface.d.ts} +15 -18
  82. package/lib/tab-core-utility/app/interfaces/common-api.interface.d.ts +24 -0
  83. package/lib/tab-core-utility/app/interfaces/grid.interface.d.ts +110 -0
  84. package/lib/tab-core-utility/app/interfaces/orgInfo.interface.d.ts +31 -0
  85. package/lib/tab-core-utility/app/interfaces/schema.interface.d.ts +11 -0
  86. package/lib/tab-core-utility/app/interfaces/user.interface.d.ts +84 -0
  87. package/lib/tab-core-utility/app/models/api-query.class.d.ts +69 -0
  88. package/lib/tab-core-utility/app/models/app-object.class.d.ts +74 -0
  89. package/lib/tab-core-utility/app/models/common.class.d.ts +24 -0
  90. package/lib/tab-core-utility/app/models/data-source-queries.class.d.ts +95 -0
  91. package/lib/tab-core-utility/app/utils/filter.util.d.ts +30 -0
  92. package/lib/tab-core-utility/app/utils/form-builder.util.d.ts +13 -0
  93. package/lib/tab-core-utility/app/utils/json.util.d.ts +25 -0
  94. package/lib/tab-core-utility/app/utils/operators.util.d.ts +21 -0
  95. package/lib/tab-core-utility/app/utils/req-res.util.d.ts +61 -0
  96. package/lib/tab-core-utility/app/utils/tab-app.util.d.ts +48 -0
  97. package/lib/tab-core-utility/auth/auth.service.d.ts +53 -0
  98. package/lib/tab-core-utility/auth/idb-storage.service.d.ts +14 -0
  99. package/lib/tab-core-utility/auth/local-storage.service.d.ts +22 -0
  100. package/lib/tab-core-utility/auth/session-storage.service.d.ts +22 -0
  101. package/lib/tab-core-utility/core/error-handler/error-handler-interceptor.service.d.ts +3 -0
  102. package/lib/tab-core-utility/core/error-handler/error-handler.store.d.ts +10 -0
  103. package/lib/tab-core-utility/core/error-handler/models/error-handler.state.d.ts +5 -0
  104. package/lib/tab-core-utility/core/http-client/api-url.token.d.ts +3 -0
  105. package/lib/tab-core-utility/core/http-client/api.service.d.ts +65 -0
  106. package/lib/tab-core-utility/core/util/auth.utils.d.ts +9 -0
  107. package/lib/tab-core-utility/store/auth.store.d.ts +19 -0
  108. package/lib/tab-core-utility/store/orginfo.store.d.ts +22 -0
  109. package/lib/tab-core-utility/store/schema.store.d.ts +32 -0
  110. package/package.json +31 -18
  111. package/.eslintrc.json +0 -92
  112. package/README.md +0 -7
  113. package/jest.config.ts +0 -22
  114. package/ng-package.json +0 -7
  115. package/project.json +0 -42
  116. package/src/lib/tab-core-utility/app/constants/api-constants.ts +0 -33
  117. package/src/lib/tab-core-utility/app/constants/common.ts +0 -34
  118. package/src/lib/tab-core-utility/app/constants/error-messages.ts +0 -21
  119. package/src/lib/tab-core-utility/app/constants/storage-constants.ts +0 -17
  120. package/src/lib/tab-core-utility/app/crud/tab-delete.service.ts +0 -144
  121. package/src/lib/tab-core-utility/app/crud/tab-get.service.ts +0 -160
  122. package/src/lib/tab-core-utility/app/crud/tab-insert.service.ts +0 -75
  123. package/src/lib/tab-core-utility/app/crud/tab-update.service.ts +0 -105
  124. package/src/lib/tab-core-utility/app/crud/tab-workflow.service.ts +0 -39
  125. package/src/lib/tab-core-utility/app/enums/controllers.enum.ts +0 -24
  126. package/src/lib/tab-core-utility/app/enums/dsq.enum.ts +0 -46
  127. package/src/lib/tab-core-utility/app/enums/permission.enum.ts +0 -18
  128. package/src/lib/tab-core-utility/app/enums/query.enum.ts +0 -12
  129. package/src/lib/tab-core-utility/app/enums/workflow.enum.ts +0 -35
  130. package/src/lib/tab-core-utility/app/helpers/common/app.helpers.ts +0 -65
  131. package/src/lib/tab-core-utility/app/helpers/common/dsq.helpers.ts +0 -80
  132. package/src/lib/tab-core-utility/app/helpers/common/req-res.helpers.ts +0 -75
  133. package/src/lib/tab-core-utility/app/helpers/common/where-clause.helpers.ts +0 -262
  134. package/src/lib/tab-core-utility/app/helpers/screen/forms.helpers.ts +0 -33
  135. package/src/lib/tab-core-utility/app/helpers/screen/grid-column-data.helpers.ts +0 -88
  136. package/src/lib/tab-core-utility/app/helpers/screen/grid.helpers.ts +0 -113
  137. package/src/lib/tab-core-utility/app/helpers/screen/media-upload.helpers.ts +0 -74
  138. package/src/lib/tab-core-utility/app/helpers/screen/plugin.helpers.ts +0 -52
  139. package/src/lib/tab-core-utility/app/helpers/screen/screen.helpers.ts +0 -20
  140. package/src/lib/tab-core-utility/app/interfaces/common-api.interface.ts +0 -27
  141. package/src/lib/tab-core-utility/app/interfaces/grid.interface.ts +0 -118
  142. package/src/lib/tab-core-utility/app/interfaces/orgInfo.interface.ts +0 -34
  143. package/src/lib/tab-core-utility/app/interfaces/schema.interface.ts +0 -11
  144. package/src/lib/tab-core-utility/app/interfaces/user.interface.ts +0 -91
  145. package/src/lib/tab-core-utility/app/models/api-query.class.ts +0 -92
  146. package/src/lib/tab-core-utility/app/models/app-object.class.ts +0 -87
  147. package/src/lib/tab-core-utility/app/models/common.class.ts +0 -30
  148. package/src/lib/tab-core-utility/app/models/data-source-queries.class.ts +0 -114
  149. package/src/lib/tab-core-utility/app/utils/filter.util.ts +0 -78
  150. package/src/lib/tab-core-utility/app/utils/form-builder.util.ts +0 -31
  151. package/src/lib/tab-core-utility/app/utils/json.util.ts +0 -137
  152. package/src/lib/tab-core-utility/app/utils/operators.util.ts +0 -129
  153. package/src/lib/tab-core-utility/app/utils/req-res.util.ts +0 -189
  154. package/src/lib/tab-core-utility/app/utils/tab-app.util.ts +0 -131
  155. package/src/lib/tab-core-utility/auth/auth.service.spec.ts +0 -167
  156. package/src/lib/tab-core-utility/auth/auth.service.ts +0 -91
  157. package/src/lib/tab-core-utility/auth/idb-storage.service.ts +0 -77
  158. package/src/lib/tab-core-utility/auth/local-storage.service.spec.ts +0 -47
  159. package/src/lib/tab-core-utility/auth/local-storage.service.ts +0 -46
  160. package/src/lib/tab-core-utility/auth/session-storage.service.spec.ts +0 -47
  161. package/src/lib/tab-core-utility/auth/session-storage.service.ts +0 -46
  162. package/src/lib/tab-core-utility/core/error-handler/error-handler-interceptor.service.ts +0 -32
  163. package/src/lib/tab-core-utility/core/error-handler/error-handler.store.spec.ts +0 -16
  164. package/src/lib/tab-core-utility/core/error-handler/error-handler.store.ts +0 -26
  165. package/src/lib/tab-core-utility/core/error-handler/models/error-handler.state.ts +0 -9
  166. package/src/lib/tab-core-utility/core/http-client/api-url.token.ts +0 -4
  167. package/src/lib/tab-core-utility/core/http-client/api.service.spec.ts +0 -18
  168. package/src/lib/tab-core-utility/core/http-client/api.service.ts +0 -105
  169. package/src/lib/tab-core-utility/core/util/auth.utils.ts +0 -22
  170. package/src/lib/tab-core-utility/store/auth.store.ts +0 -54
  171. package/src/lib/tab-core-utility/store/orginfo.store.ts +0 -57
  172. package/src/lib/tab-core-utility/store/schema.store.ts +0 -85
  173. package/src/test-setup.ts +0 -8
  174. package/tsconfig.json +0 -29
  175. package/tsconfig.lib.json +0 -17
  176. package/tsconfig.lib.prod.json +0 -7
  177. package/tsconfig.spec.json +0 -16
@@ -1,167 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
- import {
3
- HttpClientTestingModule,
4
- HttpTestingController,
5
- } from '@angular/common/http/testing';
6
- import { AuthService } from './auth.service';
7
- import { ApiService } from '../core/http-client/api.service';
8
- import { UserResponse } from '../app/interfaces/user.interface';
9
- import { ApiResponse } from '../app/interfaces/common-api.interface';
10
- import { LocalStorageService } from './local-storage.service';
11
-
12
- describe('AuthService', () => {
13
- let authService: AuthService;
14
- let httpMock: HttpTestingController;
15
-
16
- beforeEach(() => {
17
- TestBed.configureTestingModule({
18
- imports: [HttpClientTestingModule],
19
- providers: [AuthService, ApiService, LocalStorageService],
20
- });
21
- authService = TestBed.inject(AuthService);
22
- httpMock = TestBed.inject(HttpTestingController);
23
- });
24
-
25
- afterEach(() => {
26
- httpMock.verify();
27
- });
28
-
29
- it('should be created', () => {
30
- expect(authService).toBeTruthy();
31
- });
32
-
33
- it('should fetch user details', () => {
34
- const mockUrl = 'mockUrl';
35
- const mockResponse: UserResponse = {
36
- /* mock user response object */
37
- user: {
38
- id: '1',
39
- email: 'john.doe@example.com',
40
- token: 'example_token',
41
- username: 'john_doe',
42
- bio: 'Sample biography',
43
- image: 'https://example.com/profile.jpg',
44
- },
45
- };
46
-
47
- authService.user(mockUrl).subscribe((response: UserResponse) => {
48
- expect(response).toEqual(mockResponse);
49
- });
50
-
51
- const request = httpMock.expectOne(mockUrl);
52
- expect(request.request.method).toBe('GET');
53
- request.flush(mockResponse);
54
- });
55
-
56
- it('should sign in with given credentials', () => {
57
- const mockUrl = 'mockUrl';
58
- const mockCredentials = {
59
- /* mock login credentials */
60
- email: 'john.doe@example.com',
61
- password: '123456',
62
- };
63
- const mockResponse: UserResponse = {
64
- /* mock user response object */
65
- user: {
66
- id: '1',
67
- email: 'john.doe@example.com',
68
- token: 'example_token',
69
- username: 'john_doe',
70
- bio: 'Sample biography',
71
- image: 'https://example.com/profile.jpg',
72
- },
73
- };
74
-
75
- authService
76
- .signIn(mockUrl, mockCredentials)
77
- .subscribe((response: UserResponse) => {
78
- expect(response).toEqual(mockResponse);
79
- });
80
-
81
- const request = httpMock.expectOne(mockUrl);
82
- expect(request.request.method).toBe('POST');
83
- expect(request.request.body).toEqual(mockCredentials);
84
- request.flush(mockResponse);
85
- });
86
-
87
- it('should register new user with provided credentials', () => {
88
- const mockUrl = 'mockUrl';
89
- const mockCredentials = {
90
- /* mock login credentials */
91
- username: 'john.doe',
92
- email: 'john.doe@example.com',
93
- password: '123456',
94
- };
95
- const mockResponse: UserResponse = {
96
- /* mock user response object */
97
- user: {
98
- id: '1',
99
- email: 'john.doe@example.com',
100
- token: 'example_token',
101
- username: 'john_doe',
102
- bio: 'Sample biography',
103
- image: 'https://example.com/profile.jpg',
104
- },
105
- };
106
-
107
- authService
108
- .register(mockUrl, mockCredentials)
109
- .subscribe((response: UserResponse) => {
110
- expect(response).toEqual(mockResponse);
111
- });
112
-
113
- const request = httpMock.expectOne(mockUrl);
114
- expect(request.request.method).toBe('POST');
115
- expect(request.request.body).toEqual(mockCredentials);
116
- request.flush(mockResponse);
117
- });
118
-
119
- it('should forgot password in with given credentials', () => {
120
- const mockUrl = 'mockUrl';
121
- const email = { email: 'test@example.com' };
122
- const response: ApiResponse = {
123
- requestId: '123456',
124
- isSuccess: true,
125
- result: [],
126
- errors: [],
127
- };
128
- authService
129
- .forgotPassword(mockUrl, email)
130
- .subscribe((response: ApiResponse) => {
131
- expect(response).toEqual(response);
132
- });
133
-
134
- const request = httpMock.expectOne(mockUrl);
135
- expect(request.request.method).toBe('POST');
136
- expect(request.request.body).toEqual(email);
137
- request.flush(response);
138
- });
139
-
140
- it('should reset password in with given credentials', () => {
141
- const mockUrl = 'mockUrl';
142
- const password = { password: '123456' };
143
- const response: ApiResponse = {
144
- requestId: '123456',
145
- isSuccess: true,
146
- result: [],
147
- errors: [],
148
- };
149
- authService
150
- .resetPassword(mockUrl, password)
151
- .subscribe((response: ApiResponse) => {
152
- expect(response).toEqual(response);
153
- });
154
-
155
- const request = httpMock.expectOne(mockUrl);
156
- expect(request.request.method).toBe('POST');
157
- expect(request.request.body).toEqual(password);
158
- request.flush(response);
159
- });
160
-
161
- it('should logout current session', () => {
162
- spyOn(localStorage, 'removeItem');
163
- const key = 'testKey';
164
- authService.logout(key);
165
- expect(localStorage.removeItem(key)).toHaveBeenCalled();
166
- });
167
- });
@@ -1,91 +0,0 @@
1
- import { Injectable, inject } from '@angular/core';
2
- import { Observable } from 'rxjs';
3
- import {
4
- ForgotPasswordUserRequest,
5
- LoginUserRequest,
6
- NewUserRequest,
7
- ResetPasswordUserRequest,
8
- } from '../app/interfaces/auth.interface';
9
- import { UserResponse } from '../app/interfaces/user.interface';
10
- import { ApiService } from '../core/http-client/api.service';
11
- import { ApiResponse } from '../app/interfaces/common-api.interface';
12
- import { LocalStorageService } from './local-storage.service';
13
-
14
- @Injectable({ providedIn: 'root' })
15
- export class AuthService {
16
- /**
17
- * Injecting required services
18
- */
19
- private readonly apiService = inject(ApiService);
20
- private readonly localStorageService = inject(LocalStorageService);
21
-
22
- // -----------------------------------------------------------------------------------------------------
23
- // @ Public methods
24
- // -----------------------------------------------------------------------------------------------------
25
-
26
- /**
27
- * Fetch user details from the database
28
- *
29
- * @param endPointName - The End Point Name to fetch user details
30
- * @returns Observable<UserResponse> - An observable of UserResponse
31
- */
32
- user(endPointName: string): Observable<UserResponse> {
33
- return this.apiService.get<UserResponse>(endPointName);
34
- }
35
-
36
- /**
37
- * Sign in with provided credentials
38
- *
39
- * @param endPointName - The End Point Name to sign in
40
- * @param credentials - The login credentials
41
- * @returns Observable<UserResponse> - An observable of UserResponse
42
- */
43
- signIn(endPointName: string, credentials: LoginUserRequest): Observable<UserResponse> {
44
- return this.apiService.post<UserResponse, LoginUserRequest>(
45
- endPointName,
46
- credentials
47
- );
48
- }
49
-
50
- /**
51
- * Register a new user
52
- *
53
- * @param endPointName - The End Point Name to register a new user
54
- * @param credentials - The new user's credentials
55
- * @returns Observable<UserResponse> - An observable of UserResponse
56
- */
57
- register(endPointName: string, credentials: NewUserRequest): Observable<UserResponse> {
58
- return this.apiService.post<UserResponse, NewUserRequest>(endPointName, credentials);
59
- }
60
-
61
- /**
62
- * Forgot password
63
- * @param endPointName - The End Point Name of API
64
- * @param email - The email of user
65
- */
66
- forgotPassword(
67
- endPointName: string,
68
- email: ForgotPasswordUserRequest
69
- ): Observable<ApiResponse> {
70
- return this.apiService.post(endPointName, email);
71
- }
72
-
73
- /**
74
- * Reset password
75
- * @param endPointName - The End Point Name of API
76
- * @param password - The password of user
77
- */
78
- resetPassword(
79
- endPointName: string,
80
- password: ResetPasswordUserRequest
81
- ): Observable<ApiResponse> {
82
- return this.apiService.post(endPointName, password);
83
- }
84
-
85
- /**
86
- * Logout current session
87
- */
88
- logout(key: string) {
89
- this.localStorageService.removeLocalStorage(key);
90
- }
91
- }
@@ -1,77 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { openDB, IDBPDatabase, DBSchema } from 'idb';
3
-
4
- interface MyDB extends DBSchema {
5
- myObjectStore: {
6
- key: string;
7
- value: { key: string; data: string };
8
- };
9
- }
10
-
11
- @Injectable({ providedIn: 'root' })
12
- export class IdbService {
13
- private readonly dbName = 'TabDatabase';
14
- private readonly dbVersion = 1;
15
- private dbPromise: Promise<IDBPDatabase<MyDB>>;
16
-
17
- constructor() {
18
- this.dbPromise = openDB<MyDB>(this.dbName, this.dbVersion, {
19
- upgrade(db) {
20
- if (!db.objectStoreNames.contains('myObjectStore')) {
21
- db.createObjectStore('myObjectStore', { keyPath: 'key' });
22
- }
23
- },
24
- });
25
- }
26
-
27
- async setItem(key: string, data: any): Promise<void> {
28
- try {
29
- if (data) {
30
- await this.setItemIndexedDb(key, data);
31
- }
32
- } catch (error) {
33
- throw new Error('Error storing data: ' + error);
34
- }
35
- }
36
-
37
- private async setItemIndexedDb(key: string, data: any): Promise<void> {
38
- const db = await this.dbPromise;
39
- const tx = db.transaction('myObjectStore', 'readwrite');
40
- const store = tx.objectStore('myObjectStore');
41
- await store.put({ key, data });
42
- await tx.done;
43
- }
44
-
45
- async getItem(key: string): Promise<any> {
46
- try {
47
- const result = await this.getItemIndexedDb(key);
48
- return result?.data;
49
- } catch (error) {
50
- throw new Error('Error retrieving data: ' + error);
51
- }
52
- }
53
-
54
- private async getItemIndexedDb(key: string): Promise<any> {
55
- const db = await this.dbPromise;
56
- const tx = db.transaction('myObjectStore', 'readonly');
57
- const store = tx.objectStore('myObjectStore');
58
- const result = await store.get(key);
59
- await tx.done;
60
- return result;
61
- }
62
-
63
- async clearIndexedDB(): Promise<void> {
64
- try {
65
- const db = await this.dbPromise;
66
- const tx = db.transaction('myObjectStore', 'readwrite');
67
- const store = tx.objectStore('myObjectStore');
68
- await store.clear();
69
- await tx.done;
70
- } catch (error) {
71
- throw new Error('Error clearing IndexedDB: ' + error)
72
- }
73
- }
74
- }
75
-
76
-
77
-
@@ -1,47 +0,0 @@
1
- import { TestBed, inject } from '@angular/core/testing';
2
- import { LocalStorageService } from './local-storage.service';
3
-
4
- describe('LocalStorageService', () => {
5
- let localStorageService: LocalStorageService;
6
-
7
- beforeEach(() => {
8
- TestBed.configureTestingModule({
9
- providers: [LocalStorageService],
10
- });
11
- });
12
-
13
- it('should be created', () => {
14
- inject([LocalStorageService], (service: LocalStorageService) => {
15
- expect(service).toBeTruthy();
16
- });
17
- });
18
-
19
- it('should set data in local storage', () => {
20
- const key = 'testKey';
21
- const data = { name: 'John Doe', age: 30 };
22
- localStorageService.setLocalStorage(key, data);
23
- expect(localStorage.getItem(key)).toEqual(JSON.stringify(data));
24
- });
25
-
26
- it('should get data from local storage', () => {
27
- const key = 'testKey';
28
- const data = { name: 'Jane Smith', age: 25 };
29
- localStorage.setItem(key, JSON.stringify(data));
30
- const retrievedData = localStorageService.getLocalStorage(key);
31
- expect(retrievedData).toEqual(data);
32
- });
33
-
34
- it('should return null when getting non-existent data from local storage', () => {
35
- const key = 'nonExistentKey';
36
- const retrievedData = localStorageService.getLocalStorage(key);
37
- expect(retrievedData).toBeNull();
38
- });
39
-
40
- it('should remove data from local storage', () => {
41
- const key = 'testKey';
42
- const data = { city: 'New York', population: 8000000 };
43
- localStorage.setItem(key, JSON.stringify(data));
44
- localStorageService.removeLocalStorage(key);
45
- expect(localStorage.getItem(key)).toBeNull();
46
- });
47
- });
@@ -1,46 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Injectable } from '@angular/core';
3
-
4
- @Injectable({ providedIn: 'root' })
5
- export class LocalStorageService {
6
- // -----------------------------------------------------------------------------------------------------
7
- // @ Public methods
8
- // -----------------------------------------------------------------------------------------------------
9
-
10
- /**
11
- * Set data in local storage
12
- * @param key - Key to store the data
13
- * @param data - Data to be stored
14
- */
15
- setLocalStorage = (key: string, data: any): void => {
16
- // localStorage.setItem(key, JSON.stringify(data));
17
- if (typeof data === 'string') {
18
- localStorage.setItem(key, data);
19
- } else {
20
- localStorage.setItem(key, JSON.stringify(data));
21
- }
22
- };
23
-
24
- /**
25
- * Get data from local storage
26
- * @param key - Key to retrieve the data
27
- * @returns The data stored in local storage
28
- */
29
- getLocalStorage = (key: string): any => {
30
- const data = localStorage.getItem(key);
31
- return data ? data: null;
32
- // if (typeof data === 'string') {
33
- // return data ? data: null;
34
- // } else {
35
- // return data ? JSON.parse(data) : null;
36
- // }
37
- };
38
-
39
- /**
40
- * Remove data from local storage
41
- * @param key - Key of the data to be removed
42
- */
43
- removeLocalStorage = (key: string): void => {
44
- localStorage.removeItem(key);
45
- };
46
- }
@@ -1,47 +0,0 @@
1
- import { TestBed, inject } from '@angular/core/testing';
2
- import { SessionStorageService } from './session-storage.service';
3
-
4
- describe('SessionStorageService', () => {
5
- let sessionStorageService: SessionStorageService;
6
-
7
- beforeEach(() => {
8
- TestBed.configureTestingModule({
9
- providers: [SessionStorageService],
10
- });
11
- });
12
-
13
- it('should be created', () => {
14
- inject([SessionStorageService], (service: SessionStorageService) => {
15
- expect(service).toBeTruthy();
16
- });
17
- });
18
-
19
- it('should set data in session storage', () => {
20
- const key = 'testKey';
21
- const data = { name: 'John Doe', age: 30 };
22
- sessionStorageService.setSessionStorage(key, data);
23
- expect(sessionStorage.getItem(key)).toEqual(JSON.stringify(data));
24
- });
25
-
26
- it('should get data from session storage', () => {
27
- const key = 'testKey';
28
- const data = { name: 'Jane Smith', age: 25 };
29
- sessionStorage.setItem(key, JSON.stringify(data));
30
- const retrievedData = sessionStorageService.getSessionStorage(key);
31
- expect(retrievedData).toEqual(data);
32
- });
33
-
34
- it('should return null when getting non-existent data from session storage', () => {
35
- const key = 'nonExistentKey';
36
- const retrievedData = sessionStorageService.getSessionStorage(key);
37
- expect(retrievedData).toBeNull();
38
- });
39
-
40
- it('should remove data from session storage', () => {
41
- const key = 'testKey';
42
- const data = { city: 'New York', population: 8000000 };
43
- sessionStorage.setItem(key, JSON.stringify(data));
44
- sessionStorageService.removeSessionStorage(key);
45
- expect(sessionStorage.getItem(key)).toBeNull();
46
- });
47
- });
@@ -1,46 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Injectable } from '@angular/core';
3
-
4
- @Injectable({ providedIn: 'root' })
5
- export class SessionStorageService {
6
- // -----------------------------------------------------------------------------------------------------
7
- // @ Public methods
8
- // -----------------------------------------------------------------------------------------------------
9
-
10
- /**
11
- * Set data in session storage
12
- * @param key - Key to store the data
13
- * @param data - Data to be stored
14
- */
15
- setSessionStorage = (key: string, data: any): void => {
16
- // sessionStorage.setItem(key, JSON.stringify(data));
17
- if (typeof data === 'string') {
18
- sessionStorage.setItem(key, data);
19
- } else {
20
- sessionStorage.setItem(key, JSON.stringify(data));
21
- }
22
- };
23
-
24
- /**
25
- * Get data from session storage
26
- * @param key - Key to retrieve the data
27
- * @returns The data stored in session storage
28
- */
29
- getSessionStorage = (key: string): any => {
30
- const data = sessionStorage.getItem(key);
31
- return data ? data: null;
32
- // if (typeof data === 'string') {
33
- // return data ? data: null;
34
- // } else {
35
- // return data ? JSON.parse(data) : null;
36
- // }
37
- };
38
-
39
- /**
40
- * Remove data from session storage
41
- * @param key - Key of the data to be removed
42
- */
43
- removeSessionStorage = (key: string): void => {
44
- sessionStorage.removeItem(key);
45
- };
46
- }
@@ -1,32 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { HttpErrorResponse, HttpEvent, HttpHandlerFn, HttpRequest } from '@angular/common/http';
3
- import { inject } from '@angular/core';
4
- import { Observable, throwError } from 'rxjs';
5
- import { catchError } from 'rxjs/operators';
6
- import { ErrorHandlerStore } from './error-handler.store';
7
-
8
- export const errorHandlingInterceptor = (
9
- request: HttpRequest<any>,
10
- next: HttpHandlerFn,
11
- ): Observable<HttpEvent<any>> => {
12
- const errorHandlerStore = inject(ErrorHandlerStore);
13
-
14
- return next(request).pipe(
15
- catchError((error) => {
16
- if (error instanceof HttpErrorResponse) {
17
- switch (error.status) {
18
- case 401:
19
- errorHandlerStore.handleError401(error);
20
- break;
21
- case 404:
22
- errorHandlerStore.handleError404(error);
23
- break;
24
- default:
25
- throwError(() => error);
26
- break;
27
- }
28
- }
29
- return throwError(() => error);
30
- }),
31
- );
32
- };
@@ -1,16 +0,0 @@
1
- import { inject, TestBed } from '@angular/core/testing';
2
-
3
- import { ErrorHandlerStore } from './error-handler.store';
4
- import { provideMockStore } from '@ngrx/store/testing';
5
-
6
- describe('ErrorHandlerStore', () => {
7
- beforeEach(() => {
8
- TestBed.configureTestingModule({
9
- providers: [ErrorHandlerStore, provideMockStore({})],
10
- });
11
- });
12
-
13
- it('should be created', inject([ErrorHandlerStore], (service: typeof ErrorHandlerStore) => {
14
- expect(service).toBeTruthy();
15
- }));
16
- });
@@ -1,26 +0,0 @@
1
- import { signalStore, withState, withMethods, patchState } from '@ngrx/signals';
2
- import { inject } from '@angular/core';
3
- import { Router } from '@angular/router';
4
- import { ErrorHandlerState, errorHandlerInitialState } from './models/error-handler.state';
5
- import { HttpErrorResponse } from '@angular/common/http';
6
-
7
- export const ErrorHandlerStore = signalStore(
8
- { providedIn: 'root' },
9
- withState<ErrorHandlerState>(errorHandlerInitialState),
10
- withMethods((store, router = inject(Router)) => ({
11
- handleError401: (error: HttpErrorResponse) => {
12
- patchState(store, {
13
- code: error.status,
14
- message: error.message,
15
- });
16
- router.navigate(['/login']);
17
- },
18
- handleError404: (error: HttpErrorResponse) => {
19
- patchState(store, {
20
- code: error.status,
21
- message: error.message,
22
- });
23
- router.navigate(['/']);
24
- },
25
- })),
26
- );
@@ -1,9 +0,0 @@
1
- export interface ErrorHandlerState {
2
- code: number;
3
- message: string | undefined;
4
- }
5
-
6
- export const errorHandlerInitialState: ErrorHandlerState = {
7
- message: undefined,
8
- code: -1,
9
- };
@@ -1,4 +0,0 @@
1
- import { InjectionToken } from '@angular/core';
2
-
3
- export const API_URL = new InjectionToken<string>('API_URL');
4
- export const Workflow_URL = new InjectionToken<string>('Workflow_URL');
@@ -1,18 +0,0 @@
1
- import { TestBed, inject } from '@angular/core/testing';
2
- import { HttpClientTestingModule } from '@angular/common/http/testing';
3
-
4
- import { ApiService } from './api.service';
5
- import { API_URL } from './api-url.token';
6
-
7
- describe('ApiService', () => {
8
- beforeEach(() => {
9
- TestBed.configureTestingModule({
10
- imports: [HttpClientTestingModule],
11
- providers: [ApiService, { provide: API_URL, useValue: 'api_url' }],
12
- });
13
- });
14
-
15
- it('should be created', inject([ApiService], (service: ApiService) => {
16
- expect(service).toBeTruthy();
17
- }));
18
- });