1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-02 02:00:06 +00:00

fix(deploy): to SASJS with complete JSON object

This commit is contained in:
Saad Jutt
2022-03-31 04:20:49 +05:00
parent ee97e8211e
commit fc0a450e94
6 changed files with 27 additions and 98 deletions

14
package-lock.json generated
View File

@@ -8,7 +8,7 @@
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@sasjs/utils": "2.40.0", "@sasjs/utils": "file:../utils/build/sasjs-utils-5.0.0.tgz",
"axios": "0.26.0", "axios": "0.26.0",
"axios-cookiejar-support": "1.0.1", "axios-cookiejar-support": "1.0.1",
"form-data": "4.0.0", "form-data": "4.0.0",
@@ -1142,10 +1142,11 @@
} }
}, },
"node_modules/@sasjs/utils": { "node_modules/@sasjs/utils": {
"version": "2.40.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.40.0.tgz", "resolved": "file:../utils/build/sasjs-utils-5.0.0.tgz",
"integrity": "sha512-U0y/eqRlvfkMHmKDlr1xmeN+Rask7TnJPuRpOz71P8QpGYTw1M9AyZvzRSk503p4KCJb8ysdcqXyGVLfhuoM+A==", "integrity": "sha512-MN4t2AgGAra0wYjsPgMG6XJOSFeQLOIDUJaI47mvl73qodqdeAAiVfCkfN7XSkfllQBVHE0X/t0AA7Imrq1uDg==",
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC",
"dependencies": { "dependencies": {
"@types/fs-extra": "9.0.13", "@types/fs-extra": "9.0.13",
"@types/prompts": "2.0.13", "@types/prompts": "2.0.13",
@@ -13870,9 +13871,8 @@
} }
}, },
"@sasjs/utils": { "@sasjs/utils": {
"version": "2.40.0", "version": "file:../utils/build/sasjs-utils-5.0.0.tgz",
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.40.0.tgz", "integrity": "sha512-MN4t2AgGAra0wYjsPgMG6XJOSFeQLOIDUJaI47mvl73qodqdeAAiVfCkfN7XSkfllQBVHE0X/t0AA7Imrq1uDg==",
"integrity": "sha512-U0y/eqRlvfkMHmKDlr1xmeN+Rask7TnJPuRpOz71P8QpGYTw1M9AyZvzRSk503p4KCJb8ysdcqXyGVLfhuoM+A==",
"requires": { "requires": {
"@types/fs-extra": "9.0.13", "@types/fs-extra": "9.0.13",
"@types/prompts": "2.0.13", "@types/prompts": "2.0.13",

View File

@@ -72,7 +72,7 @@
}, },
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@sasjs/utils": "2.40.0", "@sasjs/utils": "file:../utils/build/sasjs-utils-5.0.0.tgz",
"axios": "0.26.0", "axios": "0.26.0",
"axios-cookiejar-support": "1.0.1", "axios-cookiejar-support": "1.0.1",
"form-data": "4.0.0", "form-data": "4.0.0",

View File

@@ -5,8 +5,7 @@ import {
EditContextInput, EditContextInput,
PollOptions, PollOptions,
LoginMechanism, LoginMechanism,
ExecutionQuery, ExecutionQuery
FileTree
} from './types' } from './types'
import { SASViyaApiClient } from './SASViyaApiClient' import { SASViyaApiClient } from './SASViyaApiClient'
import { SAS9ApiClient } from './SAS9ApiClient' import { SAS9ApiClient } from './SAS9ApiClient'
@@ -18,7 +17,7 @@ import {
AuthConfig, AuthConfig,
ExtraResponseAttributes, ExtraResponseAttributes,
SasAuthResponse, SasAuthResponse,
StreamConfig ServicePackSASjs
} from '@sasjs/utils/types' } from '@sasjs/utils/types'
import { RequestClient } from './request/RequestClient' import { RequestClient } from './request/RequestClient'
import { SasjsRequestClient } from './request/SasjsRequestClient' import { SasjsRequestClient } from './request/SasjsRequestClient'
@@ -889,27 +888,21 @@ export default class SASjs {
/** /**
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`. * Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
* @param members - the JSON specifying the folders and services to be created. * @param dataJson - the JSON specifying the folders and files to be created, can also includes
* @param appLoc - the base folder in which to create the new folders and * appLoc, streamServiceName, streamWebFolder, streamLogo
* services. If not provided, is taken from SASjsConfig. * @param appLoc - (optional) the base folder in which to create the new folders and
* @param streamConfig - optional configuration object of StreamConfig for deploying streaming app. * services. If not provided, is taken from SASjsConfig. Precedence will be of appLoc present in dataJson.
* @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs. * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
*/ */
public async deployToSASjs( public async deployToSASjs(
members: FileTree, dataJson: ServicePackSASjs,
appLoc?: string, appLoc?: string,
streamConfig?: StreamConfig,
authConfig?: AuthConfig authConfig?: AuthConfig
) { ) {
if (!appLoc) { if (!appLoc) {
appLoc = this.sasjsConfig.appLoc appLoc = this.sasjsConfig.appLoc
} }
return await this.sasJSApiClient?.deploy( return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
members,
appLoc,
streamConfig,
authConfig
)
} }
public async executeJobSASjs(query: ExecutionQuery) { public async executeJobSASjs(query: ExecutionQuery) {
@@ -1102,13 +1095,8 @@ export default class SASjs {
} }
if (this.sasjsConfig.serverType === ServerType.Sasjs) { if (this.sasjsConfig.serverType === ServerType.Sasjs) {
if (this.sasJSApiClient) { if (!this.sasJSApiClient) {
this.sasJSApiClient.setConfig(this.sasjsConfig.serverUrl) this.sasJSApiClient = new SASjsApiClient(this.requestClient)
} else {
this.sasJSApiClient = new SASjsApiClient(
this.sasjsConfig.serverUrl,
this.requestClient
)
} }
} }

View File

@@ -1,5 +1,5 @@
import { AuthConfig, ServerType, StreamConfig } from '@sasjs/utils/types' import { AuthConfig, ServerType, ServicePackSASjs } from '@sasjs/utils/types'
import { FileTree, ExecutionQuery } from './types' import { ExecutionQuery } from './types'
import { RequestClient } from './request/RequestClient' import { RequestClient } from './request/RequestClient'
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs' import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs' import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
@@ -8,19 +8,11 @@ import { parseWeboutResponse } from './utils'
import { getTokens } from './auth/getTokens' import { getTokens } from './auth/getTokens'
export class SASjsApiClient { export class SASjsApiClient {
constructor( constructor(private requestClient: RequestClient) {}
private serverUrl: string,
private requestClient: RequestClient
) {}
public setConfig(serverUrl: string) {
if (serverUrl) this.serverUrl = serverUrl
}
public async deploy( public async deploy(
members: FileTree, dataJson: ServicePackSASjs,
appLoc: string, appLoc: string,
streamConfig?: StreamConfig,
authConfig?: AuthConfig authConfig?: AuthConfig
) { ) {
let access_token = (authConfig || {}).access_token let access_token = (authConfig || {}).access_token
@@ -31,6 +23,9 @@ export class SASjsApiClient {
ServerType.Sasjs ServerType.Sasjs
)) ))
} }
dataJson.appLoc = dataJson.appLoc || appLoc
const { result } = await this.requestClient.post<{ const { result } = await this.requestClient.post<{
status: string status: string
message: string message: string
@@ -38,13 +33,7 @@ export class SASjsApiClient {
example?: {} example?: {}
}>( }>(
'SASjsApi/drive/deploy', 'SASjsApi/drive/deploy',
{ dataJson,
fileTree: members,
appLoc: appLoc,
streamServiceName: streamConfig?.streamServiceName,
streamWebFolder: streamConfig?.streamWebFolder,
streamLogo: streamConfig?.streamLogo
},
access_token, access_token,
undefined, undefined,
{}, {},

View File

@@ -1,47 +0,0 @@
export interface FileTree {
members: [FolderMember, ServiceMember]
}
export enum MemberType {
folder = 'folder',
service = 'service'
}
export interface FolderMember {
name: string
type: MemberType.folder
members: [FolderMember, ServiceMember]
}
export interface ServiceMember {
name: string
type: MemberType.service
code: string
}
export const isFileTree = (arg: any): arg is FileTree =>
arg &&
arg.members &&
Array.isArray(arg.members) &&
arg.members.filter(
(member: FolderMember | ServiceMember) =>
!isFolderMember(member) && !isServiceMember(member)
).length === 0
const isFolderMember = (arg: any): arg is FolderMember =>
arg &&
typeof arg.name === 'string' &&
arg.type === MemberType.folder &&
arg.members &&
Array.isArray(arg.members) &&
arg.members.filter(
(member: FolderMember | ServiceMember) =>
!isFolderMember(member) && !isServiceMember(member)
).length === 0
const isServiceMember = (arg: any): arg is ServiceMember =>
arg &&
typeof arg.name === 'string' &&
arg.type === MemberType.service &&
arg.code &&
typeof arg.code === 'string'

View File

@@ -12,5 +12,4 @@ export * from './Session'
export * from './UploadFile' export * from './UploadFile'
export * from './PollOptions' export * from './PollOptions'
export * from './WriteStream' export * from './WriteStream'
export * from './FileTree'
export * from './ExecuteScript' export * from './ExecuteScript'