@sasjs/adapter 4.19.4 → 5.1.1
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 -15
- 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/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/src/api/viya/saveLog.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Job } from '../..'
|
|
2
|
-
import { RequestClient } from '../../request/RequestClient'
|
|
3
|
-
import { fetchLog } from '../../utils'
|
|
4
|
-
import { WriteStream } from '../../types'
|
|
5
|
-
import { writeStream } from './writeStream'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Appends logs to a supplied write stream.
|
|
9
|
-
* This is useful for getting quick feedback on longer running jobs.
|
|
10
|
-
* @param job - the job to fetch logs for
|
|
11
|
-
* @param requestClient - the pre-configured HTTP request client
|
|
12
|
-
* @param startLine - the line at which to start fetching the log
|
|
13
|
-
* @param endLine - the line at which to stop fetching the log
|
|
14
|
-
* @param logFileStream - the write stream to which the log is appended
|
|
15
|
-
* @accessToken - an optional access token for authentication/authorization
|
|
16
|
-
* The access token is not required when fetching logs from the browser.
|
|
17
|
-
*/
|
|
18
|
-
export async function saveLog(
|
|
19
|
-
job: Job,
|
|
20
|
-
requestClient: RequestClient,
|
|
21
|
-
startLine: number,
|
|
22
|
-
endLine: number,
|
|
23
|
-
logFileStream?: WriteStream,
|
|
24
|
-
accessToken?: string
|
|
25
|
-
) {
|
|
26
|
-
if (!accessToken) {
|
|
27
|
-
throw new Error(
|
|
28
|
-
`Logs for job ${job.id} cannot be fetched without a valid access token.`
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!logFileStream) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Logs for job ${job.id} cannot be written without a valid write stream.`
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const logger = process.logger || console
|
|
39
|
-
const jobLogUrl = job.links.find((l) => l.rel === 'log')
|
|
40
|
-
|
|
41
|
-
if (!jobLogUrl) {
|
|
42
|
-
throw new Error(`Log URL for job ${job.id} was not found.`)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const log = await fetchLog(
|
|
46
|
-
requestClient,
|
|
47
|
-
accessToken,
|
|
48
|
-
`${jobLogUrl.href}/content`,
|
|
49
|
-
startLine,
|
|
50
|
-
endLine
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
logger.info(`Writing logs to ${logFileStream.path}`)
|
|
54
|
-
await writeStream(logFileStream, log || '')
|
|
55
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { AuthConfig } from '@sasjs/utils/types'
|
|
2
|
-
import { Job, Session, SessionState } from '../../../types'
|
|
3
|
-
|
|
4
|
-
export const mockSession: Session = {
|
|
5
|
-
id: 's35510n',
|
|
6
|
-
state: SessionState.Idle,
|
|
7
|
-
stateUrl: '',
|
|
8
|
-
links: [],
|
|
9
|
-
attributes: {
|
|
10
|
-
sessionInactiveTimeout: 1
|
|
11
|
-
},
|
|
12
|
-
creationTimeStamp: new Date().valueOf().toString(),
|
|
13
|
-
etag: 'etag-string'
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const mockJob: Job = {
|
|
17
|
-
id: 'j0b',
|
|
18
|
-
name: 'test job',
|
|
19
|
-
uri: '/j0b',
|
|
20
|
-
createdBy: 'test user',
|
|
21
|
-
results: {
|
|
22
|
-
'_webout.json': 'test'
|
|
23
|
-
},
|
|
24
|
-
logStatistics: {
|
|
25
|
-
lineCount: 100,
|
|
26
|
-
modifiedTimeStamp: new Date().valueOf().toString()
|
|
27
|
-
},
|
|
28
|
-
links: [
|
|
29
|
-
{
|
|
30
|
-
rel: 'log',
|
|
31
|
-
href: '/log',
|
|
32
|
-
method: 'GET',
|
|
33
|
-
type: 'log',
|
|
34
|
-
uri: 'log'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
rel: 'self',
|
|
38
|
-
href: '/job',
|
|
39
|
-
method: 'GET',
|
|
40
|
-
type: 'job',
|
|
41
|
-
uri: 'job'
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
rel: 'state',
|
|
45
|
-
href: '/state',
|
|
46
|
-
method: 'GET',
|
|
47
|
-
type: 'state',
|
|
48
|
-
uri: 'state'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
rel: 'up',
|
|
52
|
-
href: '/job',
|
|
53
|
-
method: 'GET',
|
|
54
|
-
type: 'up',
|
|
55
|
-
uri: 'job'
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const mockAuthConfig: AuthConfig = {
|
|
61
|
-
client: 'cl13nt',
|
|
62
|
-
secret: '53cr3t',
|
|
63
|
-
access_token: 'acc355',
|
|
64
|
-
refresh_token: 'r3fr35h'
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export class MockStream {
|
|
68
|
-
_write(chunk: string, _: any, next: Function) {
|
|
69
|
-
next()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
reset() {}
|
|
73
|
-
|
|
74
|
-
destroy() {}
|
|
75
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { prefixMessage } from '@sasjs/utils/error'
|
|
2
|
-
import { RequestClient } from '../../request/RequestClient'
|
|
3
|
-
import { convertToCSV, isFormatsTable } from '../../utils/convertToCsv'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Uploads tables to SAS as specially formatted CSVs.
|
|
7
|
-
* This is more compact than JSON, and easier to read within SAS.
|
|
8
|
-
* @param requestClient - the pre-configured HTTP request client
|
|
9
|
-
* @param data - the JSON representation of the data to be uploaded
|
|
10
|
-
* @param accessToken - an optional access token for authentication/authorization
|
|
11
|
-
* The access token is not required when uploading tables from the browser.
|
|
12
|
-
*/
|
|
13
|
-
export async function uploadTables(
|
|
14
|
-
requestClient: RequestClient,
|
|
15
|
-
data: any,
|
|
16
|
-
accessToken?: string
|
|
17
|
-
) {
|
|
18
|
-
const uploadedFiles = []
|
|
19
|
-
|
|
20
|
-
for (const tableName in data) {
|
|
21
|
-
// $tablename keys carry only column-format metadata for the matching
|
|
22
|
-
// tablename payload; they must not be uploaded as separate files.
|
|
23
|
-
if (isFormatsTable(tableName)) continue
|
|
24
|
-
|
|
25
|
-
const csv = convertToCSV(data, tableName)
|
|
26
|
-
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
27
|
-
throw new Error(
|
|
28
|
-
'The max length of a string value in SASjs is 32765 characters.'
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const uploadResponse = await requestClient
|
|
33
|
-
.uploadFile(`/files/files#rawUpload`, csv, accessToken)
|
|
34
|
-
.catch((err) => {
|
|
35
|
-
throw prefixMessage(err, 'Error while uploading file. ')
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
uploadedFiles.push({ tableName, file: uploadResponse.result })
|
|
39
|
-
}
|
|
40
|
-
return uploadedFiles
|
|
41
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { WriteStream } from '../../types'
|
|
2
|
-
|
|
3
|
-
export const writeStream = async (
|
|
4
|
-
stream: WriteStream,
|
|
5
|
-
content: string
|
|
6
|
-
): Promise<boolean> => {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
stream.write(content + '\n', (err: Error | null | undefined) => {
|
|
9
|
-
if (err) {
|
|
10
|
-
reject(err) // Reject on write error
|
|
11
|
-
} else {
|
|
12
|
-
resolve(true) // Resolve on successful write
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
}
|
package/src/auth/AuthManager.ts
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import { ServerType } from '@sasjs/utils/types'
|
|
2
|
-
import { RequestClient } from '../request/RequestClient'
|
|
3
|
-
import { NotFoundError } from '../types/errors'
|
|
4
|
-
import { LoginOptions, LoginResult, LoginResultInternal } from '../types/Login'
|
|
5
|
-
import { serialize } from '../utils'
|
|
6
|
-
import { extractUserLongNameSas9 } from '../utils/sas9/extractUserLongNameSas9'
|
|
7
|
-
import { openWebPage } from './openWebPage'
|
|
8
|
-
import { verifySas9Login } from './verifySas9Login'
|
|
9
|
-
import { verifySasViyaLogin } from './verifySasViyaLogin'
|
|
10
|
-
import { isLogInSuccessHeaderPresent } from './'
|
|
11
|
-
|
|
12
|
-
export class AuthManager {
|
|
13
|
-
public userName = ''
|
|
14
|
-
public userLongName = ''
|
|
15
|
-
private loginUrl: string
|
|
16
|
-
private logoutUrl: string
|
|
17
|
-
private redirectedLoginUrl = `/SASLogon` //SAS 9 M8 no longer redirects from `/SASLogon/home` to the login page. `/SASLogon` seems to be stable enough across SAS versions
|
|
18
|
-
|
|
19
|
-
constructor(
|
|
20
|
-
private serverUrl: string,
|
|
21
|
-
private serverType: ServerType,
|
|
22
|
-
private requestClient: RequestClient,
|
|
23
|
-
private loginCallback: () => Promise<void>
|
|
24
|
-
) {
|
|
25
|
-
this.loginUrl = `/SASLogon/login`
|
|
26
|
-
this.logoutUrl =
|
|
27
|
-
this.serverType === ServerType.Sas9
|
|
28
|
-
? '/SASLogon/logout?'
|
|
29
|
-
: this.serverType === ServerType.SasViya
|
|
30
|
-
? '/SASLogon/logout.do?'
|
|
31
|
-
: '/SASLogon/logout'
|
|
32
|
-
|
|
33
|
-
this.redirectedLoginUrl = this.serverUrl + this.redirectedLoginUrl
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Opens Pop up window to SAS Login screen.
|
|
38
|
-
* And checks if user has finished login process.
|
|
39
|
-
*/
|
|
40
|
-
public async redirectedLogIn({
|
|
41
|
-
onLoggedOut
|
|
42
|
-
}: LoginOptions): Promise<LoginResult> {
|
|
43
|
-
const {
|
|
44
|
-
isLoggedIn: isLoggedInAlready,
|
|
45
|
-
userName: currentSessionUserName,
|
|
46
|
-
userLongName: currentSessionUserLongName
|
|
47
|
-
} = await this.fetchUserName()
|
|
48
|
-
|
|
49
|
-
if (isLoggedInAlready) {
|
|
50
|
-
const logger = process.logger || console
|
|
51
|
-
logger.log('login was not attempted as a valid session already exists')
|
|
52
|
-
|
|
53
|
-
await this.loginCallback()
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
isLoggedIn: true,
|
|
57
|
-
userName: currentSessionUserName,
|
|
58
|
-
userLongName: currentSessionUserLongName
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const loginPopup = await openWebPage(
|
|
63
|
-
this.redirectedLoginUrl,
|
|
64
|
-
'SASLogon',
|
|
65
|
-
{
|
|
66
|
-
width: 500,
|
|
67
|
-
height: 600
|
|
68
|
-
},
|
|
69
|
-
onLoggedOut
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
if (!loginPopup) {
|
|
73
|
-
return { isLoggedIn: false, userName: '', userLongName: '' }
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const { isLoggedIn } =
|
|
77
|
-
this.serverType === ServerType.SasViya
|
|
78
|
-
? await verifySasViyaLogin(loginPopup)
|
|
79
|
-
: await verifySas9Login(loginPopup)
|
|
80
|
-
|
|
81
|
-
loginPopup.close()
|
|
82
|
-
|
|
83
|
-
if (isLoggedIn) {
|
|
84
|
-
if (this.serverType === ServerType.Sas9) {
|
|
85
|
-
await this.performCASSecurityCheck()
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const { userName, userLongName } = await this.fetchUserName()
|
|
89
|
-
|
|
90
|
-
await this.loginCallback()
|
|
91
|
-
|
|
92
|
-
return { isLoggedIn: true, userName, userLongName }
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return { isLoggedIn: false, userName: '', userLongName: '' }
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Logs into the SAS server with the supplied credentials.
|
|
100
|
-
* @param username - a string representing the username.
|
|
101
|
-
* @param password - a string representing the password.
|
|
102
|
-
* @returns - a boolean `isLoggedin` and a string `username`
|
|
103
|
-
*/
|
|
104
|
-
public async logIn(username: string, password: string): Promise<LoginResult> {
|
|
105
|
-
const loginParams = {
|
|
106
|
-
_service: 'default',
|
|
107
|
-
username,
|
|
108
|
-
password
|
|
109
|
-
}
|
|
110
|
-
this.userName = ''
|
|
111
|
-
this.userLongName = ''
|
|
112
|
-
|
|
113
|
-
let {
|
|
114
|
-
isLoggedIn: isLoggedInAlready,
|
|
115
|
-
loginForm,
|
|
116
|
-
userLongName: currentSessionUserLongName
|
|
117
|
-
} = await this.checkSession()
|
|
118
|
-
|
|
119
|
-
if (isLoggedInAlready) {
|
|
120
|
-
const logger = process.logger || console
|
|
121
|
-
logger.log('login was not attempted as a valid session already exists')
|
|
122
|
-
|
|
123
|
-
await this.loginCallback()
|
|
124
|
-
|
|
125
|
-
this.userName = loginParams.username
|
|
126
|
-
this.userLongName = currentSessionUserLongName
|
|
127
|
-
return {
|
|
128
|
-
isLoggedIn: true,
|
|
129
|
-
userName: this.userName,
|
|
130
|
-
userLongName: this.userLongName
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
let loginResponse = await this.sendLoginRequest(loginForm, loginParams)
|
|
135
|
-
|
|
136
|
-
let isLoggedIn = isLogInSuccessHeaderPresent(this.serverType, loginResponse)
|
|
137
|
-
|
|
138
|
-
if (!isLoggedIn) {
|
|
139
|
-
if (isCredentialsVerifyError(loginResponse)) {
|
|
140
|
-
const newLoginForm = await this.getLoginForm(loginResponse)
|
|
141
|
-
|
|
142
|
-
loginResponse = await this.sendLoginRequest(newLoginForm, loginParams)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Sometimes due to redirection on SAS9 and SASViya we don't get the login response that says
|
|
146
|
-
// You have signed in. Therefore, we have to make an extra request for checking session to
|
|
147
|
-
// ensure either user is logged in or not.
|
|
148
|
-
|
|
149
|
-
const res = await this.checkSession()
|
|
150
|
-
isLoggedIn = res.isLoggedIn
|
|
151
|
-
this.userLongName = res.userLongName
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (isLoggedIn) {
|
|
155
|
-
if (this.serverType === ServerType.Sas9) {
|
|
156
|
-
await this.performCASSecurityCheck()
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
this.loginCallback()
|
|
160
|
-
this.userName = loginParams.username
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
isLoggedIn,
|
|
165
|
-
userName: this.userName,
|
|
166
|
-
userLongName: this.userLongName
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
private async performCASSecurityCheck() {
|
|
171
|
-
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
|
|
172
|
-
|
|
173
|
-
await this.requestClient
|
|
174
|
-
.get<string>(`/SASLogon/login?service=${casAuthenticationUrl}`, undefined)
|
|
175
|
-
.catch((err) => {
|
|
176
|
-
// ignore if resource not found error
|
|
177
|
-
if (!(err instanceof NotFoundError)) throw err
|
|
178
|
-
})
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private async sendLoginRequest(
|
|
182
|
-
loginForm: { [key: string]: any },
|
|
183
|
-
loginParams: { [key: string]: any }
|
|
184
|
-
) {
|
|
185
|
-
if (this.serverType === ServerType.Sasjs) {
|
|
186
|
-
const { username, password } = loginParams
|
|
187
|
-
const { result: loginResponse } = await this.requestClient.post<string>(
|
|
188
|
-
this.loginUrl,
|
|
189
|
-
{ username, password },
|
|
190
|
-
undefined
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
return loginResponse
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
for (const key in loginForm) {
|
|
197
|
-
loginParams[key] = loginForm[key]
|
|
198
|
-
}
|
|
199
|
-
const loginParamsStr = serialize(loginParams)
|
|
200
|
-
|
|
201
|
-
const { result: loginResponse } = await this.requestClient.post<string>(
|
|
202
|
-
this.loginUrl,
|
|
203
|
-
loginParamsStr,
|
|
204
|
-
undefined,
|
|
205
|
-
'text/plain',
|
|
206
|
-
{
|
|
207
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
208
|
-
Accept: '*/*'
|
|
209
|
-
}
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
return loginResponse
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Checks whether a session is active, or login is required.
|
|
217
|
-
* @returns - a promise which resolves with an object containing three values
|
|
218
|
-
* - a boolean `isLoggedIn`
|
|
219
|
-
* - a string `userName`,
|
|
220
|
-
* - a string `userFullName` and
|
|
221
|
-
* - a form `loginForm` if not loggedIn.
|
|
222
|
-
*/
|
|
223
|
-
public async checkSession(): Promise<LoginResultInternal> {
|
|
224
|
-
const { isLoggedIn, userName, userLongName } = await this.fetchUserName()
|
|
225
|
-
let loginForm = null
|
|
226
|
-
|
|
227
|
-
if (!isLoggedIn) {
|
|
228
|
-
//We will logout to make sure cookies are removed and login form is presented
|
|
229
|
-
//Residue can happen in case of session expiration
|
|
230
|
-
await this.logOut()
|
|
231
|
-
|
|
232
|
-
loginForm = await this.getNewLoginForm()
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return Promise.resolve({
|
|
236
|
-
isLoggedIn,
|
|
237
|
-
userName,
|
|
238
|
-
userLongName,
|
|
239
|
-
loginForm
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
private async getNewLoginForm() {
|
|
244
|
-
if (this.serverType === ServerType.Sasjs) {
|
|
245
|
-
// server will be sending CSRF token in response,
|
|
246
|
-
// need to save in cookie so that,
|
|
247
|
-
// http client will use it automatically
|
|
248
|
-
return this.requestClient.get('/', undefined).then(({ result }) => {
|
|
249
|
-
const cookie =
|
|
250
|
-
/<script>document.cookie = '(XSRF-TOKEN=.*; Max-Age=86400; SameSite=Strict; Path=\/;)'<\/script>/.exec(
|
|
251
|
-
result as string
|
|
252
|
-
)?.[1]
|
|
253
|
-
|
|
254
|
-
if (cookie) document.cookie = cookie
|
|
255
|
-
})
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const { result: formResponse } = await this.requestClient.get<string>(
|
|
259
|
-
this.loginUrl.replace('/SASLogon/login.do', '/SASLogon/login'),
|
|
260
|
-
undefined,
|
|
261
|
-
'text/plain'
|
|
262
|
-
)
|
|
263
|
-
|
|
264
|
-
return await this.getLoginForm(formResponse)
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
private async fetchUserName(): Promise<LoginResult> {
|
|
268
|
-
const url =
|
|
269
|
-
this.serverType === ServerType.SasViya
|
|
270
|
-
? `${this.serverUrl}/identities/users/@currentUser`
|
|
271
|
-
: this.serverType === ServerType.Sas9
|
|
272
|
-
? `${this.serverUrl}/SASStoredProcess`
|
|
273
|
-
: `${this.serverUrl}/SASjsApi/session`
|
|
274
|
-
|
|
275
|
-
const { result: loginResponse } = await this.requestClient
|
|
276
|
-
.get<string>(url, undefined, 'text/plain')
|
|
277
|
-
.catch((err: any) => {
|
|
278
|
-
return { result: 'authErr' }
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
const isLoggedIn = loginResponse !== 'authErr'
|
|
282
|
-
|
|
283
|
-
if (!isLoggedIn) {
|
|
284
|
-
//We will logout to make sure cookies are removed and login form is presented
|
|
285
|
-
//Residue can happen in case of session expiration
|
|
286
|
-
await this.logOut()
|
|
287
|
-
return { isLoggedIn, userName: '', userLongName: '' }
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return {
|
|
291
|
-
isLoggedIn,
|
|
292
|
-
userName: this.extractUserName(loginResponse),
|
|
293
|
-
userLongName: this.extractUserLongName(loginResponse)
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
private extractUserName = (response: any): string => {
|
|
298
|
-
switch (this.serverType) {
|
|
299
|
-
case ServerType.SasViya:
|
|
300
|
-
return response?.id
|
|
301
|
-
|
|
302
|
-
case ServerType.Sas9:
|
|
303
|
-
return ''
|
|
304
|
-
|
|
305
|
-
case ServerType.Sasjs:
|
|
306
|
-
return response?.username
|
|
307
|
-
|
|
308
|
-
default:
|
|
309
|
-
console.error('Server Type not found in extractUserName function')
|
|
310
|
-
return ''
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
private extractUserLongName = (response: any): string => {
|
|
315
|
-
switch (this.serverType) {
|
|
316
|
-
case ServerType.SasViya:
|
|
317
|
-
return response?.name
|
|
318
|
-
|
|
319
|
-
case ServerType.Sas9:
|
|
320
|
-
return extractUserLongNameSas9(response)
|
|
321
|
-
|
|
322
|
-
case ServerType.Sasjs:
|
|
323
|
-
return response?.displayName
|
|
324
|
-
|
|
325
|
-
default:
|
|
326
|
-
console.error('Server Type not found in extractUserName function')
|
|
327
|
-
return ''
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
private getLoginForm(response: any) {
|
|
332
|
-
const pattern: RegExp = /<form.+action="(.*(Logon|login)[^"]*).*>/
|
|
333
|
-
const matches = pattern.exec(response)
|
|
334
|
-
const formInputs: any = {}
|
|
335
|
-
|
|
336
|
-
if (matches && matches.length) {
|
|
337
|
-
this.setLoginUrl(matches)
|
|
338
|
-
response = response.replace(/<input/g, '\n<input')
|
|
339
|
-
const inputs = response.match(/<input.*"hidden"[^>]*>/g)
|
|
340
|
-
|
|
341
|
-
if (inputs) {
|
|
342
|
-
inputs.forEach((inputStr: string) => {
|
|
343
|
-
const valueMatch = inputStr.match(/name="([^"]*)"\svalue="([^"]*)/)
|
|
344
|
-
|
|
345
|
-
if (valueMatch && valueMatch.length) {
|
|
346
|
-
formInputs[valueMatch[1]] = valueMatch[2]
|
|
347
|
-
}
|
|
348
|
-
})
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return Object.keys(formInputs).length ? formInputs : null
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
private setLoginUrl = (matches: RegExpExecArray) => {
|
|
356
|
-
let parsedURL = matches[1].replace(/\?.*/, '')
|
|
357
|
-
if (parsedURL[0] === '/') {
|
|
358
|
-
parsedURL = parsedURL.substr(1)
|
|
359
|
-
|
|
360
|
-
const tempLoginLink = this.serverUrl
|
|
361
|
-
? `${this.serverUrl}/${parsedURL}`
|
|
362
|
-
: `${parsedURL}`
|
|
363
|
-
|
|
364
|
-
const loginUrl = tempLoginLink
|
|
365
|
-
|
|
366
|
-
this.loginUrl =
|
|
367
|
-
this.serverType === ServerType.SasViya
|
|
368
|
-
? tempLoginLink
|
|
369
|
-
: loginUrl.replace('/SASLogon/login.do', '/SASLogon/login')
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Logs out of the configured SAS server.
|
|
375
|
-
*
|
|
376
|
-
*/
|
|
377
|
-
public async logOut() {
|
|
378
|
-
this.requestClient.resetInMemoryAuthState()
|
|
379
|
-
|
|
380
|
-
return this.requestClient.get(this.logoutUrl, undefined).then(() => true)
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const isCredentialsVerifyError = (response: string): boolean =>
|
|
385
|
-
/An error occurred while the system was verifying your credentials. Please enter your credentials again./gm.test(
|
|
386
|
-
response
|
|
387
|
-
)
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { prefixMessage } from '@sasjs/utils/error'
|
|
2
|
-
import { RequestClient } from '../request/RequestClient'
|
|
3
|
-
import { getTokenRequestErrorPrefix } from './getTokenRequestErrorPrefix'
|
|
4
|
-
import { ServerType } from '@sasjs/utils/types'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Exchanges the auth code for an access token for the given client.
|
|
8
|
-
* @param requestClient - the pre-configured HTTP request client
|
|
9
|
-
* @param clientId - the client ID to authenticate with.
|
|
10
|
-
* @param authCode - the auth code received from the server.
|
|
11
|
-
*/
|
|
12
|
-
export async function getAccessTokenForSasjs(
|
|
13
|
-
requestClient: RequestClient,
|
|
14
|
-
clientId: string,
|
|
15
|
-
authCode: string
|
|
16
|
-
) {
|
|
17
|
-
const url = '/SASjsApi/auth/token'
|
|
18
|
-
const data = {
|
|
19
|
-
clientId,
|
|
20
|
-
code: authCode
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return await requestClient
|
|
24
|
-
.post(url, data, undefined)
|
|
25
|
-
.then((res) => {
|
|
26
|
-
const sasAuth = res.result as {
|
|
27
|
-
accessToken: string
|
|
28
|
-
refreshToken: string
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
access_token: sasAuth.accessToken,
|
|
32
|
-
refresh_token: sasAuth.refreshToken
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
.catch((err) => {
|
|
36
|
-
throw prefixMessage(
|
|
37
|
-
err,
|
|
38
|
-
getTokenRequestErrorPrefix(
|
|
39
|
-
'fetching access token',
|
|
40
|
-
'getAccessTokenForSasjs',
|
|
41
|
-
ServerType.Sasjs,
|
|
42
|
-
url,
|
|
43
|
-
data,
|
|
44
|
-
clientId
|
|
45
|
-
)
|
|
46
|
-
)
|
|
47
|
-
})
|
|
48
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { SasAuthResponse, ServerType } from '@sasjs/utils/types'
|
|
2
|
-
import { prefixMessage } from '@sasjs/utils/error'
|
|
3
|
-
import { RequestClient } from '../request/RequestClient'
|
|
4
|
-
import { CertificateError } from '../types/errors'
|
|
5
|
-
import { getTokenRequestErrorPrefix } from './getTokenRequestErrorPrefix'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Exchange the auth code for access / refresh tokens for the given client / secret pair.
|
|
9
|
-
* @param requestClient - the pre-configured HTTP request client.
|
|
10
|
-
* @param clientId - the client ID to authenticate with.
|
|
11
|
-
* @param clientSecret - the client secret to authenticate with.
|
|
12
|
-
* @param authCode - the auth code received from the server.
|
|
13
|
-
*/
|
|
14
|
-
export async function getAccessTokenForViya(
|
|
15
|
-
requestClient: RequestClient,
|
|
16
|
-
clientId: string,
|
|
17
|
-
clientSecret: string,
|
|
18
|
-
authCode: string
|
|
19
|
-
): Promise<SasAuthResponse> {
|
|
20
|
-
let token
|
|
21
|
-
|
|
22
|
-
if (typeof Buffer === 'undefined') {
|
|
23
|
-
token = btoa(clientId + ':' + clientSecret)
|
|
24
|
-
} else {
|
|
25
|
-
token = Buffer.from(clientId + ':' + clientSecret).toString('base64')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const url = '/SASLogon/oauth/token'
|
|
29
|
-
const headers = {
|
|
30
|
-
Authorization: 'Basic ' + token,
|
|
31
|
-
Accept: 'application/json'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const dataJson = new URLSearchParams({
|
|
35
|
-
grant_type: 'authorization_code',
|
|
36
|
-
code: authCode
|
|
37
|
-
})
|
|
38
|
-
const data = new URLSearchParams(dataJson)
|
|
39
|
-
|
|
40
|
-
const authResponse = await requestClient
|
|
41
|
-
.post(url, data, undefined, 'application/x-www-form-urlencoded', headers)
|
|
42
|
-
.then((res) => res.result as SasAuthResponse)
|
|
43
|
-
.catch((err) => {
|
|
44
|
-
if (err instanceof CertificateError) throw err
|
|
45
|
-
throw prefixMessage(
|
|
46
|
-
err,
|
|
47
|
-
getTokenRequestErrorPrefix(
|
|
48
|
-
'fetching access token',
|
|
49
|
-
'getAccessTokenForViya',
|
|
50
|
-
ServerType.SasViya,
|
|
51
|
-
url,
|
|
52
|
-
dataJson,
|
|
53
|
-
headers,
|
|
54
|
-
clientId,
|
|
55
|
-
clientSecret
|
|
56
|
-
)
|
|
57
|
-
)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
return authResponse
|
|
61
|
-
}
|