@sasjs/adapter 4.19.3 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ContextManager.js +290 -0
- package/DISCLOSURE +45 -0
- package/README.md +1 -1
- package/SAS9ApiClient.d.ts +1 -1
- package/SAS9ApiClient.js +90 -0
- package/SASViyaApiClient.js +918 -0
- package/SASjs.js +794 -0
- package/SASjsApiClient.d.ts +1 -0
- package/SASjsApiClient.js +132 -0
- package/SessionManager.js +353 -0
- package/api/viya/executeOnComputeApi.js +198 -0
- package/api/viya/getFileStream.js +32 -0
- package/api/viya/pollJobState.js +247 -0
- package/api/viya/saveLog.js +45 -0
- package/api/viya/uploadTables.js +45 -0
- package/api/viya/writeStream.js +25 -0
- package/auth/AuthManager.js +305 -0
- package/auth/getAccessTokenForSasjs.js +43 -0
- package/auth/getAccessTokenForViya.js +54 -0
- package/auth/getTokenRequestErrorPrefix.js +70 -0
- package/auth/getTokens.js +110 -0
- package/auth/index.js +20 -0
- package/auth/isAuthorizeFormRequired.js +7 -0
- package/auth/isLoginRequired.js +9 -0
- package/auth/loginHeader.js +87 -0
- package/auth/openWebPage.js +31 -0
- package/auth/refreshTokensForSasjs.js +42 -0
- package/auth/refreshTokensForViya.js +53 -0
- package/auth/verifySas9Login.js +32 -0
- package/auth/verifySasViyaLogin.js +44 -0
- package/dist/minified_sas9.js +10892 -0
- package/dist/sasjs-adapter.js +19569 -0
- package/file/generateFileUploadForm.js +43 -0
- package/file/generateTableUploadForm.js +38 -0
- package/index.js +9 -80376
- package/job-execution/ComputeJobExecutor.js +55 -0
- package/job-execution/FileUploader.js +114 -0
- package/job-execution/JesJobExecutor.js +55 -0
- package/job-execution/JobExecutor.js +40 -0
- package/job-execution/Sas9JobExecutor.d.ts +1 -1
- package/job-execution/Sas9JobExecutor.js +115 -0
- package/job-execution/SasjsJobExecutor.js +100 -0
- package/job-execution/WebJobExecutor.js +254 -0
- package/job-execution/index.js +23 -0
- package/minified/sas9/SASjs.js +198 -0
- package/minified/sas9/WebJobExecutor.js +105 -0
- package/minified/sas9/index.js +22 -0
- package/node/index.d.ts +2 -9
- package/node/index.js +1 -30570
- package/package.json +41 -12
- package/request/RequestClient.d.ts +1 -1
- package/request/RequestClient.js +717 -0
- package/request/Sas9RequestClient.d.ts +1 -1
- package/request/Sas9RequestClient.js +121 -0
- package/request/SasjsRequestClient.js +77 -0
- package/types/Context.js +2 -0
- package/types/CsrfToken.js +2 -0
- package/types/ExecuteScript.js +2 -0
- package/types/File.js +2 -0
- package/types/FileResource.js +2 -0
- package/types/Folder.js +2 -0
- package/types/Job.js +2 -0
- package/types/JobDefinition.js +2 -0
- package/types/JobResult.js +2 -0
- package/types/Link.js +2 -0
- package/types/LogStatistics.js +2 -0
- package/types/Login.js +2 -0
- package/types/PollOptions.js +2 -0
- package/types/RequestClient.js +2 -0
- package/types/SASjsConfig.d.ts +1 -1
- package/types/SASjsConfig.js +91 -0
- package/types/Session.js +14 -0
- package/types/Tables.js +28 -0
- package/types/UploadFile.js +2 -0
- package/types/WriteStream.d.ts +1 -1
- package/types/WriteStream.js +2 -0
- package/types/errors/ArgumentError.js +12 -0
- package/types/errors/AuthorizeError.js +13 -0
- package/types/errors/CertificateError.js +12 -0
- package/types/errors/ComputeJobExecutionError.js +13 -0
- package/types/errors/ErrorResponse.js +23 -0
- package/types/errors/InternalServerError.js +11 -0
- package/types/errors/InvalidJsonError.js +11 -0
- package/types/errors/InvalidSASjsCsrfError.js +12 -0
- package/types/errors/JobExecutionError.js +14 -0
- package/types/errors/JobStatePollError.js +12 -0
- package/types/errors/JsonParseArrayError.js +11 -0
- package/types/errors/LoginRequiredError.js +14 -0
- package/types/errors/NoSessionStateError.js +14 -0
- package/types/errors/NotFoundError.js +12 -0
- package/types/errors/RootFolderNotFoundError.js +22 -0
- package/types/errors/SAS9AuthError.js +11 -0
- package/types/errors/WeboutResponseError.js +12 -0
- package/types/errors/index.js +31 -0
- package/types/index.js +34 -0
- package/utils/appendExtraResponseAttributes.js +25 -0
- package/utils/asyncForEach.js +20 -0
- package/utils/compareTimestamps.js +11 -0
- package/utils/convertToCsv.js +154 -0
- package/utils/createAxiosInstance.d.ts +1 -1
- package/utils/createAxiosInstance.js +9 -0
- package/utils/delay.js +5 -0
- package/{src/utils/extractWeboutBlob.ts → utils/extractWeboutBlob.js} +19 -20
- package/utils/fetchLogByChunks.js +56 -0
- package/utils/formatDataForRequest.js +39 -0
- package/utils/getFormData.js +10 -0
- package/{node/utils/getUserLanguage.d.ts → utils/getUserLanguage.js} +5 -1
- package/utils/getValidJson.js +27 -0
- package/utils/host.d.ts +24 -0
- package/utils/host.js +36 -0
- package/utils/index.js +41 -0
- package/utils/isIeOrEdge.js +30 -0
- package/utils/isNode.js +7 -0
- package/utils/isRelativePath.js +5 -0
- package/utils/isUri.js +9 -0
- package/utils/isUrl.js +20 -0
- package/utils/loginPrompt/index.js +180 -0
- package/utils/needsRetry.js +14 -0
- package/utils/parseGeneratedCode.js +10 -0
- package/utils/parseSasViyaLog.js +17 -0
- package/utils/parseSourceCode.js +9 -0
- package/utils/parseViyaDebugResponse.js +46 -0
- package/utils/parseViyaLogDebugResponse.js +32 -0
- package/utils/parseWeboutResponse.js +22 -0
- package/utils/sas9/extractUserLongNameSas9.js +30 -0
- package/utils/serialize.js +20 -0
- package/utils/splitChunks.js +13 -0
- package/utils/validateInput.js +83 -0
- package/.env.example +0 -2
- package/.git-hooks/commit-msg +0 -39
- package/.git-hooks/pre-commit +0 -12
- package/.gitattributes +0 -1
- package/.pre-commit-config.yaml +0 -25
- package/.vscode/settings.json +0 -3
- package/SASViyaApiClient.spec.d.ts +0 -1
- package/__mocks__/axios.d.ts +0 -3
- package/api/viya/spec/executeScript.spec.d.ts +0 -1
- package/api/viya/spec/getFileStream.spec.d.ts +0 -1
- package/api/viya/spec/mockResponses.d.ts +0 -10
- package/api/viya/spec/pollJobState.spec.d.ts +0 -1
- package/api/viya/spec/saveLog.spec.d.ts +0 -1
- package/api/viya/spec/uploadTables.spec.d.ts +0 -1
- package/api/viya/spec/writeStream.spec.d.ts +0 -1
- package/auth/spec/AuthManager.spec.d.ts +0 -4
- package/auth/spec/getAccessTokenForSasjs.spec.d.ts +0 -1
- package/auth/spec/getAccessTokenForViya.spec.d.ts +0 -1
- package/auth/spec/getTokenRequestErrorPrefix.spec.d.ts +0 -1
- package/auth/spec/getTokens.spec.d.ts +0 -1
- package/auth/spec/loginHeader.spec.d.ts +0 -4
- package/auth/spec/mockResponses.d.ts +0 -23
- package/auth/spec/openWebPage.spec.d.ts +0 -1
- package/auth/spec/refreshTokensForSasjs.spec.d.ts +0 -1
- package/auth/spec/refreshTokensForViya.spec.d.ts +0 -1
- package/auth/spec/verifySas9Login.spec.d.ts +0 -1
- package/auth/spec/verifySasViyaLogin.spec.d.ts +0 -1
- package/checkNodeVersion.js +0 -16
- package/createTSDocs.js +0 -35
- package/cypress.config.js +0 -18
- package/example.html +0 -109
- package/file/spec/generateFileUploadForm.spec.d.ts +0 -1
- package/file/spec/generateTableUploadForm.spec.d.ts +0 -1
- package/index-dev.js +0 -80394
- package/job-execution/spec/ComputeJobExecutor.spec.d.ts +0 -1
- package/job-execution/spec/JesJobExecutor.spec.d.ts +0 -1
- package/job-execution/spec/Sas9JobExecutor.spec.d.ts +0 -1
- package/job-execution/spec/SasjsJobExecutor.spec.d.ts +0 -1
- package/job-execution/spec/WebJobExecutor.debug.spec.d.ts +0 -1
- package/job-execution/spec/WebJobExecutor.spec.d.ts +0 -1
- package/job-execution/spec/executionTasks.spec.d.ts +0 -1
- package/minified_sas9.js +0 -14039
- package/node/ContextManager.d.ts +0 -41
- package/node/SAS9ApiClient.d.ts +0 -30
- package/node/SASViyaApiClient.d.ts +0 -298
- package/node/SASjs.d.ts +0 -387
- package/node/SASjsApiClient.d.ts +0 -65
- package/node/SessionManager.d.ts +0 -115
- package/node/api/viya/executeOnComputeApi.d.ts +0 -21
- package/node/api/viya/getFileStream.d.ts +0 -2
- package/node/api/viya/pollJobState.d.ts +0 -57
- package/node/api/viya/saveLog.d.ts +0 -15
- package/node/api/viya/uploadTables.d.ts +0 -13
- package/node/api/viya/writeStream.d.ts +0 -2
- package/node/auth/AuthManager.d.ts +0 -49
- package/node/auth/getAccessTokenForSasjs.d.ts +0 -11
- package/node/auth/getAccessTokenForViya.d.ts +0 -10
- package/node/auth/getTokenRequestErrorPrefix.d.ts +0 -44
- package/node/auth/getTokens.d.ts +0 -22
- package/node/auth/index.d.ts +0 -4
- package/node/auth/isAuthorizeFormRequired.d.ts +0 -1
- package/node/auth/isLoginRequired.d.ts +0 -1
- package/node/auth/loginHeader.d.ts +0 -17
- package/node/auth/openWebPage.d.ts +0 -6
- package/node/auth/refreshTokensForSasjs.d.ts +0 -10
- package/node/auth/refreshTokensForViya.d.ts +0 -11
- package/node/auth/verifySas9Login.d.ts +0 -3
- package/node/auth/verifySasViyaLogin.d.ts +0 -4
- package/node/file/generateFileUploadForm.d.ts +0 -11
- package/node/file/generateTableUploadForm.d.ts +0 -5
- package/node/job-execution/ComputeJobExecutor.d.ts +0 -8
- package/node/job-execution/FileUploader.d.ts +0 -9
- package/node/job-execution/JesJobExecutor.d.ts +0 -9
- package/node/job-execution/JobExecutor.d.ts +0 -17
- package/node/job-execution/Sas9JobExecutor.d.ts +0 -19
- package/node/job-execution/SasjsJobExecutor.d.ts +0 -9
- package/node/job-execution/WebJobExecutor.d.ts +0 -18
- package/node/job-execution/index.d.ts +0 -7
- package/node/request/RequestClient.d.ts +0 -125
- package/node/request/Sas9RequestClient.d.ts +0 -25
- package/node/request/SasjsRequestClient.d.ts +0 -12
- package/node/types/Context.d.ts +0 -42
- package/node/types/CsrfToken.d.ts +0 -4
- package/node/types/ExecuteScript.d.ts +0 -4
- package/node/types/File.d.ts +0 -7
- package/node/types/FileResource.d.ts +0 -32
- package/node/types/Folder.d.ts +0 -7
- package/node/types/Job.d.ts +0 -14
- package/node/types/JobDefinition.d.ts +0 -3
- package/node/types/JobResult.d.ts +0 -3
- package/node/types/Link.d.ts +0 -7
- package/node/types/LogStatistics.d.ts +0 -4
- package/node/types/Login.d.ts +0 -14
- package/node/types/PollOptions.d.ts +0 -8
- package/node/types/RequestClient.d.ts +0 -46
- package/node/types/SASjsConfig.d.ts +0 -94
- package/node/types/Session.d.ts +0 -30
- package/node/types/Tables.d.ts +0 -7
- package/node/types/UploadFile.d.ts +0 -8
- package/node/types/WriteStream.d.ts +0 -7
- package/node/types/errors/ArgumentError.d.ts +0 -4
- package/node/types/errors/AuthorizeError.d.ts +0 -5
- package/node/types/errors/CertificateError.d.ts +0 -3
- package/node/types/errors/ComputeJobExecutionError.d.ts +0 -6
- package/node/types/errors/ErrorResponse.d.ts +0 -9
- package/node/types/errors/InternalServerError.d.ts +0 -3
- package/node/types/errors/InvalidJsonError.d.ts +0 -3
- package/node/types/errors/InvalidSASjsCsrfError.d.ts +0 -3
- package/node/types/errors/JobExecutionError.d.ts +0 -6
- package/node/types/errors/JobStatePollError.d.ts +0 -4
- package/node/types/errors/JsonParseArrayError.d.ts +0 -3
- package/node/types/errors/LoginRequiredError.d.ts +0 -3
- package/node/types/errors/NoSessionStateError.d.ts +0 -6
- package/node/types/errors/NotFoundError.d.ts +0 -4
- package/node/types/errors/RootFolderNotFoundError.d.ts +0 -3
- package/node/types/errors/SAS9AuthError.d.ts +0 -3
- package/node/types/errors/WeboutResponseError.d.ts +0 -4
- package/node/types/errors/index.d.ts +0 -15
- package/node/types/index.d.ts +0 -18
- package/node/utils/appendExtraResponseAttributes.d.ts +0 -2
- package/node/utils/asyncForEach.d.ts +0 -1
- package/node/utils/compareTimestamps.d.ts +0 -6
- package/node/utils/convertToCsv.d.ts +0 -12
- package/node/utils/createAxiosInstance.d.ts +0 -2
- package/node/utils/delay.d.ts +0 -1
- package/node/utils/extractWeboutBlob.d.ts +0 -13
- package/node/utils/fetchLogByChunks.d.ts +0 -20
- package/node/utils/formatDataForRequest.d.ts +0 -1
- package/node/utils/getFormData.d.ts +0 -2
- package/node/utils/getValidJson.d.ts +0 -5
- package/node/utils/index.d.ts +0 -25
- package/node/utils/isNode.d.ts +0 -1
- package/node/utils/isRelativePath.d.ts +0 -1
- package/node/utils/isUri.d.ts +0 -5
- package/node/utils/isUrl.d.ts +0 -5
- package/node/utils/loginPrompt/index.d.ts +0 -1
- package/node/utils/needsRetry.d.ts +0 -1
- package/node/utils/parseGeneratedCode.d.ts +0 -1
- package/node/utils/parseSasViyaLog.d.ts +0 -5
- package/node/utils/parseSourceCode.d.ts +0 -1
- package/node/utils/parseViyaDebugResponse.d.ts +0 -12
- package/node/utils/parseViyaLogDebugResponse.d.ts +0 -8
- package/node/utils/parseWeboutResponse.d.ts +0 -1
- package/node/utils/sas9/extractUserLongNameSas9.d.ts +0 -6
- package/node/utils/serialize.d.ts +0 -1
- package/node/utils/splitChunks.d.ts +0 -1
- package/node/utils/validateInput.d.ts +0 -14
- package/request/spec/SasjsRequestClient.spec.d.ts +0 -1
- package/screenshots/session-manager-first-request.png +0 -0
- package/screenshots/subsequent-session-request.png +0 -0
- package/spec/SAS9ApiClient.spec.d.ts +0 -1
- package/spec/SASjs.startComputeJob.spec.d.ts +0 -1
- package/spec/SASjsApiClient.spec.d.ts +0 -1
- package/src/ContextManager.ts +0 -454
- package/src/SAS9ApiClient.ts +0 -100
- package/src/SASViyaApiClient.ts +0 -1417
- package/src/SASjs.ts +0 -1268
- package/src/SASjsApiClient.ts +0 -177
- package/src/SessionManager.ts +0 -465
- package/src/__mocks__/axios.ts +0 -7
- package/src/api/viya/executeOnComputeApi.ts +0 -307
- package/src/api/viya/getFileStream.ts +0 -17
- package/src/api/viya/pollJobState.ts +0 -393
- package/src/api/viya/saveLog.ts +0 -55
- package/src/api/viya/spec/mockResponses.ts +0 -75
- package/src/api/viya/uploadTables.ts +0 -41
- package/src/api/viya/writeStream.ts +0 -16
- package/src/auth/AuthManager.ts +0 -387
- package/src/auth/getAccessTokenForSasjs.ts +0 -48
- package/src/auth/getAccessTokenForViya.ts +0 -61
- package/src/auth/getTokenRequestErrorPrefix.ts +0 -88
- package/src/auth/getTokens.ts +0 -127
- package/src/auth/index.ts +0 -4
- package/src/auth/isAuthorizeFormRequired.ts +0 -3
- package/src/auth/isLoginRequired.ts +0 -5
- package/src/auth/loginHeader.ts +0 -97
- package/src/auth/openWebPage.ts +0 -40
- package/src/auth/refreshTokensForSasjs.ts +0 -45
- package/src/auth/refreshTokensForViya.ts +0 -66
- package/src/auth/spec/mockResponses.ts +0 -53
- package/src/auth/verifySas9Login.ts +0 -25
- package/src/auth/verifySasViyaLogin.ts +0 -43
- package/src/file/generateFileUploadForm.ts +0 -48
- package/src/file/generateTableUploadForm.ts +0 -50
- package/src/index.ts +0 -9
- package/src/job-execution/ComputeJobExecutor.ts +0 -76
- package/src/job-execution/FileUploader.ts +0 -152
- package/src/job-execution/JesJobExecutor.ts +0 -78
- package/src/job-execution/JobExecutor.ts +0 -63
- package/src/job-execution/Sas9JobExecutor.ts +0 -137
- package/src/job-execution/SasjsJobExecutor.ts +0 -152
- package/src/job-execution/WebJobExecutor.ts +0 -341
- package/src/job-execution/index.ts +0 -7
- package/src/minified/sas9/SASjs.ts +0 -274
- package/src/minified/sas9/WebJobExecutor.ts +0 -156
- package/src/minified/sas9/index.ts +0 -3
- package/src/request/RequestClient.ts +0 -941
- package/src/request/Sas9RequestClient.ts +0 -132
- package/src/request/SasjsRequestClient.ts +0 -82
- package/src/test/SAS_server_app.ts +0 -47
- package/src/types/Context.ts +0 -39
- package/src/types/CsrfToken.ts +0 -4
- package/src/types/ExecuteScript.ts +0 -4
- package/src/types/File.ts +0 -8
- package/src/types/FileResource.ts +0 -33
- package/src/types/Folder.ts +0 -8
- package/src/types/Job.ts +0 -15
- package/src/types/JobDefinition.ts +0 -3
- package/src/types/JobResult.ts +0 -3
- package/src/types/Link.ts +0 -7
- package/src/types/LogStatistics.ts +0 -4
- package/src/types/Login.ts +0 -15
- package/src/types/PollOptions.ts +0 -9
- package/src/types/Process.d.ts +0 -5
- package/src/types/RequestClient.ts +0 -55
- package/src/types/SASjsConfig.ts +0 -95
- package/src/types/Session.ts +0 -34
- package/src/types/Tables.ts +0 -29
- package/src/types/UploadFile.ts +0 -8
- package/src/types/WriteStream.ts +0 -10
- package/src/types/errors/ArgumentError.ts +0 -7
- package/src/types/errors/AuthorizeError.ts +0 -10
- package/src/types/errors/CertificateError.ts +0 -12
- package/src/types/errors/ComputeJobExecutionError.ts +0 -12
- package/src/types/errors/ErrorResponse.ts +0 -28
- package/src/types/errors/InternalServerError.ts +0 -9
- package/src/types/errors/InvalidJsonError.ts +0 -7
- package/src/types/errors/InvalidSASjsCsrfError.ts +0 -9
- package/src/types/errors/JobExecutionError.ts +0 -11
- package/src/types/errors/JobStatePollError.ts +0 -14
- package/src/types/errors/JsonParseArrayError.ts +0 -7
- package/src/types/errors/LoginRequiredError.ts +0 -11
- package/src/types/errors/NoSessionStateError.ts +0 -15
- package/src/types/errors/NotFoundError.ts +0 -7
- package/src/types/errors/RootFolderNotFoundError.ts +0 -24
- package/src/types/errors/SAS9AuthError.ts +0 -9
- package/src/types/errors/WeboutResponseError.ts +0 -7
- package/src/types/errors/index.ts +0 -15
- package/src/types/index.ts +0 -18
- package/src/types/system/global.d.ts +0 -1
- package/src/utils/appendExtraResponseAttributes.ts +0 -22
- package/src/utils/asyncForEach.ts +0 -5
- package/src/utils/compareTimestamps.ts +0 -9
- package/src/utils/convertToCsv.ts +0 -198
- package/src/utils/createAxiosInstance.ts +0 -7
- package/src/utils/delay.ts +0 -2
- package/src/utils/fetchLogByChunks.ts +0 -63
- package/src/utils/formatDataForRequest.ts +0 -48
- package/src/utils/getFormData.ts +0 -5
- package/src/utils/getUserLanguage.ts +0 -10
- package/src/utils/getValidJson.ts +0 -23
- package/src/utils/index.ts +0 -25
- package/src/utils/isIeOrEdge.ts +0 -34
- package/src/utils/isNode.ts +0 -4
- package/src/utils/isRelativePath.ts +0 -2
- package/src/utils/isUri.ts +0 -5
- package/src/utils/isUrl.ts +0 -17
- package/src/utils/loginPrompt/index.ts +0 -177
- package/src/utils/needsRetry.ts +0 -14
- package/src/utils/parseGeneratedCode.ts +0 -7
- package/src/utils/parseSasViyaLog.ts +0 -12
- package/src/utils/parseSourceCode.ts +0 -6
- package/src/utils/parseViyaDebugResponse.ts +0 -46
- package/src/utils/parseViyaLogDebugResponse.ts +0 -22
- package/src/utils/parseWeboutResponse.ts +0 -20
- package/src/utils/sas9/extractUserLongNameSas9.ts +0 -31
- package/src/utils/serialize.ts +0 -15
- package/src/utils/splitChunks.ts +0 -12
- package/src/utils/validateInput.ts +0 -93
- package/test/ContextManager.spec.d.ts +0 -1
- package/test/FileUploader.spec.d.ts +0 -4
- package/test/FolderOperations.spec.d.ts +0 -1
- package/test/RequestClient.spec.d.ts +0 -1
- package/test/SAS_server_app.d.ts +0 -10
- package/test/SessionManager.spec.d.ts +0 -1
- package/test/getJobsInFolder.spec.d.ts +0 -1
- package/test/utils/formatDataForRequest.spec.d.ts +0 -1
- package/test/utils/getValidJson.spec.d.ts +0 -1
- package/test/utils/isUrl.spec.d.ts +0 -1
- package/test/utils/parseGeneratedCode.spec.d.ts +0 -1
- package/test/utils/parseSourceCode.spec.d.ts +0 -1
- package/types/Tables.spec.d.ts +0 -1
- package/types/errors/RootFolderNotFoundError.spec.d.ts +0 -1
- package/types/errors/spec/SAS9AuthError.spec.d.ts +0 -1
- package/utils/spec/convertToCsv.spec.d.ts +0 -1
- package/utils/spec/extractUserLongNameSas9.spec.d.ts +0 -1
- package/utils/spec/getFormData.spec.d.ts +0 -1
- package/utils/spec/parseSasViyaLog.spec.d.ts +0 -1
- package/utils/spec/parseViyaDebugResponse.spec.d.ts +0 -1
- package/utils/spec/parseViyaLogDebugResponse.spec.d.ts +0 -1
- package/utils/spec/validateInput.spec.d.ts +0 -1
package/SASjsApiClient.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class SASjsApiClient {
|
|
|
29
29
|
}>;
|
|
30
30
|
/**
|
|
31
31
|
* Creates/updates files within SASjs drive using uploaded json compressed file.
|
|
32
|
+
* This method can only be used by Node.
|
|
32
33
|
* @param zipFilePath - Compressed file path; file should only contain one JSON file and
|
|
33
34
|
* should have same name as of compressed file e.g. deploy.JSON should be compressed to deploy.JSON.zip
|
|
34
35
|
* Any other file or JSON file in zipped will be ignored!
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SASjsApiClient = void 0;
|
|
16
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
17
|
+
const types_1 = require("@sasjs/utils/types");
|
|
18
|
+
const error_1 = require("@sasjs/utils/error");
|
|
19
|
+
const getAccessTokenForSasjs_1 = require("./auth/getAccessTokenForSasjs");
|
|
20
|
+
const refreshTokensForSasjs_1 = require("./auth/refreshTokensForSasjs");
|
|
21
|
+
const getTokens_1 = require("./auth/getTokens");
|
|
22
|
+
const isNode_1 = require("./utils/isNode");
|
|
23
|
+
class SASjsApiClient {
|
|
24
|
+
constructor(requestClient) {
|
|
25
|
+
this.requestClient = requestClient;
|
|
26
|
+
}
|
|
27
|
+
getAccessTokenForRequest(authConfig) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
if (authConfig) {
|
|
30
|
+
const { access_token } = yield (0, getTokens_1.getTokens)(this.requestClient, authConfig, types_1.ServerType.Sasjs);
|
|
31
|
+
return access_token;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
|
|
37
|
+
* @param dataJson - the JSON specifying the folders and files to be created, can also includes
|
|
38
|
+
* appLoc, streamServiceName, streamWebFolder, streamLogo
|
|
39
|
+
* @param appLoc - the base folder in which to create the new folders and services.
|
|
40
|
+
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
|
41
|
+
*/
|
|
42
|
+
deploy(dataJson, appLoc, authConfig) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const access_token = yield this.getAccessTokenForRequest(authConfig);
|
|
45
|
+
dataJson.appLoc = dataJson.appLoc || appLoc;
|
|
46
|
+
const { result } = yield this.requestClient.post('SASjsApi/drive/deploy', dataJson, access_token, undefined, {}, { maxContentLength: Infinity, maxBodyLength: Infinity });
|
|
47
|
+
return Promise.resolve(result);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates/updates files within SASjs drive using uploaded json compressed file.
|
|
52
|
+
* This method can only be used by Node.
|
|
53
|
+
* @param zipFilePath - Compressed file path; file should only contain one JSON file and
|
|
54
|
+
* should have same name as of compressed file e.g. deploy.JSON should be compressed to deploy.JSON.zip
|
|
55
|
+
* Any other file or JSON file in zipped will be ignored!
|
|
56
|
+
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
|
57
|
+
*/
|
|
58
|
+
deployZipFile(zipFilePath, authConfig) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (!(0, isNode_1.isNode)()) {
|
|
61
|
+
throw new Error(`Method 'deployZipFile' can only be used by Node.`);
|
|
62
|
+
}
|
|
63
|
+
const { createReadStream } = require('@sasjs/utils/file');
|
|
64
|
+
const access_token = yield this.getAccessTokenForRequest(authConfig);
|
|
65
|
+
const file = yield createReadStream(zipFilePath);
|
|
66
|
+
const formData = new form_data_1.default();
|
|
67
|
+
formData.append('file', file);
|
|
68
|
+
const contentType = `multipart/form-data; boundary=${formData.getBoundary()}`;
|
|
69
|
+
const { result } = yield this.requestClient.post('SASjsApi/drive/deploy/upload', formData, access_token, contentType, {}, { maxContentLength: Infinity, maxBodyLength: Infinity });
|
|
70
|
+
return Promise.resolve(result);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
executeJob(query, appLoc, authConfig) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const access_token = authConfig ? authConfig.access_token : undefined;
|
|
76
|
+
let _program;
|
|
77
|
+
if (query._program.startsWith('/')) {
|
|
78
|
+
_program = query._program;
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
_program = `${appLoc}/${query._program}`;
|
|
82
|
+
const response = yield this.requestClient.post('SASjsApi/stp/execute', Object.assign(Object.assign({ _debug: 131 }, query), { _program }), access_token);
|
|
83
|
+
return { result: response.result, log: response.log };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Executes code on a SASJS server.
|
|
88
|
+
* @param code - a string of code to execute.
|
|
89
|
+
* @param runTime - a string to representing runTime for code execution
|
|
90
|
+
* @param authConfig - an object for authentication.
|
|
91
|
+
*/
|
|
92
|
+
executeScript(code, runTime = 'sas', authConfig) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const access_token = yield this.getAccessTokenForRequest(authConfig);
|
|
95
|
+
const executionResult = { log: '' };
|
|
96
|
+
yield this.requestClient
|
|
97
|
+
.post('SASjsApi/code/execute', { code, runTime }, access_token)
|
|
98
|
+
.then((res) => {
|
|
99
|
+
const { log, printOutput, result: webout } = res;
|
|
100
|
+
executionResult.log = log;
|
|
101
|
+
if (printOutput)
|
|
102
|
+
executionResult.printOutput = printOutput;
|
|
103
|
+
if (webout)
|
|
104
|
+
executionResult.webout = webout;
|
|
105
|
+
})
|
|
106
|
+
.catch((err) => {
|
|
107
|
+
throw (0, error_1.prefixMessage)(err, 'Error while sending POST request to execute code. ');
|
|
108
|
+
});
|
|
109
|
+
return executionResult;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Exchanges the auth code for an access token for the given client.
|
|
114
|
+
* @param clientId - the client ID to authenticate with.
|
|
115
|
+
* @param authCode - the auth code received from the server.
|
|
116
|
+
*/
|
|
117
|
+
getAccessToken(clientId, authCode) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
return (0, getAccessTokenForSasjs_1.getAccessTokenForSasjs)(this.requestClient, clientId, authCode);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Exchanges the refresh token for an access token.
|
|
124
|
+
* @param refreshToken - the refresh token received from the server.
|
|
125
|
+
*/
|
|
126
|
+
refreshTokens(refreshToken) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
return (0, refreshTokensForSasjs_1.refreshTokensForSasjs)(this.requestClient, refreshToken);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.SASjsApiClient = SASjsApiClient;
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SessionManager = void 0;
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const errors_1 = require("./types/errors");
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
const error_1 = require("@sasjs/utils/error");
|
|
17
|
+
const host_1 = require("./utils/host");
|
|
18
|
+
const MAX_SESSION_COUNT = 1;
|
|
19
|
+
class SessionManager {
|
|
20
|
+
constructor(serverUrl, contextName, requestClient) {
|
|
21
|
+
this.serverUrl = serverUrl;
|
|
22
|
+
this.contextName = contextName;
|
|
23
|
+
this.requestClient = requestClient;
|
|
24
|
+
this.loggedErrors = [];
|
|
25
|
+
this.sessionStateLinkError = 'Error while getting session state link. ';
|
|
26
|
+
// INFO: session pool
|
|
27
|
+
this.sessions = [];
|
|
28
|
+
this.currentContext = null;
|
|
29
|
+
this.settingContext = false;
|
|
30
|
+
this._debug = false;
|
|
31
|
+
this.printedSessionState = {
|
|
32
|
+
printed: false,
|
|
33
|
+
state: types_1.SessionState.NoState
|
|
34
|
+
};
|
|
35
|
+
if (serverUrl)
|
|
36
|
+
(0, utils_1.isUrl)(serverUrl);
|
|
37
|
+
}
|
|
38
|
+
get debug() {
|
|
39
|
+
return this._debug;
|
|
40
|
+
}
|
|
41
|
+
set debug(value) {
|
|
42
|
+
this._debug = value;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks if session is valid. Session is considered valid if time since it's creation is less than 'sessionInactiveTimeout' attribute.
|
|
46
|
+
* @param session - session object.
|
|
47
|
+
* @returns - boolean indicating if session is valid.
|
|
48
|
+
*/
|
|
49
|
+
isSessionValid(session) {
|
|
50
|
+
if (!session)
|
|
51
|
+
return false;
|
|
52
|
+
const secondsSinceSessionCreation = (new Date().getTime() - new Date(session.creationTimeStamp).getTime()) /
|
|
53
|
+
1000;
|
|
54
|
+
if (!session.attributes ||
|
|
55
|
+
secondsSinceSessionCreation >= session.attributes.sessionInactiveTimeout) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Removes session from pool of hot sessions.
|
|
64
|
+
* @param session - session object.
|
|
65
|
+
* @returns - void.
|
|
66
|
+
*/
|
|
67
|
+
removeSessionFromPool(session) {
|
|
68
|
+
this.sessions = this.sessions.filter((ses) => ses.id !== session.id);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Filters session pool to keep only valid sessions.
|
|
72
|
+
* @param session - session object.
|
|
73
|
+
* @returns - void.
|
|
74
|
+
*/
|
|
75
|
+
removeExpiredSessions() {
|
|
76
|
+
this.sessions = this.sessions.filter((session) => this.isSessionValid(session));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Throws set of errors as a single error.
|
|
80
|
+
* @param errors - array of errors or string.
|
|
81
|
+
* @param prefix - an optional final error prefix.
|
|
82
|
+
* @returns - never.
|
|
83
|
+
*/
|
|
84
|
+
throwErrors(errors, prefix) {
|
|
85
|
+
throw prefix
|
|
86
|
+
? (0, error_1.prefixMessage)(new Error(errors.join('. ')), prefix)
|
|
87
|
+
: new Error(errors
|
|
88
|
+
.map((err) => err.message ? err.message : err)
|
|
89
|
+
.join('. '));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns session.
|
|
93
|
+
* If there is a hot session available, it will be returned immediately and an asynchronous request to create new hot session will be submitted.
|
|
94
|
+
* If there is no available session, 2 session creation requests will be submitted. The session is returned once it is created and ready.
|
|
95
|
+
* @param accessToken - an optional access token.
|
|
96
|
+
* @returns - a promise which resolves with a session.
|
|
97
|
+
*/
|
|
98
|
+
getSession(accessToken) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const errors = [];
|
|
101
|
+
let isErrorThrown = false;
|
|
102
|
+
const throwIfError = () => {
|
|
103
|
+
if (errors.length && !isErrorThrown) {
|
|
104
|
+
isErrorThrown = true;
|
|
105
|
+
this.throwErrors(errors);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
this.removeExpiredSessions();
|
|
109
|
+
if (this.sessions.length) {
|
|
110
|
+
const session = this.sessions[0];
|
|
111
|
+
this.removeSessionFromPool(session);
|
|
112
|
+
this.createSessions(accessToken).catch((err) => {
|
|
113
|
+
errors.push(err);
|
|
114
|
+
});
|
|
115
|
+
this.createAndWaitForSession(accessToken).catch((err) => {
|
|
116
|
+
errors.push(err);
|
|
117
|
+
});
|
|
118
|
+
throwIfError();
|
|
119
|
+
return session;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.createSessions(accessToken).catch((err) => {
|
|
123
|
+
errors.push(err);
|
|
124
|
+
});
|
|
125
|
+
yield this.createAndWaitForSession(accessToken).catch((err) => {
|
|
126
|
+
errors.push(err);
|
|
127
|
+
});
|
|
128
|
+
this.removeExpiredSessions();
|
|
129
|
+
const session = this.sessions.pop();
|
|
130
|
+
this.removeSessionFromPool(session);
|
|
131
|
+
throwIfError();
|
|
132
|
+
return session;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns error message based on the response from SAS API.
|
|
138
|
+
* @param err - an optional access token.
|
|
139
|
+
* @param accessToken - an optional access token.
|
|
140
|
+
* @returns - an error message.
|
|
141
|
+
*/
|
|
142
|
+
getErrorMessage(err, url, method) {
|
|
143
|
+
return (`${method} request to ${url} failed with status code ${err.response.status || 'unknown'}. ` + err.response.data.message || '');
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Deletes session.
|
|
147
|
+
* @param id - a session id.
|
|
148
|
+
* @param accessToken - an optional access token.
|
|
149
|
+
* @returns - a promise which resolves when session is deleted.
|
|
150
|
+
*/
|
|
151
|
+
clearSession(id, accessToken) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const url = `/compute/sessions/${id}`;
|
|
154
|
+
return yield this.requestClient
|
|
155
|
+
.delete(url, accessToken)
|
|
156
|
+
.then(() => {
|
|
157
|
+
this.sessions = this.sessions.filter((s) => s.id !== id);
|
|
158
|
+
})
|
|
159
|
+
.catch((err) => {
|
|
160
|
+
throw (0, error_1.prefixMessage)(this.getErrorMessage(err, url, 'DELETE'), 'Error while deleting session. ');
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Creates sessions in amount equal to MAX_SESSION_COUNT.
|
|
166
|
+
* @param accessToken - an optional access token.
|
|
167
|
+
* @returns - a promise which resolves when required amount of sessions is created.
|
|
168
|
+
*/
|
|
169
|
+
createSessions(accessToken) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
const errors = [];
|
|
172
|
+
if (!this.sessions.length) {
|
|
173
|
+
yield (0, utils_1.asyncForEach)(new Array(MAX_SESSION_COUNT), () => __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
yield this.createAndWaitForSession(accessToken).catch((err) => {
|
|
175
|
+
errors.push(err);
|
|
176
|
+
});
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
if (errors.length) {
|
|
180
|
+
this.throwErrors(errors, 'Error while creating session. ');
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Waits for the current context to be set.
|
|
186
|
+
* @returns - a promise which resolves when current context is set.
|
|
187
|
+
*/
|
|
188
|
+
waitForCurrentContext() {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
return new Promise((resolve) => {
|
|
191
|
+
const timer = setInterval(() => {
|
|
192
|
+
if (this.currentContext) {
|
|
193
|
+
this.settingContext = false;
|
|
194
|
+
clearInterval(timer);
|
|
195
|
+
resolve();
|
|
196
|
+
}
|
|
197
|
+
}, 100);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Creates and waits for session to be ready.
|
|
203
|
+
* @param accessToken - an optional access token.
|
|
204
|
+
* @returns - a promise which resolves with a session.
|
|
205
|
+
*/
|
|
206
|
+
createAndWaitForSession(accessToken) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
if (!this.currentContext) {
|
|
209
|
+
if (!this.settingContext) {
|
|
210
|
+
yield this.setCurrentContext(accessToken);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
yield this.waitForCurrentContext();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const url = `${this.serverUrl}/compute/contexts/${this.currentContext.id}/sessions`;
|
|
217
|
+
const { result: createdSession, etag } = yield this.requestClient
|
|
218
|
+
.post(url, {}, accessToken)
|
|
219
|
+
.catch((err) => {
|
|
220
|
+
throw (0, error_1.prefixMessage)(this.getErrorMessage(err, url, 'POST'), `Error while creating session. `);
|
|
221
|
+
});
|
|
222
|
+
// Add response etag to Session object.
|
|
223
|
+
createdSession.etag = etag;
|
|
224
|
+
// Get session state link.
|
|
225
|
+
const stateLink = createdSession.links.find((link) => link.rel === 'state');
|
|
226
|
+
// Throw error if session state link is not present.
|
|
227
|
+
if (!stateLink)
|
|
228
|
+
throw this.sessionStateLinkError;
|
|
229
|
+
// Add session state link to Session object.
|
|
230
|
+
createdSession.stateUrl = stateLink.href;
|
|
231
|
+
yield this.waitForSession(createdSession, etag, accessToken);
|
|
232
|
+
this.sessions.push(createdSession);
|
|
233
|
+
return createdSession;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Sets current context.
|
|
238
|
+
* @param accessToken - an optional access token.
|
|
239
|
+
* @returns - a promise which resolves when current context is set.
|
|
240
|
+
*/
|
|
241
|
+
setCurrentContext(accessToken) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
if (!this.currentContext) {
|
|
244
|
+
const url = `${this.serverUrl}/compute/contexts?limit=10000`;
|
|
245
|
+
this.settingContext = true;
|
|
246
|
+
const { result: contexts } = yield this.requestClient
|
|
247
|
+
.get(url, accessToken)
|
|
248
|
+
.catch((err) => {
|
|
249
|
+
throw (0, error_1.prefixMessage)(this.getErrorMessage(err, url, 'GET'), `Error while getting list of contexts. `);
|
|
250
|
+
});
|
|
251
|
+
const contextsList = contexts && contexts.items && contexts.items.length
|
|
252
|
+
? contexts.items
|
|
253
|
+
: [];
|
|
254
|
+
const currentContext = contextsList.find((c) => c.name === this.contextName);
|
|
255
|
+
if (!currentContext) {
|
|
256
|
+
throw new Error(`The context '${this.contextName}' was not found on the server ${this.serverUrl}.`);
|
|
257
|
+
}
|
|
258
|
+
this.currentContext = currentContext;
|
|
259
|
+
Promise.resolve();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Waits for session to be ready.
|
|
265
|
+
* @param session - a session object.
|
|
266
|
+
* @param etag - an etag that can be a string or null.
|
|
267
|
+
* @param accessToken - an optional access token.
|
|
268
|
+
* @returns - a promise which resolves with a session state.
|
|
269
|
+
*/
|
|
270
|
+
waitForSession(session, etag, accessToken) {
|
|
271
|
+
var _a;
|
|
272
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
let { state: sessionState } = session;
|
|
274
|
+
const { stateUrl } = session;
|
|
275
|
+
const logger = (0, host_1.getLogger)();
|
|
276
|
+
if (sessionState === types_1.SessionState.Pending ||
|
|
277
|
+
sessionState === types_1.SessionState.Running ||
|
|
278
|
+
sessionState === types_1.SessionState.NoState) {
|
|
279
|
+
if (stateUrl) {
|
|
280
|
+
if (this.debug && !this.printedSessionState.printed) {
|
|
281
|
+
logger.info(`Polling: ${this.serverUrl + stateUrl}`);
|
|
282
|
+
this.printedSessionState.printed = true;
|
|
283
|
+
}
|
|
284
|
+
const url = `${this.serverUrl}${stateUrl}?wait=30`;
|
|
285
|
+
const { result: state, responseStatus: responseStatus } = yield this.getSessionState(url, etag, accessToken).catch((err) => {
|
|
286
|
+
throw (0, error_1.prefixMessage)(err, 'Error while waiting for session. ');
|
|
287
|
+
});
|
|
288
|
+
sessionState = state.trim();
|
|
289
|
+
if (this.debug && this.printedSessionState.state !== sessionState) {
|
|
290
|
+
logger.info(`Current session state is '${sessionState}'`);
|
|
291
|
+
this.printedSessionState.state = sessionState;
|
|
292
|
+
this.printedSessionState.printed = false;
|
|
293
|
+
}
|
|
294
|
+
if (!sessionState) {
|
|
295
|
+
const stateError = new errors_1.NoSessionStateError(responseStatus, this.serverUrl + stateUrl, (_a = session.links.find((l) => l.rel === 'log')) === null || _a === void 0 ? void 0 : _a.href);
|
|
296
|
+
if (!this.loggedErrors.find((err) => err.serverResponseStatus === stateError.serverResponseStatus)) {
|
|
297
|
+
this.loggedErrors.push(stateError);
|
|
298
|
+
logger.info(stateError.message);
|
|
299
|
+
}
|
|
300
|
+
return yield this.waitForSession(session, etag, accessToken);
|
|
301
|
+
}
|
|
302
|
+
this.loggedErrors = [];
|
|
303
|
+
return sessionState;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
throw this.sessionStateLinkError;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
this.loggedErrors = [];
|
|
311
|
+
return sessionState;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Gets session state.
|
|
317
|
+
* @param url - a URL to get session state.
|
|
318
|
+
* @param etag - an etag string.
|
|
319
|
+
* @param accessToken - an optional access token.
|
|
320
|
+
* @returns - a promise which resolves with a result string and response status.
|
|
321
|
+
*/
|
|
322
|
+
getSessionState(url, etag, accessToken) {
|
|
323
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
324
|
+
return yield this.requestClient
|
|
325
|
+
.get(url, accessToken, 'text/plain', { 'If-None-Match': etag })
|
|
326
|
+
.then((res) => ({
|
|
327
|
+
result: res.result,
|
|
328
|
+
responseStatus: res.status
|
|
329
|
+
}))
|
|
330
|
+
.catch((err) => {
|
|
331
|
+
throw (0, error_1.prefixMessage)(this.getErrorMessage(err, url, 'GET'), 'Error while getting session state. ');
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Gets variable.
|
|
337
|
+
* @param sessionId - a session id.
|
|
338
|
+
* @param variable - a variable string.
|
|
339
|
+
* @param accessToken - an optional access token.
|
|
340
|
+
* @returns - a promise which resolves with a result that confirms to SessionVariable interface, etag string and status code.
|
|
341
|
+
*/
|
|
342
|
+
getVariable(sessionId, variable, accessToken) {
|
|
343
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
344
|
+
const url = `${this.serverUrl}/compute/sessions/${sessionId}/variables/${variable}`;
|
|
345
|
+
return yield this.requestClient
|
|
346
|
+
.get(url, accessToken)
|
|
347
|
+
.catch((err) => {
|
|
348
|
+
throw (0, error_1.prefixMessage)(this.getErrorMessage(err, url, 'GET'), `Error while fetching session variable '${variable}'. `);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
exports.SessionManager = SessionManager;
|