1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +00:00

Merge pull request #67 from sasjs/issue-64

feat: added isUrl validation utility
This commit is contained in:
Krishna Acondy
2020-09-08 18:52:51 +01:00
committed by GitHub
6 changed files with 33 additions and 6 deletions

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'.`
)
}