@mapnests/gateway-web-sdk 1.0.4 → 1.0.6

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,6 +1,6 @@
1
1
  export interface BootstrapResponse {
2
2
  refresh_time?: number;
3
- expire?: number;
3
+ expire_time?: number;
4
4
  token?: string;
5
5
  [key: string]: any;
6
6
  }
@@ -24,69 +24,85 @@ export interface SessionState {
24
24
  tokenExpiry: number | null;
25
25
  error: string | null;
26
26
  errorCode: string | null;
27
+ initializationFailed: boolean;
27
28
  timeUntilRefresh: number | null;
28
29
  }
29
30
 
30
31
  export type SessionListener = (state: SessionState) => void;
31
32
 
32
33
  export default class SessionManager {
34
+ readonly config: SessionConfig & { credentials: boolean; logLevel: string };
35
+
33
36
  /**
34
37
  * Get the singleton instance of SessionManager
35
38
  * @returns SessionManager instance
36
39
  */
37
40
  static getInstance(): SessionManager;
38
-
41
+
39
42
  /**
40
43
  * Configure the session manager
41
44
  * @param config - Configuration options
42
45
  */
43
46
  configure(config: SessionConfig): void;
44
-
47
+
45
48
  /**
46
49
  * Initialize session by calling bootstrap API
47
50
  * @returns Promise resolving to bootstrap response
48
51
  */
49
52
  initialize(): Promise<BootstrapResponse>;
50
-
53
+
51
54
  /**
52
55
  * Manually refresh the session token
53
56
  * @returns Promise resolving to bootstrap response
54
57
  */
55
58
  refreshToken(): Promise<BootstrapResponse>;
56
-
59
+
57
60
  /**
58
61
  * Get current session status
59
62
  * @returns Current session state
60
63
  */
61
64
  getSessionStatus(): SessionState;
62
-
65
+
63
66
  /**
64
67
  * Subscribe to session state changes
65
68
  * @param listener - Callback function called on state changes
66
69
  * @returns Unsubscribe function
67
70
  */
68
71
  subscribe(listener: SessionListener): () => void;
69
-
72
+
70
73
  /**
71
74
  * Check if token refresh is currently in progress
72
75
  * @returns True if refresh is in progress
73
76
  */
74
77
  isRefreshing(): boolean;
75
-
78
+
76
79
  /**
77
80
  * Wait for ongoing refresh to complete
78
81
  * @returns Promise resolving to bootstrap response or void
79
82
  */
80
83
  waitForRefresh(): Promise<BootstrapResponse | void>;
81
-
84
+
82
85
  /**
83
86
  * Clean up and reset the session manager
84
87
  */
85
88
  destroy(): void;
86
-
89
+
87
90
  /**
88
91
  * Get current cf-session-id
89
92
  * @returns Current session ID or null
90
93
  */
91
94
  getSessionId(): string | null;
95
+
96
+ /**
97
+ * Get token from cookie
98
+ * @param name - Cookie name (default: configured tokenCookieName)
99
+ * @returns Token value or null
100
+ */
101
+ getToken(name?: string): string | null;
102
+
103
+ /**
104
+ * Check if token should be added to headers (HTTP or cross-origin)
105
+ * @returns True if token should be added to headers
106
+ */
107
+ shouldUseTokenHeader(): boolean;
92
108
  }
@@ -1,10 +1,17 @@
1
- import { SessionState } from '../SessionManager';
1
+ import { BootstrapResponse } from '../SessionManager';
2
2
 
3
3
  export interface UseSessionOptions {
4
4
  autoInitialize?: boolean;
5
5
  }
6
6
 
7
- export interface UseSessionReturn extends SessionState {
7
+ export interface UseSessionReturn {
8
+ isInitialized: boolean;
9
+ isLoading: boolean;
10
+ error: string | null;
11
+ lastRefreshTime: number | null;
12
+ nextRefreshTime: number | null;
13
+ timeUntilRefresh: number | null;
14
+ initializationFailed: boolean;
8
15
  refresh: () => Promise<void>;
9
16
  initialize: () => Promise<void>;
10
17
  }
package/src/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { default as SessionManager } from './SessionManager';
2
- export type { SessionConfig, SessionState, SessionListener } from './SessionManager';
2
+ export type { SessionConfig, SessionState, SessionListener, BootstrapResponse } from './SessionManager';
3
3
  export { useSession } from './hooks/useSession';
4
4
  export type { UseSessionOptions, UseSessionReturn } from './hooks/useSession';
5
- export { fetchInterceptor, setupAxiosInterceptor } from './interceptors';
5
+ export { fetchInterceptor, setupAxiosInterceptor, CLIENT_PLATFORM } from './interceptors';
6
6
  export { SessionError, ConfigurationError, BootstrapError, NetworkError, SSRError } from './errors';
7
7
  export { logger, LOG_LEVELS } from './logger';
8
8
  export type { LogLevel } from './logger';
@@ -1,3 +1,5 @@
1
+ export const CLIENT_PLATFORM: string;
2
+
1
3
  export function fetchInterceptor(url: string, options?: RequestInit): Promise<Response>;
2
4
 
3
5
  export function setupAxiosInterceptor<T = unknown>(axiosInstance: T): T;