@sasjs/adapter 4.5.1 → 4.6.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.
@@ -1,6 +1,6 @@
1
1
  import { RequestClient } from './RequestClient';
2
2
  import { AxiosResponse } from 'axios';
3
- interface SasjsParsedResponse<T> {
3
+ export interface SasjsParsedResponse<T> {
4
4
  result: T;
5
5
  log: string;
6
6
  etag: string;
@@ -15,4 +15,4 @@ export declare class SasjsRequestClient extends RequestClient {
15
15
  getHeaders: (accessToken: string | undefined, contentType: string) => any;
16
16
  protected parseResponse<T>(response: AxiosResponse<any>): SasjsParsedResponse<T>;
17
17
  }
18
- export {};
18
+ export declare const SASJS_LOGS_SEPARATOR = "SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784";
@@ -2,7 +2,6 @@ export * from './appendExtraResponseAttributes';
2
2
  export * from './asyncForEach';
3
3
  export * from './compareTimestamps';
4
4
  export * from './convertToCsv';
5
- export * from './constants';
6
5
  export * from './createAxiosInstance';
7
6
  export * from './delay';
8
7
  export * from './fetchLogByChunks';
package/package.json CHANGED
@@ -84,5 +84,5 @@
84
84
  "https": "1.0.0",
85
85
  "tough-cookie": "4.1.3"
86
86
  },
87
- "version": "4.5.1"
87
+ "version": "4.6.0"
88
88
  }
@@ -1,6 +1,6 @@
1
1
  import { RequestClient } from './RequestClient';
2
2
  import { AxiosResponse } from 'axios';
3
- interface SasjsParsedResponse<T> {
3
+ export interface SasjsParsedResponse<T> {
4
4
  result: T;
5
5
  log: string;
6
6
  etag: string;
@@ -15,4 +15,4 @@ export declare class SasjsRequestClient extends RequestClient {
15
15
  getHeaders: (accessToken: string | undefined, contentType: string) => any;
16
16
  protected parseResponse<T>(response: AxiosResponse<any>): SasjsParsedResponse<T>;
17
17
  }
18
- export {};
18
+ export declare const SASJS_LOGS_SEPARATOR = "SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784";
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  getValidJson,
3
3
  parseSasViyaDebugResponse,
4
- parseWeboutResponse,
5
- SASJS_LOGS_SEPARATOR
4
+ parseWeboutResponse
6
5
  } from '../utils'
7
6
  import { UploadFile } from '../types/UploadFile'
8
7
  import {
@@ -1,8 +1,7 @@
1
1
  import { RequestClient } from './RequestClient'
2
2
  import { AxiosResponse } from 'axios'
3
- import { SASJS_LOGS_SEPARATOR } from '../utils'
4
3
 
5
- interface SasjsParsedResponse<T> {
4
+ export interface SasjsParsedResponse<T> {
6
5
  result: T
7
6
  log: string
8
7
  etag: string
@@ -45,13 +44,30 @@ export class SasjsRequestClient extends RequestClient {
45
44
  }
46
45
  } catch {
47
46
  if (response.data.includes(SASJS_LOGS_SEPARATOR)) {
48
- const splittedResponse = response.data.split(SASJS_LOGS_SEPARATOR)
47
+ const { data } = response
48
+ const splittedResponse: string[] = data.split(SASJS_LOGS_SEPARATOR)
49
49
 
50
- webout = splittedResponse[0]
50
+ webout = splittedResponse.splice(0, 1)[0]
51
51
  if (webout !== undefined) parsedResponse = webout
52
52
 
53
- log = splittedResponse[1]
54
- printOutput = splittedResponse[2]
53
+ // log can contain nested logs
54
+ const logs = splittedResponse.splice(0, splittedResponse.length - 1)
55
+
56
+ // tests if string ends with SASJS_LOGS_SEPARATOR
57
+ const endingWithLogSepRegExp = new RegExp(`${SASJS_LOGS_SEPARATOR}$`)
58
+
59
+ // at this point splittedResponse can contain only one item
60
+ const lastChunk = splittedResponse[0]
61
+
62
+ if (lastChunk) {
63
+ // if the last chunk doesn't end with SASJS_LOGS_SEPARATOR, then it is a printOutput
64
+ // else the last chunk is part of the log and has to be joined
65
+ if (!endingWithLogSepRegExp.test(data)) printOutput = lastChunk
66
+ else if (logs.length > 1) logs.push(lastChunk)
67
+ }
68
+
69
+ // join logs into single log with SASJS_LOGS_SEPARATOR
70
+ log = logs.join(SASJS_LOGS_SEPARATOR)
55
71
  } else {
56
72
  parsedResponse = response.data
57
73
  }
@@ -59,7 +75,7 @@ export class SasjsRequestClient extends RequestClient {
59
75
 
60
76
  const returnResult: SasjsParsedResponse<T> = {
61
77
  result: parsedResponse as T,
62
- log,
78
+ log: log || '',
63
79
  etag,
64
80
  status: response.status
65
81
  }
@@ -69,3 +85,6 @@ export class SasjsRequestClient extends RequestClient {
69
85
  return returnResult
70
86
  }
71
87
  }
88
+
89
+ export const SASJS_LOGS_SEPARATOR =
90
+ 'SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784'
@@ -2,7 +2,6 @@ export * from './appendExtraResponseAttributes'
2
2
  export * from './asyncForEach'
3
3
  export * from './compareTimestamps'
4
4
  export * from './convertToCsv'
5
- export * from './constants'
6
5
  export * from './createAxiosInstance'
7
6
  export * from './delay'
8
7
  export * from './fetchLogByChunks'
package/utils/index.d.ts CHANGED
@@ -2,7 +2,6 @@ export * from './appendExtraResponseAttributes';
2
2
  export * from './asyncForEach';
3
3
  export * from './compareTimestamps';
4
4
  export * from './convertToCsv';
5
- export * from './constants';
6
5
  export * from './createAxiosInstance';
7
6
  export * from './delay';
8
7
  export * from './fetchLogByChunks';
@@ -1 +0,0 @@
1
- export declare const SASJS_LOGS_SEPARATOR = "SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784";
@@ -1,2 +0,0 @@
1
- export const SASJS_LOGS_SEPARATOR =
2
- 'SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784'
@@ -1 +0,0 @@
1
- export declare const SASJS_LOGS_SEPARATOR = "SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784";