@fusionauth/angular-sdk 0.1.7 → 1.0.2

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,42 +1,51 @@
1
1
  import { FusionAuthConfig, UserInfo } from './types';
2
+ import { Observable } from 'rxjs';
2
3
  /**
3
4
  * Service class to use with FusionAuth backend endpoints.
4
5
  */
5
6
  export declare class FusionAuthService {
6
- private config;
7
+ private core;
8
+ private autoRefreshTimer?;
9
+ private isLoggedInSubject;
7
10
  constructor(config: FusionAuthConfig);
11
+ /** An observable representing whether the user is logged in. */
12
+ isLoggedIn$: Observable<boolean>;
13
+ /** A function that returns whether the user is logged in. This returned value is non-observable. */
14
+ isLoggedIn(): boolean;
8
15
  /**
9
- * Calls the 'me' endpoint to retrieve user info.
10
- * @return {Promise<UserInfo>} the user info response.
16
+ * Refreshes the access token a single time.
17
+ * Automatic token refreshing can be enabled if the SDK is configured with `shouldAutoRefresh`.
11
18
  */
12
- getUserInfo(): Promise<UserInfo>;
19
+ refreshToken(): Promise<Response>;
13
20
  /**
14
- * Checks for the 'app.at_exp' cookie and if present sets a timer to refresh the access token.
15
- * Will attempt to refresh the configured seconds before the access token expires (default is ten seconds).
21
+ * Initializes automatic access token refreshing.
22
+ * This is handled automatically if the SDK is configured with `shouldAutoRefresh`.
16
23
  */
17
24
  initAutoRefresh(): void;
18
25
  /**
19
- * Checks that the 'app.at_exp' cookie is present and for a time in the future to determine logged-in state.
20
- * @return {boolean} app.at_exp is present and not for a time in the past
26
+ * Returns an observable request that fetches userInfo, and catches error.
21
27
  */
22
- isLoggedIn(): boolean;
28
+ getUserInfoObservable(callbacks?: {
29
+ onBegin?: () => void;
30
+ onDone?: () => void;
31
+ }): Observable<UserInfo>;
23
32
  /**
24
- * Calls the configured 'refresh' endpoint to attempt to refresh the access token cookie.
33
+ * Fetches userInfo from the 'me' endpoint.
34
+ * @throws {Error} - if an error occurred while fetching.
25
35
  */
26
- refreshToken(): Promise<void>;
36
+ getUserInfo(): Promise<UserInfo>;
27
37
  /**
28
- * Invokes a redirect to the configured 'login' endpoint.
38
+ * Initiates login flow.
39
+ * @param {string} [state] - Optional value to be echoed back to the SDK upon redirect.
29
40
  */
30
41
  startLogin(state?: string): void;
31
42
  /**
32
- * Invokes a redirect to the configured 'refresh' endpoint.
43
+ * Initiates register flow.
44
+ * @param {string} [state] - Optional value to be echoed back to the SDK upon redirect.
33
45
  */
34
46
  startRegistration(state?: string): void;
35
47
  /**
36
- * Invokes a redirect to the configured 'logout' endpoint.
48
+ * Initiates logout flow.
37
49
  */
38
50
  logout(): void;
39
- private doRedirectForPath;
40
- private getUrlForPath;
41
- private getExpTime;
42
51
  }
package/lib/types.d.ts CHANGED
@@ -1,12 +1,58 @@
1
+ /**
2
+ * Config for FusionAuth Angular SDK
3
+ */
1
4
  export interface FusionAuthConfig {
5
+ /**
6
+ * The URL of the server that performs the token exchange.
7
+ */
2
8
  serverUrl: string;
9
+ /**
10
+ * The client id of the application.
11
+ */
3
12
  clientId: string;
4
- redirectUri?: string;
13
+ /**
14
+ * The redirect URI of the application.
15
+ */
16
+ redirectUri: string;
17
+ /**
18
+ * The OAuth2 scope parameter passed to the `/oauth2/authorize` endpoint. If not specified fusionauth will default this to `openid offline_access`.
19
+ */
20
+ scope?: string;
21
+ /**
22
+ * Enables automatic token refreshing. Defaults to false.
23
+ */
24
+ shouldAutoRefresh?: boolean;
25
+ /**
26
+ * The number of seconds before the access token expiry when the auto refresh functionality kicks in if enabled. Default is 10.
27
+ */
5
28
  autoRefreshSecondsBeforeExpiry?: number;
29
+ /**
30
+ * Callback function to be invoked with the `state` value upon redirect from login or register.
31
+ */
32
+ onRedirect?: (state?: string) => void;
33
+ /**
34
+ * Callback to be invoked if a request to refresh the access token fails during autorefresh.
35
+ */
36
+ onAutoRefreshFailure?: (error: Error) => void;
37
+ /**
38
+ * The path to the login endpoint.
39
+ */
6
40
  loginPath?: string;
7
- logoutPath?: string;
41
+ /**
42
+ * The path to the register endpoint.
43
+ */
8
44
  registerPath?: string;
45
+ /**
46
+ * The path to the logout endpoint.
47
+ */
48
+ logoutPath?: string;
49
+ /**
50
+ * The path to the token refresh endpoint.
51
+ */
9
52
  tokenRefreshPath?: string;
53
+ /**
54
+ * The path to the me endpoint.
55
+ */
10
56
  mePath?: string;
11
57
  }
12
58
  export interface UserInfo {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusionauth/angular-sdk",
3
- "version": "0.1.7",
3
+ "version": "1.0.2",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^17.2.0",
6
6
  "@angular/core": "^17.2.0"