/// import { Job, Session, Context, ContextAllAttributes, Folder, File, EditContextInput, PollOptions } from './types'; import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'; import { RequestClient } from './request/RequestClient'; /** * A client for interfacing with the SAS Viya REST API. * */ export declare class SASViyaApiClient { private serverUrl; private rootFolderName; private contextName; private requestClient; constructor(serverUrl: string, rootFolderName: string, contextName: string, requestClient: RequestClient); private _debug; private sessionManager; private contextManager; private folderMap; /** * A helper method used to call appendRequest method of RequestClient * @param response - response from sasjs request * @param program - name of program * @param debug - a boolean that indicates whether debug was enabled or not */ appendRequest(response: any, program: string, debug: boolean): void; get debug(): boolean; set debug(value: boolean); /** * Returns a list of jobs in the currently set root folder. */ getJobsInFolder(folderPath: string): Promise; /** * Returns an object containing the server URL and root folder name. */ getConfig(): { serverUrl: string; rootFolderName: string; }; /** * Updates server URL and root folder name, if it was not set. * @param serverUrl - the URL of the server. * @param rootFolderName - the name for root folder. */ setConfig(serverUrl: string, rootFolderName: string): void; /** * Returns all available compute contexts on this server. * @param accessToken - an access token for an authorized user. */ getComputeContexts(accessToken?: string): Promise<{ createdBy: any; id: any; name: any; version: any; attributes: {}; }[]>; /** * Returns default(system) compute contexts. */ getDefaultComputeContexts(): string[]; /** * Returns all available launcher contexts on this server. * @param accessToken - an access token for an authorized user. */ getLauncherContexts(accessToken?: string): Promise<{ createdBy: any; id: any; name: any; version: any; attributes: {}; }[]>; /** * Returns all compute contexts on this server that the user has access to. * @param authConfig - an access token, refresh token, client and secret for an authorized user. */ getExecutableContexts(authConfig?: AuthConfig): Promise; /** * Creates a session on the given context. * @param contextName - the name of the context to create a session on. * @param accessToken - an access token for an authorized user. */ createSession(contextName: string, accessToken?: string): 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. * @param autoExecLines - the lines of code to execute during session initialization. * @param accessToken - an access token for an authorized user. * @param authorizedUsers - an optional list of authorized user IDs. */ createComputeContext(contextName: string, launchContextName: string, sharedAccountId: string, autoExecLines: string[], accessToken?: string, authorizedUsers?: 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 authorized 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 updated. * @param editedContext - an object with the properties to be updated. * @param accessToken - an access token for an authorized user. */ editComputeContext(contextName: string, editedContext: EditContextInput, accessToken?: string): Promise<{ result: 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 authorized user. */ deleteComputeContext(contextName: string, accessToken?: string): Promise<{ result: Context; etag: string; }>; /** * Executes code on the current SAS Viya server. * @param jobPath - the path to the file being submitted for execution. * @param linesOfCode - an array of code lines to execute. * @param contextName - the context to execute the code in. * @param authConfig - an object containing an access token, refresh token, client ID and secret. * @param data - execution data. * @param debug - when set to true, the log will be returned. * @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code). * @param waitForResult - when set to true, function will return the session * @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. */ executeScript(jobPath: string, linesOfCode: string[], contextName: string, authConfig?: AuthConfig, data?: null, debug?: boolean, expectWebout?: boolean, waitForResult?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar): Promise; /** * Fetches a folder. Path to the folder is required. * @param folderPath - the absolute path to the folder. * @param accessToken - an access token for authorizing the request. */ getFolder(folderPath: string, accessToken?: string): Promise; /** * Creates a file. Path to or URI of the parent folder is required. * @param fileName - the name of the new file. * @param contentBuffer - the content of the new file in Buffer. * @param parentFolderPath - the full path to the parent folder. If not * provided, the parentFolderUri must be provided. * @param parentFolderUri - the URI (eg /folders/folders/UUID) of the parent * folder. If not provided, the parentFolderPath must be provided. * @param accessToken - an access token for authorizing the request. */ createFile(fileName: string, contentBuffer: Buffer, parentFolderPath?: string, parentFolderUri?: string, accessToken?: string): Promise; /** * Creates a folder. Path to or URI of the parent folder is required. * @param folderName - the name of the new folder. * @param parentFolderPath - the full path to the parent folder. If not * provided, the parentFolderUri must be provided. * @param parentFolderUri - the URI (eg /folders/folders/UUID) of the parent * folder. If not provided, the parentFolderPath must be provided. * @param accessToken - an access token for authorizing the request. * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted. */ createFolder(folderName: string, parentFolderPath?: string, parentFolderUri?: string, accessToken?: string, isForced?: boolean): Promise; /** * Creates a Job in the specified folder (or folder uri). * @param parentFolderPath - the location of the new job. * @param parentFolderUri - the URI location of the new job. The function is a * little faster if the folder URI is supplied instead of the path. * @param jobName - the name of the new job to be created. * @param code - the SAS code for the new job. */ createJobDefinition(jobName: string, code: string, parentFolderPath?: string, parentFolderUri?: string, accessToken?: string): Promise<{ result: Job; etag: string; }>; /** * Performs a login redirect and returns an auth code for the given client. * @param clientId - the client ID to authenticate with. */ 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; /** * Deletes the client representing the supplied ID. * @param clientId - the client ID to authenticate with. * @param accessToken - an access token for authorizing the request. */ deleteClient(clientId: string, accessToken?: string): Promise; /** * Executes a job via the SAS Viya Compute API. * @param sasJob - the relative path to the job. * @param contextName - the name of the context where the job is to be executed. * @param debug - sets the _debug flag in the job arguments. * @param data - any data to be passed in as input to the job. * @param accessToken - an optional access token for an authorized user. * @param waitForResult - a boolean indicating if the function should wait for a result. * @param expectWebout - a boolean indicating whether to expect a _webout response. * @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. */ executeComputeJob(sasJob: string, contextName: string, debug?: boolean, data?: any, authConfig?: AuthConfig, waitForResult?: boolean, expectWebout?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar): Promise; /** * Executes a job via the SAS Viya Job Execution API * @param sasJob - the relative or absolute path to the job. * @param contextName - the name of the context where the job is to be executed. * @param debug - sets the _debug flag in the job arguments. * @param data - any data to be passed in as input to the job. * @param accessToken - an optional access token for an authorized user. */ executeJob(sasJob: string, contextName: string, debug: boolean, data?: any, authConfig?: AuthConfig): Promise<{ result: any; log: any; }>; private populateFolderMap; private pollJobState; private uploadTables; private getFolderDetails; private getFolderUri; private getRecycleBinUri; /** * 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 authorized 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 authorized user. */ getComputeContextById(contextId: 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 Viya 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 the 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; /** * 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; }