mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-08 13:00:05 +00:00
chore(*): change code style to use single quote
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { SASjsRequest } from "../types/SASjsRequest"
|
||||
import { SASjsRequest } from '../types/SASjsRequest'
|
||||
|
||||
/**
|
||||
* Comparator for SASjs request timestamps
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @param data - the JSON object to convert.
|
||||
*/
|
||||
export const convertToCSV = (data: any) => {
|
||||
const replacer = (key: any, value: any) => (value === null ? "" : value)
|
||||
const replacer = (key: any, value: any) => (value === null ? '' : value)
|
||||
const headerFields = Object.keys(data[0])
|
||||
let csvTest
|
||||
let invalidString = false
|
||||
@@ -14,31 +14,31 @@ export const convertToCSV = (data: any) => {
|
||||
|
||||
const longestValueForField = data
|
||||
.map((row: any, index: number) => {
|
||||
if (row[field] || row[field] === "") {
|
||||
if (row[field] || row[field] === '') {
|
||||
if (firstFoundType) {
|
||||
let currentFieldType =
|
||||
row[field] === "" || typeof row[field] === "string"
|
||||
? "chars"
|
||||
: "number"
|
||||
row[field] === '' || typeof row[field] === 'string'
|
||||
? 'chars'
|
||||
: 'number'
|
||||
|
||||
if (!hasMixedTypes) {
|
||||
hasMixedTypes = currentFieldType !== firstFoundType
|
||||
rowNumError = hasMixedTypes ? index + 1 : -1
|
||||
}
|
||||
} else {
|
||||
if (row[field] === "") {
|
||||
firstFoundType = "chars"
|
||||
if (row[field] === '') {
|
||||
firstFoundType = 'chars'
|
||||
} else {
|
||||
firstFoundType =
|
||||
typeof row[field] === "string" ? "chars" : "number"
|
||||
typeof row[field] === 'string' ? 'chars' : 'number'
|
||||
}
|
||||
}
|
||||
|
||||
let byteSize
|
||||
|
||||
if (typeof row[field] === "string") {
|
||||
if (typeof row[field] === 'string') {
|
||||
let doubleQuotesFound = row[field]
|
||||
.split("")
|
||||
.split('')
|
||||
.filter((char: any) => char === '"')
|
||||
|
||||
byteSize = getByteSize(row[field])
|
||||
@@ -61,17 +61,17 @@ export const convertToCSV = (data: any) => {
|
||||
)
|
||||
}
|
||||
|
||||
return `${field}:${firstFoundType === "chars" ? "$" : ""}${
|
||||
return `${field}:${firstFoundType === 'chars' ? '$' : ''}${
|
||||
longestValueForField
|
||||
? longestValueForField
|
||||
: firstFoundType === "chars"
|
||||
? "1"
|
||||
: "best"
|
||||
: firstFoundType === 'chars'
|
||||
? '1'
|
||||
: 'best'
|
||||
}.`
|
||||
})
|
||||
|
||||
if (invalidString) {
|
||||
return "ERROR: LARGE STRING LENGTH"
|
||||
return 'ERROR: LARGE STRING LENGTH'
|
||||
}
|
||||
csvTest = data.map((row: any) => {
|
||||
const fields = Object.keys(row).map((fieldName, index) => {
|
||||
@@ -86,15 +86,15 @@ export const convertToCSV = (data: any) => {
|
||||
value = JSON.stringify(currentCell, replacer)
|
||||
}
|
||||
|
||||
value = value.replace(/\\\\/gm, "\\")
|
||||
value = value.replace(/\\\\/gm, '\\')
|
||||
|
||||
if (containsSpecialChar) {
|
||||
if (value.includes(",") || value.includes('"')) {
|
||||
if (value.includes(',') || value.includes('"')) {
|
||||
value = '"' + value + '"'
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
!value.includes(",") &&
|
||||
!value.includes(',') &&
|
||||
value.includes('"') &&
|
||||
!value.includes('\\"')
|
||||
) {
|
||||
@@ -104,19 +104,19 @@ export const convertToCSV = (data: any) => {
|
||||
value = value.replace(/\\"/gm, '""')
|
||||
}
|
||||
|
||||
value = value.replace(/\r\n/gm, "\n")
|
||||
value = value.replace(/\r\n/gm, '\n')
|
||||
|
||||
if (value === "" && headers[index].includes("best")) {
|
||||
value = "."
|
||||
if (value === '' && headers[index].includes('best')) {
|
||||
value = '.'
|
||||
}
|
||||
|
||||
return value
|
||||
})
|
||||
return fields.join(",")
|
||||
return fields.join(',')
|
||||
})
|
||||
|
||||
let finalCSV =
|
||||
headers.join(",").replace(/,/g, " ") + "\r\n" + csvTest.join("\r\n")
|
||||
headers.join(',').replace(/,/g, ' ') + '\r\n' + csvTest.join('\r\n')
|
||||
|
||||
return finalCSV
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { convertToCSV } from "./convertToCsv"
|
||||
import { splitChunks } from "./splitChunks"
|
||||
import { convertToCSV } from './convertToCsv'
|
||||
import { splitChunks } from './splitChunks'
|
||||
|
||||
export const formatDataForRequest = (data: any) => {
|
||||
const sasjsTables = []
|
||||
@@ -10,9 +10,9 @@ export const formatDataForRequest = (data: any) => {
|
||||
tableCounter++
|
||||
sasjsTables.push(tableName)
|
||||
const csv = convertToCSV(data[tableName])
|
||||
if (csv === "ERROR: LARGE STRING LENGTH") {
|
||||
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
||||
throw new Error(
|
||||
"The max length of a string value in SASjs is 32765 characters."
|
||||
'The max length of a string value in SASjs is 32765 characters.'
|
||||
)
|
||||
}
|
||||
// if csv has length more then 16k, send in chunks
|
||||
@@ -27,7 +27,7 @@ export const formatDataForRequest = (data: any) => {
|
||||
result[`sasjs${tableCounter}data`] = csv
|
||||
}
|
||||
}
|
||||
result["sasjs_tables"] = sasjsTables.join(" ")
|
||||
result['sasjs_tables'] = sasjsTables.join(' ')
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
export * from "./asyncForEach"
|
||||
export * from "./compareTimestamps"
|
||||
export * from "./convertToCsv"
|
||||
export * from "./isAuthorizeFormRequired"
|
||||
export * from "./isLoginRequired"
|
||||
export * from "./isLoginSuccess"
|
||||
export * from "./makeRequest"
|
||||
export * from "./needsRetry"
|
||||
export * from "./parseAndSubmitAuthorizeForm"
|
||||
export * from "./parseGeneratedCode"
|
||||
export * from "./parseSourceCode"
|
||||
export * from "./parseSasViyaLog"
|
||||
export * from "./serialize"
|
||||
export * from "./splitChunks"
|
||||
export * from "./parseWeboutResponse"
|
||||
export * from './asyncForEach'
|
||||
export * from './compareTimestamps'
|
||||
export * from './convertToCsv'
|
||||
export * from './isAuthorizeFormRequired'
|
||||
export * from './isLoginRequired'
|
||||
export * from './isLoginSuccess'
|
||||
export * from './makeRequest'
|
||||
export * from './needsRetry'
|
||||
export * from './parseAndSubmitAuthorizeForm'
|
||||
export * from './parseGeneratedCode'
|
||||
export * from './parseSourceCode'
|
||||
export * from './parseSasViyaLog'
|
||||
export * from './serialize'
|
||||
export * from './splitChunks'
|
||||
export * from './parseWeboutResponse'
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
export function isIEorEdgeOrOldFirefox() {
|
||||
if (typeof window === "undefined") {
|
||||
if (typeof window === 'undefined') {
|
||||
return false
|
||||
}
|
||||
const ua = window.navigator.userAgent
|
||||
|
||||
if (ua.indexOf("Firefox") > 0) {
|
||||
if (ua.indexOf('Firefox') > 0) {
|
||||
const version = parseInt(
|
||||
ua.substring(ua.lastIndexOf("Firefox/") + 8, ua.length),
|
||||
ua.substring(ua.lastIndexOf('Firefox/') + 8, ua.length),
|
||||
10
|
||||
)
|
||||
return version <= 60
|
||||
}
|
||||
|
||||
const msie = ua.indexOf("MSIE ")
|
||||
const msie = ua.indexOf('MSIE ')
|
||||
if (msie > 0) {
|
||||
// IE 10 or older => return version number
|
||||
return true
|
||||
}
|
||||
|
||||
const trident = ua.indexOf("Trident/")
|
||||
const trident = ua.indexOf('Trident/')
|
||||
if (trident > 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
const edge = ua.indexOf("Edge/")
|
||||
const edge = ua.indexOf('Edge/')
|
||||
if (edge > 0) {
|
||||
// Edge (IE 12+) => return version number
|
||||
return true
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CsrfToken } from "../types"
|
||||
import { needsRetry } from "./needsRetry"
|
||||
import { CsrfToken } from '../types'
|
||||
import { needsRetry } from './needsRetry'
|
||||
|
||||
let retryCount: number = 0
|
||||
let retryLimit: number = 5
|
||||
@@ -8,28 +8,28 @@ export async function makeRequest<T>(
|
||||
url: string,
|
||||
request: RequestInit,
|
||||
callback: (value: CsrfToken) => any,
|
||||
contentType: "text" | "json" = "json"
|
||||
contentType: 'text' | 'json' = 'json'
|
||||
): Promise<{ result: T; etag: string | null }> {
|
||||
let retryRequest: any = null
|
||||
|
||||
const responseTransform =
|
||||
contentType === "json"
|
||||
contentType === 'json'
|
||||
? (res: Response) => res.json()
|
||||
: (res: Response) => res.text()
|
||||
let etag = null
|
||||
const result = await fetch(url, request).then(async (response) => {
|
||||
if (response.redirected && response.url.includes("SASLogon/login")) {
|
||||
if (response.redirected && response.url.includes('SASLogon/login')) {
|
||||
return Promise.reject({ status: 401 })
|
||||
}
|
||||
if (!response.ok) {
|
||||
if (response.status === 403) {
|
||||
const tokenHeader = response.headers.get("X-CSRF-HEADER")
|
||||
const tokenHeader = response.headers.get('X-CSRF-HEADER')
|
||||
|
||||
if (tokenHeader) {
|
||||
const token = response.headers.get(tokenHeader)
|
||||
callback({
|
||||
headerName: tokenHeader,
|
||||
value: token || ""
|
||||
value: token || ''
|
||||
})
|
||||
|
||||
retryRequest = {
|
||||
@@ -37,7 +37,7 @@ export async function makeRequest<T>(
|
||||
headers: { ...request.headers, [tokenHeader]: token }
|
||||
}
|
||||
return fetch(url, retryRequest).then((res) => {
|
||||
etag = res.headers.get("ETag")
|
||||
etag = res.headers.get('ETag')
|
||||
return responseTransform(res)
|
||||
})
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export async function makeRequest<T>(
|
||||
} else {
|
||||
retryCount = 0
|
||||
|
||||
throw new Error("Request retry limit exceeded")
|
||||
throw new Error('Request retry limit exceeded')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ export async function makeRequest<T>(
|
||||
return Promise.resolve()
|
||||
}
|
||||
const responseTransformed = await responseTransform(response)
|
||||
let responseText = ""
|
||||
let responseText = ''
|
||||
|
||||
if (typeof responseTransformed === "string") {
|
||||
if (typeof responseTransformed === 'string') {
|
||||
responseText = responseTransformed
|
||||
} else {
|
||||
responseText = JSON.stringify(responseTransformed)
|
||||
@@ -95,11 +95,11 @@ export async function makeRequest<T>(
|
||||
} else {
|
||||
retryCount = 0
|
||||
|
||||
throw new Error("Request retry limit exceeded")
|
||||
throw new Error('Request retry limit exceeded')
|
||||
}
|
||||
}
|
||||
|
||||
etag = response.headers.get("ETag")
|
||||
etag = response.headers.get('ETag')
|
||||
return responseTransformed
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2,13 +2,13 @@ export const needsRetry = (responseText: string): boolean => {
|
||||
return (
|
||||
!!responseText &&
|
||||
((responseText.includes('"errorCode":403') &&
|
||||
responseText.includes("_csrf") &&
|
||||
responseText.includes("X-CSRF-TOKEN")) ||
|
||||
responseText.includes('_csrf') &&
|
||||
responseText.includes('X-CSRF-TOKEN')) ||
|
||||
(responseText.includes('"status":403') &&
|
||||
responseText.includes('"error":"Forbidden"')) ||
|
||||
(responseText.includes('"status":449') &&
|
||||
responseText.includes(
|
||||
"Authentication success, retry original request"
|
||||
'Authentication success, retry original request'
|
||||
)))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,18 +5,18 @@ export const parseAndSubmitAuthorizeForm = async (
|
||||
let authUrl: string | null = null
|
||||
const params: any = {}
|
||||
|
||||
const responseBody = response.split("<body>")[1].split("</body>")[0]
|
||||
const bodyElement = document.createElement("div")
|
||||
const responseBody = response.split('<body>')[1].split('</body>')[0]
|
||||
const bodyElement = document.createElement('div')
|
||||
bodyElement.innerHTML = responseBody
|
||||
|
||||
const form = bodyElement.querySelector("#application_authorization")
|
||||
authUrl = form ? serverUrl + form.getAttribute("action") : null
|
||||
const form = bodyElement.querySelector('#application_authorization')
|
||||
authUrl = form ? serverUrl + form.getAttribute('action') : null
|
||||
|
||||
const inputs: any = form?.querySelectorAll("input")
|
||||
const inputs: any = form?.querySelectorAll('input')
|
||||
|
||||
for (const input of inputs) {
|
||||
if (input.name === "user_oauth_approval") {
|
||||
input.value = "true"
|
||||
if (input.name === 'user_oauth_approval') {
|
||||
input.value = 'true'
|
||||
}
|
||||
|
||||
params[input.name] = input.value
|
||||
@@ -33,17 +33,17 @@ export const parseAndSubmitAuthorizeForm = async (
|
||||
return new Promise((resolve, reject) => {
|
||||
if (authUrl) {
|
||||
fetch(authUrl, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: formData,
|
||||
referrerPolicy: "same-origin"
|
||||
referrerPolicy: 'same-origin'
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
} else {
|
||||
reject("Auth form url is null")
|
||||
reject('Auth form url is null')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export const parseGeneratedCode = (log: string) => {
|
||||
const startsWith = "MPRINT"
|
||||
const startsWith = 'MPRINT'
|
||||
const isGeneratedCodeLine = (line: string) =>
|
||||
line.trim().startsWith(startsWith)
|
||||
const logLines = log.split("\n").filter(isGeneratedCodeLine)
|
||||
return logLines.join("\r\n")
|
||||
const logLines = log.split('\n').filter(isGeneratedCodeLine)
|
||||
return logLines.join('\r\n')
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ export const parseSasViyaLog = (logResponse: { items: any[] }) => {
|
||||
let log
|
||||
try {
|
||||
log = logResponse.items
|
||||
? logResponse.items.map((i) => i.line).join("\n")
|
||||
? logResponse.items.map((i) => i.line).join('\n')
|
||||
: JSON.stringify(logResponse)
|
||||
} catch (e) {
|
||||
console.error("An error has occurred while parsing the log response", e)
|
||||
console.error('An error has occurred while parsing the log response', e)
|
||||
log = logResponse
|
||||
}
|
||||
return log
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const parseSourceCode = (log: string): string => {
|
||||
const isSourceCodeLine = (line: string) =>
|
||||
line.trim().substring(0, 10).trimStart().match(/^\d/)
|
||||
const logLines = log.split("\n").filter(isSourceCodeLine)
|
||||
return logLines.join("\r\n")
|
||||
const logLines = log.split('\n').filter(isSourceCodeLine)
|
||||
return logLines.join('\r\n')
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
export const parseWeboutResponse = (response: string) => {
|
||||
let sasResponse = ""
|
||||
let sasResponse = ''
|
||||
|
||||
if (response.includes(">>weboutBEGIN<<")) {
|
||||
if (response.includes('>>weboutBEGIN<<')) {
|
||||
try {
|
||||
sasResponse = response
|
||||
.split(">>weboutBEGIN<<")[1]
|
||||
.split(">>weboutEND<<")[0]
|
||||
.split('>>weboutBEGIN<<')[1]
|
||||
.split('>>weboutEND<<')[0]
|
||||
} catch (e) {
|
||||
sasResponse = ""
|
||||
sasResponse = ''
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ export const serialize = (obj: any) => {
|
||||
if (obj.hasOwnProperty(p)) {
|
||||
if (obj[p] instanceof Array) {
|
||||
for (let i = 0, n = obj[p].length; i < n; i++) {
|
||||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p][i]))
|
||||
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p][i]))
|
||||
}
|
||||
} else {
|
||||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]))
|
||||
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
|
||||
}
|
||||
}
|
||||
}
|
||||
return str.join("&")
|
||||
return str.join('&')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user