1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-10 13:50:05 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
964fe83eb8 chore(deps-dev): bump pbkdf2 from 3.1.2 to 3.1.5
Bumps [pbkdf2](https://github.com/browserify/pbkdf2) from 3.1.2 to 3.1.5.
- [Changelog](https://github.com/browserify/pbkdf2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/browserify/pbkdf2/compare/v3.1.2...v3.1.5)

---
updated-dependencies:
- dependency-name: pbkdf2
  dependency-version: 3.1.5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-19 12:22:44 +00:00
7 changed files with 179 additions and 249 deletions

136
package-lock.json generated
View File

@@ -12010,18 +12010,21 @@
} }
}, },
"node_modules/pbkdf2": { "node_modules/pbkdf2": {
"version": "3.1.2", "version": "3.1.5",
"resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.5.tgz",
"integrity": "sha512-Q3CG/cYvCO1ye4QKkuH7EXxs3VC/rI1/trd+qX2+PolbaKG0H+bgcZzrTt96mMyRtejk+JMCiLUn3y29W8qmFQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"create-hash": "^1.1.2", "create-hash": "^1.2.0",
"create-hmac": "^1.1.4", "create-hmac": "^1.1.7",
"ripemd160": "^2.0.1", "ripemd160": "^2.0.3",
"safe-buffer": "^5.0.1", "safe-buffer": "^5.2.1",
"sha.js": "^2.4.8" "sha.js": "^2.4.12",
"to-buffer": "^1.2.1"
}, },
"engines": { "engines": {
"node": ">=0.12" "node": ">= 0.10"
} }
}, },
"node_modules/pem": { "node_modules/pem": {
@@ -12780,14 +12783,75 @@
} }
}, },
"node_modules/ripemd160": { "node_modules/ripemd160": {
"version": "2.0.2", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.3.tgz",
"integrity": "sha512-5Di9UC0+8h1L6ZD2d7awM7E/T4uA1fJRlx6zk/NvdCCVEoAnFqvHmCuNeIKoCeIixBX/q8uM+6ycDvF8woqosA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"hash-base": "^3.0.0", "hash-base": "^3.1.2",
"inherits": "^2.0.1" "inherits": "^2.0.4"
},
"engines": {
"node": ">= 0.8"
} }
}, },
"node_modules/ripemd160/node_modules/hash-base": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.2.tgz",
"integrity": "sha512-Bb33KbowVTIj5s7Ked1OsqHUeCpz//tPwR+E2zJgJKo9Z5XolZ9b6bdUgjmYlwnWhoOQKoTd1TYToZGn5mAYOg==",
"dev": true,
"license": "MIT",
"dependencies": {
"inherits": "^2.0.4",
"readable-stream": "^2.3.8",
"safe-buffer": "^5.2.1",
"to-buffer": "^1.2.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/ripemd160/node_modules/readable-stream": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
"dev": true,
"license": "MIT",
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
},
"node_modules/ripemd160/node_modules/readable-stream/node_modules/safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true,
"license": "MIT"
},
"node_modules/ripemd160/node_modules/string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"dev": true,
"license": "MIT",
"dependencies": {
"safe-buffer": "~5.1.0"
}
},
"node_modules/ripemd160/node_modules/string_decoder/node_modules/safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true,
"license": "MIT"
},
"node_modules/run-parallel": { "node_modules/run-parallel": {
"version": "1.2.0", "version": "1.2.0",
"dev": true, "dev": true,
@@ -13108,15 +13172,24 @@
"license": "ISC" "license": "ISC"
}, },
"node_modules/sha.js": { "node_modules/sha.js": {
"version": "2.4.11", "version": "2.4.12",
"resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.12.tgz",
"integrity": "sha512-8LzC5+bvI45BjpfXU8V5fdU2mfeKiQe1D1gIMn7XUlF3OTUrpdJpPPH4EMAnF0DsHHdSZqCdSss5qCmJKuiO3w==",
"dev": true, "dev": true,
"license": "(MIT AND BSD-3-Clause)", "license": "(MIT AND BSD-3-Clause)",
"dependencies": { "dependencies": {
"inherits": "^2.0.1", "inherits": "^2.0.4",
"safe-buffer": "^5.0.1" "safe-buffer": "^5.2.1",
"to-buffer": "^1.2.0"
}, },
"bin": { "bin": {
"sha.js": "bin.js" "sha.js": "bin.js"
},
"engines": {
"node": ">= 0.10"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/shallow-clone": { "node_modules/shallow-clone": {
@@ -13865,6 +13938,28 @@
"dev": true, "dev": true,
"license": "BSD-3-Clause" "license": "BSD-3-Clause"
}, },
"node_modules/to-buffer": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.2.2.tgz",
"integrity": "sha512-db0E3UJjcFhpDhAF4tLo03oli3pwl3dbnzXOUIlRKrp+ldk/VUxzpWYZENsw2SZiuBjHAk7DfB0VU7NKdpb6sw==",
"dev": true,
"license": "MIT",
"dependencies": {
"isarray": "^2.0.5",
"safe-buffer": "^5.2.1",
"typed-array-buffer": "^1.0.3"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/to-buffer/node_modules/isarray": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz",
"integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==",
"dev": true,
"license": "MIT"
},
"node_modules/to-regex-range": { "node_modules/to-regex-range": {
"version": "5.0.1", "version": "5.0.1",
"dev": true, "dev": true,
@@ -14239,6 +14334,21 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/typed-array-buffer": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz",
"integrity": "sha512-nAYYwfY3qnzX30IkA6AQZjVbtK6duGontcQm1WSG1MD94YLqK0515GNApXkoxKOWMusVssAHWLh9SeaoefYFGw==",
"dev": true,
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.3",
"es-errors": "^1.3.0",
"is-typed-array": "^1.1.14"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/typedoc": { "node_modules/typedoc": {
"version": "0.23.24", "version": "0.23.24",
"dev": true, "dev": true,

View File

@@ -1,39 +1,43 @@
* { * {
box-sizing: border-box; box-sizing: border-box;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
body { body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
Ubuntu, Cantarell, sans-serif; Ubuntu, Cantarell, sans-serif;
line-height: 1.6; line-height: 1.6;
color: #333; color: #333;
background: #f5f5f5; background: #f5f5f5;
} }
.app__error { #app {
max-width: 800px; min-height: 100vh;
margin: 50px auto; }
padding: 30px;
background: white; .app__error {
border-radius: 8px; max-width: 800px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); margin: 50px auto;
padding: 30px;
h1 { background: white;
color: #e74c3c; border-radius: 8px;
margin-bottom: 15px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
h1 {
p { color: #e74c3c;
margin-bottom: 15px; margin-bottom: 15px;
} }
pre { p {
background: #2c3e50; margin-bottom: 15px;
color: #ecf0f1; }
padding: 15px;
border-radius: 4px; pre {
overflow-x: auto; background: #2c3e50;
} color: #ecf0f1;
padding: 15px;
border-radius: 4px;
overflow-x: auto;
}
} }

View File

@@ -22,7 +22,6 @@ import { sendArrTests, sendObjTests } from './testSuites/RequestData'
import { fileUploadTests } from './testSuites/FileUpload' import { fileUploadTests } from './testSuites/FileUpload'
import { computeTests } from './testSuites/Compute' import { computeTests } from './testSuites/Compute'
import { sasjsRequestTests } from './testSuites/SasjsRequests' import { sasjsRequestTests } from './testSuites/SasjsRequests'
import { viyaFileTests } from './testSuites/ViyaFile'
async function init() { async function init() {
const appContainer = document.getElementById('app') const appContainer = document.getElementById('app')
@@ -104,10 +103,9 @@ function showTests(
fileUploadTests(adapter) fileUploadTests(adapter)
] ]
// Add certain tests for SASVIYA only // Add compute tests for SASVIYA only
if (adapter.getSasjsConfig().serverType === 'SASVIYA') { if (adapter.getSasjsConfig().serverType === 'SASVIYA') {
testSuites.push(computeTests(adapter, appLoc)) testSuites.push(computeTests(adapter, appLoc))
testSuites.push(viyaFileTests(adapter, appLoc))
} }
container.innerHTML = '' container.innerHTML = ''

View File

@@ -1,31 +0,0 @@
import SASjs from '@sasjs/adapter'
import type { TestSuite } from '../types'
export const viyaFileTests = (adapter: SASjs, appLoc: string): TestSuite => ({
name: 'SAS Viya File Tests',
tests: [
{
title: 'Create html file',
description: 'Should create an html file with appropriate properties',
test: async () => {
const fileContentBuffer = Buffer.from(
`<html>` +
` <head><title>Test</title></head>` +
` <body><p>This is a test</p></body>` +
`</html>`
)
// generate a timestamp string formatted as YYYYmmDDTHHMMSS_999
const timeMark = new Date()
.toISOString()
.replace(/(\/|:|\s|-|Z)/g, '')
.replace(/\./g, '_')
const filename = `viya_createFile_test_${timeMark}.html`
return adapter.createFile(filename, fileContentBuffer, appLoc)
},
assertion: () => {
//A test that returns a boolean
return true // dummy
}
}
]
})

View File

@@ -1,12 +1,5 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
export default defineConfig({ export default defineConfig({
plugins: [
nodePolyfills({
include: ['buffer']
})
],
build: { build: {
assetsInlineLimit: 0, assetsInlineLimit: 0,
assetsDir: '' assetsDir: ''

View File

@@ -36,59 +36,6 @@ interface JobExecutionResult {
error?: object error?: object
} }
interface IViyaTypesResponse {
accept: string
count: number
items: IViyaTypesItem[]
limit: number
links: IViyaTypesLink[]
name: string
start: number
version: number
}
interface IViyaTypesItem {
description?: string
extensions?: string[]
iconUri?: string
label: string
links: IViyaTypesLink[]
mappedTypes?: string[]
mediaType?: string
mediaTypes?: string[]
name: string
pluralLabel?: string
properties?: IViyaTypesProperties
resourceUri?: string
serviceRootUri?: string
tags?: string[]
version: number
}
/**
* Generic structure for a link
* in the links array of a Viya
* types/types api response
*/
type IViyaTypesLink = Record<string, string>
/**
* Generic structure for a type's
* 'properties' object from the Viya
* types/types api response
*/
type IViyaTypesProperties = Record<string, string>
/**
* Arbitrary interface for storing
* sufficient additional detail to
* create and patch a new file.
*/
interface IViyaTypesExtensionInfo {
typeDefName: string
properties: IViyaTypesProperties | undefined
}
/** /**
* A client for interfacing with the SAS Viya REST API. * A client for interfacing with the SAS Viya REST API.
* *
@@ -115,9 +62,6 @@ export class SASViyaApiClient {
) )
private folderMap = new Map<string, Job[]>() private folderMap = new Map<string, Job[]>()
private fileExtensionMap = new Map<string, IViyaTypesExtensionInfo>()
private boolExtensionMap = false // has the fileExtensionMap been populated yet?
/** /**
* A helper method used to call appendRequest method of RequestClient * A helper method used to call appendRequest method of RequestClient
* @param response - response from sasjs request * @param response - response from sasjs request
@@ -481,107 +425,24 @@ export class SASViyaApiClient {
if (!parentFolderUri && parentFolderPath) { if (!parentFolderUri && parentFolderPath) {
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken) parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
} }
const headers = { const headers = {
Accept: 'application/vnd.sas.file+json', Accept: 'application/vnd.sas.file+json',
'Content-Disposition': `filename="${fileName}";` 'Content-Disposition': `filename="${fileName}";`
} }
const patchHeaders = {
Accept: 'application/json',
'If-Match': '*'
}
const formData = new NodeFormData() const formData = new NodeFormData()
formData.append('file', contentBuffer, fileName) formData.append('file', contentBuffer, fileName)
/** Query Viya for file metadata based on extension type. return (
* Without providing certain properties, some versions of Viya will not await this.requestClient.post<File>(
* serve files as intended. Avoid this issue by applying the properties `/files/files?parentFolderUri=${parentFolderUri}&typeDefName=file#rawUpload`,
* that Viya has registered for a file extension. formData,
*/ accessToken,
'multipart/form-data; boundary=' + (formData as any)._boundary,
// typeDefName - Viya should automatically determine this and additional headers
// properties at runtime if not provided in the file creation request. )
let typeDefName: string | undefined = undefined ).result
// Viya update 2025.09 resulted in a change to this automatic behaviour.
// We patch the new file to replicate the behaviour.
let filePatch:
| {
name: string
properties: IViyaTypesProperties | undefined
}
| undefined = undefined
// The patching process requires properties related to the file-extension
const fileExtension: string | undefined = fileName
.split('.')
.pop()
?.toLowerCase()
if (fileExtension) {
if (!this.boolExtensionMap) {
// Populate the file extension map
// 1. Get Viya's response to this api call
const typesQueryUrl = `/types/types?limit=999999`
const response = (
await this.requestClient.get(typesQueryUrl, accessToken)
).result as IViyaTypesResponse
// 2. Filter the returned items that have file extensions into a map
// using forEach as an item may relate to multiple file extensions.
response.items
.filter((e) => e.extensions)
.forEach((e) => {
e.extensions?.forEach((ext) => {
this.fileExtensionMap.set(ext, {
// "name:" is the typeDefName value required for file creation.
typeDefName: e.name,
properties: e.properties
})
})
})
// 3. Toggle the flag to avoid repeating this step
this.boolExtensionMap = true
}
const fileExtInfo = this.fileExtensionMap.get(fileExtension)
if (fileExtInfo) {
typeDefName = fileExtInfo.typeDefName
if (fileExtInfo.properties)
filePatch = { name: fileName, properties: fileExtInfo.properties }
}
}
const createFileResponse = await this.requestClient.post<File>(
`/files/files?parentFolderUri=${parentFolderUri}&typeDefName=${
typeDefName ?? 'file'
}#rawUpload`,
formData,
accessToken,
'multipart/form-data; boundary=' + (formData as any)._boundary,
headers
)
try {
// If a patch was created...
if (filePatch) {
// Get the URI of the newly created file
const fileUri = createFileResponse.result.links.filter(
(e) => e.method == 'PATCH' && e.rel == 'patch'
)[0].uri
// and apply the patch
return (
await this.requestClient.patch<File>(
`${fileUri}`,
filePatch,
accessToken,
'application/json',
patchHeaders
)
).result
}
return createFileResponse.result
} catch (e: any) {
throw new Error(`Error patching file ${fileName}.\n${e.message}`)
}
} }
/** /**

View File

@@ -272,15 +272,10 @@ export class RequestClient implements HttpClient {
public async patch<T>( public async patch<T>(
url: string, url: string,
data: any, data: any = {},
accessToken: string | undefined, accessToken?: string
contentType = 'application/json',
overrideHeaders: { [key: string]: string | number } = {}
): Promise<{ result: T; etag: string }> { ): Promise<{ result: T; etag: string }> {
const headers = { const headers = this.getHeaders(accessToken, 'application/json')
...this.getHeaders(accessToken, contentType),
...overrideHeaders
}
return this.httpClient return this.httpClient
.patch<T>(url, data, { headers, withXSRFToken: true }) .patch<T>(url, data, { headers, withXSRFToken: true })