asma-core-helpers 0.3.1 → 0.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asma-core-helpers",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Core helper utilities for ASMA applications",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -96,6 +96,7 @@ export type IAuthBindings<FE extends string> = {
96
96
  getJwtToken: () => string
97
97
  accessTokenHasExpired: () => boolean
98
98
  getActivityStatuses: (activity_ids: string[]) => Promise<Map<string, ActivityStatus>>
99
+ invalidateActivityStatuses: (activityIds?: string[]) => void
99
100
  }
100
101
  declare global {
101
102
  interface Window {
@@ -523,6 +523,18 @@ export function generateSrvAuthBindings<FE extends string>(logout?: () => void)
523
523
 
524
524
  const pendingRequests = new Map<string, Promise<Map<string, ActivityStatus>>>()
525
525
 
526
+ function invalidateActivityStatuses(activityIds?: string[]) {
527
+ if (!activityIds?.length) {
528
+ activityStatusesCached.clear()
529
+ pendingRequests.clear()
530
+ return
531
+ }
532
+
533
+ for (const id of activityIds) {
534
+ activityStatusesCached.delete(id)
535
+ }
536
+ }
537
+
526
538
  async function getActivityStatuses(activityIds: string[]): Promise<Map<string, ActivityStatus>> {
527
539
  const result = new Map<string, ActivityStatus>()
528
540
  const missingIds: number[] = []
@@ -638,6 +650,7 @@ export function generateSrvAuthBindings<FE extends string>(logout?: () => void)
638
650
  /**@deprecated - do not use it anymore is moved to features `TimeRegistration_TeamleaderOverview` */
639
651
  isTeamLeader,
640
652
  getActivityStatuses,
653
+ invalidateActivityStatuses,
641
654
  } satisfies IAuthBindings<FE>
642
655
 
643
656
  realWindow.__ASMA__SHELL__ = realWindow.__ASMA__SHELL__ || {}
@@ -685,14 +698,17 @@ function deepEqual(x: Record<string, string>, y: Record<string, string>) {
685
698
  function sortStringify(x: Record<string, string>) {
686
699
  Object.keys(x)
687
700
  .sort()
688
- .reduce((acc, key) => {
689
- const x_key = x?.[key]
690
- if (x_key) {
691
- acc[key] = x_key
692
- }
693
-
694
- return acc
695
- }, {} as Record<string, string>)
701
+ .reduce(
702
+ (acc, key) => {
703
+ const x_key = x?.[key]
704
+ if (x_key) {
705
+ acc[key] = x_key
706
+ }
707
+
708
+ return acc
709
+ },
710
+ {} as Record<string, string>,
711
+ )
696
712
 
697
713
  return JSON.stringify(x)
698
714
  }
@@ -722,7 +738,7 @@ function attachAdditionalHeaders(headers: Record<string, string>) {
722
738
  const genesis_user_secret = localStorage.getItem('genesis-user-secret') || undefined
723
739
 
724
740
  if (domain === 'advoca' && genesis_user_secret) {
725
- headers = { ...headers, 'genesis-user-secret': `genesis_user-secret.${genesis_user_secret}` }
741
+ headers = { ...headers, 'genesis-user-secret': `genesis-user-secret.${genesis_user_secret}` }
726
742
  }
727
743
 
728
744
  return headers