1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-10 08:54:35 +00:00

chore: tidied up branch

This commit is contained in:
Trevor Moody
2025-11-22 16:49:28 +00:00
parent a3c5e985f7
commit 824ee6f8da
3 changed files with 53 additions and 33 deletions

View File

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

View File

@@ -481,11 +481,14 @@ export class SASViyaApiClient {
if (!parentFolderUri && parentFolderPath) {
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
}
const headers = {
Accept: 'application/vnd.sas.file+json',
'Content-Disposition': `filename="${fileName}";`
}
const patchHeaders = {
Accept: 'application/json',
'If-Match': '*'
}
const formData = new NodeFormData()
formData.append('file', contentBuffer, fileName)
@@ -529,7 +532,8 @@ export class SASViyaApiClient {
.forEach((e) => {
e.extensions?.forEach((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
})
})
@@ -546,34 +550,38 @@ export class SASViyaApiClient {
}
}
return (
await this.requestClient
.post<File>(
`/files/files?parentFolderUri=${parentFolderUri}&typeDefName=${
typeDefName ?? 'file'
}#rawUpload`,
formData,
accessToken,
'multipart/form-data; boundary=' + (formData as any)._boundary,
headers
)
.then(async (res) => {
// If a patch was created...
if (filePatch) {
// Get the URI of the newly created file
const fileUri = res.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
)
}
return res
})
).result
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,10 +272,15 @@ export class RequestClient implements HttpClient {
public async patch<T>(
url: string,
data: any = {},
accessToken?: string
data: any,
accessToken: string | undefined,
contentType = 'application/json',
overrideHeaders: { [key: string]: string | number } = {}
): Promise<{ result: T; etag: string }> {
const headers = this.getHeaders(accessToken, 'application/json')
const headers = {
...this.getHeaders(accessToken, contentType),
...overrideHeaders
}
return this.httpClient
.patch<T>(url, data, { headers, withXSRFToken: true })