mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
223
docs/classes/reflection-640.reflection-158.fileuploader.html
Normal file
223
docs/classes/reflection-640.reflection-158.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
296
docs/classes/reflection-640.reflection-158.sas9apiclient.html
Normal file
296
docs/classes/reflection-640.reflection-158.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1038
docs/classes/reflection-640.reflection-158.sasjs.html
Normal file
1038
docs/classes/reflection-640.reflection-158.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1006
docs/classes/reflection-640.reflection-158.sasviyaapiclient.html
Normal file
1006
docs/classes/reflection-640.reflection-158.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
259
docs/classes/reflection-640.reflection-158.sessionmanager.html
Normal file
259
docs/classes/reflection-640.reflection-158.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
223
docs/classes/reflection-641.reflection-158.fileuploader.html
Normal file
223
docs/classes/reflection-641.reflection-158.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
296
docs/classes/reflection-641.reflection-158.sas9apiclient.html
Normal file
296
docs/classes/reflection-641.reflection-158.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1038
docs/classes/reflection-641.reflection-158.sasjs.html
Normal file
1038
docs/classes/reflection-641.reflection-158.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1012
docs/classes/reflection-641.reflection-158.sasviyaapiclient.html
Normal file
1012
docs/classes/reflection-641.reflection-158.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
259
docs/classes/reflection-641.reflection-158.sessionmanager.html
Normal file
259
docs/classes/reflection-641.reflection-158.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
223
docs/classes/reflection-644.reflection-162.fileuploader.html
Normal file
223
docs/classes/reflection-644.reflection-162.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
296
docs/classes/reflection-644.reflection-162.sas9apiclient.html
Normal file
296
docs/classes/reflection-644.reflection-162.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1038
docs/classes/reflection-644.reflection-162.sasjs.html
Normal file
1038
docs/classes/reflection-644.reflection-162.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1006
docs/classes/reflection-644.reflection-162.sasviyaapiclient.html
Normal file
1006
docs/classes/reflection-644.reflection-162.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
259
docs/classes/reflection-644.reflection-162.sessionmanager.html
Normal file
259
docs/classes/reflection-644.reflection-162.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
223
docs/classes/reflection-648.reflection-166.fileuploader.html
Normal file
223
docs/classes/reflection-648.reflection-166.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
296
docs/classes/reflection-648.reflection-166.sas9apiclient.html
Normal file
296
docs/classes/reflection-648.reflection-166.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1064
docs/classes/reflection-648.reflection-166.sasjs.html
Normal file
1064
docs/classes/reflection-648.reflection-166.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1006
docs/classes/reflection-648.reflection-166.sasviyaapiclient.html
Normal file
1006
docs/classes/reflection-648.reflection-166.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
259
docs/classes/reflection-648.reflection-166.sessionmanager.html
Normal file
259
docs/classes/reflection-648.reflection-166.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
223
docs/classes/reflection-678.reflection-166.fileuploader.html
Normal file
223
docs/classes/reflection-678.reflection-166.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
296
docs/classes/reflection-678.reflection-166.sas9apiclient.html
Normal file
296
docs/classes/reflection-678.reflection-166.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1170
docs/classes/reflection-678.reflection-166.sasjs.html
Normal file
1170
docs/classes/reflection-678.reflection-166.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1118
docs/classes/reflection-678.reflection-166.sasviyaapiclient.html
Normal file
1118
docs/classes/reflection-678.reflection-166.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
259
docs/classes/reflection-678.reflection-166.sessionmanager.html
Normal file
259
docs/classes/reflection-678.reflection-166.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-640.html
Normal file
106
docs/modules/reflection-640.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-640.reflection-158.html
Normal file
128
docs/modules/reflection-640.reflection-158.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-641.html
Normal file
106
docs/modules/reflection-641.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-641.reflection-158.html
Normal file
128
docs/modules/reflection-641.reflection-158.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-644.html
Normal file
106
docs/modules/reflection-644.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-644.reflection-162.html
Normal file
128
docs/modules/reflection-644.reflection-162.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-648.html
Normal file
106
docs/modules/reflection-648.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-648.reflection-166.html
Normal file
128
docs/modules/reflection-648.reflection-166.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-678.html
Normal file
106
docs/modules/reflection-678.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-678.reflection-166.html
Normal file
128
docs/modules/reflection-678.reflection-166.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -3,6 +3,7 @@ import {
|
||||
parseAndSubmitAuthorizeForm,
|
||||
convertToCSV,
|
||||
makeRequest,
|
||||
isUri,
|
||||
isUrl
|
||||
} from './utils'
|
||||
import * as NodeFormData from 'form-data'
|
||||
@@ -38,6 +39,7 @@ export class SASViyaApiClient {
|
||||
this.contextName,
|
||||
this.setCsrfToken
|
||||
)
|
||||
private isForceDeploy: boolean = false
|
||||
|
||||
/**
|
||||
* Returns a map containing the directory structure in the currently set root folder.
|
||||
@@ -465,12 +467,15 @@ export class SASViyaApiClient {
|
||||
* 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.
|
||||
* @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted.
|
||||
*/
|
||||
public async createFolder(
|
||||
folderName: string,
|
||||
parentFolderPath?: string,
|
||||
parentFolderUri?: string,
|
||||
accessToken?: string
|
||||
accessToken?: string,
|
||||
isForced?: boolean
|
||||
): Promise<Folder> {
|
||||
if (!parentFolderPath && !parentFolderUri) {
|
||||
throw new Error('Parent folder path or uri is required')
|
||||
@@ -479,6 +484,8 @@ export class SASViyaApiClient {
|
||||
if (!parentFolderUri && parentFolderPath) {
|
||||
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
|
||||
if (!parentFolderUri) {
|
||||
if (isForced) this.isForceDeploy = true
|
||||
|
||||
console.log(`Parent folder is not present: ${parentFolderPath}`)
|
||||
|
||||
const newParentFolderPath = parentFolderPath.substring(
|
||||
@@ -499,6 +506,35 @@ export class SASViyaApiClient {
|
||||
accessToken
|
||||
)
|
||||
console.log(`Parent Folder "${newFolderName}" successfully created.`)
|
||||
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
||||
} else if (isForced && accessToken && !this.isForceDeploy) {
|
||||
this.isForceDeploy = true
|
||||
|
||||
await this.deleteFolder(parentFolderPath, accessToken)
|
||||
|
||||
const newParentFolderPath = parentFolderPath.substring(
|
||||
0,
|
||||
parentFolderPath.lastIndexOf('/')
|
||||
)
|
||||
const newFolderName = `${parentFolderPath.split('/').pop()}`
|
||||
|
||||
if (newParentFolderPath === '') {
|
||||
throw new Error('Root Folder should have been present on server')
|
||||
}
|
||||
|
||||
console.log(
|
||||
`Creating Parent Folder:\n${newFolderName} in ${newParentFolderPath}`
|
||||
)
|
||||
|
||||
const parentFolder = await this.createFolder(
|
||||
newFolderName,
|
||||
newParentFolderPath,
|
||||
undefined,
|
||||
accessToken
|
||||
)
|
||||
|
||||
console.log(`Parent Folder "${newFolderName}" successfully created.`)
|
||||
|
||||
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
||||
}
|
||||
}
|
||||
@@ -721,7 +757,7 @@ export class SASViyaApiClient {
|
||||
/**
|
||||
* Deletes the client representing the supplied ID.
|
||||
* @param clientId - the client ID to authenticate with.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
* @param accessToken - an access token for authorizing the request.
|
||||
*/
|
||||
public async deleteClient(clientId: string, accessToken?: string) {
|
||||
const url = this.serverUrl + `/oauth/clients/${clientId}`
|
||||
@@ -1190,6 +1226,101 @@ export class SASViyaApiClient {
|
||||
return `/folders/folders/${folder.id}`
|
||||
}
|
||||
|
||||
private async getRecycleBinUri(accessToken: string) {
|
||||
const url = '/folders/folders/@myRecycleBin'
|
||||
const requestInfo = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + accessToken
|
||||
}
|
||||
}
|
||||
|
||||
const { result: folder } = await this.request<Folder>(
|
||||
`${this.serverUrl}${url}`,
|
||||
requestInfo
|
||||
).catch((err) => {
|
||||
return { result: null }
|
||||
})
|
||||
|
||||
if (!folder) return undefined
|
||||
|
||||
return `/folders/folders/${folder.id}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a Viya folder to a new location. The folder may be renamed at the same time.
|
||||
* @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.
|
||||
* @param targetParentFolder - the full path or URI of the _parent_ folder to which the `sourceFolder` will be moved (eg `/Public/newDestination`). To move a folder, a user has to have write permissions in targetParentFolder. Providing URI instead of path will save one extra request.
|
||||
* @param targetFolderName - the name of the "moved" folder. If left blank, the original folder name will be used (eg `myFolder` in `/Public/newDestination/myFolder` for the example above). Optional field.
|
||||
* @param accessToken - an access token for authorizing the request.
|
||||
*/
|
||||
public async moveFolder(
|
||||
sourceFolder: string,
|
||||
targetParentFolder: string,
|
||||
targetFolderName: string,
|
||||
accessToken: string
|
||||
) {
|
||||
// checks if 'sourceFolder' is already a URI
|
||||
const sourceFolderUri = isUri(sourceFolder)
|
||||
? sourceFolder
|
||||
: await this.getFolderUri(sourceFolder, accessToken)
|
||||
|
||||
// checks if 'targetParentFolder' is already a URI
|
||||
const targetParentFolderUri = isUri(targetParentFolder)
|
||||
? targetParentFolder
|
||||
: await this.getFolderUri(targetParentFolder, accessToken)
|
||||
|
||||
const sourceFolderId = sourceFolderUri?.split('/').pop()
|
||||
const url = sourceFolderUri
|
||||
|
||||
const requestInfo = {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + accessToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: sourceFolderId,
|
||||
name: targetFolderName,
|
||||
parentFolderUri: targetParentFolderUri
|
||||
})
|
||||
}
|
||||
|
||||
const { result: folder } = await this.request<Folder>(
|
||||
`${this.serverUrl}${url}`,
|
||||
requestInfo
|
||||
).catch((err) => {
|
||||
throw err
|
||||
})
|
||||
|
||||
if (!folder) return undefined
|
||||
|
||||
return folder
|
||||
}
|
||||
|
||||
/**
|
||||
* For performance (and in case of accidental error) the `deleteFolder` function does not actually delete the folder (and all it's content and subfolder content). Instead the folder is simply moved to the recycle bin. Deletion time will be added to the folder name.
|
||||
* @param folderPath - the full path (eg `/Public/example/deleteThis`) of the folder to be deleted.
|
||||
* @param accessToken - an access token for authorizing the request.
|
||||
*/
|
||||
public async deleteFolder(folderPath: string, accessToken: string) {
|
||||
const recycleBinUri = await this.getRecycleBinUri(accessToken)
|
||||
const folderName = folderPath.split('/').pop() || ''
|
||||
const date = new Date()
|
||||
const timeMark = date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
|
||||
const deletedFolderName = folderName + ' ' + timeMark
|
||||
|
||||
const movedFolder = await this.moveFolder(
|
||||
folderPath,
|
||||
recycleBinUri!,
|
||||
deletedFolderName,
|
||||
accessToken
|
||||
)
|
||||
|
||||
return movedFolder
|
||||
}
|
||||
|
||||
setCsrfTokenLocal = (csrfToken: CsrfToken) => {
|
||||
this.csrfToken = csrfToken
|
||||
this.setCsrfToken(csrfToken)
|
||||
|
||||
31
src/SASjs.ts
31
src/SASjs.ts
@@ -176,12 +176,22 @@ export default class SASjs {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a folder at SAS file system
|
||||
* @param folderName - name of the folder 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.
|
||||
* @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted. Applicable for SAS VIYA only.
|
||||
*/
|
||||
public async createFolder(
|
||||
folderName: string,
|
||||
parentFolderPath: string,
|
||||
parentFolderUri?: string,
|
||||
accessToken?: string,
|
||||
sasApiClient?: SASViyaApiClient
|
||||
sasApiClient?: SASViyaApiClient,
|
||||
isForced?: boolean
|
||||
) {
|
||||
if (this.sasjsConfig.serverType !== ServerType.SASViya) {
|
||||
throw new Error('This operation is only supported on SAS Viya servers.')
|
||||
@@ -197,7 +207,8 @@ export default class SASjs {
|
||||
folderName,
|
||||
parentFolderPath,
|
||||
parentFolderUri,
|
||||
accessToken
|
||||
accessToken,
|
||||
isForced
|
||||
)
|
||||
}
|
||||
|
||||
@@ -526,12 +537,14 @@ export default class SASjs {
|
||||
* If not provided, is taken from SASjsConfig.
|
||||
* @param accessToken - an optional access token to be passed in when
|
||||
* using this function from the command line.
|
||||
* @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted.
|
||||
*/
|
||||
public async deployServicePack(
|
||||
serviceJson: any,
|
||||
appLoc?: string,
|
||||
serverUrl?: string,
|
||||
accessToken?: string
|
||||
accessToken?: string,
|
||||
isForced = false
|
||||
) {
|
||||
if (this.sasjsConfig.serverType !== ServerType.SASViya) {
|
||||
throw new Error('This operation is only supported on SAS Viya servers.')
|
||||
@@ -582,7 +595,8 @@ export default class SASjs {
|
||||
appLoc,
|
||||
members,
|
||||
accessToken,
|
||||
sasApiClient
|
||||
sasApiClient,
|
||||
isForced
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1289,7 +1303,8 @@ export default class SASjs {
|
||||
parentFolder: string,
|
||||
membersJson: any[],
|
||||
accessToken?: string,
|
||||
sasApiClient?: SASViyaApiClient
|
||||
sasApiClient?: SASViyaApiClient,
|
||||
isForced?: boolean
|
||||
) {
|
||||
await asyncForEach(membersJson, async (member: any) => {
|
||||
switch (member.type) {
|
||||
@@ -1299,7 +1314,8 @@ export default class SASjs {
|
||||
parentFolder,
|
||||
undefined,
|
||||
accessToken,
|
||||
sasApiClient
|
||||
sasApiClient,
|
||||
isForced
|
||||
)
|
||||
break
|
||||
case 'service':
|
||||
@@ -1320,7 +1336,8 @@ export default class SASjs {
|
||||
`${parentFolder}/${member.name}`,
|
||||
member.members,
|
||||
accessToken,
|
||||
sasApiClient
|
||||
sasApiClient,
|
||||
isForced
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -13,4 +13,5 @@ export * from './parseSasViyaLog'
|
||||
export * from './serialize'
|
||||
export * from './splitChunks'
|
||||
export * from './parseWeboutResponse'
|
||||
export * from './isUri'
|
||||
export * from './isUrl'
|
||||
|
||||
5
src/utils/isUri.ts
Normal file
5
src/utils/isUri.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Checks if string is in URI format
|
||||
* @param str string to check
|
||||
*/
|
||||
export const isUri = (str: string): boolean => /^\/folders\/folders\//.test(str)
|
||||
Reference in New Issue
Block a user