1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 09:24:35 +00:00

Compare commits

..

13 Commits

Author SHA1 Message Date
Yury Shkoda
5aee9d955e Merge pull request #106 from sasjs/cli-issue-105
feat(context): made getContextByName function public
2020-09-24 08:38:47 +03:00
Yury Shkoda
7fb1da31e4 Merge branch 'master' into cli-issue-105 2020-09-24 08:35:28 +03:00
Allan Bowe
1aa92c0a69 Merge pull request #107 from sasjs/access-token-missed
Access token missed
2020-09-23 21:26:46 +02:00
Mihajlo Medjedovic
4c097a69fd style: lint 2020-09-23 20:43:41 +02:00
Mihajlo Medjedovic
2634933e84 fix: accessToken not passed in function calls 2020-09-23 20:41:31 +02:00
Yury Shkoda
d60c0850c2 docs(context): update docs related to getComputeContextByName function 2020-09-23 17:21:27 +03:00
Yury Shkoda
491bc3371c feat(context): made getContextByName function public 2020-09-23 16:38:21 +03:00
Krishna Acondy
c1bab07b08 Merge pull request #105 from sasjs/file-upload-csrf
fix(jes-job-execution): prevent file upload requests failing with invalid CSRF token
2020-09-23 08:04:18 +01:00
Krishna Acondy
95f3ebd51d chore(dx): add pull request template 2020-09-22 12:40:11 +01:00
Krishna Acondy
0e5b72b54f Merge branch 'master' into file-upload-csrf 2020-09-22 12:29:48 +01:00
Krishna Acondy
33ce592379 fix(*): fix build issue with iconv-loader 2020-09-22 10:51:44 +01:00
Krishna Acondy
9f6591d7e3 chore(sasjs-tests): fix failing tests, bump adapter version 2020-09-22 09:32:45 +01:00
Krishna Acondy
5343ca00d8 fix(file-upload): maintain separate CSRF token for file uploads 2020-09-22 09:26:16 +01:00
34 changed files with 3893 additions and 47 deletions

17
PULL_REQUEST_TEMPLATE.md Normal file
View File

@@ -0,0 +1,17 @@
## Issue
Link any related issue(s) in this section.
## Intent
What this PR intends to achieve.
## Implementation
What code changes have been made to achieve the intent.
## Checks
- [ ] Code is formatted correctly (`npm run lint:fix`).
- [ ] All unit tests are passing (`npm test`).
- [ ] All `sasjs-tests` are passing (instructions available [here](https://github.com/sasjs/adapter/blob/master/sasjs-tests/README.md)).

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1357,9 +1357,9 @@
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
},
"@sasjs/adapter": {
"version": "1.3.13",
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.3.13.tgz",
"integrity": "sha512-dWcDxgY3FB7Yx1I5dPpeQeyJDu4lezhIFrjn6lbdwRhV15aqOt4l9o9qZP+VbgOXqyi9gN0Y+p+vs2chBDFQqg==",
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.12.0.tgz",
"integrity": "sha512-0uGQH9ynomWzdBaEujEtcR38q6V7LCgG0mrb1Wellv6cC/IHD3j6WfeZZAgtiMPeOSJjbCDBOlVnzC2TlBqJFw==",
"requires": {
"es6-promise": "^4.2.8",
"form-data": "^3.0.0",

View File

@@ -4,7 +4,7 @@
"homepage": ".",
"private": true,
"dependencies": {
"@sasjs/adapter": "^1.3.13",
"@sasjs/adapter": "^1.12.0",
"@sasjs/test-framework": "^1.4.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",

View File

@@ -88,7 +88,7 @@ export const sendArrTests = (adapter: SASjs): TestSuite => ({
return adapter.request("common/sendArr", data).catch((e) => e);
},
assertion: (error: any) => {
return !!error && !!error.MESSAGE;
return !!error && !!error.body && !!error.body.message;
}
},
{
@@ -185,7 +185,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
};
return adapter.request("common/sendObj", invalidData).catch((e) => e);
},
assertion: (error: any) => !!error && !!error.MESSAGE
assertion: (error: any) => !!error && !!error.body && !!error.body.message
},
{
title: "Single string value",
@@ -219,7 +219,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
.catch((e) => e);
},
assertion: (error: any) => {
return !!error && !!error.MESSAGE;
return !!error && !!error.body && !!error.body.message;
}
},
{

View File

@@ -36,6 +36,7 @@ export class SASViyaApiClient {
}
private csrfToken: CsrfToken | null = null
private fileUploadCsrfToken: CsrfToken | null = null
private sessionManager = new SessionManager(
this.serverUrl,
this.contextName,
@@ -312,7 +313,7 @@ export class SASViyaApiClient {
headers.Authorization = `Bearer ${accessToken}`
}
const originalContext = await this.getContextByName(
const originalContext = await this.getComputeContextByName(
contextName,
accessToken
)
@@ -371,7 +372,7 @@ export class SASViyaApiClient {
headers.Authorization = `Bearer ${accessToken}`
}
const context = await this.getContextByName(contextName, accessToken)
const context = await this.getComputeContextByName(contextName, accessToken)
const deleteContextRequest: RequestInit = {
method: 'DELETE',
@@ -931,7 +932,10 @@ export class SASViyaApiClient {
if (isRelativePath(sasJob)) {
const folderName = sasJob.split('/')[0]
await this.populateFolderMap(`${this.rootFolderName}/${folderName}`)
await this.populateFolderMap(
`${this.rootFolderName}/${folderName}`,
accessToken
)
if (!this.folderMap.get(`${this.rootFolderName}/${folderName}`)) {
throw new Error(
@@ -1028,7 +1032,10 @@ export class SASViyaApiClient {
if (isRelativePath(sasJob)) {
const folderName = sasJob.split('/')[0]
await this.populateFolderMap(`${this.rootFolderName}/${folderName}`)
await this.populateFolderMap(
`${this.rootFolderName}/${folderName}`,
accessToken
)
if (!this.folderMap.get(`${this.rootFolderName}/${folderName}`)) {
throw new Error(
@@ -1335,7 +1342,9 @@ export class SASViyaApiClient {
const uploadResponse = await this.request<any>(
`${this.serverUrl}/files/files#rawUpload`,
createFileRequest
createFileRequest,
'json',
'fileUpload'
)
uploadedFiles.push({ tableName, file: uploadResponse.result })
@@ -1384,7 +1393,13 @@ export class SASViyaApiClient {
return `/folders/folders/${folder.id}`
}
private async getContextByName(
/**
* Returns a JSON representation of a compute context.
* @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
* @param contextName - the name of the context to return.
* @param accessToken - an access token for an authorized user.
*/
public async getComputeContextByName(
contextName: string,
accessToken?: string
): Promise<Context> {
@@ -1490,22 +1505,36 @@ export class SASViyaApiClient {
this.setCsrfToken(csrfToken)
}
setFileUploadCsrfToken = (csrfToken: CsrfToken) => {
this.fileUploadCsrfToken = csrfToken
}
private async request<T>(
url: string,
options: RequestInit,
contentType: 'text' | 'json' = 'json'
contentType: 'text' | 'json' = 'json',
type: 'fileUpload' | 'other' = 'other'
) {
if (this.csrfToken) {
options.headers = {
...options.headers,
[this.csrfToken.headerName]: this.csrfToken.value
const callback =
type === 'fileUpload'
? this.setFileUploadCsrfToken
: this.setCsrfTokenLocal
if (type === 'other') {
if (this.csrfToken) {
options.headers = {
...options.headers,
[this.csrfToken.headerName]: this.csrfToken.value
}
}
} else {
if (this.fileUploadCsrfToken) {
options.headers = {
...options.headers,
[this.fileUploadCsrfToken.headerName]: this.fileUploadCsrfToken.value
}
}
}
return await makeRequest<T>(
url,
options,
this.setCsrfTokenLocal,
contentType
)
return await makeRequest<T>(url, options, callback, contentType)
}
}

View File

@@ -167,6 +167,24 @@ export default class SASjs {
return await this.sasViyaApiClient!.deleteContext(contextName, accessToken)
}
/**
* Returns a JSON representation of a compute context.
* @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
* @param contextName - the name of the context to return.
* @param accessToken - an access token for an authorized user.
*/
public async getComputeContextByName(
contextName: string,
accessToken?: string
) {
this.isMethodSupported('getComputeContextByName', ServerType.SASViya)
return await this.sasViyaApiClient!.getComputeContextByName(
contextName,
accessToken
)
}
public async createSession(contextName: string, accessToken: string) {
this.isMethodSupported('createSession', ServerType.SASViya)

View File

@@ -40,8 +40,7 @@ const browserConfig = {
filename: null,
exclude: [/node_modules/],
test: /\.ts($|\?)/i
}),
new webpack.IgnorePlugin(/\/iconv-loader$/)
})
]
}