# Class SASjs

SASjs is a JavaScript adapter for SAS.

### Hierarchy

- SASjs

### Constructors

- constructor

### Methods

- checkSession
- clearSasRequests
- createContext
- createFolder
- createJobDefinition
- createSession
- deleteClient
- deleteContext
- deleteFolder
- deployServicePack
- editContext
- executeScriptSAS9
- executeScriptSASViya
- getAccessToken
- getAllContexts
- getAuthCode
- getComputeContextById
- getComputeContextByName
- getCsrfApi
- getCsrfWeb
- getExecutableContexts
- getSasRequests
- getSasjsConfig
- getUserName
- logIn
- logOut
- moveFolder
- refreshTokens
- request
- setDebugState
- setSASjsConfig
- startComputeJob
- uploadFile

## Constructors

### constructor

- new SASjs(config?: any): SASjs

- - Defined in SASjs.ts:73

  #### Parameters

  - ##### Optional config: any

  #### Returns SASjs

## Methods

### checkSession

- checkSession(): Promise<object>

- - Defined in SASjs.ts:418

  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 SASjs.ts:1355

  #### Returns void

### createContext

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

- - Defined in SASjs.ts:119

  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>

### createFolder

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

- - Defined in SASjs.ts:234

  Creates a folder at SAS file system.

  #### 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 SASjs.ts:292

  #### Parameters

  - ##### jobName: string

  - ##### code: string

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

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

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

  - ##### Optional sasApiClient: SASViyaApiClient

  #### Returns Promise<object>

### createSession

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

- - Defined in SASjs.ts:202

  #### Parameters

  - ##### contextName: string

  - ##### accessToken: string

  #### Returns Promise<Session>

### deleteClient

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

- - Defined in SASjs.ts:353

  #### Parameters

  - ##### clientId: string

  - ##### accessToken: string

  #### Returns Promise<object>

### deleteContext

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

- - Defined in SASjs.ts:164

  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 SASjs.ts:263

  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 SASjs.ts:613

  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>

### editContext

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

- - Defined in SASjs.ts:145

  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>

### executeScriptSAS9

- executeScriptSAS9(linesOfCode: string[], serverName: string, repositoryName: string): Promise<undefined | string>

- - Defined in SASjs.ts:84

  #### Parameters

  - ##### linesOfCode: string[]

  - ##### serverName: string

  - ##### repositoryName: string

  #### Returns Promise<undefined | string>

### executeScriptSASViya

- executeScriptSASViya(fileName: string, linesOfCode: string[], contextName: string, accessToken?: undefined | string): Promise<any>

- - Defined in SASjs.ts:208

  #### Parameters

  - ##### fileName: string

  - ##### linesOfCode: string[]

  - ##### contextName: string

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

  #### Returns Promise<any>

### getAccessToken

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

- - Defined in SASjs.ts:325

  #### Parameters

  - ##### clientId: string

  - ##### clientSecret: string

  - ##### authCode: string

  #### Returns Promise<any>

### getAllContexts

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

- - Defined in SASjs.ts:98

  #### Parameters

  - ##### accessToken: string

  #### Returns Promise<object[]>

### getAuthCode

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

- - Defined in SASjs.ts:319

  #### Parameters

  - ##### clientId: string

  #### Returns Promise<null | string>

### getComputeContextById

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

- - Defined in SASjs.ts:193

  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 SASjs.ts:176

  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>

### getCsrfApi

- getCsrfApi(): undefined | string

- - Defined in SASjs.ts:379

  Returns the _csrf token of the current session for the API approach.

  #### Returns undefined | string

### getCsrfWeb

- getCsrfWeb(): undefined | string

- - Defined in SASjs.ts:387

  Returns the _csrf token of the current session for the WEB approach.

  #### Returns undefined | string

### getExecutableContexts

- getExecutableContexts(accessToken: string): Promise<any[]>

- - Defined in SASjs.ts:104

  #### Parameters

  - ##### accessToken: string

  #### Returns Promise<any[]>

### getSasRequests

- getSasRequests(): SASjsRequest[]

- - Defined in SASjs.ts:1350

  #### Returns SASjsRequest[]

### getSasjsConfig

- getSasjsConfig(): SASjsConfig

- - Defined in SASjs.ts:363

  Returns the current SASjs configuration.

  #### Returns SASjsConfig

### getUserName

- getUserName(): string

- - Defined in SASjs.ts:371

  Returns the username of the user currently logged in.

  #### Returns string

### logIn

- logIn(username: string, password: string): Promise<object>

- - Defined in SASjs.ts:434

  Logs into the SAS server with the supplied credentials.

  #### Parameters

  - ##### username: string

    a string representing the username.

  - ##### password: string

    a string representing the password.

  #### Returns Promise<object>

### logOut

- logOut(): Promise<unknown>

- - Defined in SASjs.ts:503

  Logs out of the configured SAS server.

  #### Returns Promise<unknown>

### moveFolder

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

- - Defined in SASjs.ts:276

  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<any>

- - Defined in SASjs.ts:339

  #### Parameters

  - ##### clientId: string

  - ##### clientSecret: string

  - ##### refreshToken: string

  #### Returns Promise<any>

### request

- request(sasJob: string, data: any, config?: any, loginRequiredCallback?: any, accessToken?: undefined | string): Promise<any>

- - Defined in SASjs.ts:554

  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: 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 loginRequiredCallback: any

    provide a function here to be called if the user is not logged in (eg to display a login form). The request will be resubmitted after logon.

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

  #### Returns Promise<any>

### setDebugState

- setDebugState(value: boolean): void

- - Defined in SASjs.ts:407

  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 SASjs.ts:395

  Sets the SASjs configuration.

  #### Parameters

  - ##### config: SASjsConfig

    SASjs configuration.

  #### Returns Promise<void>

### startComputeJob

- startComputeJob(sasJob: string, data: any, config?: any, accessToken?: undefined | string): Promise<any>

- - Defined in SASjs.ts:687

  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 accessToken: undefined | string

    a valid access token that is authorised to execute compute jobs. The access token is not required when the user is authenticated via the browser.

  #### Returns Promise<any>

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

### uploadFile

- uploadFile(sasJob: string, files: UploadFile[], params: any): Promise<unknown>

- - Defined in SASjs.ts:522

  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: any

    request URL parameters.

  #### Returns Promise<unknown>

Generated using TypeDoc