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

Compare commits

...

7 Commits

Author SHA1 Message Date
Krishna Acondy
5f74b6990c Merge pull request #67 from sasjs/issue-64
feat: added isUrl validation utility
2020-09-08 18:52:51 +01:00
Krishna Acondy
a53b1ab421 Merge branch 'master' into issue-64 2020-09-08 18:51:20 +01:00
Krishna Acondy
3fdc56cdfe Merge pull request #68 from sasjs/dependabot/npm_and_yarn/types/jest-26.0.13
chore(deps-dev): bump @types/jest from 26.0.10 to 26.0.13
2020-09-08 18:49:58 +01:00
Krishna Acondy
e318d8816e Merge branch 'master' into dependabot/npm_and_yarn/types/jest-26.0.13 2020-09-08 18:47:32 +01:00
Yury Shkoda
3da5aba62a fix: removed unnecessary check for www subdomain 2020-09-08 16:07:02 +03:00
dependabot-preview[bot]
3f40737514 chore(deps-dev): bump @types/jest from 26.0.10 to 26.0.13
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 26.0.10 to 26.0.13.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-09-07 18:32:51 +00:00
Yury Shkoda
0eb9bc43ff feat: added isUrl validation utility 2020-09-07 16:32:53 +03:00
8 changed files with 43 additions and 16 deletions

18
package-lock.json generated
View File

@@ -1103,9 +1103,9 @@
"dev": true
},
"supports-color": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
"integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==",
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"
@@ -1648,9 +1648,9 @@
}
},
"@types/jest": {
"version": "26.0.10",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.10.tgz",
"integrity": "sha512-i2m0oyh8w/Lum7wWK/YOZJakYF8Mx08UaKA1CtbmFeDquVhAEdA7znacsVSf2hJ1OQ/OfVMGN90pw/AtzF8s/Q==",
"version": "26.0.13",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.13.tgz",
"integrity": "sha512-sCzjKow4z9LILc6DhBvn5AkIfmQzDZkgtVVKmGwVrs5tuid38ws281D4l+7x1kP487+FlKDh5kfMZ8WSPAdmdA==",
"dev": true,
"requires": {
"jest-diff": "^25.2.1",
@@ -5904,9 +5904,9 @@
"dev": true
},
"supports-color": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
"integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==",
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"

View File

@@ -37,7 +37,7 @@
"license": "ISC",
"devDependencies": {
"@types/isomorphic-fetch": "0.0.35",
"@types/jest": "^26.0.10",
"@types/jest": "^26.0.13",
"cp": "^0.2.0",
"jest": "^25.5.4",
"path": "^0.12.7",

View File

@@ -1,4 +1,4 @@
import { isLogInRequired, needsRetry } from './utils'
import { isLogInRequired, needsRetry, isUrl } from './utils'
import { CsrfToken } from './types/CsrfToken'
import { UploadFile } from './types/UploadFile'
@@ -11,7 +11,10 @@ export class FileUploader {
private jobsPath: string,
private setCsrfTokenWeb: any,
private csrfToken: CsrfToken | null = null
) {}
) {
if (serverUrl) isUrl(serverUrl)
}
private retryCount = 0
public uploadFile(sasJob: string, files: UploadFile[], params: any) {

View File

@@ -1,9 +1,13 @@
import { isUrl } from './utils'
/**
* A client for interfacing with the SAS9 REST API
*
*/
export class SAS9ApiClient {
constructor(private serverUrl: string) {}
constructor(private serverUrl: string) {
if (serverUrl) isUrl(serverUrl)
}
/**
* returns on object containing the server URL

View File

@@ -2,7 +2,8 @@ import {
isAuthorizeFormRequired,
parseAndSubmitAuthorizeForm,
convertToCSV,
makeRequest
makeRequest,
isUrl
} from './utils'
import * as NodeFormData from 'form-data'
import * as path from 'path'
@@ -26,7 +27,10 @@ export class SASViyaApiClient {
if (!rootFolderName) {
throw new Error('Root folder must be provided.')
}
if (serverUrl) isUrl(serverUrl)
}
private csrfToken: CsrfToken | null = null
private rootFolder: Folder | null = null
private sessionManager = new SessionManager(

View File

@@ -1,5 +1,5 @@
import { Session, Context, CsrfToken } from './types'
import { asyncForEach, makeRequest } from './utils'
import { asyncForEach, makeRequest, isUrl } from './utils'
const MAX_SESSION_COUNT = 1
@@ -8,7 +8,10 @@ export class SessionManager {
private serverUrl: string,
private contextName: string,
private setCsrfToken: (csrfToken: CsrfToken) => void
) {}
) {
if (serverUrl) isUrl(serverUrl)
}
private sessions: Session[] = []
private currentContext: Context | null = null
private csrfToken: CsrfToken | null = null

View File

@@ -13,3 +13,4 @@ export * from './parseSasViyaLog'
export * from './serialize'
export * from './splitChunks'
export * from './parseWeboutResponse'
export * from './isUrl'

12
src/utils/isUrl.ts Normal file
View File

@@ -0,0 +1,12 @@
export const isUrl = (url: string): boolean => {
const pattern = new RegExp(
'^(http://|https://)[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$',
'gi'
)
if (pattern.test(url)) return true
else
throw new Error(
`'${url}' is not a valid url. An example of a valid url is 'http://valid-url.com'.`
)
}