turbogui-angular
Version:
A library that tries to help with the most common user interface elements on several frameworks and platforms
240 lines • 11.1 kB
TypeScript
import { DialogService } from './dialog.service';
import { BrowserService } from './browser.service';
import * as i0 from "@angular/core";
/**
* Allows us to easily perform requests to a remote API that is developed with Turbo framework.
*/
export declare abstract class TurboApiService {
private readonly dialogService;
private readonly browserService;
/**
* URI Path to the web service that performs the user login
*/
loginServiceURI: string;
/**
* URI Path to the web service that allows us to create extra user tokens
*/
tokenCreationServiceURI: string;
/**
* URI Path to the web service that performs the user log out
*/
logOutServiceURI: string;
/**
* URI Path to the web service that performs the verification for a user email
*/
mailVerifyServiceURI: string;
/**
* The username that is currently defined and will be used by the login methods
*/
private _userName;
/**
* The password for the user that is currently defined and will be used by the login methods
*/
private _password;
/**
* Contains the last email account that has been verified (or tried to verify) by this service, if any
*/
private _lastVerifiedMail;
/**
* Check public getter for docs
*/
private _isLogged;
/**
* @see token() getter for more info
*/
private _token;
/**
* List of operations that are allowed to the currently loged user. It gets filled just after login is performed
*/
private _operations;
/**
* Private http manager instance that will be exclusive to this turbo api caller service.
*/
private readonly httpManager;
constructor(dialogService: DialogService, browserService: BrowserService);
/**
* The username that is currently defined and will be used by the login methods
*/
set userName(v: string);
/**
* The username that is currently defined and will be used by the login methods
*/
get userName(): string;
/**
* The password for the user that is currently defined and will be used by the login methods
*/
set password(v: string);
/**
* The password for the user that is currently defined and will be used by the login methods
*/
get password(): string;
/**
* Define the root url that will be used for all the API calls
*/
set baseUrl(url: string);
/**
* Define the root url that will be used for all the API calls
*/
get baseUrl(): string;
/**
* If the current browser URL contains a hash fragment (The part after the # character) that contains encoded user or password
* values, this method will parse and automatically set them as the credentials to use.
*
* The URL hash is not altered in any way by this method.
*
* @returns True if any credentials were found and loaded, false if nothing happened
*/
loadCredentialsFromURLHashFragment(): boolean;
/**
* If the current browser URL contains a hash fragment (The part after the # character) that contains encoded user, mail and
* has verification code values, this method will perform the request to server to verify that email account for the user.
*
* The URI path to the mail verification service must be correctly defined at this.mailVerifyServiceURI property.
*
* @returns A promise that resolves with the server response if the verification is successful,
* or rejects with an error if the verification fails. Response will have 4 possible values:
* undefined - meaning that the URL hash fragment didn't contain valid verification values
* -1 - meaning verification failed
* 0 - meaning verification succeeded
* 1 - meaning the email was already previouly verified
*/
verifyUserMailFromURLHashFragment(): Promise<any>;
/**
* Obtain the lat user mail account that has been verified (or attempted to verify) by this service.
*/
getLastVerifiedMail(): string;
/**
* Authenticates the userName and password that are currently defined at the respective properties of this service.
* Returns a promise that resolves with the server's response or rejects with an error if the login fails.
* Path to the login service must be correctly defined at this.loginWebService
*
* The authentication process is performed by sending an encoded credentials request to the login web service using the
* currently defined user name and psw.
*
* Here's an example of a call:
*
* login().then(response => {
* console.log('Login successful:', response);
* }).catch(() => {
* console.error('Login failed:');
* });
*
* @returns A promise that resolves with the server response if the login is successful,
* or rejects with an error if the login fails.
*/
login(): Promise<any>;
/**
* Perform a request to the API service to create a new token for the user that is currently logged in.
*
* @param options The parameters that will affect the token behaviour. To learn more about each option, please
* refer to the turbodepot UsersManager class createToken method documentation
*
* @returns A promise that resolves with the created token string if the request is successful, or rejects
* with an error (containing all the error response details) if the request fails.
*/
createUserToken(options: {
lifeTime?: number;
useCount?: number;
isLifeTimeRecycled?: boolean;
}): Promise<any>;
/**
* Checks if the user and password credentials are filled and not empty.
* If any of the two values is empty, false will be returned
*/
get isUserAndPswDefined(): boolean;
/**
* Tells if the user name and psw that are specified on this service are currently logged or not. This means
* also a token is active.
*/
get isLogged(): boolean;
/**
* Gives the value for the currently active user authentication token or an empty string if no user logged
*/
get token(): string;
/**
* Checks if the currently logged user is allowed to perform the specified operation.
* This will check the user permisions as defined on server side and return true if the operation is allowed
* or false if not. We can then decide what to do (hide an app section, block a button, etc)
*
* @param operation The name of the operation to check
*
* @returns True if the operation is allowed, false otherwise
*/
isUserAllowedTo(operation: string): boolean;
/**
* Performs a standard request to an API service and returns a promise that resolves with the response data.
*
* Following is an example of a call:
*
* this.apiService.call('users/user-create', this.userData, {handleErrors: false}).then(response => {
*
* console.log('Success:', response);
*
* }).catch(error => {
*
* console.error('Error:', error.message);
* });
*
* @param apiPath - A relative URL (based on the defined base root url) that defines the path to the service to call.
* For example: 'users/login'
* @param parameters - An object containing key-value pairs that are sent as the request body.
* token parameter is not necessary, it is automatically appended
* @param options An object defining several options for the request:
* resultFormat: 'JSON' by default. The expected format of the response.
* busyState: Enabled by default. Enables or disables the busy state to lock user interaction while performing the http calls.
* handleErrors: Enabled by default. If set to true, an error dialog will be automatically shown when the call fails.
* If set to false, the promise will generate a reject error that must be handled by our code.
*
* @returns A promise that resolves with the response data correctly parsed if the request is successful, or rejects
* with an error (containing all the error response details) if the request fails.
*/
call(apiPath: string, parameters?: {}, options?: {
resultFormat?: 'STRING' | 'JSON';
busyState?: boolean;
handleErrors?: boolean;
}): Promise<any>;
/**
* Performs a request to chain several api calls into a single http request, via the chain services mechanism of the turboframework API.
* Returns a promise that resolves with an array of response objects. One for each of the request calls.
*
* @param apiPath - A relative URL (based on the defined base root url) that defines the path to the root of the chain services call.
* For example: 'turbosite/chain/chain-services'
* @param services - An array of objects, were each object contains a valid structure for the chain services call.
* Token parameter is not necessary, it is automatically appended
* @param options An object defining several options for the request:
* busyState: Enables or disables the busy state to lock user interaction while performing the http calls. Enabled by default
* handleErrors: Enabled by default. If set to true, an error dialog will be automatically shown when the call fails.
* If set to false, the promise will generate a reject error that must be handled by our code.
*
* @returns A promise that resolves with the response data correctly parsed if the request is successful, or rejects
* with an error (containing all the error response details) if the request fails.
*/
callChain(apiPath: string, services: {}[], options?: {
busyState?: boolean;
handleErrors?: boolean;
}): Promise<any>;
/**
* Aux method to show an error dialog when a request fails and error handling is enabled
*/
private showErrorDialog;
/**
* Perform the logout for the currently logged user
*
* @param options An object defining several options for the request:
* handleErrors: Enabled by default. If set to true, an error dialog will be automatically shown when the call fails.
* If set to false, the promise will generate a reject error that must be handled by our code.
*
* @returns A promise that resolves correctly if the logout is correct, or rejects with an error (containing all the error
* response details) if the request fails.
*/
logout(options?: {
handleErrors?: boolean;
}): Promise<unknown>;
/**
* Aux methot to clear all the currently logged user data
*/
private _clearUserAndToken;
static ɵfac: i0.ɵɵFactoryDeclaration<TurboApiService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<TurboApiService>;
}
//# sourceMappingURL=turbo-api.service.d.ts.map