@sasjs/adapter 3.10.10 → 3.10.13

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.
Files changed (43) hide show
  1. package/README.md +2 -1
  2. package/SASjs.d.ts +2 -1
  3. package/SASjsApiClient.d.ts +2 -1
  4. package/index.js +2 -2
  5. package/job-execution/JobExecutor.d.ts +1 -0
  6. package/job-execution/Sas9JobExecutor.d.ts +1 -1
  7. package/job-execution/SasjsJobExecutor.d.ts +9 -0
  8. package/job-execution/WebJobExecutor.d.ts +0 -2
  9. package/job-execution/index.d.ts +1 -0
  10. package/node/SASjs.d.ts +2 -1
  11. package/node/SASjsApiClient.d.ts +2 -1
  12. package/node/index.js +2 -2
  13. package/node/job-execution/JobExecutor.d.ts +1 -0
  14. package/node/job-execution/Sas9JobExecutor.d.ts +1 -1
  15. package/node/job-execution/SasjsJobExecutor.d.ts +9 -0
  16. package/node/job-execution/WebJobExecutor.d.ts +0 -2
  17. package/node/job-execution/index.d.ts +1 -0
  18. package/node/request/SasjsRequestClient.d.ts +7 -0
  19. package/node/types/errors/InvalidSASjsCsrfError.d.ts +3 -0
  20. package/node/utils/constants.d.ts +1 -0
  21. package/node/utils/index.d.ts +1 -0
  22. package/package.json +1 -1
  23. package/request/SasjsRequestClient.d.ts +7 -0
  24. package/src/SASjs.ts +15 -3
  25. package/src/SASjsApiClient.ts +9 -8
  26. package/src/auth/AuthManager.ts +10 -2
  27. package/src/job-execution/FileUploader.ts +3 -15
  28. package/src/job-execution/JobExecutor.ts +14 -1
  29. package/src/job-execution/Sas9JobExecutor.ts +1 -1
  30. package/src/job-execution/SasjsJobExecutor.ts +141 -0
  31. package/src/job-execution/WebJobExecutor.ts +4 -78
  32. package/src/job-execution/index.ts +1 -0
  33. package/src/request/RequestClient.ts +17 -25
  34. package/src/request/SasjsRequestClient.ts +31 -0
  35. package/src/types/errors/InvalidSASjsCsrfError.ts +9 -0
  36. package/src/utils/constants.ts +2 -0
  37. package/src/utils/index.ts +1 -0
  38. package/types/errors/InvalidSASjsCsrfError.d.ts +3 -0
  39. package/utils/constants.d.ts +1 -0
  40. package/utils/index.d.ts +1 -0
  41. package/node/types/errors/InvalidCsrfError.d.ts +0 -3
  42. package/src/types/errors/InvalidCsrfError.ts +0 -9
  43. package/types/errors/InvalidCsrfError.d.ts +0 -3
@@ -1,9 +1,12 @@
1
1
  import { RequestClient } from './RequestClient'
2
+ import { AxiosResponse } from 'axios'
3
+ import { SASJS_LOGS_SEPARATOR, getValidJson } from '../utils'
2
4
 
3
5
  /**
4
6
  * Specific request client for SASJS.
5
7
  * Append tokens in headers.
6
8
  */
9
+
7
10
  export class SasjsRequestClient extends RequestClient {
8
11
  getHeaders = (accessToken: string | undefined, contentType: string) => {
9
12
  const headers: any = {}
@@ -20,4 +23,32 @@ export class SasjsRequestClient extends RequestClient {
20
23
 
21
24
  return headers
22
25
  }
26
+
27
+ protected parseResponse<T>(response: AxiosResponse<any>) {
28
+ const etag = response?.headers ? response.headers['etag'] : ''
29
+ let parsedResponse
30
+ let log
31
+
32
+ try {
33
+ if (typeof response.data === 'string') {
34
+ parsedResponse = JSON.parse(response.data)
35
+ } else {
36
+ parsedResponse = response.data
37
+ }
38
+ } catch {
39
+ if (response.data.includes(SASJS_LOGS_SEPARATOR)) {
40
+ parsedResponse = getValidJson(
41
+ response.data.split(SASJS_LOGS_SEPARATOR)[0]
42
+ )
43
+ log = response.data.split(SASJS_LOGS_SEPARATOR)[1]
44
+ } else parsedResponse = response.data
45
+ }
46
+
47
+ return {
48
+ result: parsedResponse as T,
49
+ log,
50
+ etag,
51
+ status: response.status
52
+ }
53
+ }
23
54
  }
@@ -0,0 +1,9 @@
1
+ export class InvalidSASjsCsrfError extends Error {
2
+ constructor() {
3
+ const message = 'Invalid CSRF token!'
4
+
5
+ super(`Auth error: ${message}`)
6
+ this.name = 'InvalidSASjsCsrfError'
7
+ Object.setPrototypeOf(this, InvalidSASjsCsrfError.prototype)
8
+ }
9
+ }
@@ -0,0 +1,2 @@
1
+ export const SASJS_LOGS_SEPARATOR =
2
+ 'SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784'
@@ -2,6 +2,7 @@ export * from './appendExtraResponseAttributes'
2
2
  export * from './asyncForEach'
3
3
  export * from './compareTimestamps'
4
4
  export * from './convertToCsv'
5
+ export * from './constants'
5
6
  export * from './createAxiosInstance'
6
7
  export * from './delay'
7
8
  export * from './fetchLogByChunks'
@@ -0,0 +1,3 @@
1
+ export declare class InvalidSASjsCsrfError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1 @@
1
+ export declare const SASJS_LOGS_SEPARATOR = "SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784";
package/utils/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './appendExtraResponseAttributes';
2
2
  export * from './asyncForEach';
3
3
  export * from './compareTimestamps';
4
4
  export * from './convertToCsv';
5
+ export * from './constants';
5
6
  export * from './createAxiosInstance';
6
7
  export * from './delay';
7
8
  export * from './fetchLogByChunks';
@@ -1,3 +0,0 @@
1
- export declare class InvalidCsrfError extends Error {
2
- constructor();
3
- }
@@ -1,9 +0,0 @@
1
- export class InvalidCsrfError extends Error {
2
- constructor() {
3
- const message = 'Invalid CSRF token!'
4
-
5
- super(`Auth error: ${message}`)
6
- this.name = 'InvalidCsrfError'
7
- Object.setPrototypeOf(this, InvalidCsrfError.prototype)
8
- }
9
- }
@@ -1,3 +0,0 @@
1
- export declare class InvalidCsrfError extends Error {
2
- constructor();
3
- }