@sasjs/adapter 3.10.18 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -86,5 +86,5 @@
86
86
  "https": "1.0.0",
87
87
  "tough-cookie": "4.0.0"
88
88
  },
89
- "version": "3.10.18"
89
+ "version": "4.0.0"
90
90
  }
package/src/SASjs.ts CHANGED
@@ -17,7 +17,8 @@ import {
17
17
  AuthConfig,
18
18
  ExtraResponseAttributes,
19
19
  SasAuthResponse,
20
- ServicePackSASjs
20
+ ServicePackSASjs,
21
+ AuthConfigSas9
21
22
  } from '@sasjs/utils/types'
22
23
  import { RequestClient } from './request/RequestClient'
23
24
  import { SasjsRequestClient } from './request/SasjsRequestClient'
@@ -33,6 +34,16 @@ import {
33
34
  import { ErrorResponse } from './types/errors'
34
35
  import { LoginOptions, LoginResult } from './types/Login'
35
36
 
37
+ interface ExecuteScriptParams {
38
+ linesOfCode: string[]
39
+ fileName?: string
40
+ contextName?: string
41
+ runTime?: string
42
+ authConfig?: AuthConfig
43
+ authConfigSas9?: AuthConfigSas9
44
+ debug?: boolean
45
+ }
46
+
36
47
  const defaultConfig: SASjsConfig = {
37
48
  serverUrl: '',
38
49
  pathSASJS: '/SASjsApi/stp/execute',
@@ -79,74 +90,73 @@ export default class SASjs {
79
90
  }
80
91
 
81
92
  /**
82
- * Executes SAS code on a SAS 9 server. Requires a runner to be present in
83
- * the users home directory in metadata.
84
- * @param linesOfCode - lines of sas code from the file to run.
85
- * @param username - a string representing the username.
86
- * @param password - a string representing the password.
93
+ * Executes code on a SAS server.
94
+ * @param linesOfCode - lines of code to run.
95
+ * @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.
96
+ * @param contextName - (required for server type sas viya) context name on which code will be run on the server.
97
+ * @param runTime - (required for server type sasjs) a string to represent runTime for code execution.
98
+ * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
99
+ * @param authConfigSas9 - (required for server type sas9) a valid username and password that are authorised to execute scripts.
100
+ * @param debug - (optional) if true, global debug config will be overriden
87
101
  */
88
- public async executeScriptSAS9(
89
- linesOfCode: string[],
90
- userName: string,
91
- password: string
92
- ) {
93
- this.isMethodSupported('executeScriptSAS9', [ServerType.Sas9])
102
+ public async executeScript({
103
+ linesOfCode,
104
+ fileName,
105
+ contextName,
106
+ runTime,
107
+ authConfig,
108
+ authConfigSas9,
109
+ debug
110
+ }: ExecuteScriptParams) {
111
+ this.isMethodSupported('executeScript', [
112
+ ServerType.Sas9,
113
+ ServerType.Sasjs,
114
+ ServerType.SasViya
115
+ ])
94
116
 
95
- return await this.sas9ApiClient?.executeScript(
96
- linesOfCode,
97
- userName,
98
- password
99
- )
100
- }
117
+ if (this.sasjsConfig.serverType === ServerType.Sas9) {
118
+ if (!authConfigSas9)
119
+ throw new Error('Auth config for sas9 is not provided')
101
120
 
102
- /**
103
- * Executes SAS code on a SASJS server
104
- * @param code - a string of code from the file to run.
105
- * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
106
- */
107
- public async executeScriptSASjs(
108
- code: string,
109
- runTime?: string,
110
- authConfig?: AuthConfig
111
- ) {
112
- this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
121
+ return await this.sas9ApiClient?.executeScript(
122
+ linesOfCode,
123
+ authConfigSas9.userName,
124
+ authConfigSas9.password
125
+ )
126
+ }
113
127
 
114
- return await this.sasJSApiClient?.executeScript(code, runTime, authConfig)
115
- }
128
+ if (this.sasjsConfig.serverType === ServerType.Sasjs) {
129
+ return await this.sasJSApiClient?.executeScript(
130
+ linesOfCode.join('\n'),
131
+ runTime,
132
+ authConfig
133
+ )
134
+ }
116
135
 
117
- /**
118
- * Executes sas code in a SAS Viya compute session.
119
- * @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
120
- * @param linesOfCode - lines of sas code from the file to run.
121
- * @param contextName - context name on which code will be run on the server.
122
- * @param authConfig - (optional) the access token, refresh token, client and secret for authorizing the request.
123
- * @param debug - (optional) if true, global debug config will be overriden
124
- */
125
- public async executeScriptSASViya(
126
- fileName: string,
127
- linesOfCode: string[],
128
- contextName: string,
129
- authConfig?: AuthConfig,
130
- debug?: boolean
131
- ) {
132
- this.isMethodSupported('executeScriptSASViya', [ServerType.SasViya])
136
+ if (this.sasjsConfig.serverType === ServerType.SasViya) {
137
+ contextName = contextName || this.sasjsConfig.contextName
133
138
 
134
- contextName = contextName || this.sasjsConfig.contextName
139
+ if (!contextName) {
140
+ throw new Error(
141
+ 'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
142
+ )
143
+ }
135
144
 
136
- if (!contextName) {
137
- throw new Error(
138
- 'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
145
+ if (!fileName) {
146
+ throw new Error(
147
+ 'File name is required in case of SAS VIYA. Please provide a `fileName`.'
148
+ )
149
+ }
150
+
151
+ return await this.sasViyaApiClient!.executeScript(
152
+ fileName,
153
+ linesOfCode,
154
+ contextName,
155
+ authConfig,
156
+ null,
157
+ debug ? debug : this.sasjsConfig.debug
139
158
  )
140
159
  }
141
-
142
- return await this.sasViyaApiClient!.executeScript(
143
- fileName,
144
- linesOfCode,
145
- contextName,
146
- authConfig,
147
- null,
148
- debug ? debug : this.sasjsConfig.debug
149
- )
150
160
  }
151
161
 
152
162
  /**
@@ -826,33 +836,6 @@ export default class SASjs {
826
836
  )
827
837
  }
828
838
 
829
- /**
830
- * Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
831
- * @param dataJson - the JSON specifying the folders and files to be created, can also includes
832
- * appLoc, streamServiceName, streamWebFolder, streamLogo
833
- * @param appLoc - (optional) the base folder in which to create the new folders and
834
- * services. If not provided, is taken from SASjsConfig. Precedence will be of appLoc present in dataJson.
835
- * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
836
- */
837
- public async deployToSASjs(
838
- dataJson: ServicePackSASjs,
839
- appLoc?: string,
840
- authConfig?: AuthConfig
841
- ) {
842
- if (!appLoc) {
843
- appLoc = this.sasjsConfig.appLoc
844
- }
845
- return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
846
- }
847
-
848
- public async executeJobSASjs(query: ExecutionQuery, authConfig?: AuthConfig) {
849
- return await this.sasJSApiClient?.executeJob(
850
- query,
851
- this.sasjsConfig.appLoc,
852
- authConfig
853
- )
854
- }
855
-
856
839
  /**
857
840
  * Kicks off execution of the given job via the compute API.
858
841
  * @returns an object representing the compute session created for the given job.
@@ -8,6 +8,13 @@ import { getTokens } from './auth/getTokens'
8
8
  export class SASjsApiClient {
9
9
  constructor(private requestClient: RequestClient) {}
10
10
 
11
+ /**
12
+ * Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
13
+ * @param dataJson - the JSON specifying the folders and files to be created, can also includes
14
+ * appLoc, streamServiceName, streamWebFolder, streamLogo
15
+ * @param appLoc - the base folder in which to create the new folders and services.
16
+ * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
17
+ */
11
18
  public async deploy(
12
19
  dataJson: ServicePackSASjs,
13
20
  appLoc: string,
package/src/index.ts CHANGED
@@ -3,4 +3,6 @@ export * from './types'
3
3
  export * from './types/errors'
4
4
  export * from './SASViyaApiClient'
5
5
  export * from './SAS9ApiClient'
6
+ export * from './SASjsApiClient'
7
+ export * from './request/SasjsRequestClient'
6
8
  export default SASjs