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

Compare commits

..

1 Commits

Author SHA1 Message Date
snyk-bot
28e0e3a147 fix: upgrade axios from 0.26.0 to 0.26.1
Snyk has created this PR to upgrade axios from 0.26.0 to 0.26.1.

See this package in npm:
https://www.npmjs.com/package/axios

See this project in Snyk:
https://app.snyk.io/org/allanbowe/project/2cf085e5-c256-4a84-bf6a-227076754853?utm_source=github&utm_medium=referral&page=upgrade-pr
2022-03-30 20:49:57 +00:00
7 changed files with 108 additions and 42 deletions

28
package-lock.json generated
View File

@@ -8,8 +8,8 @@
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@sasjs/utils": "2.42.0", "@sasjs/utils": "2.40.0",
"axios": "0.26.0", "axios": "^0.26.1",
"axios-cookiejar-support": "1.0.1", "axios-cookiejar-support": "1.0.1",
"form-data": "4.0.0", "form-data": "4.0.0",
"https": "1.0.0", "https": "1.0.0",
@@ -1142,9 +1142,9 @@
} }
}, },
"node_modules/@sasjs/utils": { "node_modules/@sasjs/utils": {
"version": "2.42.0", "version": "2.40.0",
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.42.0.tgz", "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.40.0.tgz",
"integrity": "sha512-Y69l89PYNF/h9xvVH72om/39xA+cY80bhiVLzp/fJb3BlvzCf4RNswBBanUOv2I5JNa7gPpJuE7mEiXOlhD3eg==", "integrity": "sha512-U0y/eqRlvfkMHmKDlr1xmeN+Rask7TnJPuRpOz71P8QpGYTw1M9AyZvzRSk503p4KCJb8ysdcqXyGVLfhuoM+A==",
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"@types/fs-extra": "9.0.13", "@types/fs-extra": "9.0.13",
@@ -2189,9 +2189,9 @@
} }
}, },
"node_modules/axios": { "node_modules/axios": {
"version": "0.26.0", "version": "0.26.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
"integrity": "sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==", "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
"dependencies": { "dependencies": {
"follow-redirects": "^1.14.8" "follow-redirects": "^1.14.8"
} }
@@ -13870,9 +13870,9 @@
} }
}, },
"@sasjs/utils": { "@sasjs/utils": {
"version": "2.42.0", "version": "2.40.0",
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.42.0.tgz", "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.40.0.tgz",
"integrity": "sha512-Y69l89PYNF/h9xvVH72om/39xA+cY80bhiVLzp/fJb3BlvzCf4RNswBBanUOv2I5JNa7gPpJuE7mEiXOlhD3eg==", "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",
@@ -14787,9 +14787,9 @@
"dev": true "dev": true
}, },
"axios": { "axios": {
"version": "0.26.0", "version": "0.26.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
"integrity": "sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==", "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
"requires": { "requires": {
"follow-redirects": "^1.14.8" "follow-redirects": "^1.14.8"
} }

View File

@@ -72,8 +72,8 @@
}, },
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@sasjs/utils": "2.42.0", "@sasjs/utils": "2.40.0",
"axios": "0.26.0", "axios": "0.26.1",
"axios-cookiejar-support": "1.0.1", "axios-cookiejar-support": "1.0.1",
"form-data": "4.0.0", "form-data": "4.0.0",
"https": "1.0.0", "https": "1.0.0",

View File

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

View File

@@ -1,5 +1,5 @@
import { AuthConfig, ServerType, ServicePackSASjs } from '@sasjs/utils/types' import { AuthConfig, ServerType, StreamConfig } from '@sasjs/utils/types'
import { ExecutionQuery } from './types' import { FileTree, 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,11 +8,19 @@ import { parseWeboutResponse } from './utils'
import { getTokens } from './auth/getTokens' import { getTokens } from './auth/getTokens'
export class SASjsApiClient { export class SASjsApiClient {
constructor(private requestClient: RequestClient) {} constructor(
private serverUrl: string,
private requestClient: RequestClient
) {}
public setConfig(serverUrl: string) {
if (serverUrl) this.serverUrl = serverUrl
}
public async deploy( public async deploy(
dataJson: ServicePackSASjs, members: FileTree,
appLoc: string, appLoc: string,
streamConfig?: StreamConfig,
authConfig?: AuthConfig authConfig?: AuthConfig
) { ) {
let access_token = (authConfig || {}).access_token let access_token = (authConfig || {}).access_token
@@ -23,9 +31,6 @@ 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
@@ -33,7 +38,13 @@ 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,
{}, {},

47
src/types/FileTree.ts Normal file
View File

@@ -0,0 +1,47 @@
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,4 +12,5 @@ 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'

View File

@@ -16,15 +16,10 @@ export const parseSasViyaDebugResponse = async (
requestClient: RequestClient, requestClient: RequestClient,
serverUrl: string serverUrl: string
) => { ) => {
// On viya 3.5, iframe is like <iframe style="width: 99%; height: 500px" src="..."></iframe>
// On viya 4, iframe is like <iframe style="width: 99%; height: 500px; background-color:Canvas;" src=...></iframe>
const iframeStart = response.split( const iframeStart = response.split(
/<iframe style="width: 99%; height: 500px" src="|<iframe style="width: 99%; height: 500px; background-color:Canvas;" src=/ '<iframe style="width: 99%; height: 500px" src="'
)[1] )[1]
const jsonUrl = iframeStart const jsonUrl = iframeStart ? iframeStart.split('"></iframe>')[0] : null
? iframeStart.split(/"><\/iframe>|><\/iframe>/)[0]
: null
if (!jsonUrl) { if (!jsonUrl) {
throw new Error('Unable to find webout file URL.') throw new Error('Unable to find webout file URL.')
} }