UNPKG

@sasjs/adapter

Version:

JavaScript adapter for SAS

101 lines (100 loc) 4.86 kB
import { SASjsConfig, UploadFile } from '../../types'; import { AuthConfig, ExtraResponseAttributes } from '@sasjs/utils/types'; import { LoginOptions, LoginResult } from '../../types/Login'; /** * SASjs is a JavaScript adapter for SAS. * */ export default class SASjs { private sasjsConfig; private jobsPath; private fileUploader; private authManager; private requestClient; private webJobExecutor; constructor(config?: Partial<SASjsConfig>); /** * Logs into the SAS server with the supplied credentials. * @param username - a string representing the username. * @param password - a string representing the password. * @param clientId - a string representing the client ID. */ logIn(username?: string, password?: string, clientId?: string, options?: LoginOptions): Promise<LoginResult>; /** * Logs out of the configured SAS server. */ logOut(): Promise<boolean>; /** * Returns the current SASjs configuration. * */ getSasjsConfig(): SASjsConfig; /** * this method returns an array of SASjsRequest * @returns SASjsRequest[] */ getSasRequests(): import("../../types").SASjsRequest[]; /** * Sets the debug state. Turning this on will enable additional logging in the adapter. * @param value - boolean indicating debug state (on/off). */ setDebugState(value: boolean): void; /** * Uploads a file to the given service. * @param sasJob - the path to the SAS program (ultimately resolves to * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored * Process). Is prepended at runtime with the value of `appLoc`. * @param files - array of files to be uploaded, including File object and file name. * @param params - request URL parameters. * @param config - provide any changes to the config here, for instance to * enable/disable `debug`. Any change provided will override the global config, * for that particular function call. * @param loginRequiredCallback - a function that is called if the * user is not logged in (eg to display a login form). The request will be * resubmitted after successful login. */ uploadFile(sasJob: string, files: UploadFile[], params: { [key: string]: any; } | null, config?: { [key: string]: any; }, loginRequiredCallback?: () => any): Promise<unknown>; /** * Makes a request to program specified in `SASjob` (could be a Viya Job, a * SAS 9 Stored Process, or a SASjs Server Stored Program). The response * object will always contain table names in lowercase, and column names in * uppercase. Values are returned formatted by default, unformatted * values can be configured as an option in the `%webout` macro. * * @param sasJob - the path to the SAS program (ultimately resolves to * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored * Process). Is prepended at runtime with the value of `appLoc`. * @param data - a JSON object containing one or more tables to be sent to * SAS. For an example of the table structure, see the project README. This * value can be `null` if no inputs are required. * @param config - provide any changes to the config here, for instance to * enable/disable `debug`. Any change provided will override the global config, * for that particular function call. * @param loginRequiredCallback - a function that is called if the * user is not logged in (eg to display a login form). The request will be * resubmitted after successful login. * When using a `loginRequiredCallback`, the call to the request will look, for example, like so: * `await request(sasJobPath, data, config, () => setIsLoggedIn(false))` * If you are not passing in any data and configuration, it will look like so: * `await request(sasJobPath, {}, {}, () => setIsLoggedIn(false))` * @param extraResponseAttributes - a array of predefined values that are used * to provide extra attributes (same names as those values) to be added in response * Supported values are declared in ExtraResponseAttributes type. */ request(sasJob: string, data: { [key: string]: any; } | null, config?: { [key: string]: any; }, loginRequiredCallback?: () => any, authConfig?: AuthConfig, extraResponseAttributes?: ExtraResponseAttributes[]): Promise<unknown>; /** * Checks whether a session is active, or login is required. * @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`. */ checkSession(): Promise<import("../../types").LoginResultInternal>; private setupConfiguration; private resendWaitingRequests; }