UNPKG

@telstra/core

Version:
85 lines (84 loc) 2.89 kB
export interface IAuthCredentials { client_id: string; client_secret: string; } export interface IAuthConfigProps { TELSTRA_CLIENT_ID: string; TELSTRA_CLIENT_SECRET: string; } export interface IAuthTokenData { access_token: string; expires_at: Date; } /** * @interface IAuthManager * @description Authentication manager interface to manage the authentication data. * @exports IAuthManager */ export interface IAuthManager { /** * @property {boolean} hasCredentials * @description A boolean value indicating whether the authentication credentials are available. */ readonly hasCredentials: boolean; /** * @method getCredentials * @description Retrieves the authentication credentials in the following order of precedence: * 1. Credentials defined in the constructor. * 2. Credentials defined in the imported JSON file located at ~/.telstra/credentials. * 3. Credentials defined in the environment variables. * If no credentials are found, an error is thrown. * @memberof AuthManager * @public * @async * @instance * @returns {Promise<IAuthCredentials>} Returns a promise that resolves to the authentication credentials. * @throws {CredentialsError} Throws an error if no credentials are found or if the credentials are invalid. * @throws {InvalidAuthCredentialsError} Throws an error if the credentials are invalid. * @throws {NoCredentialsFoundError} Throws an error if no credentials are found. */ getCredentials(): Promise<IAuthCredentials>; /** * @method getAuthToken * @description Retrieves the authentication token data. * @memberof IAuthManager * @public * @instance * @returns {Promise<IAuthTokenData | null>} Returns the authentication token data. */ getAuthTokenData(): Promise<IAuthTokenData | null>; /** * @method setAuthTokenData * @param {IAuthTokenData} authTokenData * @returns {Promise<boolean>} * @description Set the authentication token data. * @memberof IAuthManager * @public * @async * @instance * @throws {InvalidTokenError} Invalid token */ setAuthTokenData(authTokenData: IAuthTokenData): Promise<boolean>; /** * @method resetAuthToken * @returns {Promise<boolean>} * @description Reset the auth token data to null * @memberof IAuthManager * @public * @async * @instance */ resetAuthToken(): Promise<boolean>; /** * @method setAuthTokenRetryCount * @param {number} count * @returns {Promise<boolean>} * @description Set the auth token retry count * @memberof IAuthManager * @public * @async * @instance * @throws {InvalidTokenRetryCountError} Invalid retry count */ setAuthTokenRetryCount(count: number): Promise<boolean>; }