mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-06 04:00:05 +00:00
feat: added forced deploy
This commit is contained in:
@@ -34,6 +34,7 @@ export class SASViyaApiClient {
|
|||||||
this.contextName,
|
this.contextName,
|
||||||
this.setCsrfToken
|
this.setCsrfToken
|
||||||
)
|
)
|
||||||
|
private isForceDeploy: boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a map containing the directory structure in the currently set root folder.
|
* Returns a map containing the directory structure in the currently set root folder.
|
||||||
@@ -365,7 +366,8 @@ export class SASViyaApiClient {
|
|||||||
folderName: string,
|
folderName: string,
|
||||||
parentFolderPath?: string,
|
parentFolderPath?: string,
|
||||||
parentFolderUri?: string,
|
parentFolderUri?: string,
|
||||||
accessToken?: string
|
accessToken?: string,
|
||||||
|
isForced?: boolean
|
||||||
): Promise<Folder> {
|
): Promise<Folder> {
|
||||||
if (!parentFolderPath && !parentFolderUri) {
|
if (!parentFolderPath && !parentFolderUri) {
|
||||||
throw new Error('Parent folder path or uri is required')
|
throw new Error('Parent folder path or uri is required')
|
||||||
@@ -394,6 +396,44 @@ export class SASViyaApiClient {
|
|||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
console.log(`Parent Folder "${newFolderName}" successfully created.`)
|
console.log(`Parent Folder "${newFolderName}" successfully created.`)
|
||||||
|
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
||||||
|
} else if (isForced && accessToken && !this.isForceDeploy) {
|
||||||
|
this.isForceDeploy = true
|
||||||
|
const recycleBin = await this.getRecycleBin(accessToken)
|
||||||
|
const recycleBinUri = recycleBin?.id || ''
|
||||||
|
const oldFolderName = parentFolderPath?.split('/').pop() || ''
|
||||||
|
const parentFolderId = parentFolderUri?.split('/').pop() || ''
|
||||||
|
|
||||||
|
await this.moveFolder(
|
||||||
|
parentFolderId,
|
||||||
|
recycleBinUri,
|
||||||
|
oldFolderName,
|
||||||
|
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}`
|
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1085,6 +1125,60 @@ export class SASViyaApiClient {
|
|||||||
return `/folders/folders/${folder.id}`
|
return `/folders/folders/${folder.id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getRecycleBin(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 folder
|
||||||
|
}
|
||||||
|
|
||||||
|
private async moveFolder(
|
||||||
|
from: string,
|
||||||
|
to: string,
|
||||||
|
folderName: string,
|
||||||
|
accessToken: string
|
||||||
|
) {
|
||||||
|
const url = '/folders/folders/' + from
|
||||||
|
const requestInfo = {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: 'Bearer ' + accessToken
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
id: from,
|
||||||
|
name: folderName,
|
||||||
|
parentFolderUri: '/folders/folders/' + to
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const { result: folder } = await this.request<Folder>(
|
||||||
|
`${this.serverUrl}${url}`,
|
||||||
|
requestInfo
|
||||||
|
).catch((err) => {
|
||||||
|
return { result: null }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!folder) return undefined
|
||||||
|
|
||||||
|
return folder
|
||||||
|
}
|
||||||
|
|
||||||
setCsrfTokenLocal = (csrfToken: CsrfToken) => {
|
setCsrfTokenLocal = (csrfToken: CsrfToken) => {
|
||||||
this.csrfToken = csrfToken
|
this.csrfToken = csrfToken
|
||||||
this.setCsrfToken(csrfToken)
|
this.setCsrfToken(csrfToken)
|
||||||
|
|||||||
21
src/SASjs.ts
21
src/SASjs.ts
@@ -139,7 +139,8 @@ export default class SASjs {
|
|||||||
parentFolderPath: string,
|
parentFolderPath: string,
|
||||||
parentFolderUri?: string,
|
parentFolderUri?: string,
|
||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
sasApiClient?: SASViyaApiClient
|
sasApiClient?: SASViyaApiClient,
|
||||||
|
isForced?: boolean
|
||||||
) {
|
) {
|
||||||
if (this.sasjsConfig.serverType !== ServerType.SASViya) {
|
if (this.sasjsConfig.serverType !== ServerType.SASViya) {
|
||||||
throw new Error('This operation is only supported on SAS Viya servers.')
|
throw new Error('This operation is only supported on SAS Viya servers.')
|
||||||
@@ -155,7 +156,8 @@ export default class SASjs {
|
|||||||
folderName,
|
folderName,
|
||||||
parentFolderPath,
|
parentFolderPath,
|
||||||
parentFolderUri,
|
parentFolderUri,
|
||||||
accessToken
|
accessToken,
|
||||||
|
isForced
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,7 +491,8 @@ export default class SASjs {
|
|||||||
serviceJson: any,
|
serviceJson: any,
|
||||||
appLoc?: string,
|
appLoc?: string,
|
||||||
serverUrl?: string,
|
serverUrl?: string,
|
||||||
accessToken?: string
|
accessToken?: string,
|
||||||
|
isForced = false
|
||||||
) {
|
) {
|
||||||
if (this.sasjsConfig.serverType !== ServerType.SASViya) {
|
if (this.sasjsConfig.serverType !== ServerType.SASViya) {
|
||||||
throw new Error('This operation is only supported on SAS Viya servers.')
|
throw new Error('This operation is only supported on SAS Viya servers.')
|
||||||
@@ -540,7 +543,8 @@ export default class SASjs {
|
|||||||
appLoc,
|
appLoc,
|
||||||
members,
|
members,
|
||||||
accessToken,
|
accessToken,
|
||||||
sasApiClient
|
sasApiClient,
|
||||||
|
isForced
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1247,7 +1251,8 @@ export default class SASjs {
|
|||||||
parentFolder: string,
|
parentFolder: string,
|
||||||
membersJson: any[],
|
membersJson: any[],
|
||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
sasApiClient?: SASViyaApiClient
|
sasApiClient?: SASViyaApiClient,
|
||||||
|
isForced?: boolean
|
||||||
) {
|
) {
|
||||||
await asyncForEach(membersJson, async (member: any) => {
|
await asyncForEach(membersJson, async (member: any) => {
|
||||||
switch (member.type) {
|
switch (member.type) {
|
||||||
@@ -1257,7 +1262,8 @@ export default class SASjs {
|
|||||||
parentFolder,
|
parentFolder,
|
||||||
undefined,
|
undefined,
|
||||||
accessToken,
|
accessToken,
|
||||||
sasApiClient
|
sasApiClient,
|
||||||
|
isForced
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
case 'service':
|
case 'service':
|
||||||
@@ -1278,7 +1284,8 @@ export default class SASjs {
|
|||||||
`${parentFolder}/${member.name}`,
|
`${parentFolder}/${member.name}`,
|
||||||
member.members,
|
member.members,
|
||||||
accessToken,
|
accessToken,
|
||||||
sasApiClient
|
sasApiClient,
|
||||||
|
isForced
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user