@techextensor/tab-sdk 0.0.0

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 (50) hide show
  1. package/.editorconfig +16 -0
  2. package/.vscode/extensions.json +6 -0
  3. package/.vscode/launch.json +20 -0
  4. package/.vscode/tasks.json +42 -0
  5. package/README.md +27 -0
  6. package/documents/LibraryCreationGuide.md +82 -0
  7. package/documents/Method Access/analytics.md +6 -0
  8. package/documents/Method Access/app.md +22 -0
  9. package/documents/Method Access/auth.md +14 -0
  10. package/documents/Method Access/crud.md +17 -0
  11. package/documents/Method Access/file.md +5 -0
  12. package/documents/Method Access/form.md +14 -0
  13. package/documents/Method Access/http.md +4 -0
  14. package/documents/Method Access/metadata-utils.md +62 -0
  15. package/documents/Method Access/release.md +5 -0
  16. package/documents/Method Access/report.md +6 -0
  17. package/documents/Method Access/store.md +75 -0
  18. package/documents/Method Access/transition.md +5 -0
  19. package/documents/Method Access/translator.md +16 -0
  20. package/documents/Method Access/ui-actions.md +22 -0
  21. package/nx.json +35 -0
  22. package/package.json +46 -0
  23. package/projects/tab-sdk/README.md +24 -0
  24. package/projects/tab-sdk/ng-package.json +7 -0
  25. package/projects/tab-sdk/package.json +19 -0
  26. package/projects/tab-sdk/project.json +37 -0
  27. package/projects/tab-sdk/src/lib/app/analytics.service.ts +54 -0
  28. package/projects/tab-sdk/src/lib/app/app.service.ts +188 -0
  29. package/projects/tab-sdk/src/lib/app/file.service.ts +92 -0
  30. package/projects/tab-sdk/src/lib/app/release.service.ts +38 -0
  31. package/projects/tab-sdk/src/lib/app/report.service.ts +51 -0
  32. package/projects/tab-sdk/src/lib/app/translator.service.ts +80 -0
  33. package/projects/tab-sdk/src/lib/auth/auth.service.ts +119 -0
  34. package/projects/tab-sdk/src/lib/crud/crud.service.ts +187 -0
  35. package/projects/tab-sdk/src/lib/enum/store.enum.ts +4 -0
  36. package/projects/tab-sdk/src/lib/enum/ui.enum.ts +11 -0
  37. package/projects/tab-sdk/src/lib/http/http.service.ts +63 -0
  38. package/projects/tab-sdk/src/lib/interface/http.interface.ts +8 -0
  39. package/projects/tab-sdk/src/lib/interface/ui.interface.ts +28 -0
  40. package/projects/tab-sdk/src/lib/store/store.service.ts +831 -0
  41. package/projects/tab-sdk/src/lib/tab-sdk.service.ts +84 -0
  42. package/projects/tab-sdk/src/lib/ui/form.service.ts +92 -0
  43. package/projects/tab-sdk/src/lib/ui/ui.service.ts +404 -0
  44. package/projects/tab-sdk/src/lib/util/util.service.ts +53 -0
  45. package/projects/tab-sdk/src/lib/workflow/transition.service.ts +40 -0
  46. package/projects/tab-sdk/src/public-api.ts +10 -0
  47. package/projects/tab-sdk/tsconfig.lib.json +15 -0
  48. package/projects/tab-sdk/tsconfig.lib.prod.json +11 -0
  49. package/projects/tab-sdk/tsconfig.spec.json +15 -0
  50. package/tsconfig.json +37 -0
@@ -0,0 +1,831 @@
1
+ import { inject, Injectable } from '@angular/core';
2
+ import { LocalStorageService, SessionStorageService, StorageConstants } from '@techextensor/tab-core-utility';
3
+ import { StorageType } from '../enum/store.enum';
4
+
5
+ @Injectable({
6
+ providedIn: 'root'
7
+ })
8
+ export class StoreService {
9
+ private readonly _localStorageService: LocalStorageService = inject(LocalStorageService);
10
+ private readonly _sessionStorageService: SessionStorageService = inject(SessionStorageService);
11
+
12
+ /**
13
+ * Retrieves the tenant ID from the local storage.
14
+ */
15
+ get tenantId(): string | null {
16
+ return this.getOrgInfo()?.Id || null;
17
+ }
18
+
19
+ /**
20
+ * Sets the tenant ID in the organization info.
21
+ *
22
+ * @param value - The tenant ID to set.
23
+ */
24
+ set tenantId(value: string | null) {
25
+ // Retrieve the existing organization info or initialize a new object
26
+ const orgInfo = this.getOrgInfo() || {};
27
+
28
+ // Update the tenant ID value
29
+ orgInfo.Id = value;
30
+
31
+ // Save the updated organization info back to storage
32
+ this.setOrgInfo(orgInfo);
33
+ }
34
+
35
+ /**
36
+ * Retrieves the tenant name from the organization info.
37
+ */
38
+ get tenantName(): string | null {
39
+ // Retrieve the organization info from storage
40
+ const orgInfo = this.getOrgInfo();
41
+
42
+ // Return the tenant name if it exists, otherwise return null
43
+ return orgInfo?.OrganizationName || null;
44
+ }
45
+
46
+ /**
47
+ * Sets the tenant name in the organization info.
48
+ *
49
+ * @param value - The tenant name to set.
50
+ */
51
+ set tenantName(value: string | null) {
52
+ // Retrieve the existing organization info or initialize a new object
53
+ const orgInfo = this.getOrgInfo() || {};
54
+
55
+ // Update the organization name value
56
+ orgInfo.OrganizationName = value;
57
+
58
+ // Save the updated organization info back to storage
59
+ this.setOrgInfo(orgInfo);
60
+ }
61
+
62
+ /**
63
+ * Retrieves the subdomain from the organization info.
64
+ *
65
+ * @returns The subdomain if it exists, otherwise `null`.
66
+ */
67
+ get subdomain(): string | null {
68
+ // Retrieve the organization info from storage
69
+ const orgInfo = this.getOrgInfo();
70
+
71
+ // Return the subdomain if it exists, otherwise return null
72
+ return orgInfo?.Subdomain || null;
73
+ }
74
+
75
+ /**
76
+ * Sets the subdomain in the organization info.
77
+ *
78
+ * @param value - The subdomain to set.
79
+ */
80
+ set subdomain(value: string | null) {
81
+ // Retrieve the existing organization info or initialize a new object
82
+ const orgInfo = this.getOrgInfo() || {};
83
+
84
+ // Update the subdomain value
85
+ orgInfo.Subdomain = value;
86
+
87
+ // Save the updated organization info back to storage
88
+ this.setOrgInfo(orgInfo);
89
+ }
90
+
91
+ /**
92
+ * Retrieves the locale settings from the organization info.
93
+ *
94
+ * @returns The locale settings if they exist, otherwise `null`.
95
+ */
96
+ get orgLocaleSettings(): any {
97
+ // Retrieve the locale settings from the organization info
98
+ let localSettings = this.getOrgInfo()?.LocaleSettings;
99
+
100
+ // If the locale settings are a string, parse them as JSON
101
+ if(typeof localSettings === 'string') {
102
+ localSettings = JSON.parse(localSettings);
103
+ }
104
+
105
+ // Return the locale settings
106
+ return localSettings;
107
+ }
108
+
109
+ /**
110
+ * Sets the locale settings in the organization info.
111
+ *
112
+ * @param value - The locale settings to set.
113
+ */
114
+ set orgLocaleSettings(value: any) {
115
+ // Retrieve the existing organization info or initialize a new object
116
+ const orgInfo = this.getOrgInfo() || {};
117
+
118
+ // Update the locale settings value
119
+ orgInfo.LocaleSettings = value;
120
+
121
+ // Save the updated organization info back to storage
122
+ this.setOrgInfo(orgInfo);
123
+ }
124
+
125
+ /**
126
+ * Retrieves the app ID from the app info.
127
+ *
128
+ * @returns The app ID if it exists, otherwise `null`.
129
+ */
130
+ get appId(): string | null {
131
+ return this.getAppInfo()?.Id || null;
132
+ }
133
+
134
+ /**
135
+ * Sets the app ID in the app info.
136
+ *
137
+ * @param value - The app ID to set.
138
+ */
139
+ set appId(value: string | null) {
140
+ // Retrieve the existing app info or initialize a new object
141
+ const appInfo = this.getAppInfo() || {};
142
+
143
+ // Update the app ID value
144
+ appInfo.Id = value;
145
+
146
+ // Save the updated app info back to storage
147
+ this.setAppInfo(appInfo);
148
+ }
149
+
150
+ /**
151
+ * Retrieves the app name from the app info.
152
+ *
153
+ * @returns The app name if it exists, otherwise `null`.
154
+ */
155
+ get appName(): string | null {
156
+ // Retrieve and return the app name from the app info, or return null if it doesn't exist
157
+ return this.getAppInfo()?.AppName || null;
158
+ }
159
+
160
+ /**
161
+ * Sets the app name in the app info.
162
+ *
163
+ * @param value - The app name to set.
164
+ */
165
+ set appName(value: string | null) {
166
+ // Retrieve the existing app info or initialize a new object
167
+ const appInfo = this.getAppInfo() || {};
168
+
169
+ // Update the app name value
170
+ appInfo.AppName = value;
171
+
172
+ // Save the updated app info back to storage
173
+ this.setAppInfo(appInfo);
174
+ }
175
+
176
+ /**
177
+ * Retrieves the environment ID from the environment info.
178
+ *
179
+ * @returns The environment ID if it exists, otherwise `null`.
180
+ */
181
+ get environmentId(): string | null {
182
+ // Retrieve and return the environment ID from the environment info, or return null if it doesn't exist
183
+ return this.getEnvironmentInfo()?.Id || null;
184
+ }
185
+
186
+ /**
187
+ * Sets the environment ID in the environment info.
188
+ *
189
+ * @param value - The environment ID to set.
190
+ */
191
+ set environmentId(value: string | null) {
192
+ // Retrieve the existing environment info or initialize a new object
193
+ const environmentInfo = this.getEnvironmentInfo() || {};
194
+
195
+ // Update the environment ID value
196
+ environmentInfo.Id = value;
197
+
198
+ // Save the updated environment info back to storage
199
+ this.setEnvironmentInfo(environmentInfo);
200
+ }
201
+
202
+ /**
203
+ * Retrieves the environment name from the environment info.
204
+ *
205
+ * @returns The environment name if it exists, otherwise `null`.
206
+ */
207
+ get environmentName(): string | null {
208
+ // Retrieve and return the environment name from the environment info, or return null if it doesn't exist
209
+ return this.getEnvironmentInfo()?.Name || null;
210
+ }
211
+
212
+ /**
213
+ * Sets the environment name in the environment info.
214
+ *
215
+ * @param value - The environment name to set.
216
+ */
217
+ set environmentName(value: string | null) {
218
+ // Retrieve the existing environment info or initialize a new object
219
+ const environmentInfo = this.getEnvironmentInfo() || {};
220
+
221
+ // Update the environment name value
222
+ environmentInfo.Name = value;
223
+
224
+ // Save the updated environment info back to storage
225
+ this.setEnvironmentInfo(environmentInfo);
226
+ }
227
+
228
+ /**
229
+ * Retrieves the token from the token info.
230
+ *
231
+ * @returns The token if it exists, otherwise `null`.
232
+ */
233
+ get token(): string | null {
234
+ // Retrieve and return the token from the token info, or return null if it doesn't exist
235
+ return this.getTokenInfo()?.token || null;
236
+ }
237
+
238
+ /**
239
+ * Sets the token in the token info.
240
+ *
241
+ * @param value - The token to set.
242
+ */
243
+ set token(value: string | null) {
244
+ // Retrieve the existing token info or initialize a new object
245
+ const tokenInfo = this.getTokenInfo() || {};
246
+
247
+ // Update the token value
248
+ tokenInfo.token = value;
249
+
250
+ // Save the updated token info back to storage
251
+ this.setTokenInfo(tokenInfo);
252
+ }
253
+
254
+ /**
255
+ * Retrieves the refresh token from the token info.
256
+ *
257
+ * @returns The refresh token if it exists, otherwise `null`.
258
+ */
259
+ get refreshToken(): string | null {
260
+ // Retrieve and return the refresh token from the token info, or return null if it doesn't exist
261
+ return this.getTokenInfo()?.refreshToken || null;
262
+ }
263
+
264
+ /**
265
+ * Sets the refresh token in the token info.
266
+ *
267
+ * @param value - The refresh token to set.
268
+ */
269
+ set refreshToken(value: string | null) {
270
+ // Retrieve the existing token info or initialize a new object
271
+ const tokenInfo = this.getTokenInfo() || {};
272
+
273
+ // Update the refresh token value
274
+ tokenInfo.refreshToken = value;
275
+
276
+ // Save the updated token info back to storage
277
+ this.setTokenInfo(tokenInfo);
278
+ }
279
+
280
+ /**
281
+ * Retrieves the refresh token expiry time from the token info.
282
+ *
283
+ * @returns The refresh token expiry time if it exists, otherwise `null`.
284
+ */
285
+ get refreshTokenExpiry(): string | null {
286
+ // Retrieve and return the refresh token expiry time from the token info,
287
+ // or return null if it doesn't exist
288
+ return this.getTokenInfo()?.refreshTokenExpiry || null;
289
+ }
290
+
291
+ /**
292
+ * Sets the refresh token expiry time in the token info.
293
+ *
294
+ * @param value - The refresh token expiry time to set.
295
+ */
296
+ set refreshTokenExpiry(value: string | null) {
297
+ // Retrieve the existing token info or initialize a new object
298
+ const tokenInfo = this.getTokenInfo() || {};
299
+
300
+ // Update the refresh token expiry time
301
+ tokenInfo.refreshTokenExpiry = value;
302
+
303
+ // Save the updated token info back to storage
304
+ this.setTokenInfo(tokenInfo);
305
+ }
306
+
307
+ /**
308
+ * Retrieves the static token from the token info.
309
+ *
310
+ * @returns The static token if it exists, otherwise `null`.
311
+ */
312
+ get staticToken(): string | null {
313
+ // Retrieve and return the static token from the token info,
314
+ // or return null if it doesn't exist
315
+ return this.getTokenInfo()?.staticToken || null;
316
+ }
317
+
318
+ /**
319
+ * Sets the static token in the token info.
320
+ *
321
+ * @param value - The static token to set.
322
+ */
323
+ set staticToken(value: string | null) {
324
+ // Retrieve the existing token info or initialize a new object
325
+ const tokenInfo = this.getTokenInfo() || {};
326
+
327
+ // Update the static token value
328
+ tokenInfo.staticToken = value;
329
+
330
+ // Save the updated token info back to storage
331
+ this.setTokenInfo(tokenInfo);
332
+ }
333
+
334
+ /**
335
+ * Retrieves the user ID from the user info.
336
+ *
337
+ * @returns The user ID if it exists, otherwise `null`.
338
+ */
339
+ get userId(): string | null {
340
+ // Retrieve and return the user ID from the user info, or return null if it doesn't exist
341
+ return this.getUserInfo()?.user?.Id || null;
342
+ }
343
+
344
+ /**
345
+ * Retrieves the user's roles from the user information.
346
+ *
347
+ * @returns An array of user roles if they exist, otherwise `null`.
348
+ */
349
+ get userRoles(): any[] | null {
350
+ // Retrieve and return the user roles from the user info, or return null if they don't exist
351
+ return this.getUserInfo()?.user?.Roles || null;
352
+ }
353
+
354
+ /**
355
+ * Retrieves the user's teams from the user information.
356
+ *
357
+ * @returns An array of user teams if they exist, otherwise `null`.
358
+ */
359
+ get userTeams(): any[] | null {
360
+ // Retrieve and return the user teams from the user info, or return null if they don't exist
361
+ return this.getUserInfo()?.user?.Teams || null;
362
+ }
363
+
364
+ /**
365
+ * Removes the tenant ID from the organization information.
366
+ */
367
+ removeTenantId(): void {
368
+ this.removeFromOrgInfo('Id');
369
+ }
370
+
371
+ /**
372
+ * Removes the tenant name from the organization information.
373
+ */
374
+ removeTenantName(): void {
375
+ // Remove the tenant name from the organization information
376
+ this.removeFromOrgInfo('OrganizationName');
377
+ }
378
+
379
+ /**
380
+ * Removes the subdomain from the organization information.
381
+ *
382
+ * This removes the subdomain property from the organization information
383
+ * stored in local storage.
384
+ */
385
+ removeSubdomain(): void {
386
+ // Remove the subdomain from the organization information
387
+ this.removeFromOrgInfo('Subdomain');
388
+ }
389
+
390
+ /**
391
+ * Removes the app ID from the app information.
392
+ *
393
+ * This removes the app ID property from the app information stored in local storage.
394
+ */
395
+ removeAppId(): void {
396
+ this.removeFromAppInfo('Id');
397
+ }
398
+
399
+ /**
400
+ * Removes the app name from the app information.
401
+ *
402
+ * This removes the app name property from the app information stored in local storage.
403
+ */
404
+ removeAppName(): void {
405
+ this.removeFromAppInfo('AppName');
406
+ }
407
+
408
+ /**
409
+ * Removes the environment ID from the environment information.
410
+ *
411
+ * This removes the ID property from the environment information
412
+ * stored in local storage.
413
+ */
414
+ removeEnvironmentId(): void {
415
+ // Remove the environment ID from the environment information
416
+ this.removeFromEnvironmentInfo('Id');
417
+ }
418
+
419
+ /**
420
+ * Removes the environment name from the environment information.
421
+ *
422
+ * This removes the Name property from the environment information
423
+ * stored in local storage.
424
+ */
425
+ removeEnvironmentName(): void {
426
+ // Remove the environment name from the environment information
427
+ this.removeFromEnvironmentInfo('Name');
428
+ }
429
+
430
+ /**
431
+ * Removes the token from the token info.
432
+ *
433
+ * This removes the token property from the token information stored in session
434
+ * storage.
435
+ */
436
+ removeToken(): void {
437
+ // Remove the token from the token info
438
+ this.removeFromTokenInfo('token');
439
+ }
440
+
441
+ /**
442
+ * Removes the refresh token from the token information.
443
+ *
444
+ * This removes the refresh token property from the token information stored in session
445
+ * storage.
446
+ */
447
+ removeRefreshToken(): void {
448
+ this.removeFromTokenInfo('refreshToken');
449
+ }
450
+
451
+ /**
452
+ * Removes the refresh token expiry time from the token information.
453
+ *
454
+ * This removes the refresh token expiry time property from the token information stored in session
455
+ * storage.
456
+ */
457
+ removeRefreshTokenExpiry(): void {
458
+ // Remove the refresh token expiry from the token info
459
+ this.removeFromTokenInfo('refreshTokenExpiry');
460
+ }
461
+
462
+ /**
463
+ * Removes the static token from the token information.
464
+ *
465
+ * This removes the static token property from the token information stored in session
466
+ * storage.
467
+ */
468
+ removeStaticToken(): void {
469
+ // Remove the static token from the token info
470
+ this.removeFromTokenInfo('staticToken');
471
+ }
472
+
473
+ /**
474
+ * Removes the specified key from the organization information.
475
+ *
476
+ * This removes the specified key from the organization information stored in local storage.
477
+ *
478
+ * @param key The key to remove from the organization information.
479
+ */
480
+ private removeFromOrgInfo(key: string): void {
481
+ const orgInfo = this.getOrgInfo();
482
+ if (orgInfo) {
483
+ // Remove the key from the organization information
484
+ delete orgInfo[key];
485
+ // Save the updated organization information back to local storage
486
+ this.setOrgInfo(orgInfo);
487
+ }
488
+ }
489
+
490
+ /**
491
+ * Removes the specified key from the app information.
492
+ *
493
+ * This removes the specified key from the app information stored in session
494
+ * storage.
495
+ *
496
+ * @param key The key to remove from the app information.
497
+ */
498
+ private removeFromAppInfo(key: string): void {
499
+ const appInfo = this.getAppInfo();
500
+ if (appInfo) {
501
+ // Remove the key from the app information
502
+ delete appInfo[key];
503
+ // Save the updated app information back to session storage
504
+ this.setAppInfo(appInfo);
505
+ }
506
+ }
507
+
508
+ /**
509
+ * Removes the specified key from the environment information.
510
+ *
511
+ * This removes the specified key from the environment information stored in session
512
+ * storage.
513
+ *
514
+ * @param key The key to remove from the environment information.
515
+ */
516
+ private removeFromEnvironmentInfo(key: string): void {
517
+ const environmentInfo = this.getEnvironmentInfo();
518
+ if (environmentInfo) {
519
+ // Remove the key from the environment information
520
+ delete environmentInfo[key];
521
+ // Save the updated environment information back to session storage
522
+ this.setEnvironmentInfo(environmentInfo);
523
+ }
524
+ }
525
+
526
+ /**
527
+ * Removes the specified key from the token information.
528
+ *
529
+ * This removes the specified key from the token information stored in session
530
+ * storage.
531
+ *
532
+ * @param key The key to remove from the token information.
533
+ */
534
+ private removeFromTokenInfo(key: string): void {
535
+ const tokenInfo = this.getTokenInfo();
536
+ if (tokenInfo) {
537
+ // Remove the key from the token information
538
+ delete tokenInfo[key];
539
+ // Save the updated token information back to session storage
540
+ this.setTokenInfo(tokenInfo);
541
+ }
542
+ }
543
+
544
+ /**
545
+ * Retrieves the organization information from local storage.
546
+ *
547
+ * @returns The organization information object or null if it doesn't exist.
548
+ */
549
+ getOrgInfo(): any {
550
+ return this.getFromStorage(StorageType.Local, StorageConstants.orgInfo);
551
+ }
552
+
553
+ /**
554
+ * Saves the organization information to local storage.
555
+ *
556
+ * @param orgInfo - The organization information to store.
557
+ */
558
+ setOrgInfo(orgInfo: any): void {
559
+ // temp once remove from dropdown, we can remove this
560
+ if (orgInfo.Id) {
561
+ this.setSession(StorageConstants.TenantId, orgInfo.Id);
562
+ } else {
563
+ this.removeSession(StorageConstants.TenantId);
564
+ }
565
+
566
+ // Save the organization info to local storage
567
+ this.setToStorage(StorageType.Local, StorageConstants.orgInfo, orgInfo);
568
+ }
569
+
570
+ /**
571
+ * Retrieves the app information from session storage.
572
+ *
573
+ * @returns The app information object or null if it doesn't exist.
574
+ */
575
+ getAppInfo(): any {
576
+ return this.getFromStorage(StorageType.Session, StorageConstants.appInfo);
577
+ }
578
+
579
+ /**
580
+ * Saves the app information to session storage.
581
+ *
582
+ * @param appInfo - The app information to store.
583
+ */
584
+ setAppInfo(appInfo: any): void {
585
+ // temp once remove from dropdown, we can remove this
586
+ if (appInfo?.Id) {
587
+ this.setSession(StorageConstants.AppId, appInfo.Id);
588
+ } else {
589
+ this.removeSession(StorageConstants.AppId);
590
+ }
591
+
592
+ if (appInfo?.AppName) {
593
+ this.setSession(StorageConstants.applicationCode, appInfo.AppName);
594
+ } else {
595
+ this.removeSession(StorageConstants.applicationCode);
596
+ }
597
+
598
+ // Save the app info to session storage
599
+ this.setToStorage(StorageType.Session, StorageConstants.appInfo, appInfo);
600
+ }
601
+
602
+ /**
603
+ * Retrieves the environment information from session storage.
604
+ *
605
+ * @returns The environment information object or null if it doesn't exist.
606
+ */
607
+ getEnvironmentInfo(): any {
608
+ return this.getFromStorage(StorageType.Session, StorageConstants.environmentInfo);
609
+ }
610
+
611
+ /**
612
+ * Saves the environment information to session storage.
613
+ *
614
+ * @param envInfo - The environment information to store.
615
+ */
616
+ setEnvironmentInfo(envInfo: any): void {
617
+ // Save the environment info to session storage
618
+ this.setToStorage(StorageType.Session, StorageConstants.environmentInfo, envInfo);
619
+ }
620
+
621
+ /**
622
+ * Retrieves the token information from session storage.
623
+ *
624
+ * @returns The token information object or null if it doesn't exist.
625
+ */
626
+ getTokenInfo(): any {
627
+ return this.getFromStorage(StorageType.Session, StorageConstants.tokenInfo);
628
+ }
629
+
630
+ /**
631
+ * Saves the token information to session storage.
632
+ *
633
+ * @param tokenInfo - The token information to store.
634
+ */
635
+ setTokenInfo(tokenInfo: any): void {
636
+ // temp once remove from dropdown, we can remove this
637
+ if (tokenInfo?.token) {
638
+ this.setSession(StorageConstants.token, tokenInfo?.token);
639
+ } else {
640
+ this.removeSession(StorageConstants.token);
641
+ }
642
+
643
+ // Save the token info to session storage
644
+ this.setToStorage(StorageType.Session, StorageConstants.tokenInfo, tokenInfo);
645
+ }
646
+
647
+ /**
648
+ * Retrieves the user information from local storage.
649
+ *
650
+ * @returns The user information object or null if it doesn't exist.
651
+ */
652
+ getUserInfo(): any {
653
+ return this.getFromStorage(StorageType.Local, StorageConstants.userInfo);
654
+ }
655
+
656
+ /**
657
+ * Sets the user information in local storage.
658
+ *
659
+ * @param userInfo The user information to store.
660
+ */
661
+ setUserInfo(userInfo: any): void {
662
+ // Save the user info to local storage
663
+ this.setToStorage(StorageType.Local, StorageConstants.userInfo, userInfo);
664
+ }
665
+
666
+ /**
667
+ * Sets a key-value pair in local storage.
668
+ *
669
+ * @param key The key to store the value under.
670
+ * @param data The value to store.
671
+ */
672
+ setLocal(key: string, data: any): void {
673
+ this.setToStorage(StorageType.Local, key, data);
674
+ }
675
+
676
+ /**
677
+ * Retrieves a value from local storage by key.
678
+ *
679
+ * @param key The key associated with the value to retrieve.
680
+ * @returns The value stored in local storage, or null if it doesn't exist.
681
+ */
682
+ getLocal(key: string): any {
683
+ return this.getFromStorage(StorageType.Local, key);
684
+ }
685
+
686
+ /**
687
+ * Removes a key-value pair from local storage.
688
+ *
689
+ * @param key The key associated with the value to remove.
690
+ */
691
+ removeLocal(key: string): void {
692
+ // Remove the key from local storage
693
+ this.removeFromStorage(StorageType.Local, key);
694
+ }
695
+
696
+ /**
697
+ * Clears all local storage data.
698
+ */
699
+ clearLocal(): void {
700
+ this.clearStorage(StorageType.Local);
701
+ }
702
+
703
+ /**
704
+ * Sets a key-value pair in session storage.
705
+ *
706
+ * @param key The key to store the value under.
707
+ * @param data The value to store.
708
+ */
709
+ setSession(key: string, data: any): void {
710
+ // Save data to session storage under the specified key
711
+ this.setToStorage(StorageType.Session, key, data);
712
+ }
713
+
714
+ /**
715
+ * Retrieves a value from session storage by key.
716
+ *
717
+ * @param key The key associated with the value to retrieve.
718
+ * @returns The value stored in session storage, or null if it doesn't exist.
719
+ */
720
+ getSession(key: string): any {
721
+ // Retrieve the value from session storage
722
+ return this.getFromStorage(StorageType.Session, key);
723
+ }
724
+
725
+ /**
726
+ * Removes a key-value pair from session storage.
727
+ *
728
+ * @param key The key associated with the value to remove.
729
+ */
730
+ removeSession(key: string): void {
731
+ // Remove the key from session storage
732
+ this.removeFromStorage(StorageType.Session, key);
733
+ }
734
+
735
+ /**
736
+ * Clears all session storage data.
737
+ */
738
+ clearSession(): void {
739
+ // Remove all key-value pairs from session storage
740
+ this.clearStorage(StorageType.Session);
741
+ }
742
+
743
+ /**
744
+ * Clears all authentication-related data from local and session storage.
745
+ *
746
+ * This method is typically used after a user logs out.
747
+ */
748
+ clearAuth(): void {
749
+ // Remove user info from local storage
750
+ this.removeFromStorage(StorageType.Local, StorageConstants.userInfo);
751
+ // Remove token info from session storage
752
+ this.removeFromStorage(StorageType.Session, StorageConstants.tokenInfo);
753
+ }
754
+
755
+ /**
756
+ * Generic getter method for retrieving data from either local or session storage.
757
+ *
758
+ * @param storage The type of storage to retrieve from.
759
+ * @param key The key associated with the data to retrieve.
760
+ * @returns The retrieved data, deserialized from JSON if it was stored as a string.
761
+ */
762
+ private getFromStorage(storage: StorageType, key: string): any {
763
+ // Retrieve the data from the specified storage
764
+ const data = storage === StorageType.Local
765
+ ? this._localStorageService.getLocalStorage(key)
766
+ : this._sessionStorageService.getSessionStorage(key);
767
+
768
+ try {
769
+ // Attempt to parse the data as JSON
770
+ return typeof data === 'string' ? JSON.parse(data) : data;
771
+ } catch (e) {
772
+ // If the data cannot be parsed, return it as is
773
+ return data;
774
+ }
775
+ }
776
+
777
+ /**
778
+ * Sets a key-value pair in the specified storage type.
779
+ *
780
+ * @param storage The type of storage to use (local or session).
781
+ * @param key The key under which the data should be stored.
782
+ * @param data The data to store.
783
+ */
784
+ private setToStorage(storage: StorageType, key: string, data: any): void {
785
+ // Check if the storage type is local
786
+ if (storage === StorageType.Local) {
787
+ // Set the data in local storage
788
+ this._localStorageService.setLocalStorage(key, data);
789
+ } else {
790
+ // Otherwise, set the data in session storage
791
+ this._sessionStorageService.setSessionStorage(key, data);
792
+ }
793
+ }
794
+
795
+ /**
796
+ * Removes a key-value pair from the specified storage type.
797
+ *
798
+ * This method removes the given key from either local or session storage
799
+ * based on the specified storage type.
800
+ *
801
+ * @param storage The type of storage to remove from (local or session).
802
+ * @param key The key associated with the value to remove.
803
+ */
804
+ private removeFromStorage(storage: StorageType, key: string): void {
805
+ if (storage === StorageType.Local) {
806
+ // Remove the key from local storage
807
+ this._localStorageService.removeLocalStorage(key);
808
+ } else {
809
+ // Remove the key from session storage
810
+ this._sessionStorageService.removeSessionStorage(key);
811
+ }
812
+ }
813
+
814
+ /**
815
+ * Clears all key-value pairs from the specified storage type.
816
+ *
817
+ * This method clears all key-value pairs from either local or session storage
818
+ * based on the specified storage type.
819
+ *
820
+ * @param storage The type of storage to clear (local or session).
821
+ */
822
+ private clearStorage(storage: StorageType): void {
823
+ if (storage === StorageType.Local) {
824
+ // Clear local storage
825
+ this._localStorageService.clearLocalStorage();
826
+ } else {
827
+ // Clear session storage
828
+ this._sessionStorageService.clearSessionStorage();
829
+ }
830
+ }
831
+ }