mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-04 03:00:05 +00:00
Merge branch 'master' into issue-276
This commit is contained in:
6
package-lock.json
generated
6
package-lock.json
generated
@@ -1276,6 +1276,12 @@
|
|||||||
"integrity": "sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==",
|
"integrity": "sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/mime": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-Jus9s4CDbqwocc5pOAnh8ShfrnMcPHuJYzVcSUU7lrh8Ni5HuIqX3oilL86p3dlTrk0LzHRCgA/GQ7uNCw6l2Q==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/minimist": {
|
"@types/minimist": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.1.tgz",
|
||||||
|
|||||||
@@ -39,11 +39,13 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.23",
|
"@types/jest": "^26.0.23",
|
||||||
|
"@types/mime": "^2.0.3",
|
||||||
"@types/tough-cookie": "^4.0.0",
|
"@types/tough-cookie": "^4.0.0",
|
||||||
"cp": "^0.2.0",
|
"cp": "^0.2.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"jest": "^27.0.4",
|
"jest": "^27.0.4",
|
||||||
"jest-extended": "^0.11.5",
|
"jest-extended": "^0.11.5",
|
||||||
|
"mime": "^2.5.2",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
Context,
|
Context,
|
||||||
ContextAllAttributes,
|
ContextAllAttributes,
|
||||||
Folder,
|
Folder,
|
||||||
|
File,
|
||||||
EditContextInput,
|
EditContextInput,
|
||||||
JobDefinition,
|
JobDefinition,
|
||||||
PollOptions
|
PollOptions
|
||||||
@@ -30,6 +31,7 @@ import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
|||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { SasAuthResponse, MacroVar } from '@sasjs/utils/types'
|
import { SasAuthResponse, MacroVar } from '@sasjs/utils/types'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
|
import * as mime from 'mime'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A client for interfacing with the SAS Viya REST API.
|
* A client for interfacing with the SAS Viya REST API.
|
||||||
@@ -536,6 +538,53 @@ export class SASViyaApiClient {
|
|||||||
.then((res) => res.result)
|
.then((res) => res.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a file. Path to or URI of the parent folder is required.
|
||||||
|
* @param fileName - the name of the new file.
|
||||||
|
* @param contentBuffer - the content of the new file in Buffer.
|
||||||
|
* @param parentFolderPath - the full path to the parent folder. If not
|
||||||
|
* provided, the parentFolderUri must be provided.
|
||||||
|
* @param parentFolderUri - the URI (eg /folders/folders/UUID) of the parent
|
||||||
|
* folder. If not provided, the parentFolderPath must be provided.
|
||||||
|
* @param accessToken - an access token for authorizing the request.
|
||||||
|
*/
|
||||||
|
public async createFile(
|
||||||
|
fileName: string,
|
||||||
|
contentBuffer: Buffer,
|
||||||
|
parentFolderPath?: string,
|
||||||
|
parentFolderUri?: string,
|
||||||
|
accessToken?: string
|
||||||
|
): Promise<File> {
|
||||||
|
if (!parentFolderPath && !parentFolderUri) {
|
||||||
|
throw new Error('Path or URI of the parent folder is required.')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parentFolderUri && parentFolderPath) {
|
||||||
|
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
Accept: 'application/vnd.sas.file+json',
|
||||||
|
'Content-Disposition': `filename="${fileName}";`
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new NodeFormData()
|
||||||
|
formData.append('file', contentBuffer, fileName)
|
||||||
|
|
||||||
|
const mimeType =
|
||||||
|
mime.getType(fileName.match(/\.[0-9a-z]+$/i)?.[0] || '') ?? 'text/plain'
|
||||||
|
|
||||||
|
return (
|
||||||
|
await this.requestClient.post<File>(
|
||||||
|
`/files/files?parentFolderUri=${parentFolderUri}&typeDefName=file#rawUpload`,
|
||||||
|
formData,
|
||||||
|
accessToken,
|
||||||
|
'multipart/form-data; boundary=' + (formData as any)._boundary,
|
||||||
|
headers
|
||||||
|
)
|
||||||
|
).result
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a folder. Path to or URI of the parent folder is required.
|
* Creates a folder. Path to or URI of the parent folder is required.
|
||||||
* @param folderName - the name of the new folder.
|
* @param folderName - the name of the new folder.
|
||||||
|
|||||||
46
src/SASjs.ts
46
src/SASjs.ts
@@ -268,7 +268,7 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a folder at SAS file system.
|
* Creates a folder in the logical SAS folder tree
|
||||||
* @param folderName - name of the folder to be created.
|
* @param folderName - name of the folder to be created.
|
||||||
* @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder.
|
* @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder.
|
||||||
* @param parentFolderUri - the URI of the parent folder.
|
* @param parentFolderUri - the URI of the parent folder.
|
||||||
@@ -300,6 +300,40 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a file in the logical SAS folder tree
|
||||||
|
* @param fileName - name of the file to be created.
|
||||||
|
* @param content - content of the file to be created.
|
||||||
|
* @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder.
|
||||||
|
* @param parentFolderUri - the URI of the parent folder.
|
||||||
|
* @param accessToken - the access token to authorizing the request.
|
||||||
|
* @param sasApiClient - a client for interfacing with SAS API.
|
||||||
|
*/
|
||||||
|
public async createFile(
|
||||||
|
fileName: string,
|
||||||
|
content: Buffer,
|
||||||
|
parentFolderPath: string,
|
||||||
|
parentFolderUri?: string,
|
||||||
|
accessToken?: string,
|
||||||
|
sasApiClient?: SASViyaApiClient
|
||||||
|
) {
|
||||||
|
if (sasApiClient)
|
||||||
|
return await sasApiClient.createFile(
|
||||||
|
fileName,
|
||||||
|
content,
|
||||||
|
parentFolderPath,
|
||||||
|
parentFolderUri,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
|
return await this.sasViyaApiClient!.createFile(
|
||||||
|
fileName,
|
||||||
|
content,
|
||||||
|
parentFolderPath,
|
||||||
|
parentFolderUri,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a folder from the SAS file system.
|
* Fetches a folder from the SAS file system.
|
||||||
* @param folderPath - path of the folder to be fetched.
|
* @param folderPath - path of the folder to be fetched.
|
||||||
@@ -951,6 +985,16 @@ export default class SASjs {
|
|||||||
isForced
|
isForced
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
case 'file':
|
||||||
|
await this.createFile(
|
||||||
|
member.name,
|
||||||
|
member.code,
|
||||||
|
parentFolder,
|
||||||
|
undefined,
|
||||||
|
accessToken,
|
||||||
|
sasApiClient
|
||||||
|
)
|
||||||
|
break
|
||||||
case 'service':
|
case 'service':
|
||||||
await this.createJobDefinition(
|
await this.createJobDefinition(
|
||||||
member.name,
|
member.name,
|
||||||
|
|||||||
8
src/types/File.ts
Normal file
8
src/types/File.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Link } from './Link'
|
||||||
|
|
||||||
|
export interface File {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
parentUri: string
|
||||||
|
links: Link[]
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
export * from './Context'
|
export * from './Context'
|
||||||
export * from './CsrfToken'
|
export * from './CsrfToken'
|
||||||
export * from './Folder'
|
export * from './Folder'
|
||||||
|
export * from './File'
|
||||||
export * from './Job'
|
export * from './Job'
|
||||||
export * from './JobDefinition'
|
export * from './JobDefinition'
|
||||||
export * from './JobResult'
|
export * from './JobResult'
|
||||||
|
|||||||
Reference in New Issue
Block a user