graphdb
Version:
Javascript client library supporting GraphDB and RDF4J REST API.
98 lines (97 loc) • 3.44 kB
TypeScript
export = Server;
/**
* Implementation of the server operations.
*
* If the server against which this client will be used has security enabled,
* then it should be configured with the username and password in the
* {@link ServerClientConfig}. In this case a login attempt is made before any
* API method to be executed. Upon successful login an {@link User} which holds
* the credentials and the authorization token in the context of the client is
* created. In all consecutive API calls the authorization token is sent as a
* http header.
*
* By default {@link ServerClientConfig} is configured with
* <code>keepAlive = true</code> which means that upon authorization token
* expiration current logged-in user would be re-logged automatically before
* next API call. This configuration can be changed within the configuration.
*
* @class
*
* @author Mihail Radkov
* @author Svilen Velikov
* @author Boyan Tonchev
*/
declare class Server {
/**
* @param {ServerClientConfig} config for the server client.
**/
constructor(config: ServerClientConfig);
config: ServerClientConfig;
authenticationService: AuthenticationService;
/**
* Initializes the http client.
*/
initHttpClient(): void;
httpClient: HttpClient;
/**
* Initializes the logger.
*/
initLogger(): void;
logger: ConsoleLogger;
/**
* Executes http request wrapped in provided request builder.
* If the server config provides username and password, then a logging attempt
* is made. Upon successful login the auth data is stored for later requests.
*
* @public
*
* @param {HttpRequestBuilder} requestBuilder
*
* @return {Promise<HttpResponse|Error>} a promise which resolves to response
* wrapper or rejects with error if thrown during execution.
*/
public execute(requestBuilder: HttpRequestBuilder): Promise<HttpResponse | Error>;
/**
* Performs a logout of logged-in user.
*
* This method normally shouldn't be called as it does nothing but just clears
* current authentication token. After that any consecutive API call against
* the secured server will throw <code>Unauthorized</code> error with status
* code <code>401</code> because the token is not sent any more, which in
* result will force re-login for the same user to be executed by default,
* unless the client is configured with
* <code>ServerClientConfig.keepAlive = false</code>
*
* @private
*
* @return {Promise} returns a promise which resolves with undefined.
*/
private logout;
/**
* Allow request config to be altered before sending.
*
* @private
* @param {HttpRequestBuilder} requestBuilder
*/
private decorateRequestConfig;
/**
* Logged user getter.
* @return {User} user
*/
getLoggedUser(): User;
/**
* User setter
* @param {User} user
*
* @return {Server}
*/
setLoggedUser(user: User): Server;
user: User;
}
import ServerClientConfig = require("./server-client-config");
import AuthenticationService = require("../service/authentication-service");
import HttpClient = require("../http/http-client");
import ConsoleLogger = require("../logging/console-logger");
import HttpRequestBuilder = require("../http/http-request-builder");
import HttpResponse = require("../http/http-response");
import User = require("../auth/user");