@sasjs/adapter
Version:
JavaScript adapter for SAS
116 lines (115 loc) • 4.32 kB
TypeScript
import { Session, SessionVariable } from './types';
import { RequestClient } from './request/RequestClient';
export declare class SessionManager {
private serverUrl;
private contextName;
private requestClient;
private loggedErrors;
private sessionStateLinkError;
constructor(serverUrl: string, contextName: string, requestClient: RequestClient);
private sessions;
private currentContext;
private settingContext;
private _debug;
private printedSessionState;
get debug(): boolean;
set debug(value: boolean);
/**
* Checks if session is valid. Session is considered valid if time since it's creation is less than 'sessionInactiveTimeout' attribute.
* @param session - session object.
* @returns - boolean indicating if session is valid.
*/
private isSessionValid;
/**
* Removes session from pool of hot sessions.
* @param session - session object.
* @returns - void.
*/
private removeSessionFromPool;
/**
* Filters session pool to keep only valid sessions.
* @param session - session object.
* @returns - void.
*/
private removeExpiredSessions;
/**
* Throws set of errors as a single error.
* @param errors - array of errors or string.
* @param prefix - an optional final error prefix.
* @returns - never.
*/
private throwErrors;
/**
* Returns session.
* If there is a hot session available, it will be returned immediately and an asynchronous request to create new hot session will be submitted.
* If there is no available session, 2 session creation requests will be submitted. The session is returned once it is created and ready.
* @param accessToken - an optional access token.
* @returns - a promise which resolves with a session.
*/
getSession(accessToken?: string): Promise<Session>;
/**
* Returns error message based on the response from SAS API.
* @param err - an optional access token.
* @param accessToken - an optional access token.
* @returns - an error message.
*/
private getErrorMessage;
/**
* Deletes session.
* @param id - a session id.
* @param accessToken - an optional access token.
* @returns - a promise which resolves when session is deleted.
*/
clearSession(id: string, accessToken?: string): Promise<void>;
/**
* Creates sessions in amount equal to MAX_SESSION_COUNT.
* @param accessToken - an optional access token.
* @returns - a promise which resolves when required amount of sessions is created.
*/
private createSessions;
/**
* Waits for the current context to be set.
* @returns - a promise which resolves when current context is set.
*/
private waitForCurrentContext;
/**
* Creates and waits for session to be ready.
* @param accessToken - an optional access token.
* @returns - a promise which resolves with a session.
*/
private createAndWaitForSession;
/**
* Sets current context.
* @param accessToken - an optional access token.
* @returns - a promise which resolves when current context is set.
*/
private setCurrentContext;
/**
* Waits for session to be ready.
* @param session - a session object.
* @param etag - an etag that can be a string or null.
* @param accessToken - an optional access token.
* @returns - a promise which resolves with a session state.
*/
private waitForSession;
/**
* Gets session state.
* @param url - a URL to get session state.
* @param etag - an etag string.
* @param accessToken - an optional access token.
* @returns - a promise which resolves with a result string and response status.
*/
private getSessionState;
/**
* Gets variable.
* @param sessionId - a session id.
* @param variable - a variable string.
* @param accessToken - an optional access token.
* @returns - a promise which resolves with a result that confirms to SessionVariable interface, etag string and status code.
*/
getVariable(sessionId: string, variable: string, accessToken?: string): Promise<{
result: SessionVariable;
etag: string;
status: number;
}>;
}