/// import { SASjsConfig, UploadFile, EditContextInput, PollOptions } from './types'; import { SASViyaApiClient } from './SASViyaApiClient'; import { SASjsAuthResponse } from './SASjsApiClient'; import { MacroVar, AuthConfig, ExtraResponseAttributes, SasAuthResponse, AuthConfigSas9 } from '@sasjs/utils/types'; import { LoginOptions, LoginResult } from './types/Login'; interface ExecuteScriptParams { linesOfCode: string[]; fileName?: string; contextName?: string; runTime?: string; authConfig?: AuthConfig; authConfigSas9?: AuthConfigSas9; debug?: boolean; } /** * SASjs is a JavaScript adapter for SAS. * */ export default class SASjs { private sasjsConfig; private jobsPath; private sasViyaApiClient; private sas9ApiClient; private sasJSApiClient; private fileUploader; private authManager; private requestClient; private webJobExecutor; private sasjsJobExecutor; private computeJobExecutor; private jesJobExecutor; private sas9JobExecutor; constructor(config?: Partial); getCsrfToken(type?: 'general' | 'file'): import("./types").CsrfToken | undefined; /** * Executes code on a SAS server. * @param linesOfCode - lines of code to run. * @param fileName - (required for server type sas viya) name of the file to run. It will be converted to path to the file being submitted for execution. * @param contextName - (required for server type sas viya) context name on which code will be run on the server. * @param runTime - (required for server type sasjs) a string to represent runTime for code execution. * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts. * @param authConfigSas9 - (required for server type sas9) a valid username and password that are authorised to execute scripts. * @param debug - (optional) if true, global debug config will be overriden */ executeScript({ linesOfCode, fileName, contextName, runTime, authConfig, authConfigSas9, debug }: ExecuteScriptParams): Promise; /** * Gets compute contexts. * @param accessToken - an access token for an authorised user. */ getComputeContexts(accessToken: string): Promise<{ createdBy: any; id: any; name: any; version: any; attributes: {}; }[]>; /** * Gets launcher contexts. * @param accessToken - an access token for an authorised user. */ getLauncherContexts(accessToken: string): Promise<{ createdBy: any; id: any; name: any; version: any; attributes: {}; }[]>; /** * Gets default(system) launcher contexts. */ getDefaultComputeContexts(): string[]; /** * Gets executable compute contexts. * @param authConfig - an access token, refresh token, client and secret for an authorised user. */ getExecutableContexts(authConfig: AuthConfig): Promise; /** * Creates a compute context on the given server. * @param contextName - the name of the context to be created. * @param launchContextName - the name of the launcher context used by the compute service. * @param sharedAccountId - the ID of the account to run the servers for this context as. * @param autoExecLines - the lines of code to execute during session initialization. * @param accessToken - an access token for an authorised user. * @param authorisedUsers - an optional list of authorised user IDs. */ createComputeContext(contextName: string, launchContextName: string, sharedAccountId: string, autoExecLines: string[], accessToken: string, authorisedUsers?: string[]): Promise; /** * Creates a launcher context on the given server. * @param contextName - the name of the context to be created. * @param description - the description of the context to be created. * @param launchType - launch type of the context to be created. * @param accessToken - an access token for an authorised user. */ createLauncherContext(contextName: string, description: string, launchType: string, accessToken: string): Promise; /** * Updates a compute context on the given server. * @param contextName - the original name of the context to be deleted. * @param editedContext - an object with the properties to be updated. * @param accessToken - an access token for an authorised user. */ editComputeContext(contextName: string, editedContext: EditContextInput, accessToken?: string): Promise<{ result: import("./types").Context; etag: string; }>; /** * Deletes a compute context on the given server. * @param contextName - the name of the context to be deleted. * @param accessToken - an access token for an authorised user. */ deleteComputeContext(contextName: string, accessToken?: string): Promise<{ result: import("./types").Context; etag: string; }>; /** * Returns a JSON representation of a compute context. * @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" } * @param contextName - the name of the context to return. * @param accessToken - an access token for an authorised user. */ getComputeContextByName(contextName: string, accessToken?: string): Promise; /** * Returns a JSON representation of a compute context. * @param contextId - an id of the context to return. * @param accessToken - an access token for an authorised user. */ getComputeContextById(contextId: string, accessToken?: string): Promise; createSession(contextName: string, accessToken: string): Promise; /** * Creates a folder in the logical SAS folder tree * @param folderName - name of the folder to be created. * @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder. * @param parentFolderUri - the URI of the parent folder. * @param accessToken - the access token to authorizing the request. * @param sasApiClient - a client for interfacing with SAS API. * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted. Applicable for SAS VIYA only. */ createFolder(folderName: string, parentFolderPath: string, parentFolderUri?: string, accessToken?: string, sasApiClient?: SASViyaApiClient, isForced?: boolean): Promise; /** * Creates a file in the logical SAS folder tree * @param fileName - name of the file to be created. * @param content - content of the file to be created. * @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder. * @param parentFolderUri - the URI of the parent folder. * @param accessToken - the access token to authorizing the request. * @param sasApiClient - a client for interfacing with SAS API. */ createFile(fileName: string, content: Buffer, parentFolderPath: string, parentFolderUri?: string, accessToken?: string, sasApiClient?: SASViyaApiClient): Promise; /** * Fetches a folder from the SAS file system. * @param folderPath - path of the folder to be fetched. * @param accessToken - the access token to authorize the request. */ getFolder(folderPath: string, accessToken?: string): Promise; /** * For performance (and in case of accidental error) the `deleteFolder` function does not actually delete the folder (and all its content and subfolder content). Instead the folder is simply moved to the recycle bin. Deletion time will be added to the folder name. * @param folderPath - the full path (eg `/Public/example/deleteThis`) of the folder to be deleted. * @param accessToken - an access token for authorizing the request. */ deleteFolder(folderPath: string, accessToken: string): Promise; /** * Lists children folders for given Viya folder. * @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder listed. Providing URI instead of path will save one extra request. * @param accessToken - an access token for authorizing the request. */ listFolder(sourceFolder: string, accessToken?: string, limit?: number): Promise; /** * Moves folder to a new location. The folder may be renamed at the same time. * @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request. * @param targetParentFolder - the full path or URI of the _parent_ folder to which the `sourceFolder` will be moved (eg `/Public/newDestination`). To move a folder, a user has to have write permissions in targetParentFolder. Providing URI instead of path will save one extra request. * @param targetFolderName - the name of the "moved" folder. If left blank, the original folder name will be used (eg `myFolder` in `/Public/newDestination/myFolder` for the example above). Optional field. * @param accessToken - an access token for authorizing the request. */ moveFolder(sourceFolder: string, targetParentFolder: string, targetFolderName: string, accessToken: string): Promise; createJobDefinition(jobName: string, code: string, parentFolderPath?: string, parentFolderUri?: string, accessToken?: string, sasApiClient?: SASViyaApiClient): Promise<{ result: import("./types").Job; etag: string; }>; getAuthCode(clientId: string): Promise; /** * Exchanges the auth code for an access token for the given client. * @param clientId - the client ID to authenticate with. * @param clientSecret - the client secret to authenticate with. * @param authCode - the auth code received from the server. */ getAccessToken(clientId: string, clientSecret: string, authCode: string): Promise; /** * Exchanges the refresh token for an access token for the given client. * @param clientId - the client ID to authenticate with. * @param clientSecret - the client secret to authenticate with. * @param refreshToken - the refresh token received from the server. */ refreshTokens(clientId: string, clientSecret: string, refreshToken: string): Promise; deleteClient(clientId: string, accessToken: string): Promise; /** * Returns the current SASjs configuration. * */ getSasjsConfig(): SASjsConfig; /** * Returns the username of the user currently logged in. * */ getUserName(): string; /** * Sets the SASjs configuration. * @param config - SASjs configuration. */ setSASjsConfig(config: SASjsConfig): Promise; /** * 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; /** * 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; /** * 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; /** * Logs out of the configured SAS server. */ logOut(): Promise; /** * 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; /** * 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; /** * Creates the folders and services at the given location `appLoc` on the given server `serverUrl`. * @param serviceJson - the JSON specifying the folders and services to be created. * @param appLoc - the base folder in which to create the new folders and * services. If not provided, is taken from SASjsConfig. * @param serverUrl - the server on which to deploy the folders and services. * If not provided, is taken from SASjsConfig. * @param accessToken - an optional access token to be passed in when * using this function from the command line. * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted. */ deployServicePack(serviceJson: any, appLoc?: string, serverUrl?: string, accessToken?: string, isForced?: boolean): Promise; /** * Kicks off execution of the given job via the compute API. * @returns an object representing the compute session created for the given job. * @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. Can be `null` if no inputs 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 authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs. * The access token is not required when the user is authenticated via the browser. * @param waitForResult - a boolean that indicates whether the function needs to wait for execution to complete. * @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }. * @param printPid - a boolean that indicates whether the function should print (PID) of the started job. * @param variables - an object that represents macro variables. */ startComputeJob(sasJob: string, data: any, config?: any, authConfig?: AuthConfig, waitForResult?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar): Promise; private resendWaitingRequests; /** * Fetches content of the log file * @param logUrl - url of the log file. * @param accessToken - an access token for an authorised user. */ fetchLogFileContent(logUrl: string, accessToken?: string): Promise; /** * this method returns an array of SASjsRequest * @returns SASjsRequest[] */ getSasRequests(): import("./types").SASjsRequest[]; clearSasRequests(): void; private setupConfiguration; private createFoldersAndServices; private isMethodSupported; } export {};