@teamhanko/hanko-frontend-sdk 1.4.0 → 1.5.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.
- package/README.md +8 -11
- package/dist/Hanko.d.ts +8 -3
- package/dist/lib/Dto.d.ts +38 -0
- package/dist/lib/client/HttpClient.d.ts +1 -2
- package/dist/lib/client/SessionClient.d.ts +12 -1
- package/dist/lib/events/CustomEvents.d.ts +4 -3
- package/dist/lib/events/Dispatcher.d.ts +0 -15
- package/dist/lib/events/Relay.d.ts +44 -39
- package/dist/lib/events/Scheduler.d.ts +51 -24
- package/dist/lib/events/SessionChannel.d.ts +61 -0
- package/dist/lib/events/SessionState.d.ts +38 -0
- package/dist/lib/events/WindowActivityManager.d.ts +36 -0
- package/dist/lib/flow-api/types/action.d.ts +1 -0
- package/dist/lib/flow-api/types/payload.d.ts +2 -0
- package/dist/lib/state/State.d.ts +0 -3
- package/dist/sdk.cjs +1 -1
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.modern.js +1 -1
- package/dist/sdk.modern.js.map +1 -1
- package/dist/sdk.module.js +1 -1
- package/dist/sdk.module.js.map +1 -1
- package/dist/sdk.umd.js +1 -1
- package/dist/sdk.umd.js.map +1 -1
- package/package.json +1 -1
- package/dist/lib/Session.d.ts +0 -61
- package/dist/lib/state/session/SessionState.d.ts +0 -76
package/README.md
CHANGED
|
@@ -43,9 +43,12 @@ You can pass certain options, when creating a new `Hanko` instance:
|
|
|
43
43
|
|
|
44
44
|
```js
|
|
45
45
|
const defaultOptions = {
|
|
46
|
-
timeout: 13000,
|
|
47
|
-
cookieName: "hanko",
|
|
48
|
-
localStorageKey: "hanko"
|
|
46
|
+
timeout: 13000, // The timeout (in ms) for the HTTP requests.
|
|
47
|
+
cookieName: "hanko", // The cookie name under which the session token is set.
|
|
48
|
+
localStorageKey: "hanko", // The prefix / name of the localStorage keys.
|
|
49
|
+
sessionCheckInterval: 30000, // Interval (in ms) for session validity checks. Must be greater than 3000 (3s).
|
|
50
|
+
sessionCheckChannelName: "hanko-session-check" // The broadcast channel name for inter-tab communication
|
|
51
|
+
|
|
49
52
|
};
|
|
50
53
|
const hanko = new Hanko("http://localhost:3000", defaultOptions);
|
|
51
54
|
```
|
|
@@ -164,18 +167,12 @@ The following events are available:
|
|
|
164
167
|
|
|
165
168
|
- "hanko-session-created": Will be triggered after a session has been created and the user has completed possible
|
|
166
169
|
additional steps (e.g. passkey registration or password recovery). It will also be triggered when the user logs in via
|
|
167
|
-
another browser window. The event can be used to obtain the JWT.
|
|
168
|
-
JWT is only available, when the Hanko API configuration allows to obtain the JWT. When using Hanko-Cloud
|
|
169
|
-
the JWT is always present, for self-hosted Hanko-APIs you can restrict the cookie to be readable by the backend only, as long as
|
|
170
|
-
your backend runs under the same domain as your frontend. To do so, make sure the config parameter "session.enable_auth_token_header"
|
|
171
|
-
is turned off via the [Hanko-API configuration](https://github.com/teamhanko/hanko/wiki). If you want the JWT to be contained in the event details, you need to turn on
|
|
172
|
-
"session.enable_auth_token_header" when using a cross-domain setup. When it's a same-domain setup you need to turn off
|
|
173
|
-
"session.cookie.http_only" to make the JWT accessible to the frontend.
|
|
170
|
+
another browser window. The event can be used to obtain the JWT claims.
|
|
174
171
|
|
|
175
172
|
```js
|
|
176
173
|
hanko.onSessionCreated((sessionDetail) => {
|
|
177
174
|
// A new JWT has been issued.
|
|
178
|
-
|
|
175
|
+
console.info("Session created", sessionDetail.claims);
|
|
179
176
|
})
|
|
180
177
|
```
|
|
181
178
|
|
package/dist/Hanko.d.ts
CHANGED
|
@@ -5,10 +5,9 @@ import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
|
|
|
5
5
|
import { TokenClient } from "./lib/client/TokenClient";
|
|
6
6
|
import { Listener } from "./lib/events/Listener";
|
|
7
7
|
import { Relay } from "./lib/events/Relay";
|
|
8
|
-
import { Session } from "./lib/Session";
|
|
9
8
|
import { CookieSameSite } from "./lib/Cookie";
|
|
10
9
|
import { Flow } from "./lib/flow-api/Flow";
|
|
11
|
-
import { SessionClient } from "./lib/client/SessionClient";
|
|
10
|
+
import { SessionClient, Session } from "./lib/client/SessionClient";
|
|
12
11
|
/**
|
|
13
12
|
* The options for the Hanko class
|
|
14
13
|
*
|
|
@@ -24,6 +23,8 @@ import { SessionClient } from "./lib/client/SessionClient";
|
|
|
24
23
|
* if email delivery by Hanko is enabled. If email delivery by Hanko is disabled and the
|
|
25
24
|
* relying party configures a webhook for the "email.send" event, then the set language is
|
|
26
25
|
* reflected in the payload of the token contained in the webhook request.
|
|
26
|
+
* @property {number=} sessionCheckInterval - Interval for session validity checks in milliseconds. Must be greater than 3000 (3s), defaults to 3000 otherwise.
|
|
27
|
+
* @property {string=} sessionCheckChannelName - The broadcast channel name for inter-tab communication.
|
|
27
28
|
*/
|
|
28
29
|
export interface HankoOptions {
|
|
29
30
|
timeout?: number;
|
|
@@ -32,6 +33,8 @@ export interface HankoOptions {
|
|
|
32
33
|
cookieSameSite?: CookieSameSite;
|
|
33
34
|
localStorageKey?: string;
|
|
34
35
|
lang?: string;
|
|
36
|
+
sessionCheckInterval?: number;
|
|
37
|
+
sessionCheckChannelName?: string;
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
40
|
* A class that bundles all available SDK functions.
|
|
@@ -48,8 +51,8 @@ declare class Hanko extends Listener {
|
|
|
48
51
|
enterprise: EnterpriseClient;
|
|
49
52
|
token: TokenClient;
|
|
50
53
|
sessionClient: SessionClient;
|
|
51
|
-
relay: Relay;
|
|
52
54
|
session: Session;
|
|
55
|
+
relay: Relay;
|
|
53
56
|
flow: Flow;
|
|
54
57
|
constructor(api: string, options?: HankoOptions);
|
|
55
58
|
/**
|
|
@@ -69,5 +72,7 @@ export interface InternalOptions {
|
|
|
69
72
|
cookieSameSite?: CookieSameSite;
|
|
70
73
|
localStorageKey: string;
|
|
71
74
|
lang?: string;
|
|
75
|
+
sessionCheckInterval?: number;
|
|
76
|
+
sessionCheckChannelName?: string;
|
|
72
77
|
}
|
|
73
78
|
export { Hanko };
|
package/dist/lib/Dto.d.ts
CHANGED
|
@@ -227,7 +227,45 @@ export interface Identity {
|
|
|
227
227
|
id: string;
|
|
228
228
|
provider: string;
|
|
229
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Represents the claims associated with a session or token.
|
|
232
|
+
*
|
|
233
|
+
* @interface
|
|
234
|
+
* @category SDK
|
|
235
|
+
* @subcategory DTO
|
|
236
|
+
* @property {string} subject - The subject or identifier of the claims.
|
|
237
|
+
* @property {string} [issued_at] - The timestamp when the claims were issued (optional).
|
|
238
|
+
* @property {string} expiration - The timestamp when the claims expire.
|
|
239
|
+
* @property {string[]} [audience] - The intended audience(s) for the claims (optional).
|
|
240
|
+
* @property {string} [issuer] - The entity that issued the claims (optional).
|
|
241
|
+
* @property {Pick<Email, "address" | "is_primary" | "is_verified">} [email] - Email information associated with the subject (optional).
|
|
242
|
+
* @property {string} [username] - The subject's username (optional).
|
|
243
|
+
* @property {string} session_id - The session identifier linked to the claims.
|
|
244
|
+
*/
|
|
245
|
+
export interface Claims {
|
|
246
|
+
subject: string;
|
|
247
|
+
issued_at?: string;
|
|
248
|
+
expiration: string;
|
|
249
|
+
audience?: string[];
|
|
250
|
+
issuer?: string;
|
|
251
|
+
email?: Pick<Email, "address" | "is_primary" | "is_verified">;
|
|
252
|
+
username?: string;
|
|
253
|
+
session_id: string;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Represents the response from a session validation or retrieval operation.
|
|
257
|
+
*
|
|
258
|
+
* @interface
|
|
259
|
+
* @category SDK
|
|
260
|
+
* @subcategory DTO
|
|
261
|
+
* @property {boolean} is_valid - Indicates whether the session is valid.
|
|
262
|
+
* @property {Claims} [claims] - The claims associated with the session (optional).
|
|
263
|
+
* @property {string} [expiration_time] - The expiration timestamp of the session (optional).
|
|
264
|
+
* @property {string} [user_id] - The user ID linked to the session (optional).
|
|
265
|
+
*/
|
|
230
266
|
export interface SessionCheckResponse {
|
|
231
267
|
is_valid: boolean;
|
|
268
|
+
claims?: Claims;
|
|
232
269
|
expiration_time?: string;
|
|
270
|
+
user_id?: string;
|
|
233
271
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SessionState } from "../state/session/SessionState";
|
|
2
1
|
import { Dispatcher } from "../events/Dispatcher";
|
|
3
2
|
import { Cookie } from "../Cookie";
|
|
4
3
|
/**
|
|
@@ -88,12 +87,12 @@ export interface HttpClientOptions {
|
|
|
88
87
|
declare class HttpClient {
|
|
89
88
|
timeout: number;
|
|
90
89
|
api: string;
|
|
91
|
-
sessionState: SessionState;
|
|
92
90
|
dispatcher: Dispatcher;
|
|
93
91
|
cookie: Cookie;
|
|
94
92
|
lang: string;
|
|
95
93
|
constructor(api: string, options: HttpClientOptions);
|
|
96
94
|
_fetch(path: string, options: RequestInit, xhr?: XMLHttpRequest): Promise<Response>;
|
|
95
|
+
_fetch_blocking(path: string, options: RequestInit, xhr?: XMLHttpRequest): string;
|
|
97
96
|
/**
|
|
98
97
|
* Processes the response headers on login and extracts the JWT and expiration time.
|
|
99
98
|
*
|
|
@@ -16,5 +16,16 @@ export declare class SessionClient extends Client {
|
|
|
16
16
|
* @return {Promise<SessionCheckResponse>}
|
|
17
17
|
* @throws {TechnicalError}
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
validate(): Promise<SessionCheckResponse>;
|
|
20
|
+
}
|
|
21
|
+
export declare class Session extends Client {
|
|
22
|
+
/**
|
|
23
|
+
* Checks if the current session is still valid. This function is to be removed - please replace
|
|
24
|
+
* any usage with the new 'SessionClient.validate()' function.
|
|
25
|
+
*
|
|
26
|
+
* @return {boolean}
|
|
27
|
+
* @throws {TechnicalError}
|
|
28
|
+
* @deprecated
|
|
29
|
+
*/
|
|
30
|
+
isValid(): boolean;
|
|
20
31
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Claims } from "../Dto";
|
|
1
2
|
/**
|
|
2
3
|
* The type of the `hanko-session-created` event.
|
|
3
4
|
* @typedef {string} sessionCreatedType
|
|
@@ -40,11 +41,11 @@ export declare const userCreatedType: "hanko-user-created";
|
|
|
40
41
|
* @interface
|
|
41
42
|
* @category SDK
|
|
42
43
|
* @subcategory Events
|
|
43
|
-
* @property {
|
|
44
|
-
* @property {
|
|
44
|
+
* @property {number} expirationSeconds - This property is deprecated. The number of seconds until the JWT expires.
|
|
45
|
+
* @property {Claims} claims - The JSON web token associated with the session. Only present when the Hanko-API allows the JWT to be accessible client-side.
|
|
45
46
|
*/
|
|
46
47
|
export interface SessionDetail {
|
|
47
|
-
|
|
48
|
+
claims: Claims;
|
|
48
49
|
expirationSeconds: number;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
import { SessionDetail } from "./CustomEvents";
|
|
2
|
-
import { SessionState } from "../state/session/SessionState";
|
|
3
|
-
/**
|
|
4
|
-
* Options for Dispatcher
|
|
5
|
-
*
|
|
6
|
-
* @category SDK
|
|
7
|
-
* @subcategory Internal
|
|
8
|
-
* @property {string} localStorageKey - The prefix / name of the local storage keys.
|
|
9
|
-
*/
|
|
10
|
-
interface DispatcherOptions {
|
|
11
|
-
localStorageKey: string;
|
|
12
|
-
}
|
|
13
2
|
/**
|
|
14
3
|
* A class that dispatches custom events.
|
|
15
4
|
*
|
|
16
5
|
* @category SDK
|
|
17
6
|
* @subcategory Internal
|
|
18
|
-
* @param {DispatcherOptions} options - The options that can be used
|
|
19
7
|
*/
|
|
20
8
|
export declare class Dispatcher {
|
|
21
9
|
_dispatchEvent: any;
|
|
22
|
-
_sessionState: SessionState;
|
|
23
|
-
constructor(options: DispatcherOptions);
|
|
24
10
|
/**
|
|
25
11
|
* Dispatches a custom event.
|
|
26
12
|
*
|
|
@@ -48,4 +34,3 @@ export declare class Dispatcher {
|
|
|
48
34
|
*/
|
|
49
35
|
dispatchUserDeletedEvent(): void;
|
|
50
36
|
}
|
|
51
|
-
export {};
|
|
@@ -1,61 +1,66 @@
|
|
|
1
1
|
import { Listener } from "./Listener";
|
|
2
|
-
import { Scheduler } from "./Scheduler";
|
|
3
2
|
import { Dispatcher } from "./Dispatcher";
|
|
4
|
-
import {
|
|
3
|
+
import { InternalOptions } from "../../Hanko";
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @category SDK
|
|
9
|
-
* @subcategory Internal
|
|
10
|
-
* @property {string} cookieName - The name of the session cookie set from the SDK.
|
|
11
|
-
* @property {string} localStorageKey - The prefix / name of the local storage keys.
|
|
12
|
-
*/
|
|
13
|
-
interface RelayOptions {
|
|
14
|
-
cookieName: string;
|
|
15
|
-
localStorageKey: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* A class that dispatches events and scheduled events, based on other events.
|
|
5
|
+
* A class that manages session checks, dispatches events based on session status,
|
|
6
|
+
* and uses broadcast channels for inter-tab communication.
|
|
19
7
|
*
|
|
20
8
|
* @category SDK
|
|
21
9
|
* @subcategory Internal
|
|
22
10
|
* @extends Dispatcher
|
|
23
|
-
* @param {
|
|
11
|
+
* @param {string} api - The API endpoint URL.
|
|
12
|
+
* @param {InternalOptions} options - The internal configuration options of the SDK.
|
|
24
13
|
*/
|
|
25
14
|
export declare class Relay extends Dispatcher {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
listener: Listener;
|
|
16
|
+
private readonly checkInterval;
|
|
17
|
+
private readonly client;
|
|
18
|
+
private readonly sessionState;
|
|
19
|
+
private readonly windowActivityManager;
|
|
20
|
+
private readonly scheduler;
|
|
21
|
+
private readonly sessionChannel;
|
|
22
|
+
private isLoggedIn;
|
|
23
|
+
constructor(api: string, options: InternalOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Sets up all event listeners and initializes session management.
|
|
26
|
+
* This method is crucial for ensuring the session is monitored across all tabs.
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
private initializeEventListeners;
|
|
30
|
+
/**
|
|
31
|
+
* Initiates session checking based on the last check time.
|
|
32
|
+
* This method decides when the next check should occur to balance between performance and freshness.
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
private startSessionCheck;
|
|
36
|
+
/**
|
|
37
|
+
* Validates the current session and updates session information.
|
|
38
|
+
* This method checks if the session is still valid and updates local data accordingly.
|
|
39
|
+
* @returns {Promise<SessionCheckResult>} - A promise that resolves with the session check result.
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private checkSession;
|
|
30
43
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
44
|
+
* Resets session-related states when a session expires.
|
|
45
|
+
* Ensures that authentication state is cleared and an expiration event is dispatched.
|
|
46
|
+
* Assumes the user is logged out by default if the session state is unknown.
|
|
34
47
|
* @private
|
|
35
|
-
* @param {SessionDetail} detail - The event detail.
|
|
36
48
|
*/
|
|
37
|
-
private
|
|
49
|
+
private onSessionExpired;
|
|
38
50
|
/**
|
|
39
|
-
*
|
|
40
|
-
* multiple SDK instances).
|
|
41
|
-
*
|
|
51
|
+
* Handles session expired events from broadcast messages.
|
|
42
52
|
* @private
|
|
43
53
|
*/
|
|
44
|
-
private
|
|
54
|
+
private onChannelSessionExpired;
|
|
45
55
|
/**
|
|
46
|
-
* Handles
|
|
47
|
-
*
|
|
48
|
-
* or a "hanko-session-expired" event.
|
|
49
|
-
*
|
|
56
|
+
* Handles session creation events from broadcast messages.
|
|
57
|
+
* @param {BroadcastMessage} msg - The broadcast message containing session details.
|
|
50
58
|
* @private
|
|
51
|
-
* @param {StorageEvent} event - The storage event object.
|
|
52
59
|
*/
|
|
53
|
-
private
|
|
60
|
+
private onChannelSessionCreated;
|
|
54
61
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
62
|
+
* Handles leadership requests from other tabs.
|
|
57
63
|
* @private
|
|
58
64
|
*/
|
|
59
|
-
private
|
|
65
|
+
private onChannelLeadershipRequested;
|
|
60
66
|
}
|
|
61
|
-
export {};
|
|
@@ -1,43 +1,70 @@
|
|
|
1
|
+
import { SessionCheckResponse } from "../Dto";
|
|
2
|
+
export type SessionCheckResult = (Omit<SessionCheckResponse, "expiration_time"> & {
|
|
3
|
+
expiration: number;
|
|
4
|
+
}) | null;
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
6
|
+
* Callback type for performing a session check.
|
|
4
7
|
* @ignore
|
|
5
|
-
* @param {number} timeoutID - the ID returned by `setTimeout()`
|
|
6
|
-
* @param {string} type - The type, helps to organize the tasks.
|
|
7
|
-
* @param {Function} func - The function to be called within the task.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
timeoutID: number;
|
|
11
|
-
type: string;
|
|
12
|
-
func: () => any;
|
|
13
|
-
};
|
|
9
|
+
type SessionCheckCallback = () => Promise<SessionCheckResult>;
|
|
14
10
|
/**
|
|
15
|
-
*
|
|
11
|
+
* Callback type for handling session timeout events.
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
type SessionExpiredCallback = () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Manages scheduling for periodic and timeout-based session checks.
|
|
16
17
|
*
|
|
17
18
|
* @category SDK
|
|
18
19
|
* @subcategory Internal
|
|
20
|
+
* @param {number} checkInterval - The interval in milliseconds between periodic session checks.
|
|
21
|
+
* @param {SessionCheckCallback} checkSession - The callback function to perform a session check.
|
|
22
|
+
* @param {SessionExpiredCallback} onSessionExpired - The callback function to handle session timeout events.
|
|
19
23
|
*/
|
|
20
24
|
export declare class Scheduler {
|
|
21
|
-
|
|
25
|
+
private intervalID;
|
|
26
|
+
private timeoutID;
|
|
27
|
+
private readonly checkInterval;
|
|
28
|
+
private readonly checkSession;
|
|
29
|
+
private readonly onSessionExpired;
|
|
30
|
+
constructor(checkInterval: number, checkSession: SessionCheckCallback, onSessionExpired: SessionExpiredCallback);
|
|
22
31
|
/**
|
|
23
|
-
*
|
|
32
|
+
* Handles the session expiration when it is about to expire soon.
|
|
33
|
+
* Stops any ongoing checks and schedules a timeout for the expiration.
|
|
24
34
|
*
|
|
25
|
-
* @
|
|
26
|
-
* @param {Task} task - The task to be removed.
|
|
35
|
+
* @param {number} timeToExpiration - The time in milliseconds until the session expires.
|
|
27
36
|
*/
|
|
28
|
-
|
|
37
|
+
scheduleSessionExpiry(timeToExpiration: number): void;
|
|
29
38
|
/**
|
|
30
|
-
*
|
|
39
|
+
* Starts the session check process.
|
|
40
|
+
* Determines when the next check should run based on the last known check time and session expiration.
|
|
41
|
+
* If the session is expiring soon, schedules an expiration event instead of starting periodic checks.
|
|
31
42
|
*
|
|
32
|
-
* @param {
|
|
43
|
+
* @param {number} lastCheck - The timestamp (in milliseconds) of the last session check.
|
|
44
|
+
* @param {number} expiration - The timestamp (in milliseconds) of when the session expires.
|
|
45
|
+
*/
|
|
46
|
+
start(lastCheck?: number, expiration?: number): void;
|
|
47
|
+
/**
|
|
48
|
+
* Stops the session check process and clears all timers.
|
|
49
|
+
*/
|
|
50
|
+
stop(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if the scheduler is currently running.
|
|
53
|
+
* @returns {boolean} True if the scheduler is running; otherwise, false.
|
|
54
|
+
*/
|
|
55
|
+
isRunning(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if the session is about to expire.
|
|
58
|
+
* @param {number} expiration - Timestamp when the session will expire.
|
|
59
|
+
* @returns {boolean} True if the session is about to expire; otherwise, false.
|
|
33
60
|
*/
|
|
34
|
-
|
|
61
|
+
sessionExpiresSoon(expiration: number): boolean;
|
|
35
62
|
/**
|
|
36
|
-
*
|
|
63
|
+
* Calculates the time until the next session check should occur.
|
|
37
64
|
*
|
|
38
|
-
* @param {
|
|
39
|
-
* @
|
|
40
|
-
* @param {number} timeoutSeconds - The timeout after which the task should be executed, in seconds.
|
|
65
|
+
* @param {number} lastCheck - The timestamp (in milliseconds) of the last session check.
|
|
66
|
+
* @returns {number} The time in milliseconds until the next check should be performed.
|
|
41
67
|
*/
|
|
42
|
-
|
|
68
|
+
calcTimeToNextCheck(lastCheck: number): number;
|
|
43
69
|
}
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Claims } from "../Dto";
|
|
2
|
+
/**
|
|
3
|
+
* Enum-like type defining the actions that can be broadcasted.
|
|
4
|
+
*
|
|
5
|
+
* @ignore
|
|
6
|
+
* @category SDK
|
|
7
|
+
* @subcategory Internal
|
|
8
|
+
*/
|
|
9
|
+
type Action = "sessionExpired" | "sessionCreated" | "requestLeadership";
|
|
10
|
+
/**
|
|
11
|
+
* Interface representing the data structure of a channel event.
|
|
12
|
+
*
|
|
13
|
+
* @interface
|
|
14
|
+
* @property {Action} action - The type of action being broadcasted.
|
|
15
|
+
* @property {Claims=} claims - Optional claims associated with the event.
|
|
16
|
+
* @property {boolean=} is_valid - Optional indication of the session validity.
|
|
17
|
+
* @category SDK
|
|
18
|
+
* @subcategory Internal
|
|
19
|
+
*/
|
|
20
|
+
export interface BroadcastMessage {
|
|
21
|
+
action: Action;
|
|
22
|
+
claims?: Claims;
|
|
23
|
+
is_valid?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Callback type for handling broadcast messages.
|
|
27
|
+
*
|
|
28
|
+
* @ignore
|
|
29
|
+
*/
|
|
30
|
+
type Callback = (msg: BroadcastMessage) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Manages inter-tab communication using the BroadcastChannel API.
|
|
33
|
+
*
|
|
34
|
+
* @category SDK
|
|
35
|
+
* @subcategory Internal
|
|
36
|
+
* @param {string} channelName - The name of the broadcast channel.
|
|
37
|
+
* @param {Callback} onSessionExpired - Callback invoked when the session has expired.
|
|
38
|
+
* @param {Callback} onSessionCreated - Callback invoked when a session is created.
|
|
39
|
+
* @param {Callback} onLeadershipRequested - Callback invoked when a leadership request is received.
|
|
40
|
+
*/
|
|
41
|
+
export declare class SessionChannel {
|
|
42
|
+
channel: BroadcastChannel;
|
|
43
|
+
onSessionExpired: Callback;
|
|
44
|
+
onSessionCreated: Callback;
|
|
45
|
+
onLeadershipRequested: Callback;
|
|
46
|
+
constructor(channelName: string, onSessionExpired: Callback, onSessionCreated: Callback, onLeadershipRequested: Callback);
|
|
47
|
+
/**
|
|
48
|
+
* Sends a message via the broadcast channel to inform other tabs of session changes.
|
|
49
|
+
*
|
|
50
|
+
* @param {BroadcastMessage} msg - The messsage to broadcast.
|
|
51
|
+
*/
|
|
52
|
+
post(msg: BroadcastMessage): void;
|
|
53
|
+
/**
|
|
54
|
+
* Handles incoming messages from the broadcast channel.
|
|
55
|
+
*
|
|
56
|
+
* @param {MessageEvent} event - The message event containing the broadcast data.
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
private handleMessage;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the session state with expiration and last check timestamps.
|
|
3
|
+
*
|
|
4
|
+
* @category SDK
|
|
5
|
+
* @subcategory Internal
|
|
6
|
+
*/
|
|
7
|
+
export interface State {
|
|
8
|
+
expiration: number;
|
|
9
|
+
lastCheck: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Manages session state persistence using localStorage.
|
|
13
|
+
*
|
|
14
|
+
* @category SDK
|
|
15
|
+
* @subcategory Internal
|
|
16
|
+
*/
|
|
17
|
+
export declare class SessionState {
|
|
18
|
+
private readonly storageKey;
|
|
19
|
+
private readonly defaultState;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of SessionState.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} storageKey - The key used to store session state in localStorage.
|
|
24
|
+
*/
|
|
25
|
+
constructor(storageKey: string);
|
|
26
|
+
/**
|
|
27
|
+
* Loads the current session state from localStorage.
|
|
28
|
+
*
|
|
29
|
+
* @returns {State} The parsed session state or a default state if not found.
|
|
30
|
+
*/
|
|
31
|
+
load(): State;
|
|
32
|
+
/**
|
|
33
|
+
* Saves the session state to localStorage.
|
|
34
|
+
*
|
|
35
|
+
* @param {State | null} session - The session state to save. If null, the default state is used.
|
|
36
|
+
*/
|
|
37
|
+
save(session: State | null): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type Callback = () => void;
|
|
2
|
+
/**
|
|
3
|
+
* Manages window focus and blur events.
|
|
4
|
+
*
|
|
5
|
+
* @class
|
|
6
|
+
* @category SDK
|
|
7
|
+
* @subcategory Internal
|
|
8
|
+
* @param {Callback} onActivityCallback - Callback to invoke when the window gains focus.
|
|
9
|
+
* @param {Callback} onInactivityCallback - Callback to invoke when the window loses focus.
|
|
10
|
+
*/
|
|
11
|
+
export declare class WindowActivityManager {
|
|
12
|
+
private readonly onActivityCallback;
|
|
13
|
+
private readonly onInactivityCallback;
|
|
14
|
+
constructor(onActivityCallback: Callback, onInactivityCallback: Callback);
|
|
15
|
+
/**
|
|
16
|
+
* Handles the focus event and invokes the activity callback.
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
private handleFocus;
|
|
20
|
+
/**
|
|
21
|
+
* Handles the blur event and invokes the inactivity callback.
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
private handleBlur;
|
|
25
|
+
/**
|
|
26
|
+
* Handles the visibility change event and invokes appropriate callbacks.
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
private handleVisibilityChange;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the current window has focus.
|
|
32
|
+
* @returns {boolean} True if the window has focus; otherwise, false.
|
|
33
|
+
*/
|
|
34
|
+
hasFocus: () => boolean;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -40,6 +40,7 @@ export interface ProfileInitActions {
|
|
|
40
40
|
export interface LoginMethodChooserActions {
|
|
41
41
|
readonly continue_to_password_login?: Action<null>;
|
|
42
42
|
readonly continue_to_passcode_confirmation?: Action<null>;
|
|
43
|
+
readonly webauthn_generate_request_options?: Action<null>;
|
|
43
44
|
readonly back: Action<null>;
|
|
44
45
|
}
|
|
45
46
|
export interface LoginOTPActions {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CredentialCreationOptionsJSON, CredentialRequestOptionsJSON } from "@github/webauthn-json/src/webauthn-json/basic/json";
|
|
2
|
+
import { Claims } from "../../Dto";
|
|
2
3
|
export interface PasscodeConfirmationPayload {
|
|
3
4
|
readonly passcode_resent: boolean;
|
|
4
5
|
readonly resend_after: number;
|
|
@@ -83,6 +84,7 @@ export interface LastLogin {
|
|
|
83
84
|
export interface SuccessPayload {
|
|
84
85
|
readonly user: User;
|
|
85
86
|
readonly last_login?: LastLogin;
|
|
87
|
+
readonly claims: Claims;
|
|
86
88
|
}
|
|
87
89
|
export interface ThirdPartyPayload {
|
|
88
90
|
readonly redirect_url: string;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { LocalStorageSession } from "./session/SessionState";
|
|
2
1
|
/**
|
|
3
2
|
* @interface
|
|
4
3
|
* @category SDK
|
|
5
4
|
* @subcategory Internal
|
|
6
|
-
* @property {LocalStorageUsers=} users - The user states.
|
|
7
5
|
*/
|
|
8
6
|
interface LocalStorage {
|
|
9
|
-
session?: LocalStorageSession;
|
|
10
7
|
}
|
|
11
8
|
/**
|
|
12
9
|
* A class to read and write local storage contents.
|