@intellegens/cornerstone-client 0.0.1 → 0.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.
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/services/auth/index.d.ts +46 -0
- package/services/auth/types/index.d.ts +2 -0
- package/services/auth/types/user-info.d.ts +18 -0
- package/services/auth/types/user.d.ts +16 -0
- package/services/config/index.d.ts +37 -0
- package/services/index.d.ts +2 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './services';
|
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { User, UserInfo } from './types';
|
|
2
|
+
export { User, UserInfo };
|
|
3
|
+
/**
|
|
4
|
+
* Auth class is responsible for managing user authentication operations.
|
|
5
|
+
* It supports login, logout, and checking the current user's details.
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class Auth
|
|
9
|
+
*/
|
|
10
|
+
export declare class Auth<TId, TUser = User<TId>> {
|
|
11
|
+
private _apiUrl;
|
|
12
|
+
user: TUser | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of Auth.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} apiUrl
|
|
17
|
+
* @memberof Auth
|
|
18
|
+
*/
|
|
19
|
+
constructor(apiUrl: string);
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the current user's details if they are logged in.
|
|
22
|
+
*
|
|
23
|
+
* @return {Promise<TUser>} Currently logged in user
|
|
24
|
+
* @throws {Error} Error if fetch fails
|
|
25
|
+
* @memberof Auth
|
|
26
|
+
*/
|
|
27
|
+
whoAmI(): Promise<TUser>;
|
|
28
|
+
/**
|
|
29
|
+
* Logs in a user using their username and password, and retrieves the user data.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} username Login credentials: username
|
|
32
|
+
* @param {string} password Login credentials: password
|
|
33
|
+
* @return {Promise<TUser>} Currently logged in user
|
|
34
|
+
* @throws {Error} Error if fetch fails
|
|
35
|
+
* @memberof Auth
|
|
36
|
+
*/
|
|
37
|
+
login(username: string, password: string): Promise<TUser>;
|
|
38
|
+
/**
|
|
39
|
+
* Logs out the current user and clears their authentication state.
|
|
40
|
+
*
|
|
41
|
+
* @return {Promise<void>}
|
|
42
|
+
* @throws {Error} Error if fetch fails
|
|
43
|
+
* @memberof Auth
|
|
44
|
+
*/
|
|
45
|
+
logout(): Promise<void>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { User } from './user';
|
|
2
|
+
/**
|
|
3
|
+
* Represents user information along with access token expiry.
|
|
4
|
+
*
|
|
5
|
+
* @template TId The type of the user identifier.
|
|
6
|
+
* @template TUser The type of the user object, defaulting to `User<TId>`.
|
|
7
|
+
*
|
|
8
|
+
* @param {TUser} user The user object containing user details.
|
|
9
|
+
* @param {Date} accessTokenExpiry The date and time when the access token will expire.
|
|
10
|
+
*
|
|
11
|
+
* @typedef {Object} UserInfo
|
|
12
|
+
* @property {TUser} user The user object.
|
|
13
|
+
* @property {Date} accessTokenExpiry The expiry date of the access token.
|
|
14
|
+
*/
|
|
15
|
+
export type UserInfo<TId, TUser = User<TId>> = {
|
|
16
|
+
user: TUser;
|
|
17
|
+
accessTokenExpiry: Date;
|
|
18
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a user with an identifier and email address.
|
|
3
|
+
*
|
|
4
|
+
* @template TId The type of the user identifier.
|
|
5
|
+
*
|
|
6
|
+
* @param {TId} id The unique identifier for the user.
|
|
7
|
+
* @param {string} email The email address associated with the user.
|
|
8
|
+
*
|
|
9
|
+
* @typedef {Object} User
|
|
10
|
+
* @property {TId} id The unique identifier of the user.
|
|
11
|
+
* @property {string} email The email address of the user.
|
|
12
|
+
*/
|
|
13
|
+
export type User<TId> = {
|
|
14
|
+
id: TId;
|
|
15
|
+
email: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration class for managing the API
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @class Config
|
|
6
|
+
*/
|
|
7
|
+
export declare class Config {
|
|
8
|
+
/**
|
|
9
|
+
* The base URL of the API. It is undefined by default and gets populated through the initialization process.
|
|
10
|
+
*
|
|
11
|
+
* @type {(string | undefined)}
|
|
12
|
+
* @memberof Config
|
|
13
|
+
*/
|
|
14
|
+
apiBaseUrl: string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the configuration by detecting the API base URL.
|
|
17
|
+
*
|
|
18
|
+
* This method calls all methods that need to be called during the config phase.
|
|
19
|
+
*
|
|
20
|
+
* @async
|
|
21
|
+
* @return {Promise<void>} Resolves when the API base URL is detected.
|
|
22
|
+
* @memberof Config
|
|
23
|
+
*/
|
|
24
|
+
initialize(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Detects the API base URL by checking the `CORNERSTONE-API-BASEURL` header and the `websettings.json` file.
|
|
27
|
+
*
|
|
28
|
+
* First, it checks the response headers of the current URL for the 'CORNERSTONE-API-BASEURL' header.
|
|
29
|
+
* If the header is not found, it attempts to load the `websettings.json` file and looks for an `api` field.
|
|
30
|
+
* If no API base URL is found, it defaults to `undefined`.
|
|
31
|
+
*
|
|
32
|
+
* @return {Promise<string | undefined>} Returns the API base URL
|
|
33
|
+
* @throws {Error} Throws error if fetch fails
|
|
34
|
+
* @memberof Config
|
|
35
|
+
*/
|
|
36
|
+
detectApiBaseUrl(): Promise<string | undefined>;
|
|
37
|
+
}
|