1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +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 { 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

@@ -481,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)
@@ -529,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
}) })
}) })
@@ -546,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}`)
}
} }
/** /**

View File

@@ -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 })