@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
|
@@ -0,0 +1,254 @@
|
|
|
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.WebJobExecutor = void 0;
|
|
16
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
17
|
+
const types_1 = require("@sasjs/utils/types");
|
|
18
|
+
const errors_1 = require("../types/errors");
|
|
19
|
+
const generateFileUploadForm_1 = require("../file/generateFileUploadForm");
|
|
20
|
+
const generateTableUploadForm_1 = require("../file/generateTableUploadForm");
|
|
21
|
+
const utils_1 = require("../utils");
|
|
22
|
+
const JobExecutor_1 = require("./JobExecutor");
|
|
23
|
+
class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
|
|
24
|
+
constructor(serverUrl, serverType, jobsPath, requestClient, sasViyaApiClient) {
|
|
25
|
+
super(serverUrl, serverType);
|
|
26
|
+
this.jobsPath = jobsPath;
|
|
27
|
+
this.requestClient = requestClient;
|
|
28
|
+
this.sasViyaApiClient = sasViyaApiClient;
|
|
29
|
+
}
|
|
30
|
+
execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
|
|
31
|
+
var _a;
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const loginCallback = loginRequiredCallback;
|
|
34
|
+
const program = (0, utils_1.isRelativePath)(sasJob)
|
|
35
|
+
? config.appLoc
|
|
36
|
+
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
|
|
37
|
+
: sasJob
|
|
38
|
+
: sasJob;
|
|
39
|
+
let apiUrl = `${config.serverUrl}${this.jobsPath}/?${'_program=' + program}`;
|
|
40
|
+
if (config.serverType === types_1.ServerType.SasViya) {
|
|
41
|
+
let jobUri;
|
|
42
|
+
try {
|
|
43
|
+
jobUri = yield this.getJobUri(program);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (e instanceof errors_1.LoginRequiredError) {
|
|
48
|
+
this.appendWaitingRequest(() => {
|
|
49
|
+
return this.execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes).then((res) => {
|
|
50
|
+
resolve(res);
|
|
51
|
+
}, (err) => {
|
|
52
|
+
reject(err);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
if (loginCallback)
|
|
56
|
+
yield loginCallback();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
reject(new errors_1.ErrorResponse(e === null || e === void 0 ? void 0 : e.message, e));
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
if (jobUri.length > 0) {
|
|
64
|
+
apiUrl += '&_job=' + jobUri;
|
|
65
|
+
/**
|
|
66
|
+
* Using both _job and _program parameters will cause a conflict in the JES web app, as it's not clear whether or not the server should make the extra fetch for the job uri.
|
|
67
|
+
* To handle this, we add the extra underscore and recreate the _program variable in the SAS side of the SASjs adapter so it remains available for backend developers.
|
|
68
|
+
*/
|
|
69
|
+
apiUrl = apiUrl.replace('_program=', '__program=');
|
|
70
|
+
}
|
|
71
|
+
// Append context name to URL if provided and non-empty
|
|
72
|
+
apiUrl += ((_a = config.contextName) === null || _a === void 0 ? void 0 : _a.trim())
|
|
73
|
+
? `&_contextname=${encodeURIComponent(config.contextName)}`
|
|
74
|
+
: '';
|
|
75
|
+
if (config.runAsTask === true) {
|
|
76
|
+
apiUrl += '&_executionTasks=true';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
let requestParams = Object.assign({}, this.getRequestParams(config));
|
|
80
|
+
/**
|
|
81
|
+
* Use the available form data object (FormData in Browser, NodeFormData in
|
|
82
|
+
* Node)
|
|
83
|
+
*/
|
|
84
|
+
let formData = (0, utils_1.getFormData)();
|
|
85
|
+
// FIXME(viya - SAS Track CS0409737): remove when Viya stops rejecting empty multipart on
|
|
86
|
+
// _executionTasks=true. Dummy file keeps the body non-empty
|
|
87
|
+
const hasExecutionTasksFlag = config.runAsTask === true;
|
|
88
|
+
// Move debug params to URL for viya; viya seems to honor them more
|
|
89
|
+
// reliably in the query string than the multipart body.
|
|
90
|
+
if (hasExecutionTasksFlag &&
|
|
91
|
+
config.debug &&
|
|
92
|
+
config.serverType === types_1.ServerType.SasViya) {
|
|
93
|
+
const debugKeys = ['_debug', '_omitSessionResults'];
|
|
94
|
+
debugKeys.forEach((key) => {
|
|
95
|
+
if (requestParams[key] !== undefined) {
|
|
96
|
+
apiUrl += `&${key}=${encodeURIComponent(requestParams[key])}`;
|
|
97
|
+
delete requestParams[key];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (data) {
|
|
102
|
+
const stringifiedData = JSON.stringify(data);
|
|
103
|
+
if (config.serverType === types_1.ServerType.Sas9 ||
|
|
104
|
+
stringifiedData.length > 500000 ||
|
|
105
|
+
stringifiedData.includes(';')) {
|
|
106
|
+
// file upload approach
|
|
107
|
+
try {
|
|
108
|
+
formData = (0, generateFileUploadForm_1.generateFileUploadForm)(formData, data);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
return Promise.reject(new errors_1.ErrorResponse(e === null || e === void 0 ? void 0 : e.message, e));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// param based approach
|
|
116
|
+
try {
|
|
117
|
+
const { formData: newFormData, requestParams: params } = (0, generateTableUploadForm_1.generateTableUploadForm)(formData, data);
|
|
118
|
+
formData = newFormData;
|
|
119
|
+
requestParams = Object.assign(Object.assign({}, requestParams), params);
|
|
120
|
+
if (config.serverType === types_1.ServerType.SasViya &&
|
|
121
|
+
hasExecutionTasksFlag) {
|
|
122
|
+
addDummyFile(formData);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
return Promise.reject(new errors_1.ErrorResponse(e === null || e === void 0 ? void 0 : e.message, e));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
if (config.serverType === types_1.ServerType.SasViya && hasExecutionTasksFlag) {
|
|
132
|
+
addDummyFile(formData);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const key in requestParams) {
|
|
136
|
+
if (requestParams.hasOwnProperty(key)) {
|
|
137
|
+
formData.append(key, requestParams[key]);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/* The NodeFormData object does not set the request header - so, set it */
|
|
141
|
+
const contentType = formData instanceof form_data_1.default && typeof FormData === 'undefined'
|
|
142
|
+
? `multipart/form-data; boundary=${formData.getHeaders()['content-type']}`
|
|
143
|
+
: 'multipart/form-data';
|
|
144
|
+
const requestPromise = new Promise((resolve, reject) => {
|
|
145
|
+
this.requestClient.post(apiUrl, formData, authConfig === null || authConfig === void 0 ? void 0 : authConfig.access_token, contentType)
|
|
146
|
+
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
this.requestClient.appendRequest(res, sasJob, config.debug);
|
|
148
|
+
let jsonResponse = res.result;
|
|
149
|
+
if (config.debug) {
|
|
150
|
+
switch (this.serverType) {
|
|
151
|
+
case types_1.ServerType.SasViya:
|
|
152
|
+
// Route on the shape of the response itself. The JES web app
|
|
153
|
+
// returns the webout inline in a script-constructed Blob when
|
|
154
|
+
// it runs the job as a compute task, and as an iframe file URL
|
|
155
|
+
// otherwise - but the _debug value sent does not determine
|
|
156
|
+
// which: a _debug=128 request without _EXECUTIONTASKS gets the
|
|
157
|
+
// iframe form back. A result that is already an object has
|
|
158
|
+
// been parsed upstream, and parseSasViyaDebugResponse also
|
|
159
|
+
// falls back to blob extraction, so either parser copes with
|
|
160
|
+
// a response that mixes the two.
|
|
161
|
+
jsonResponse =
|
|
162
|
+
typeof res.result !== 'string' || (0, utils_1.hasWeboutBlob)(res.result)
|
|
163
|
+
? yield (0, utils_1.parseSasViyaLogDebugResponse)(res.result)
|
|
164
|
+
: yield (0, utils_1.parseSasViyaDebugResponse)(res.result, this.requestClient, this.serverUrl);
|
|
165
|
+
break;
|
|
166
|
+
case types_1.ServerType.Sas9:
|
|
167
|
+
jsonResponse =
|
|
168
|
+
typeof res.result === 'string'
|
|
169
|
+
? (0, utils_1.parseWeboutResponse)(res.result, apiUrl)
|
|
170
|
+
: res.result;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const responseObject = (0, utils_1.appendExtraResponseAttributes)({ result: jsonResponse, log: res.log }, extraResponseAttributes);
|
|
175
|
+
resolve(responseObject);
|
|
176
|
+
}))
|
|
177
|
+
.catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
if (e instanceof errors_1.JobExecutionError) {
|
|
179
|
+
this.requestClient.appendRequest(e, sasJob, config.debug);
|
|
180
|
+
reject(new errors_1.ErrorResponse(e === null || e === void 0 ? void 0 : e.message, e));
|
|
181
|
+
}
|
|
182
|
+
if (e instanceof errors_1.LoginRequiredError) {
|
|
183
|
+
if (!loginRequiredCallback) {
|
|
184
|
+
reject(new errors_1.ErrorResponse('Request is not authenticated. Make sure .env file exists with valid credentials.', e));
|
|
185
|
+
}
|
|
186
|
+
this.appendWaitingRequest(() => {
|
|
187
|
+
return this.execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes).then((res) => {
|
|
188
|
+
resolve(res);
|
|
189
|
+
}, (err) => {
|
|
190
|
+
reject(err);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
if (loginCallback)
|
|
194
|
+
yield loginCallback();
|
|
195
|
+
}
|
|
196
|
+
else
|
|
197
|
+
reject(new errors_1.ErrorResponse(e === null || e === void 0 ? void 0 : e.message, e));
|
|
198
|
+
}));
|
|
199
|
+
});
|
|
200
|
+
return requestPromise;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
getRequestParams(config) {
|
|
204
|
+
const requestParams = super.getRequestParams(config);
|
|
205
|
+
// FIXME(viya - possible issue with default debug flags)
|
|
206
|
+
// runAsTask on Viya: use _debug=128 (not 131) and omit _omittextlog
|
|
207
|
+
if (config.debug &&
|
|
208
|
+
config.serverType === types_1.ServerType.SasViya &&
|
|
209
|
+
config.runAsTask === true) {
|
|
210
|
+
requestParams['_debug'] = 128;
|
|
211
|
+
delete requestParams['_omittextlog'];
|
|
212
|
+
}
|
|
213
|
+
return requestParams;
|
|
214
|
+
}
|
|
215
|
+
getJobUri(sasJob) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
if (!this.sasViyaApiClient)
|
|
218
|
+
return '';
|
|
219
|
+
let uri = '';
|
|
220
|
+
// sasJob arrives with the appLoc already applied, so the folder is
|
|
221
|
+
// everything before the last segment. Reading the first two segments only
|
|
222
|
+
// would look up folder 'services' and job 'common' for a job like
|
|
223
|
+
// services/common/configure.
|
|
224
|
+
const folderPathParts = sasJob.split('/');
|
|
225
|
+
const jobName = folderPathParts.pop() || '';
|
|
226
|
+
const folderPath = folderPathParts.join('/');
|
|
227
|
+
if (!jobName) {
|
|
228
|
+
throw new Error('Job name is empty, null or undefined.');
|
|
229
|
+
}
|
|
230
|
+
const locJobs = yield this.sasViyaApiClient.getJobsInFolder(folderPath);
|
|
231
|
+
if (locJobs) {
|
|
232
|
+
const job = locJobs.find((el) => el.name === jobName && el.contentType === 'jobDefinition');
|
|
233
|
+
if (job) {
|
|
234
|
+
uri = job.uri;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return uri;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.WebJobExecutor = WebJobExecutor;
|
|
242
|
+
function addDummyFile(formData) {
|
|
243
|
+
if ((0, utils_1.isNode)()) {
|
|
244
|
+
;
|
|
245
|
+
formData.append('_sasjs_noop', '', {
|
|
246
|
+
filename: '_sasjs_noop.txt',
|
|
247
|
+
contentType: 'text/plain'
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
;
|
|
252
|
+
formData.append('_sasjs_noop', new Blob([''], { type: 'text/plain' }), '_sasjs_noop.txt');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ComputeJobExecutor"), exports);
|
|
18
|
+
__exportStar(require("./FileUploader"), exports);
|
|
19
|
+
__exportStar(require("./JesJobExecutor"), exports);
|
|
20
|
+
__exportStar(require("./JobExecutor"), exports);
|
|
21
|
+
__exportStar(require("./Sas9JobExecutor"), exports);
|
|
22
|
+
__exportStar(require("./WebJobExecutor"), exports);
|
|
23
|
+
__exportStar(require("./SasjsJobExecutor"), exports);
|
|
@@ -0,0 +1,198 @@
|
|
|
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
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
const types_1 = require("../../types");
|
|
14
|
+
const auth_1 = require("../../auth");
|
|
15
|
+
const types_2 = require("@sasjs/utils/types");
|
|
16
|
+
const RequestClient_1 = require("../../request/RequestClient");
|
|
17
|
+
const FileUploader_1 = require("../../job-execution/FileUploader");
|
|
18
|
+
const WebJobExecutor_1 = require("./WebJobExecutor");
|
|
19
|
+
const ErrorResponse_1 = require("../../types/errors/ErrorResponse");
|
|
20
|
+
const defaultConfig = {
|
|
21
|
+
serverUrl: '',
|
|
22
|
+
pathSASJS: '/SASjsApi/stp/execute',
|
|
23
|
+
pathSAS9: '/SASStoredProcess/do',
|
|
24
|
+
pathSASViya: '/SASJobExecution',
|
|
25
|
+
appLoc: '/Public/seedapp',
|
|
26
|
+
serverType: types_2.ServerType.Sas9,
|
|
27
|
+
debug: false,
|
|
28
|
+
contextName: 'SAS Job Execution compute context',
|
|
29
|
+
useComputeApi: null,
|
|
30
|
+
loginMechanism: types_1.LoginMechanism.Default
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* SASjs is a JavaScript adapter for SAS.
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
class SASjs {
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.sasjsConfig = new types_1.SASjsConfig();
|
|
39
|
+
this.jobsPath = '';
|
|
40
|
+
this.fileUploader = null;
|
|
41
|
+
this.authManager = null;
|
|
42
|
+
this.requestClient = null;
|
|
43
|
+
this.webJobExecutor = null;
|
|
44
|
+
this.resendWaitingRequests = () => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
yield ((_a = this.webJobExecutor) === null || _a === void 0 ? void 0 : _a.resendWaitingRequests());
|
|
47
|
+
yield ((_b = this.fileUploader) === null || _b === void 0 ? void 0 : _b.resendWaitingRequests());
|
|
48
|
+
});
|
|
49
|
+
this.sasjsConfig = Object.assign(Object.assign({}, defaultConfig), config);
|
|
50
|
+
this.setupConfiguration();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Logs into the SAS server with the supplied credentials.
|
|
54
|
+
* @param username - a string representing the username.
|
|
55
|
+
* @param password - a string representing the password.
|
|
56
|
+
* @param clientId - a string representing the client ID.
|
|
57
|
+
*/
|
|
58
|
+
logIn(username, password, clientId, options = {}) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (this.sasjsConfig.loginMechanism === types_1.LoginMechanism.Default) {
|
|
61
|
+
if (!username || !password)
|
|
62
|
+
throw new Error('A username and password are required when using the default login mechanism.');
|
|
63
|
+
return this.authManager.logIn(username, password);
|
|
64
|
+
}
|
|
65
|
+
if (typeof window === typeof undefined) {
|
|
66
|
+
throw new Error('The redirected login mechanism is only available for use in the browser.');
|
|
67
|
+
}
|
|
68
|
+
return this.authManager.redirectedLogIn(options);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Logs out of the configured SAS server.
|
|
73
|
+
*/
|
|
74
|
+
logOut() {
|
|
75
|
+
return this.authManager.logOut();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the current SASjs configuration.
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
getSasjsConfig() {
|
|
82
|
+
return this.sasjsConfig;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* this method returns an array of SASjsRequest
|
|
86
|
+
* @returns SASjsRequest[]
|
|
87
|
+
*/
|
|
88
|
+
getSasRequests() {
|
|
89
|
+
const requests = [...this.requestClient.getRequests()];
|
|
90
|
+
const sortedRequests = requests.sort(utils_1.compareTimestamps);
|
|
91
|
+
return sortedRequests;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sets the debug state. Turning this on will enable additional logging in the adapter.
|
|
95
|
+
* @param value - boolean indicating debug state (on/off).
|
|
96
|
+
*/
|
|
97
|
+
setDebugState(value) {
|
|
98
|
+
this.sasjsConfig.debug = value;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Uploads a file to the given service.
|
|
102
|
+
* @param sasJob - the path to the SAS program (ultimately resolves to
|
|
103
|
+
* the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
|
|
104
|
+
* Process). Is prepended at runtime with the value of `appLoc`.
|
|
105
|
+
* @param files - array of files to be uploaded, including File object and file name.
|
|
106
|
+
* @param params - request URL parameters.
|
|
107
|
+
* @param config - provide any changes to the config here, for instance to
|
|
108
|
+
* enable/disable `debug`. Any change provided will override the global config,
|
|
109
|
+
* for that particular function call.
|
|
110
|
+
* @param loginRequiredCallback - a function that is called if the
|
|
111
|
+
* user is not logged in (eg to display a login form). The request will be
|
|
112
|
+
* resubmitted after successful login.
|
|
113
|
+
*/
|
|
114
|
+
uploadFile(sasJob, files, params, config = {}, loginRequiredCallback) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
config = Object.assign(Object.assign({}, this.sasjsConfig), config);
|
|
117
|
+
const data = { files, params };
|
|
118
|
+
return yield this.fileUploader.execute(sasJob, data, config, loginRequiredCallback);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Makes a request to program specified in `SASjob` (could be a Viya Job, a
|
|
123
|
+
* SAS 9 Stored Process, or a SASjs Server Stored Program). The response
|
|
124
|
+
* object will always contain table names in lowercase, and column names in
|
|
125
|
+
* uppercase. Values are returned formatted by default, unformatted
|
|
126
|
+
* values can be configured as an option in the `%webout` macro.
|
|
127
|
+
*
|
|
128
|
+
* @param sasJob - the path to the SAS program (ultimately resolves to
|
|
129
|
+
* the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
|
|
130
|
+
* Process). Is prepended at runtime with the value of `appLoc`.
|
|
131
|
+
* @param data - a JSON object containing one or more tables to be sent to
|
|
132
|
+
* SAS. For an example of the table structure, see the project README. This
|
|
133
|
+
* value can be `null` if no inputs are required.
|
|
134
|
+
* @param config - provide any changes to the config here, for instance to
|
|
135
|
+
* enable/disable `debug`. Any change provided will override the global config,
|
|
136
|
+
* for that particular function call.
|
|
137
|
+
* @param loginRequiredCallback - a function that is called if the
|
|
138
|
+
* user is not logged in (eg to display a login form). The request will be
|
|
139
|
+
* resubmitted after successful login.
|
|
140
|
+
* When using a `loginRequiredCallback`, the call to the request will look, for example, like so:
|
|
141
|
+
* `await request(sasJobPath, data, config, () => setIsLoggedIn(false))`
|
|
142
|
+
* If you are not passing in any data and configuration, it will look like so:
|
|
143
|
+
* `await request(sasJobPath, {}, {}, () => setIsLoggedIn(false))`
|
|
144
|
+
* @param extraResponseAttributes - a array of predefined values that are used
|
|
145
|
+
* to provide extra attributes (same names as those values) to be added in response
|
|
146
|
+
* Supported values are declared in ExtraResponseAttributes type.
|
|
147
|
+
*/
|
|
148
|
+
request(sasJob, data, config = {}, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
config = Object.assign(Object.assign({}, this.sasjsConfig), config);
|
|
151
|
+
const validationResult = (0, utils_1.validateInput)(data);
|
|
152
|
+
// status is true if the data passes validation checks above
|
|
153
|
+
if (validationResult.status) {
|
|
154
|
+
return yield this.webJobExecutor.execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return Promise.reject(new ErrorResponse_1.ErrorResponse(validationResult.msg));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Checks whether a session is active, or login is required.
|
|
163
|
+
* @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
|
|
164
|
+
*/
|
|
165
|
+
checkSession() {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
return this.authManager.checkSession();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
setupConfiguration() {
|
|
171
|
+
if (this.sasjsConfig.serverUrl === undefined ||
|
|
172
|
+
this.sasjsConfig.serverUrl === '') {
|
|
173
|
+
if (typeof location !== 'undefined') {
|
|
174
|
+
let url = `${location.protocol}//${location.hostname}`;
|
|
175
|
+
if (location.port)
|
|
176
|
+
url = `${url}:${location.port}`;
|
|
177
|
+
this.sasjsConfig.serverUrl = url;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
this.sasjsConfig.serverUrl = '';
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (this.sasjsConfig.serverUrl.slice(-1) === '/') {
|
|
184
|
+
this.sasjsConfig.serverUrl = this.sasjsConfig.serverUrl.slice(0, -1);
|
|
185
|
+
}
|
|
186
|
+
if (!this.requestClient) {
|
|
187
|
+
this.requestClient = new RequestClient_1.RequestClient(this.sasjsConfig.serverUrl, this.sasjsConfig.httpsAgentOptions, this.sasjsConfig.requestHistoryLimit, this.sasjsConfig.verbose);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
this.requestClient.setConfig(this.sasjsConfig.serverUrl, this.sasjsConfig.httpsAgentOptions);
|
|
191
|
+
}
|
|
192
|
+
this.jobsPath = this.sasjsConfig.pathSAS9;
|
|
193
|
+
this.authManager = new auth_1.AuthManager(this.sasjsConfig.serverUrl, this.sasjsConfig.serverType, this.requestClient, this.resendWaitingRequests);
|
|
194
|
+
this.fileUploader = new FileUploader_1.FileUploader(this.sasjsConfig.serverUrl, this.sasjsConfig.serverType, this.jobsPath, this.requestClient);
|
|
195
|
+
this.webJobExecutor = new WebJobExecutor_1.WebJobExecutor(this.sasjsConfig.serverUrl, this.sasjsConfig.serverType, this.jobsPath, this.requestClient);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.default = SASjs;
|
|
@@ -0,0 +1,105 @@
|
|
|
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.WebJobExecutor = void 0;
|
|
13
|
+
const errors_1 = require("../../types/errors");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
const JobExecutor_1 = require("../../job-execution/JobExecutor");
|
|
16
|
+
const parseWeboutResponse_1 = require("../../utils/parseWeboutResponse");
|
|
17
|
+
class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
|
|
18
|
+
constructor(serverUrl, serverType, jobsPath, requestClient) {
|
|
19
|
+
super(serverUrl, serverType);
|
|
20
|
+
this.jobsPath = jobsPath;
|
|
21
|
+
this.requestClient = requestClient;
|
|
22
|
+
}
|
|
23
|
+
execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const loginCallback = loginRequiredCallback;
|
|
26
|
+
const program = (0, utils_1.isRelativePath)(sasJob)
|
|
27
|
+
? config.appLoc
|
|
28
|
+
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
|
|
29
|
+
: sasJob
|
|
30
|
+
: sasJob;
|
|
31
|
+
let apiUrl = `${config.serverUrl}${this.jobsPath}/?${'_program=' + program}`;
|
|
32
|
+
let requestParams = Object.assign({}, this.getRequestParams(config));
|
|
33
|
+
let formData = new FormData();
|
|
34
|
+
if (data) {
|
|
35
|
+
try {
|
|
36
|
+
formData = generateFileUploadForm(formData, data);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
return Promise.reject(new errors_1.ErrorResponse(e === null || e === void 0 ? void 0 : e.message, e));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const key in requestParams) {
|
|
43
|
+
if (requestParams.hasOwnProperty(key)) {
|
|
44
|
+
formData.append(key, requestParams[key]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const requestPromise = new Promise((resolve, reject) => {
|
|
48
|
+
this.requestClient.post(apiUrl, formData, authConfig === null || authConfig === void 0 ? void 0 : authConfig.access_token)
|
|
49
|
+
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
this.requestClient.appendRequest(res, sasJob, config.debug);
|
|
51
|
+
const jsonResponse = config.debug && typeof res.result === 'string'
|
|
52
|
+
? (0, parseWeboutResponse_1.parseWeboutResponse)(res.result, apiUrl)
|
|
53
|
+
: res.result;
|
|
54
|
+
const responseObject = (0, utils_1.appendExtraResponseAttributes)({ result: jsonResponse, log: res.log }, extraResponseAttributes);
|
|
55
|
+
resolve(responseObject);
|
|
56
|
+
}))
|
|
57
|
+
.catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (e instanceof errors_1.JobExecutionError) {
|
|
59
|
+
this.requestClient.appendRequest(e, sasJob, config.debug);
|
|
60
|
+
reject(new errors_1.ErrorResponse(e === null || e === void 0 ? void 0 : e.message, e));
|
|
61
|
+
}
|
|
62
|
+
if (e instanceof errors_1.LoginRequiredError) {
|
|
63
|
+
if (!loginRequiredCallback) {
|
|
64
|
+
reject(new errors_1.ErrorResponse('Request is not authenticated. Make sure .env file exists with valid credentials.', e));
|
|
65
|
+
}
|
|
66
|
+
this.appendWaitingRequest(() => {
|
|
67
|
+
return this.execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes).then((res) => {
|
|
68
|
+
resolve(res);
|
|
69
|
+
}, (err) => {
|
|
70
|
+
reject(err);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
if (loginCallback)
|
|
74
|
+
yield loginCallback();
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
reject(new errors_1.ErrorResponse(e === null || e === void 0 ? void 0 : e.message, e));
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
return requestPromise;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.WebJobExecutor = WebJobExecutor;
|
|
85
|
+
/**
|
|
86
|
+
* One of the approaches SASjs takes to send tables-formatted JSON (see README)
|
|
87
|
+
* to SAS is as multipart form data, where each table is provided as a specially
|
|
88
|
+
* formatted CSV file.
|
|
89
|
+
*/
|
|
90
|
+
const generateFileUploadForm = (formData, data) => {
|
|
91
|
+
for (const tableName in data) {
|
|
92
|
+
if (!Array.isArray(data[tableName]))
|
|
93
|
+
continue;
|
|
94
|
+
const name = tableName;
|
|
95
|
+
const csv = (0, utils_1.convertToCSV)(data, tableName);
|
|
96
|
+
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
97
|
+
throw new Error('The max length of a string value in SASjs is 32765 characters.');
|
|
98
|
+
}
|
|
99
|
+
const file = new Blob([csv], {
|
|
100
|
+
type: 'application/csv'
|
|
101
|
+
});
|
|
102
|
+
formData.append(name, file, `${name}.csv`);
|
|
103
|
+
}
|
|
104
|
+
return formData;
|
|
105
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
const SASjs_1 = __importDefault(require("./SASjs"));
|
|
21
|
+
__exportStar(require("../../types"), exports);
|
|
22
|
+
exports.default = SASjs_1.default;
|
package/node/index.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export * from './types/errors';
|
|
4
|
-
export * from './SASViyaApiClient';
|
|
5
|
-
export * from './SAS9ApiClient';
|
|
6
|
-
export * from './SASjsApiClient';
|
|
7
|
-
export * from './request/SasjsRequestClient';
|
|
8
|
-
export type { OnTokensRefreshed } from './auth/getTokens';
|
|
9
|
-
export default SASjs;
|
|
1
|
+
export * from '../index'
|
|
2
|
+
export { default } from '../index'
|