@sasjs/adapter 3.6.0 → 3.7.2

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.
@@ -35,10 +35,11 @@ export interface HttpClient {
35
35
  export declare class RequestClient implements HttpClient {
36
36
  protected baseUrl: string;
37
37
  private requests;
38
+ private requestsLimit;
38
39
  protected csrfToken: CsrfToken;
39
40
  protected fileUploadCsrfToken: CsrfToken | undefined;
40
41
  protected httpClient: AxiosInstance;
41
- constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions);
42
+ constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions, requestsLimit?: number);
42
43
  setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions): void;
43
44
  saveLocalStorageToken(accessToken: string, refreshToken: string): void;
44
45
  getCsrfToken(type?: 'general' | 'file'): CsrfToken | undefined;
@@ -60,7 +60,7 @@ export declare class SASjsConfig {
60
60
  */
61
61
  useComputeApi: boolean | null;
62
62
  /**
63
- * Optional settings to configure HTTPS Agent.
63
+ * Optional setting to configure HTTPS Agent.
64
64
  * By providing `key`, `cert`, `ca` to connect with server
65
65
  * Other options can be set `rejectUnauthorized` and `requestCert`
66
66
  */
@@ -69,6 +69,11 @@ export declare class SASjsConfig {
69
69
  * Supported login mechanisms are - Redirected and Default
70
70
  */
71
71
  loginMechanism: LoginMechanism;
72
+ /**
73
+ * Optional setting to configure request history limit. Increasing this limit
74
+ * may affect browser performance, especially with debug (logs) enabled.
75
+ */
76
+ requestHistoryLimit?: number;
72
77
  }
73
78
  export declare enum LoginMechanism {
74
79
  Default = "Default",
@@ -2,7 +2,7 @@
2
2
  * Converts the given JSON object array to a CSV string.
3
3
  * @param data - the array of JSON objects to convert.
4
4
  */
5
- export declare const convertToCSV: (data: any, sasFormats?: {
5
+ export declare const convertToCSV: (data: any[], sasFormats?: {
6
6
  formats: {
7
7
  [key: string]: string;
8
8
  };
package/package.json CHANGED
@@ -80,5 +80,5 @@
80
80
  "https": "1.0.0",
81
81
  "tough-cookie": "4.0.0"
82
82
  },
83
- "version": "3.6.0"
83
+ "version": "3.7.2"
84
84
  }
@@ -35,10 +35,11 @@ export interface HttpClient {
35
35
  export declare class RequestClient implements HttpClient {
36
36
  protected baseUrl: string;
37
37
  private requests;
38
+ private requestsLimit;
38
39
  protected csrfToken: CsrfToken;
39
40
  protected fileUploadCsrfToken: CsrfToken | undefined;
40
41
  protected httpClient: AxiosInstance;
41
- constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions);
42
+ constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions, requestsLimit?: number);
42
43
  setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions): void;
43
44
  saveLocalStorageToken(accessToken: string, refreshToken: string): void;
44
45
  getCsrfToken(type?: 'general' | 'file'): CsrfToken | undefined;
package/src/SASjs.ts CHANGED
@@ -1034,7 +1034,8 @@ export default class SASjs {
1034
1034
  : RequestClient
1035
1035
  this.requestClient = new RequestClientClass(
1036
1036
  this.sasjsConfig.serverUrl,
1037
- this.sasjsConfig.httpsAgentOptions
1037
+ this.sasjsConfig.httpsAgentOptions,
1038
+ this.sasjsConfig.requestHistoryLimit
1038
1039
  )
1039
1040
  } else {
1040
1041
  this.requestClient.setConfig(
@@ -5,8 +5,11 @@ export const generateFileUploadForm = (
5
5
  data: any
6
6
  ): FormData => {
7
7
  for (const tableName in data) {
8
+ if (!Array.isArray(data[tableName])) continue
9
+
8
10
  const name = tableName
9
11
  const csv = convertToCSV(data[tableName])
12
+
10
13
  if (csv === 'ERROR: LARGE STRING LENGTH') {
11
14
  throw new Error(
12
15
  'The max length of a string value in SASjs is 32765 characters.'
@@ -52,17 +52,25 @@ export class SasJsJobExecutor extends BaseJobExecutor {
52
52
  authConfig?.access_token
53
53
  )
54
54
  .then(async (res: any) => {
55
+ const parsedSasjsServerLog = res.result.log
56
+ .map((logLine: any) => logLine.line)
57
+ .join('\n')
58
+
55
59
  const resObj = {
56
60
  result: res.result._webout,
57
- log: res.result.log
61
+ log: parsedSasjsServerLog
58
62
  }
59
63
  this.requestClient!.appendRequest(resObj, sasJob, config.debug)
60
64
 
61
65
  let jsonResponse = res.result
62
66
 
63
67
  if (config.debug) {
64
- const webout = parseWeboutResponse(res.result._webout, apiUrl)
65
- jsonResponse = getValidJson(webout)
68
+ if (typeof res.result._webout === 'object') {
69
+ jsonResponse = res.result._webout
70
+ } else {
71
+ const webout = parseWeboutResponse(res.result._webout, apiUrl)
72
+ jsonResponse = getValidJson(webout)
73
+ }
66
74
  } else {
67
75
  jsonResponse = getValidJson(res.result._webout)
68
76
  }
@@ -146,11 +146,16 @@ export class WebJobExecutor extends BaseJobExecutor {
146
146
  const requestPromise = new Promise((resolve, reject) => {
147
147
  this.requestClient!.post(apiUrl, formData, authConfig?.access_token)
148
148
  .then(async (res: any) => {
149
+ const parsedSasjsServerLog =
150
+ this.serverType === ServerType.Sasjs
151
+ ? res.result.log.map((logLine: any) => logLine.line).join('\n')
152
+ : res.result.log
153
+
149
154
  const resObj =
150
155
  this.serverType === ServerType.Sasjs
151
156
  ? {
152
157
  result: res.result._webout,
153
- log: res.result.log
158
+ log: parsedSasjsServerLog
154
159
  }
155
160
  : res
156
161
  this.requestClient!.appendRequest(resObj, sasJob, config.debug)
@@ -173,8 +178,12 @@ export class WebJobExecutor extends BaseJobExecutor {
173
178
  : res.result
174
179
  break
175
180
  case ServerType.Sasjs:
176
- const webout = parseWeboutResponse(res.result._webout, apiUrl)
177
- jsonResponse = getValidJson(webout)
181
+ if (typeof res.result._webout === 'object') {
182
+ jsonResponse = res.result._webout
183
+ } else {
184
+ const webout = parseWeboutResponse(res.result._webout, apiUrl)
185
+ jsonResponse = getValidJson(webout)
186
+ }
178
187
  break
179
188
  }
180
189
  } else if (this.serverType === ServerType.Sasjs) {
@@ -56,6 +56,7 @@ export interface HttpClient {
56
56
 
57
57
  export class RequestClient implements HttpClient {
58
58
  private requests: SASjsRequest[] = []
59
+ private requestsLimit: number = 10
59
60
 
60
61
  protected csrfToken: CsrfToken = { headerName: '', value: '' }
61
62
  protected fileUploadCsrfToken: CsrfToken | undefined
@@ -63,9 +64,11 @@ export class RequestClient implements HttpClient {
63
64
 
64
65
  constructor(
65
66
  protected baseUrl: string,
66
- httpsAgentOptions?: https.AgentOptions
67
+ httpsAgentOptions?: https.AgentOptions,
68
+ requestsLimit?: number
67
69
  ) {
68
70
  this.createHttpClient(baseUrl, httpsAgentOptions)
71
+ if (requestsLimit) this.requestsLimit = requestsLimit
69
72
  }
70
73
 
71
74
  public setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions) {
@@ -149,7 +152,7 @@ export class RequestClient implements HttpClient {
149
152
  SASWORK: sasWork
150
153
  })
151
154
 
152
- if (this.requests.length > 20) {
155
+ if (this.requests.length > this.requestsLimit) {
153
156
  this.requests.splice(0, 1)
154
157
  }
155
158
  }
@@ -60,7 +60,7 @@ export class SASjsConfig {
60
60
  */
61
61
  useComputeApi: boolean | null = null
62
62
  /**
63
- * Optional settings to configure HTTPS Agent.
63
+ * Optional setting to configure HTTPS Agent.
64
64
  * By providing `key`, `cert`, `ca` to connect with server
65
65
  * Other options can be set `rejectUnauthorized` and `requestCert`
66
66
  */
@@ -69,6 +69,11 @@ export class SASjsConfig {
69
69
  * Supported login mechanisms are - Redirected and Default
70
70
  */
71
71
  loginMechanism: LoginMechanism = LoginMechanism.Default
72
+ /**
73
+ * Optional setting to configure request history limit. Increasing this limit
74
+ * may affect browser performance, especially with debug (logs) enabled.
75
+ */
76
+ requestHistoryLimit?: number = 10
72
77
  }
73
78
 
74
79
  export enum LoginMechanism {
@@ -3,7 +3,7 @@
3
3
  * @param data - the array of JSON objects to convert.
4
4
  */
5
5
  export const convertToCSV = (
6
- data: any,
6
+ data: any[],
7
7
  sasFormats?: { formats: { [key: string]: string } }
8
8
  ) => {
9
9
  let formats = sasFormats?.formats
@@ -76,7 +76,7 @@ export const convertToCSV = (
76
76
  return byteSize
77
77
  }
78
78
  })
79
- .sort((a: number, b: number) => b - a)[0]
79
+ .sort((a: any, b: any) => b - a)[0]
80
80
 
81
81
  if (longestValueForField && longestValueForField > 32765) {
82
82
  invalidString = true
@@ -60,7 +60,7 @@ export declare class SASjsConfig {
60
60
  */
61
61
  useComputeApi: boolean | null;
62
62
  /**
63
- * Optional settings to configure HTTPS Agent.
63
+ * Optional setting to configure HTTPS Agent.
64
64
  * By providing `key`, `cert`, `ca` to connect with server
65
65
  * Other options can be set `rejectUnauthorized` and `requestCert`
66
66
  */
@@ -69,6 +69,11 @@ export declare class SASjsConfig {
69
69
  * Supported login mechanisms are - Redirected and Default
70
70
  */
71
71
  loginMechanism: LoginMechanism;
72
+ /**
73
+ * Optional setting to configure request history limit. Increasing this limit
74
+ * may affect browser performance, especially with debug (logs) enabled.
75
+ */
76
+ requestHistoryLimit?: number;
72
77
  }
73
78
  export declare enum LoginMechanism {
74
79
  Default = "Default",
@@ -2,7 +2,7 @@
2
2
  * Converts the given JSON object array to a CSV string.
3
3
  * @param data - the array of JSON objects to convert.
4
4
  */
5
- export declare const convertToCSV: (data: any, sasFormats?: {
5
+ export declare const convertToCSV: (data: any[], sasFormats?: {
6
6
  formats: {
7
7
  [key: string]: string;
8
8
  };