mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-10 05:40:06 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3cff286c57 | ||
|
|
d17124f375 |
@@ -276,17 +276,17 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a compute context on the given server.
|
* Updates a compute context on the given server.
|
||||||
* @param contextId - the ID of the context to be deleted.
|
* @param contextName - the original name of the context to be updated.
|
||||||
* @param editedContext - an object with the properties to be updated.
|
* @param editedContext - an object with the properties to be updated.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
*/
|
*/
|
||||||
public async editContext(
|
public async editContext(
|
||||||
contextId: string,
|
contextName: string,
|
||||||
editedContext: EditContextInput,
|
editedContext: EditContextInput,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
) {
|
) {
|
||||||
if (!contextId) {
|
if (!contextName) {
|
||||||
throw new Error('Invalid context ID.')
|
throw new Error('Invalid context name.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
@@ -297,8 +297,13 @@ export class SASViyaApiClient {
|
|||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const originalContext = await this.getContextByName(
|
||||||
|
contextName,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
|
|
||||||
const { result: context, etag } = await this.request<Context>(
|
const { result: context, etag } = await this.request<Context>(
|
||||||
`${this.serverUrl}/compute/contexts/${contextId}`,
|
`${this.serverUrl}/compute/contexts/${originalContext.id}`,
|
||||||
{
|
{
|
||||||
headers
|
headers
|
||||||
}
|
}
|
||||||
@@ -307,11 +312,11 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
if (e && e.status === 404) {
|
if (e && e.status === 404) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The context with ID ${contextId} was not found on this server.`
|
`The context ${contextName} was not found on this server.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`An error occurred when fetching the context with ID ${contextId}`
|
`An error occurred when fetching the context ${contextName}`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -331,7 +336,7 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await this.request<Context>(
|
return await this.request<Context>(
|
||||||
`${this.serverUrl}/compute/contexts/${contextId}`,
|
`${this.serverUrl}/compute/contexts/${context.id}`,
|
||||||
updateContextRequest
|
updateContextRequest
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -354,16 +359,7 @@ export class SASViyaApiClient {
|
|||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
const context = await this.getContextByName(contextName, accessToken)
|
||||||
`${this.serverUrl}/compute/contexts?filter=eq(name, "${contextName}")`,
|
|
||||||
{ headers }
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!contexts || !(contexts.items && contexts.items.length)) {
|
|
||||||
throw new Error(
|
|
||||||
`The context ${contextName} was not found on ${this.serverUrl}.`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const deleteContextRequest: RequestInit = {
|
const deleteContextRequest: RequestInit = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
@@ -371,7 +367,7 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await this.request<Context>(
|
return await this.request<Context>(
|
||||||
`${this.serverUrl}/compute/contexts/${contexts.items[0].id}`,
|
`${this.serverUrl}/compute/contexts/${context.id}`,
|
||||||
deleteContextRequest
|
deleteContextRequest
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1328,6 +1324,38 @@ export class SASViyaApiClient {
|
|||||||
return `/folders/folders/${folder.id}`
|
return `/folders/folders/${folder.id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getContextByName(
|
||||||
|
contextName: string,
|
||||||
|
accessToken?: string
|
||||||
|
): Promise<Context> {
|
||||||
|
const headers: any = {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessToken) {
|
||||||
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||||
|
`${this.serverUrl}/compute/contexts?filter=eq(name, "${contextName}")`,
|
||||||
|
{ headers }
|
||||||
|
).catch((e) => {
|
||||||
|
console.error(e)
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`An error occurred when fetching the context with ID ${contextName}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!contexts || !(contexts.items && contexts.items.length)) {
|
||||||
|
throw new Error(
|
||||||
|
`The context ${contextName} was not found on ${this.serverUrl}.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return contexts.items[0]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves a Viya folder to a new location. The folder may be renamed at the same time.
|
* 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 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.
|
||||||
|
|||||||
@@ -140,12 +140,12 @@ export default class SASjs {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a compute context on the given server.
|
* Updates a compute context on the given server.
|
||||||
* @param contextId - the ID of the context to be deleted.
|
* @param contextName - the original name of the context to be deleted.
|
||||||
* @param editedContext - an object with the properties to be updated.
|
* @param editedContext - an object with the properties to be updated.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
*/
|
*/
|
||||||
public async editContext(
|
public async editContext(
|
||||||
contextId: string,
|
contextName: string,
|
||||||
editedContext: EditContextInput,
|
editedContext: EditContextInput,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
) {
|
) {
|
||||||
@@ -153,7 +153,7 @@ export default class SASjs {
|
|||||||
throw new Error('This operation is only supported on SAS Viya servers.')
|
throw new Error('This operation is only supported on SAS Viya servers.')
|
||||||
}
|
}
|
||||||
return await this.sasViyaApiClient!.editContext(
|
return await this.sasViyaApiClient!.editContext(
|
||||||
contextId,
|
contextName,
|
||||||
editedContext,
|
editedContext,
|
||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user