mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-05 11:40:06 +00:00
Compare commits
3 Commits
d0aaad024b
...
viyaNewFil
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
824ee6f8da | ||
|
|
a3c5e985f7 | ||
|
|
68e0da8a91 |
@@ -1,43 +1,39 @@
|
|||||||
* {
|
* {
|
||||||
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 {
|
.app__error {
|
||||||
min-height: 100vh;
|
max-width: 800px;
|
||||||
}
|
margin: 50px auto;
|
||||||
|
padding: 30px;
|
||||||
.app__error {
|
background: white;
|
||||||
max-width: 800px;
|
border-radius: 8px;
|
||||||
margin: 50px auto;
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||||
padding: 30px;
|
|
||||||
background: white;
|
h1 {
|
||||||
border-radius: 8px;
|
color: #e74c3c;
|
||||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
h1 {
|
|
||||||
color: #e74c3c;
|
p {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
pre {
|
||||||
margin-bottom: 15px;
|
background: #2c3e50;
|
||||||
}
|
color: #ecf0f1;
|
||||||
|
padding: 15px;
|
||||||
pre {
|
border-radius: 4px;
|
||||||
background: #2c3e50;
|
overflow-x: auto;
|
||||||
color: #ecf0f1;
|
}
|
||||||
padding: 15px;
|
|
||||||
border-radius: 4px;
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,7 @@ 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')
|
||||||
@@ -103,9 +104,10 @@ function showTests(
|
|||||||
fileUploadTests(adapter)
|
fileUploadTests(adapter)
|
||||||
]
|
]
|
||||||
|
|
||||||
// Add compute tests for SASVIYA only
|
// Add certain 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 = ''
|
||||||
|
|||||||
31
sasjs-tests/src/testSuites/ViyaFile.ts
Normal file
31
sasjs-tests/src/testSuites/ViyaFile.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
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: ''
|
||||||
|
|||||||
@@ -70,18 +70,14 @@ interface IViyaTypesItem {
|
|||||||
* in the links array of a Viya
|
* in the links array of a Viya
|
||||||
* types/types api response
|
* types/types api response
|
||||||
*/
|
*/
|
||||||
interface IViyaTypesLink {
|
type IViyaTypesLink = Record<string, string>
|
||||||
[key: string]: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic structure for a type's
|
* Generic structure for a type's
|
||||||
* 'properties' object from the Viya
|
* 'properties' object from the Viya
|
||||||
* types/types api response
|
* types/types api response
|
||||||
*/
|
*/
|
||||||
interface IViyaTypesProperties {
|
type IViyaTypesProperties = Record<string, string>
|
||||||
[key: string]: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arbitrary interface for storing
|
* Arbitrary interface for storing
|
||||||
@@ -485,11 +481,14 @@ 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)
|
||||||
@@ -533,7 +532,8 @@ export class SASViyaApiClient {
|
|||||||
.forEach((e) => {
|
.forEach((e) => {
|
||||||
e.extensions?.forEach((ext) => {
|
e.extensions?.forEach((ext) => {
|
||||||
this.fileExtensionMap.set(ext, {
|
this.fileExtensionMap.set(ext, {
|
||||||
typeDefName: e.name, // "name:" is the typeDefName value required for file creation.
|
// "name:" is the typeDefName value required for file creation.
|
||||||
|
typeDefName: e.name,
|
||||||
properties: e.properties
|
properties: e.properties
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -550,34 +550,38 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const createFileResponse = await this.requestClient.post<File>(
|
||||||
await this.requestClient
|
`/files/files?parentFolderUri=${parentFolderUri}&typeDefName=${
|
||||||
.post<File>(
|
typeDefName ?? 'file'
|
||||||
`/files/files?parentFolderUri=${parentFolderUri}&typeDefName=${
|
}#rawUpload`,
|
||||||
typeDefName ?? 'file'
|
formData,
|
||||||
}#rawUpload`,
|
accessToken,
|
||||||
formData,
|
'multipart/form-data; boundary=' + (formData as any)._boundary,
|
||||||
accessToken,
|
headers
|
||||||
'multipart/form-data; boundary=' + (formData as any)._boundary,
|
)
|
||||||
headers
|
|
||||||
)
|
try {
|
||||||
.then(async (res) => {
|
// If a patch was created...
|
||||||
// If a patch was created...
|
if (filePatch) {
|
||||||
if (filePatch) {
|
// Get the URI of the newly created file
|
||||||
// Get the URI of the newly created file
|
const fileUri = createFileResponse.result.links.filter(
|
||||||
const fileUri = res.result.links.filter(
|
(e) => e.method == 'PATCH' && e.rel == 'patch'
|
||||||
(e) => e.method == 'PATCH' && e.rel == 'patch'
|
)[0].uri
|
||||||
)[0].uri
|
// and apply the patch
|
||||||
// and apply the patch
|
return (
|
||||||
return await this.requestClient.patch<File>(
|
await this.requestClient.patch<File>(
|
||||||
`${fileUri}`,
|
`${fileUri}`,
|
||||||
filePatch,
|
filePatch,
|
||||||
accessToken
|
accessToken,
|
||||||
)
|
'application/json',
|
||||||
}
|
patchHeaders
|
||||||
return res
|
)
|
||||||
})
|
).result
|
||||||
).result
|
}
|
||||||
|
return createFileResponse.result
|
||||||
|
} catch (e: any) {
|
||||||
|
throw new Error(`Error patching file ${fileName}.\n${e.message}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -272,10 +272,15 @@ export class RequestClient implements HttpClient {
|
|||||||
|
|
||||||
public async patch<T>(
|
public async patch<T>(
|
||||||
url: string,
|
url: string,
|
||||||
data: any = {},
|
data: any,
|
||||||
accessToken?: string
|
accessToken: string | undefined,
|
||||||
|
contentType = 'application/json',
|
||||||
|
overrideHeaders: { [key: string]: string | number } = {}
|
||||||
): Promise<{ result: T; etag: string }> {
|
): Promise<{ result: T; etag: string }> {
|
||||||
const headers = this.getHeaders(accessToken, 'application/json')
|
const headers = {
|
||||||
|
...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 })
|
||||||
|
|||||||
Reference in New Issue
Block a user