# Class SASjs

SASjs is a JavaScript adapter for SAS.

### Hierarchy

- SASjs

### Constructors

- constructor

### Methods

- checkSession
- clearSasRequests
- createComputeContext
- createFile
- createFolder
- createJobDefinition
- createLauncherContext
- createSession
- deleteClient
- deleteComputeContext
- deleteFolder
- deployServicePack
- deployToSASjs
- editComputeContext
- executeJobSASjs
- executeScriptSAS9
- executeScriptSASViya
- fetchLogFileContent
- getAccessToken
- getAuthCode
- getComputeContextById
- getComputeContextByName
- getComputeContexts
- getCsrfToken
- getDefaultComputeContexts
- getExecutableContexts
- getFolder
- getLauncherContexts
- getSasRequests
- getSasjsConfig
- getUserName
- listFolder
- logIn
- logOut
- moveFolder
- refreshTokens
- request
- setDebugState
- setSASjsConfig
- startComputeJob
- uploadFile

## Constructors

### constructor

- new SASjs(config?: Partial<SASjsConfig>): SASjs

- - Defined in src/SASjs.ts:62

  #### Parameters

  - ##### Optional config: Partial<SASjsConfig>

  #### Returns SASjs

## Methods

### checkSession

- checkSession(): Promise<object>

- - Defined in src/SASjs.ts:532

  Checks whether a session is active, or login is required.

  #### Returns Promise<object>

  - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.

### clearSasRequests

- clearSasRequests(): void

- - Defined in src/SASjs.ts:939

  #### Returns void

### createComputeContext

- createComputeContext(contextName: string, launchContextName: string, sharedAccountId: string, autoExecLines: string[], accessToken: string, authorizedUsers?: string[]): Promise<Context>

- - Defined in src/SASjs.ts:139

  Creates a compute context on the given server.

  #### Parameters

  - ##### contextName: string

    the name of the context to be created.

  - ##### launchContextName: string

    the name of the launcher context used by the compute service.

  - ##### sharedAccountId: string

    the ID of the account to run the servers for this context as.

  - ##### autoExecLines: string[]

    the lines of code to execute during session initialization.

  - ##### accessToken: string

    an access token for an authorized user.

  - ##### Optional authorizedUsers: string[]

    an optional list of authorized user IDs.

  #### Returns Promise<Context>

### createFile

- createFile(fileName: string, content: Buffer, parentFolderPath: string, parentFolderUri?: undefined | string, accessToken?: undefined | string, sasApiClient?: SASViyaApiClient): Promise<File>

- - Defined in src/SASjs.ts:328

  Creates a file in the logical SAS folder tree

  #### Parameters

  - ##### fileName: string

    name of the file to be created.

  - ##### content: Buffer

    content of the file to be created.

  - ##### parentFolderPath: string

    the full path (eg `/Public/example/myFolder`) of the parent folder.

  - ##### Optional parentFolderUri: undefined | string

    the URI of the parent folder.

  - ##### Optional accessToken: undefined | string

    the access token to authorizing the request.

  - ##### Optional sasApiClient: SASViyaApiClient

    a client for interfacing with SAS API.

  #### Returns Promise<File>

### createFolder

- createFolder(folderName: string, parentFolderPath: string, parentFolderUri?: undefined | string, accessToken?: undefined | string, sasApiClient?: SASViyaApiClient, isForced?: undefined | false | true): Promise<Folder>

- - Defined in src/SASjs.ts:295

  Creates a folder in the logical SAS folder tree

  #### Parameters

  - ##### folderName: string

    name of the folder to be created.

  - ##### parentFolderPath: string

    the full path (eg `/Public/example/myFolder`) of the parent folder.

  - ##### Optional parentFolderUri: undefined | string

    the URI of the parent folder.

  - ##### Optional accessToken: undefined | string

    the access token to authorizing the request.

  - ##### Optional sasApiClient: SASViyaApiClient

    a client for interfacing with SAS API.

  - ##### Optional isForced: undefined | false | true

    flag that indicates if target folder already exists, it and all subfolders have to be deleted. Applicable for SAS VIYA only.

  #### Returns Promise<Folder>

### createJobDefinition

- createJobDefinition(jobName: string, code: string, parentFolderPath?: undefined | string, parentFolderUri?: undefined | string, accessToken?: undefined | string, sasApiClient?: SASViyaApiClient): Promise<object>

- - Defined in src/SASjs.ts:416

  #### Parameters

  - ##### jobName: string

  - ##### code: string

  - ##### Optional parentFolderPath: undefined | string

  - ##### Optional parentFolderUri: undefined | string

  - ##### Optional accessToken: undefined | string

  - ##### Optional sasApiClient: SASViyaApiClient

  #### Returns Promise<object>

### createLauncherContext

- createLauncherContext(contextName: string, description: string, launchType: string, accessToken: string): Promise<Context>

- - Defined in src/SASjs.ts:166

  Creates a launcher context on the given server.

  #### Parameters

  - ##### contextName: string

    the name of the context to be created.

  - ##### description: string

    the description of the context to be created.

  - ##### launchType: string

    launch type of the context to be created.

  - ##### accessToken: string

    an access token for an authorized user.

  #### Returns Promise<Context>

### createSession

- createSession(contextName: string, accessToken: string): Promise<Session>

- - Defined in src/SASjs.ts:248

  #### Parameters

  - ##### contextName: string

  - ##### accessToken: string

  #### Returns Promise<Session>

### deleteClient

- deleteClient(clientId: string, accessToken: string): Promise<unknown>

- - Defined in src/SASjs.ts:483

  #### Parameters

  - ##### clientId: string

  - ##### accessToken: string

  #### Returns Promise<unknown>

### deleteComputeContext

- deleteComputeContext(contextName: string, accessToken?: undefined | string): Promise<object>

- - Defined in src/SASjs.ts:207

  Deletes a compute context on the given server.

  #### Parameters

  - ##### contextName: string

    the name of the context to be deleted.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<object>

### deleteFolder

- deleteFolder(folderPath: string, accessToken: string): Promise<undefined | Folder>

- - Defined in src/SASjs.ts:368

  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.

  #### Parameters

  - ##### folderPath: string

    the full path (eg `/Public/example/deleteThis`) of the folder to be deleted.

  - ##### accessToken: string

    an access token for authorizing the request.

  #### Returns Promise<undefined | Folder>

### deployServicePack

- deployServicePack(serviceJson: any, appLoc?: undefined | string, serverUrl?: undefined | string, accessToken?: undefined | string, isForced?: boolean): Promise<void>

- - Defined in src/SASjs.ts:770

  Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.

  #### Parameters

  - ##### serviceJson: any

    the JSON specifying the folders and services to be created.

  - ##### Optional appLoc: undefined | string

    the base folder in which to create the new folders and services. If not provided, is taken from SASjsConfig.

  - ##### Optional serverUrl: undefined | string

    the server on which to deploy the folders and services. If not provided, is taken from SASjsConfig.

  - ##### Optional accessToken: undefined | string

    an optional access token to be passed in when using this function from the command line.

  - ##### Default value isForced: boolean = false

    flag that indicates if target folder already exists, it and all subfolders have to be deleted.

  #### Returns Promise<void>

### deployToSASjs

- deployToSASjs(members: [FolderMember, ServiceMember]): Promise<undefined | object>

- - Defined in src/SASjs.ts:831

  #### Parameters

  - ##### members: [FolderMember, ServiceMember]

  #### Returns Promise<undefined | object>

### editComputeContext

- editComputeContext(contextName: string, editedContext: EditContextInput, accessToken?: undefined | string): Promise<object>

- - Defined in src/SASjs.ts:188

  Updates a compute context on the given server.

  #### Parameters

  - ##### contextName: string

    the original name of the context to be deleted.

  - ##### editedContext: EditContextInput

    an object with the properties to be updated.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<object>

### executeJobSASjs

- executeJobSASjs(query: ExecutionQuery): Promise<undefined | object>

- - Defined in src/SASjs.ts:835

  #### Parameters

  - ##### query: ExecutionQuery

  #### Returns Promise<undefined | object>

### executeScriptSAS9

- executeScriptSAS9(linesOfCode: string[], userName: string, password: string): Promise<undefined | string>

- - Defined in src/SASjs.ts:77

  #### Parameters

  - ##### linesOfCode: string[]

  - ##### userName: string

  - ##### password: string

  #### Returns Promise<undefined | string>

### executeScriptSASViya

- executeScriptSASViya(fileName: string, linesOfCode: string[], contextName: string, authConfig?: AuthConfig, debug?: undefined | false | true): Promise<any>

- - Defined in src/SASjs.ts:262

  Executes the sas code against given sas server

  #### Parameters

  - ##### fileName: string

    name of the file to run. It will be converted to path to the file being submitted for execution.

  - ##### linesOfCode: string[]

    lines of sas code from the file to run.

  - ##### contextName: string

    context name on which code will be run on the server.

  - ##### Optional authConfig: AuthConfig

    (optional) the access token, refresh token, client and secret for authorizing the request.

  - ##### Optional debug: undefined | false | true

    (optional) if true, global debug config will be overriden

  #### Returns Promise<any>

### fetchLogFileContent

- fetchLogFileContent(logUrl: string, accessToken?: undefined | string): Promise<string>

- - Defined in src/SASjs.ts:905

  Fetches content of the log file

  #### Parameters

  - ##### logUrl: string

    url of the log file.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<string>

### getAccessToken

- getAccessToken(clientId: string, clientSecret: string, authCode: string): Promise<SasAuthResponse>

- - Defined in src/SASjs.ts:455

  Exchanges the auth code for an access token for the given client.

  #### Parameters

  - ##### clientId: string

    the client ID to authenticate with.

  - ##### clientSecret: string

    the client secret to authenticate with.

  - ##### authCode: string

    the auth code received from the server.

  #### Returns Promise<SasAuthResponse>

### getAuthCode

- getAuthCode(clientId: string): Promise<null | string>

- - Defined in src/SASjs.ts:443

  #### Parameters

  - ##### clientId: string

  #### Returns Promise<null | string>

### getComputeContextById

- getComputeContextById(contextId: string, accessToken?: undefined | string): Promise<ContextAllAttributes>

- - Defined in src/SASjs.ts:239

  Returns a JSON representation of a compute context.

  #### Parameters

  - ##### contextId: string

    an id of the context to return.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<ContextAllAttributes>

### getComputeContextByName

- getComputeContextByName(contextName: string, accessToken?: undefined | string): Promise<Context>

- - Defined in src/SASjs.ts:222

  Returns a JSON representation of a compute context.

  example:

    { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }

  #### Parameters

  - ##### contextName: string

    the name of the context to return.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<Context>

### getComputeContexts

- getComputeContexts(accessToken: string): Promise<object[]>

- - Defined in src/SASjs.ts:95

  Gets compute contexts.

  #### Parameters

  - ##### accessToken: string

    an access token for an authorized user.

  #### Returns Promise<object[]>

### getCsrfToken

- getCsrfToken(type?: "general" | "file"): undefined | CsrfToken

- - Defined in src/SASjs.ts:73

  #### Parameters

  - ##### Default value type: "general" | "file" = "general"

  #### Returns undefined | CsrfToken

### getDefaultComputeContexts

- getDefaultComputeContexts(): string[]

- - Defined in src/SASjs.ts:114

  Gets default(system) launcher contexts.

  #### Returns string[]

### getExecutableContexts

- getExecutableContexts(authConfig: AuthConfig): Promise<any[]>

- - Defined in src/SASjs.ts:124

  Gets executable compute contexts.

  #### Parameters

  - ##### authConfig: AuthConfig

    an access token, refresh token, client and secret for an authorized user.

  #### Returns Promise<any[]>

### getFolder

- getFolder(folderPath: string, accessToken?: undefined | string): Promise<unknown>

- - Defined in src/SASjs.ts:358

  Fetches a folder from the SAS file system.

  #### Parameters

  - ##### folderPath: string

    path of the folder to be fetched.

  - ##### Optional accessToken: undefined | string

    the access token to authorize the request.

  #### Returns Promise<unknown>

### getLauncherContexts

- getLauncherContexts(accessToken: string): Promise<object[]>

- - Defined in src/SASjs.ts:105

  Gets launcher contexts.

  #### Parameters

  - ##### accessToken: string

    an access token for an authorized user.

  #### Returns Promise<object[]>

### getSasRequests

- getSasRequests(): SASjsRequest[]

- - Defined in src/SASjs.ts:933

  this method returns an array of SASjsRequest

  #### Returns SASjsRequest[]

  SASjsRequest[]

### getSasjsConfig

- getSasjsConfig(): SASjsConfig

- - Defined in src/SASjs.ts:493

  Returns the current SASjs configuration.

  #### Returns SASjsConfig

### getUserName

- getUserName(): string

- - Defined in src/SASjs.ts:501

  Returns the username of the user currently logged in.

  #### Returns string

### listFolder

- listFolder(sourceFolder: string, accessToken?: undefined | string, limit?: undefined | number): Promise<undefined | any[]>

- - Defined in src/SASjs.ts:379

  Lists children folders for given Viya folder.

  #### Parameters

  - ##### sourceFolder: string

    the full path (eg `/Public/example/myFolder`) or URI of the source folder listed. Providing URI instead of path will save one extra request.

  - ##### Optional accessToken: undefined | string

    an access token for authorizing the request.

  - ##### Optional limit: undefined | number

  #### Returns Promise<undefined | any[]>

### logIn

- logIn(username?: undefined | string, password?: undefined | string, options?: LoginOptions): Promise<LoginResult>

- - Defined in src/SASjs.ts:541

  Logs into the SAS server with the supplied credentials.

  #### Parameters

  - ##### Optional username: undefined | string

    a string representing the username.

  - ##### Optional password: undefined | string

    a string representing the password.

  - ##### Default value options: LoginOptions = {}

  #### Returns Promise<LoginResult>

### logOut

- logOut(): Promise<boolean>

- - Defined in src/SASjs.ts:567

  Logs out of the configured SAS server.

  #### Returns Promise<boolean>

### moveFolder

- moveFolder(sourceFolder: string, targetParentFolder: string, targetFolderName: string, accessToken: string): Promise<undefined | Folder>

- - Defined in src/SASjs.ts:400

  Moves folder to a new location. The folder may be renamed at the same time.

  #### Parameters

  - ##### sourceFolder: string

    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.

  - ##### targetParentFolder: string

    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.

  - ##### targetFolderName: string

    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.

  - ##### accessToken: string

    an access token for authorizing the request.

  #### Returns Promise<undefined | Folder>

### refreshTokens

- refreshTokens(clientId: string, clientSecret: string, refreshToken: string): Promise<SasAuthResponse>

- - Defined in src/SASjs.ts:469

  #### Parameters

  - ##### clientId: string

  - ##### clientSecret: string

  - ##### refreshToken: string

  #### Returns Promise<SasAuthResponse>

### request

- request(sasJob: string, data: object | null, config?: object, loginRequiredCallback?: undefined | function, authConfig?: AuthConfig, extraResponseAttributes?: ExtraResponseAttributes[]): Promise<any>

- - Defined in src/SASjs.ts:631

  Makes a request to the SAS Service specified in `SASjob`. 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.

  #### Parameters

  - ##### sasJob: string

    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`.

  - ##### data: object | null

    a JSON object containing one or more tables to be sent to SAS. Can be `null` if no inputs required.

  - ##### Default value config: object = {}

    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.

    - ##### [key: string]: any

  - ##### Optional loginRequiredCallback: undefined | function

    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))`

  - ##### Optional authConfig: AuthConfig

  - ##### Default value extraResponseAttributes: 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.

  #### Returns Promise<any>

### setDebugState

- setDebugState(value: boolean): void

- - Defined in src/SASjs.ts:521

  Sets the debug state. Turning this on will enable additional logging in the adapter.

  #### Parameters

  - ##### value: boolean

    boolean indicating debug state (on/off).

  #### Returns void

### setSASjsConfig

- setSASjsConfig(config: SASjsConfig): Promise<void>

- - Defined in src/SASjs.ts:509

  Sets the SASjs configuration.

  #### Parameters

  - ##### config: SASjsConfig

    SASjs configuration.

  #### Returns Promise<void>

### startComputeJob

- startComputeJob(sasJob: string, data: any, config?: any, authConfig?: AuthConfig, waitForResult?: undefined | false | true, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar): Promise<any>

- - Defined in src/SASjs.ts:857

  Kicks off execution of the given job via the compute API.

  #### Parameters

  - ##### sasJob: string

    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`.

  - ##### data: any

    a JSON object containing one or more tables to be sent to SAS. Can be `null` if no inputs required.

  - ##### Default value config: any = {}

    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.

  - ##### Optional authConfig: 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.

  - ##### Optional waitForResult: undefined | false | true

    a boolean that indicates whether the function needs to wait for execution to complete.

  - ##### Optional pollOptions: PollOptions

    an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }.

  - ##### Default value printPid: boolean = false

    a boolean that indicates whether the function should print (PID) of the started job.

  - ##### Optional variables: MacroVar

    an object that represents macro variables.

  #### Returns Promise<any>

  an object representing the compute session created for the given job.

### uploadFile

- uploadFile(sasJob: string, files: UploadFile[], params: object | null, config?: object, loginRequiredCallback?: undefined | function): Promise<unknown>

- - Defined in src/SASjs.ts:585

  Uploads a file to the given service.

  #### Parameters

  - ##### sasJob: string

    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`.

  - ##### files: UploadFile[]

    array of files to be uploaded, including File object and file name.

  - ##### params: object | null

    request URL parameters.

  - ##### Default value config: object = {}

    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.

    - ##### [key: string]: any

  - ##### Optional loginRequiredCallback: undefined | function

    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.

  #### Returns Promise<unknown>

Generated using TypeDoc