mirror of
https://github.com/sasjs/adapter.git
synced 2026-06-08 18:20:20 +00:00
feat(debug): add viya debug log parser - parse JSON from inline blob
This commit is contained in:
@@ -16,6 +16,7 @@ import { SASViyaApiClient } from '../SASViyaApiClient'
|
||||
import {
|
||||
isRelativePath,
|
||||
parseSasViyaDebugResponse,
|
||||
parseSasViyaLogDebugResponse,
|
||||
appendExtraResponseAttributes,
|
||||
parseWeboutResponse,
|
||||
getFormData,
|
||||
@@ -188,11 +189,14 @@ export class WebJobExecutor extends BaseJobExecutor {
|
||||
if (config.debug) {
|
||||
switch (this.serverType) {
|
||||
case ServerType.SasViya:
|
||||
jsonResponse = await parseSasViyaDebugResponse(
|
||||
res.result,
|
||||
this.requestClient,
|
||||
this.serverUrl
|
||||
)
|
||||
jsonResponse =
|
||||
config.useComputeApi === null && config.runAsTask === true
|
||||
? await parseSasViyaLogDebugResponse(res.result)
|
||||
: await parseSasViyaDebugResponse(
|
||||
res.result,
|
||||
this.requestClient,
|
||||
this.serverUrl
|
||||
)
|
||||
break
|
||||
case ServerType.Sas9:
|
||||
jsonResponse =
|
||||
|
||||
@@ -15,6 +15,7 @@ export * from './parseGeneratedCode'
|
||||
export * from './parseSasViyaLog'
|
||||
export * from './parseSourceCode'
|
||||
export * from './parseViyaDebugResponse'
|
||||
export * from './parseViyaLogDebugResponse'
|
||||
export * from './parseWeboutResponse'
|
||||
export * from './serialize'
|
||||
export * from './splitChunks'
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { getValidJson } from './getValidJson'
|
||||
|
||||
/**
|
||||
* When querying a Viya job using the Web approach with _DEBUG=log (used when
|
||||
* runAsTask is true), the webout JSON is inlined into the response via:
|
||||
* var blob = new Blob([`{...}`], {type: 'application/json'});
|
||||
* No follow-up request is needed — extract and parse the JSON directly.
|
||||
*/
|
||||
export const parseSasViyaLogDebugResponse = async (response: string) => {
|
||||
const blobMatch = response.match(
|
||||
/new Blob\(\[`([\s\S]*?)`\],\s*\{type:\s*'application\/json'\}\)/
|
||||
)
|
||||
if (!blobMatch) {
|
||||
throw new Error('Unable to find webout blob in debug log response.')
|
||||
}
|
||||
|
||||
return getValidJson(blobMatch[1])
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { parseSasViyaLogDebugResponse } from '../parseViyaLogDebugResponse'
|
||||
|
||||
describe('parseSasViyaLogDebugResponse', () => {
|
||||
it('should extract and parse JSON from inline Blob', async () => {
|
||||
const resultData = { message: 'success' }
|
||||
const response = `<html><body><script>
|
||||
var blob = new Blob([\`${JSON.stringify(resultData)}\`], {type: 'application/json'});
|
||||
</script></body></html>`
|
||||
|
||||
const result = await parseSasViyaLogDebugResponse(response)
|
||||
|
||||
expect(result).toEqual(resultData)
|
||||
})
|
||||
|
||||
it('should extract and parse multiline JSON from inline Blob', async () => {
|
||||
const resultData = {
|
||||
SYSDATE: '13MAY26',
|
||||
SYSCC: '0',
|
||||
saslibs: [{ LIBRARYREF: 'FORMATS' }]
|
||||
}
|
||||
const response = `<script>
|
||||
var blob = new Blob([\`{"SYSDATE" : "13MAY26"
|
||||
,"SYSCC" : "0"
|
||||
,"saslibs": [{"LIBRARYREF":"FORMATS"}]
|
||||
}
|
||||
\`], {type: 'application/json'});
|
||||
</script>`
|
||||
|
||||
const result = await parseSasViyaLogDebugResponse(response)
|
||||
|
||||
expect(result).toEqual(resultData)
|
||||
})
|
||||
|
||||
it('should throw an error if blob is not found', async () => {
|
||||
const response = `<html><body>No blob here</body></html>`
|
||||
|
||||
await expect(parseSasViyaLogDebugResponse(response)).rejects.toThrow(
|
||||
'Unable to find webout blob in debug log response.'
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user