@stack-spot/portal-network 0.209.0 → 0.210.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
1
  import { AuthenticationError, SessionExpiredError } from '@stack-spot/auth'
2
- import { requestPermission } from '@stack-spot/opa'
2
+ import { requestPermission, setup as setupPermissions } from '@stack-spot/opa'
3
3
  import { events } from 'fetch-event-stream'
4
- import { getBaseUrlByTenantWithOverride } from '../api-addresses'
4
+ import { getApisBaseUrlConfig, getBaseUrlByTenantWithOverride, getPermissionsAPIMap } from '../api-addresses'
5
5
  import { StackspotAPIError } from '../error/StackspotAPIError'
6
+ import { queryClient } from './react-query-client'
6
7
  import { Env, FetchEventStream, HTTPMethod, SessionManager, Tenant } from './types'
7
8
 
8
9
  /**
@@ -41,6 +42,14 @@ export abstract class NetworkClient {
41
42
  NetworkClient.sessionManager = sessionManager
42
43
  NetworkClient.env = env
43
44
  NetworkClient.tenant = tenant
45
+ const url = getApisBaseUrlConfig(env, tenant).permissionValidation
46
+ const apiMap = getPermissionsAPIMap(env, tenant)
47
+ sessionManager.onChange?.((session) => {
48
+ if (session) {
49
+ queryClient.invalidateQueries()
50
+ setupPermissions({ url, session, apiMap })
51
+ }
52
+ })
44
53
  }
45
54
 
46
55
  /**
@@ -65,7 +74,7 @@ export abstract class NetworkClient {
65
74
  * @returns the final baseURL for the current environment, considering overrides if available.
66
75
  */
67
76
  protected getBaseURL(): string {
68
- return getBaseUrlByTenantWithOverride(this.baseURL, NetworkClient.env, NetworkClient.tenant);
77
+ return getBaseUrlByTenantWithOverride(this.baseURL, NetworkClient.env, NetworkClient.tenant)
69
78
  }
70
79
 
71
80
  /**
@@ -8,6 +8,7 @@ export interface SessionManager {
8
8
  hasSession(): boolean,
9
9
  endSession(): void,
10
10
  getSession(): Session,
11
+ onChange?: (listener: (session: Session | undefined) => void) => (() => void),
11
12
  }
12
13
 
13
14
  export type Tenant = 'stackspot' | 'itau'