@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.
Files changed (418) hide show
  1. package/ContextManager.js +290 -0
  2. package/DISCLOSURE +45 -0
  3. package/README.md +1 -1
  4. package/SAS9ApiClient.d.ts +1 -1
  5. package/SAS9ApiClient.js +90 -0
  6. package/SASViyaApiClient.js +918 -0
  7. package/SASjs.js +794 -0
  8. package/SASjsApiClient.d.ts +1 -0
  9. package/SASjsApiClient.js +132 -0
  10. package/SessionManager.js +353 -0
  11. package/api/viya/executeOnComputeApi.js +198 -0
  12. package/api/viya/getFileStream.js +32 -0
  13. package/api/viya/pollJobState.js +247 -0
  14. package/api/viya/saveLog.js +45 -0
  15. package/api/viya/uploadTables.js +45 -0
  16. package/api/viya/writeStream.js +25 -0
  17. package/auth/AuthManager.js +305 -0
  18. package/auth/getAccessTokenForSasjs.js +43 -0
  19. package/auth/getAccessTokenForViya.js +54 -0
  20. package/auth/getTokenRequestErrorPrefix.js +70 -0
  21. package/auth/getTokens.js +110 -0
  22. package/auth/index.js +20 -0
  23. package/auth/isAuthorizeFormRequired.js +7 -0
  24. package/auth/isLoginRequired.js +9 -0
  25. package/auth/loginHeader.js +87 -0
  26. package/auth/openWebPage.js +31 -0
  27. package/auth/refreshTokensForSasjs.js +42 -0
  28. package/auth/refreshTokensForViya.js +53 -0
  29. package/auth/verifySas9Login.js +32 -0
  30. package/auth/verifySasViyaLogin.js +44 -0
  31. package/dist/minified_sas9.js +10892 -0
  32. package/dist/sasjs-adapter.js +19569 -0
  33. package/file/generateFileUploadForm.js +43 -0
  34. package/file/generateTableUploadForm.js +38 -0
  35. package/index.js +9 -80376
  36. package/job-execution/ComputeJobExecutor.js +55 -0
  37. package/job-execution/FileUploader.js +114 -0
  38. package/job-execution/JesJobExecutor.js +55 -0
  39. package/job-execution/JobExecutor.js +40 -0
  40. package/job-execution/Sas9JobExecutor.d.ts +1 -1
  41. package/job-execution/Sas9JobExecutor.js +115 -0
  42. package/job-execution/SasjsJobExecutor.js +100 -0
  43. package/job-execution/WebJobExecutor.js +254 -0
  44. package/job-execution/index.js +23 -0
  45. package/minified/sas9/SASjs.js +198 -0
  46. package/minified/sas9/WebJobExecutor.js +105 -0
  47. package/minified/sas9/index.js +22 -0
  48. package/node/index.d.ts +2 -9
  49. package/node/index.js +1 -30570
  50. package/package.json +41 -15
  51. package/request/RequestClient.d.ts +1 -1
  52. package/request/RequestClient.js +717 -0
  53. package/request/Sas9RequestClient.d.ts +1 -1
  54. package/request/Sas9RequestClient.js +121 -0
  55. package/request/SasjsRequestClient.js +77 -0
  56. package/types/Context.js +2 -0
  57. package/types/CsrfToken.js +2 -0
  58. package/types/ExecuteScript.js +2 -0
  59. package/types/File.js +2 -0
  60. package/types/FileResource.js +2 -0
  61. package/types/Folder.js +2 -0
  62. package/types/Job.js +2 -0
  63. package/types/JobDefinition.js +2 -0
  64. package/types/JobResult.js +2 -0
  65. package/types/Link.js +2 -0
  66. package/types/LogStatistics.js +2 -0
  67. package/types/Login.js +2 -0
  68. package/types/PollOptions.js +2 -0
  69. package/types/RequestClient.js +2 -0
  70. package/types/SASjsConfig.d.ts +1 -1
  71. package/types/SASjsConfig.js +91 -0
  72. package/types/Session.js +14 -0
  73. package/types/Tables.js +28 -0
  74. package/types/UploadFile.js +2 -0
  75. package/types/WriteStream.d.ts +1 -1
  76. package/types/WriteStream.js +2 -0
  77. package/types/errors/ArgumentError.js +12 -0
  78. package/types/errors/AuthorizeError.js +13 -0
  79. package/types/errors/CertificateError.js +12 -0
  80. package/types/errors/ComputeJobExecutionError.js +13 -0
  81. package/types/errors/ErrorResponse.js +23 -0
  82. package/types/errors/InternalServerError.js +11 -0
  83. package/types/errors/InvalidJsonError.js +11 -0
  84. package/types/errors/InvalidSASjsCsrfError.js +12 -0
  85. package/types/errors/JobExecutionError.js +14 -0
  86. package/types/errors/JobStatePollError.js +12 -0
  87. package/types/errors/JsonParseArrayError.js +11 -0
  88. package/types/errors/LoginRequiredError.js +14 -0
  89. package/types/errors/NoSessionStateError.js +14 -0
  90. package/types/errors/NotFoundError.js +12 -0
  91. package/types/errors/RootFolderNotFoundError.js +22 -0
  92. package/types/errors/SAS9AuthError.js +11 -0
  93. package/types/errors/WeboutResponseError.js +12 -0
  94. package/types/errors/index.js +31 -0
  95. package/types/index.js +34 -0
  96. package/utils/appendExtraResponseAttributes.js +25 -0
  97. package/utils/asyncForEach.js +20 -0
  98. package/utils/compareTimestamps.js +11 -0
  99. package/utils/convertToCsv.js +154 -0
  100. package/utils/createAxiosInstance.d.ts +1 -1
  101. package/utils/createAxiosInstance.js +9 -0
  102. package/utils/delay.js +5 -0
  103. package/{src/utils/extractWeboutBlob.ts → utils/extractWeboutBlob.js} +19 -20
  104. package/utils/fetchLogByChunks.js +56 -0
  105. package/utils/formatDataForRequest.js +39 -0
  106. package/utils/getFormData.js +10 -0
  107. package/{node/utils/getUserLanguage.d.ts → utils/getUserLanguage.js} +5 -1
  108. package/utils/getValidJson.js +27 -0
  109. package/utils/host.d.ts +24 -0
  110. package/utils/host.js +36 -0
  111. package/utils/index.js +41 -0
  112. package/utils/isIeOrEdge.js +30 -0
  113. package/utils/isNode.js +7 -0
  114. package/utils/isRelativePath.js +5 -0
  115. package/utils/isUri.js +9 -0
  116. package/utils/isUrl.js +20 -0
  117. package/utils/loginPrompt/index.js +180 -0
  118. package/utils/needsRetry.js +14 -0
  119. package/utils/parseGeneratedCode.js +10 -0
  120. package/utils/parseSasViyaLog.js +17 -0
  121. package/utils/parseSourceCode.js +9 -0
  122. package/utils/parseViyaDebugResponse.js +46 -0
  123. package/utils/parseViyaLogDebugResponse.js +32 -0
  124. package/utils/parseWeboutResponse.js +22 -0
  125. package/utils/sas9/extractUserLongNameSas9.js +30 -0
  126. package/utils/serialize.js +20 -0
  127. package/utils/splitChunks.js +13 -0
  128. package/utils/validateInput.js +83 -0
  129. package/.env.example +0 -2
  130. package/.git-hooks/commit-msg +0 -39
  131. package/.git-hooks/pre-commit +0 -12
  132. package/.gitattributes +0 -1
  133. package/.pre-commit-config.yaml +0 -25
  134. package/.vscode/settings.json +0 -3
  135. package/SASViyaApiClient.spec.d.ts +0 -1
  136. package/__mocks__/axios.d.ts +0 -3
  137. package/api/viya/spec/executeScript.spec.d.ts +0 -1
  138. package/api/viya/spec/getFileStream.spec.d.ts +0 -1
  139. package/api/viya/spec/mockResponses.d.ts +0 -10
  140. package/api/viya/spec/pollJobState.spec.d.ts +0 -1
  141. package/api/viya/spec/saveLog.spec.d.ts +0 -1
  142. package/api/viya/spec/uploadTables.spec.d.ts +0 -1
  143. package/api/viya/spec/writeStream.spec.d.ts +0 -1
  144. package/auth/spec/AuthManager.spec.d.ts +0 -4
  145. package/auth/spec/getAccessTokenForSasjs.spec.d.ts +0 -1
  146. package/auth/spec/getAccessTokenForViya.spec.d.ts +0 -1
  147. package/auth/spec/getTokenRequestErrorPrefix.spec.d.ts +0 -1
  148. package/auth/spec/getTokens.spec.d.ts +0 -1
  149. package/auth/spec/loginHeader.spec.d.ts +0 -4
  150. package/auth/spec/mockResponses.d.ts +0 -23
  151. package/auth/spec/openWebPage.spec.d.ts +0 -1
  152. package/auth/spec/refreshTokensForSasjs.spec.d.ts +0 -1
  153. package/auth/spec/refreshTokensForViya.spec.d.ts +0 -1
  154. package/auth/spec/verifySas9Login.spec.d.ts +0 -1
  155. package/auth/spec/verifySasViyaLogin.spec.d.ts +0 -1
  156. package/createTSDocs.js +0 -35
  157. package/cypress.config.js +0 -18
  158. package/example.html +0 -109
  159. package/file/spec/generateFileUploadForm.spec.d.ts +0 -1
  160. package/file/spec/generateTableUploadForm.spec.d.ts +0 -1
  161. package/index-dev.js +0 -80394
  162. package/job-execution/spec/ComputeJobExecutor.spec.d.ts +0 -1
  163. package/job-execution/spec/JesJobExecutor.spec.d.ts +0 -1
  164. package/job-execution/spec/Sas9JobExecutor.spec.d.ts +0 -1
  165. package/job-execution/spec/SasjsJobExecutor.spec.d.ts +0 -1
  166. package/job-execution/spec/WebJobExecutor.debug.spec.d.ts +0 -1
  167. package/job-execution/spec/WebJobExecutor.spec.d.ts +0 -1
  168. package/job-execution/spec/executionTasks.spec.d.ts +0 -1
  169. package/minified_sas9.js +0 -14039
  170. package/node/ContextManager.d.ts +0 -41
  171. package/node/SAS9ApiClient.d.ts +0 -30
  172. package/node/SASViyaApiClient.d.ts +0 -298
  173. package/node/SASjs.d.ts +0 -387
  174. package/node/SASjsApiClient.d.ts +0 -65
  175. package/node/SessionManager.d.ts +0 -115
  176. package/node/api/viya/executeOnComputeApi.d.ts +0 -21
  177. package/node/api/viya/getFileStream.d.ts +0 -2
  178. package/node/api/viya/pollJobState.d.ts +0 -57
  179. package/node/api/viya/saveLog.d.ts +0 -15
  180. package/node/api/viya/uploadTables.d.ts +0 -13
  181. package/node/api/viya/writeStream.d.ts +0 -2
  182. package/node/auth/AuthManager.d.ts +0 -49
  183. package/node/auth/getAccessTokenForSasjs.d.ts +0 -11
  184. package/node/auth/getAccessTokenForViya.d.ts +0 -10
  185. package/node/auth/getTokenRequestErrorPrefix.d.ts +0 -44
  186. package/node/auth/getTokens.d.ts +0 -22
  187. package/node/auth/index.d.ts +0 -4
  188. package/node/auth/isAuthorizeFormRequired.d.ts +0 -1
  189. package/node/auth/isLoginRequired.d.ts +0 -1
  190. package/node/auth/loginHeader.d.ts +0 -17
  191. package/node/auth/openWebPage.d.ts +0 -6
  192. package/node/auth/refreshTokensForSasjs.d.ts +0 -10
  193. package/node/auth/refreshTokensForViya.d.ts +0 -11
  194. package/node/auth/verifySas9Login.d.ts +0 -3
  195. package/node/auth/verifySasViyaLogin.d.ts +0 -4
  196. package/node/file/generateFileUploadForm.d.ts +0 -11
  197. package/node/file/generateTableUploadForm.d.ts +0 -5
  198. package/node/job-execution/ComputeJobExecutor.d.ts +0 -8
  199. package/node/job-execution/FileUploader.d.ts +0 -9
  200. package/node/job-execution/JesJobExecutor.d.ts +0 -9
  201. package/node/job-execution/JobExecutor.d.ts +0 -17
  202. package/node/job-execution/Sas9JobExecutor.d.ts +0 -19
  203. package/node/job-execution/SasjsJobExecutor.d.ts +0 -9
  204. package/node/job-execution/WebJobExecutor.d.ts +0 -18
  205. package/node/job-execution/index.d.ts +0 -7
  206. package/node/request/RequestClient.d.ts +0 -125
  207. package/node/request/Sas9RequestClient.d.ts +0 -25
  208. package/node/request/SasjsRequestClient.d.ts +0 -12
  209. package/node/types/Context.d.ts +0 -42
  210. package/node/types/CsrfToken.d.ts +0 -4
  211. package/node/types/ExecuteScript.d.ts +0 -4
  212. package/node/types/File.d.ts +0 -7
  213. package/node/types/FileResource.d.ts +0 -32
  214. package/node/types/Folder.d.ts +0 -7
  215. package/node/types/Job.d.ts +0 -14
  216. package/node/types/JobDefinition.d.ts +0 -3
  217. package/node/types/JobResult.d.ts +0 -3
  218. package/node/types/Link.d.ts +0 -7
  219. package/node/types/LogStatistics.d.ts +0 -4
  220. package/node/types/Login.d.ts +0 -14
  221. package/node/types/PollOptions.d.ts +0 -8
  222. package/node/types/RequestClient.d.ts +0 -46
  223. package/node/types/SASjsConfig.d.ts +0 -94
  224. package/node/types/Session.d.ts +0 -30
  225. package/node/types/Tables.d.ts +0 -7
  226. package/node/types/UploadFile.d.ts +0 -8
  227. package/node/types/WriteStream.d.ts +0 -7
  228. package/node/types/errors/ArgumentError.d.ts +0 -4
  229. package/node/types/errors/AuthorizeError.d.ts +0 -5
  230. package/node/types/errors/CertificateError.d.ts +0 -3
  231. package/node/types/errors/ComputeJobExecutionError.d.ts +0 -6
  232. package/node/types/errors/ErrorResponse.d.ts +0 -9
  233. package/node/types/errors/InternalServerError.d.ts +0 -3
  234. package/node/types/errors/InvalidJsonError.d.ts +0 -3
  235. package/node/types/errors/InvalidSASjsCsrfError.d.ts +0 -3
  236. package/node/types/errors/JobExecutionError.d.ts +0 -6
  237. package/node/types/errors/JobStatePollError.d.ts +0 -4
  238. package/node/types/errors/JsonParseArrayError.d.ts +0 -3
  239. package/node/types/errors/LoginRequiredError.d.ts +0 -3
  240. package/node/types/errors/NoSessionStateError.d.ts +0 -6
  241. package/node/types/errors/NotFoundError.d.ts +0 -4
  242. package/node/types/errors/RootFolderNotFoundError.d.ts +0 -3
  243. package/node/types/errors/SAS9AuthError.d.ts +0 -3
  244. package/node/types/errors/WeboutResponseError.d.ts +0 -4
  245. package/node/types/errors/index.d.ts +0 -15
  246. package/node/types/index.d.ts +0 -18
  247. package/node/utils/appendExtraResponseAttributes.d.ts +0 -2
  248. package/node/utils/asyncForEach.d.ts +0 -1
  249. package/node/utils/compareTimestamps.d.ts +0 -6
  250. package/node/utils/convertToCsv.d.ts +0 -12
  251. package/node/utils/createAxiosInstance.d.ts +0 -2
  252. package/node/utils/delay.d.ts +0 -1
  253. package/node/utils/extractWeboutBlob.d.ts +0 -13
  254. package/node/utils/fetchLogByChunks.d.ts +0 -20
  255. package/node/utils/formatDataForRequest.d.ts +0 -1
  256. package/node/utils/getFormData.d.ts +0 -2
  257. package/node/utils/getValidJson.d.ts +0 -5
  258. package/node/utils/index.d.ts +0 -25
  259. package/node/utils/isNode.d.ts +0 -1
  260. package/node/utils/isRelativePath.d.ts +0 -1
  261. package/node/utils/isUri.d.ts +0 -5
  262. package/node/utils/isUrl.d.ts +0 -5
  263. package/node/utils/loginPrompt/index.d.ts +0 -1
  264. package/node/utils/needsRetry.d.ts +0 -1
  265. package/node/utils/parseGeneratedCode.d.ts +0 -1
  266. package/node/utils/parseSasViyaLog.d.ts +0 -5
  267. package/node/utils/parseSourceCode.d.ts +0 -1
  268. package/node/utils/parseViyaDebugResponse.d.ts +0 -12
  269. package/node/utils/parseViyaLogDebugResponse.d.ts +0 -8
  270. package/node/utils/parseWeboutResponse.d.ts +0 -1
  271. package/node/utils/sas9/extractUserLongNameSas9.d.ts +0 -6
  272. package/node/utils/serialize.d.ts +0 -1
  273. package/node/utils/splitChunks.d.ts +0 -1
  274. package/node/utils/validateInput.d.ts +0 -14
  275. package/request/spec/SasjsRequestClient.spec.d.ts +0 -1
  276. package/screenshots/session-manager-first-request.png +0 -0
  277. package/screenshots/subsequent-session-request.png +0 -0
  278. package/spec/SAS9ApiClient.spec.d.ts +0 -1
  279. package/spec/SASjs.startComputeJob.spec.d.ts +0 -1
  280. package/spec/SASjsApiClient.spec.d.ts +0 -1
  281. package/src/ContextManager.ts +0 -454
  282. package/src/SAS9ApiClient.ts +0 -100
  283. package/src/SASViyaApiClient.ts +0 -1417
  284. package/src/SASjs.ts +0 -1268
  285. package/src/SASjsApiClient.ts +0 -177
  286. package/src/SessionManager.ts +0 -465
  287. package/src/__mocks__/axios.ts +0 -7
  288. package/src/api/viya/executeOnComputeApi.ts +0 -307
  289. package/src/api/viya/getFileStream.ts +0 -17
  290. package/src/api/viya/pollJobState.ts +0 -393
  291. package/src/api/viya/saveLog.ts +0 -55
  292. package/src/api/viya/spec/mockResponses.ts +0 -75
  293. package/src/api/viya/uploadTables.ts +0 -41
  294. package/src/api/viya/writeStream.ts +0 -16
  295. package/src/auth/AuthManager.ts +0 -387
  296. package/src/auth/getAccessTokenForSasjs.ts +0 -48
  297. package/src/auth/getAccessTokenForViya.ts +0 -61
  298. package/src/auth/getTokenRequestErrorPrefix.ts +0 -88
  299. package/src/auth/getTokens.ts +0 -127
  300. package/src/auth/index.ts +0 -4
  301. package/src/auth/isAuthorizeFormRequired.ts +0 -3
  302. package/src/auth/isLoginRequired.ts +0 -5
  303. package/src/auth/loginHeader.ts +0 -97
  304. package/src/auth/openWebPage.ts +0 -40
  305. package/src/auth/refreshTokensForSasjs.ts +0 -45
  306. package/src/auth/refreshTokensForViya.ts +0 -66
  307. package/src/auth/spec/mockResponses.ts +0 -53
  308. package/src/auth/verifySas9Login.ts +0 -25
  309. package/src/auth/verifySasViyaLogin.ts +0 -43
  310. package/src/file/generateFileUploadForm.ts +0 -48
  311. package/src/file/generateTableUploadForm.ts +0 -50
  312. package/src/index.ts +0 -9
  313. package/src/job-execution/ComputeJobExecutor.ts +0 -76
  314. package/src/job-execution/FileUploader.ts +0 -152
  315. package/src/job-execution/JesJobExecutor.ts +0 -78
  316. package/src/job-execution/JobExecutor.ts +0 -63
  317. package/src/job-execution/Sas9JobExecutor.ts +0 -137
  318. package/src/job-execution/SasjsJobExecutor.ts +0 -152
  319. package/src/job-execution/WebJobExecutor.ts +0 -341
  320. package/src/job-execution/index.ts +0 -7
  321. package/src/minified/sas9/SASjs.ts +0 -274
  322. package/src/minified/sas9/WebJobExecutor.ts +0 -156
  323. package/src/minified/sas9/index.ts +0 -3
  324. package/src/request/RequestClient.ts +0 -941
  325. package/src/request/Sas9RequestClient.ts +0 -132
  326. package/src/request/SasjsRequestClient.ts +0 -82
  327. package/src/test/SAS_server_app.ts +0 -47
  328. package/src/types/Context.ts +0 -39
  329. package/src/types/CsrfToken.ts +0 -4
  330. package/src/types/ExecuteScript.ts +0 -4
  331. package/src/types/File.ts +0 -8
  332. package/src/types/FileResource.ts +0 -33
  333. package/src/types/Folder.ts +0 -8
  334. package/src/types/Job.ts +0 -15
  335. package/src/types/JobDefinition.ts +0 -3
  336. package/src/types/JobResult.ts +0 -3
  337. package/src/types/Link.ts +0 -7
  338. package/src/types/LogStatistics.ts +0 -4
  339. package/src/types/Login.ts +0 -15
  340. package/src/types/PollOptions.ts +0 -9
  341. package/src/types/Process.d.ts +0 -5
  342. package/src/types/RequestClient.ts +0 -55
  343. package/src/types/SASjsConfig.ts +0 -95
  344. package/src/types/Session.ts +0 -34
  345. package/src/types/Tables.ts +0 -29
  346. package/src/types/UploadFile.ts +0 -8
  347. package/src/types/WriteStream.ts +0 -10
  348. package/src/types/errors/ArgumentError.ts +0 -7
  349. package/src/types/errors/AuthorizeError.ts +0 -10
  350. package/src/types/errors/CertificateError.ts +0 -12
  351. package/src/types/errors/ComputeJobExecutionError.ts +0 -12
  352. package/src/types/errors/ErrorResponse.ts +0 -28
  353. package/src/types/errors/InternalServerError.ts +0 -9
  354. package/src/types/errors/InvalidJsonError.ts +0 -7
  355. package/src/types/errors/InvalidSASjsCsrfError.ts +0 -9
  356. package/src/types/errors/JobExecutionError.ts +0 -11
  357. package/src/types/errors/JobStatePollError.ts +0 -14
  358. package/src/types/errors/JsonParseArrayError.ts +0 -7
  359. package/src/types/errors/LoginRequiredError.ts +0 -11
  360. package/src/types/errors/NoSessionStateError.ts +0 -15
  361. package/src/types/errors/NotFoundError.ts +0 -7
  362. package/src/types/errors/RootFolderNotFoundError.ts +0 -24
  363. package/src/types/errors/SAS9AuthError.ts +0 -9
  364. package/src/types/errors/WeboutResponseError.ts +0 -7
  365. package/src/types/errors/index.ts +0 -15
  366. package/src/types/index.ts +0 -18
  367. package/src/types/system/global.d.ts +0 -1
  368. package/src/utils/appendExtraResponseAttributes.ts +0 -22
  369. package/src/utils/asyncForEach.ts +0 -5
  370. package/src/utils/compareTimestamps.ts +0 -9
  371. package/src/utils/convertToCsv.ts +0 -198
  372. package/src/utils/createAxiosInstance.ts +0 -7
  373. package/src/utils/delay.ts +0 -2
  374. package/src/utils/fetchLogByChunks.ts +0 -63
  375. package/src/utils/formatDataForRequest.ts +0 -48
  376. package/src/utils/getFormData.ts +0 -5
  377. package/src/utils/getUserLanguage.ts +0 -10
  378. package/src/utils/getValidJson.ts +0 -23
  379. package/src/utils/index.ts +0 -25
  380. package/src/utils/isIeOrEdge.ts +0 -34
  381. package/src/utils/isNode.ts +0 -4
  382. package/src/utils/isRelativePath.ts +0 -2
  383. package/src/utils/isUri.ts +0 -5
  384. package/src/utils/isUrl.ts +0 -17
  385. package/src/utils/loginPrompt/index.ts +0 -177
  386. package/src/utils/needsRetry.ts +0 -14
  387. package/src/utils/parseGeneratedCode.ts +0 -7
  388. package/src/utils/parseSasViyaLog.ts +0 -12
  389. package/src/utils/parseSourceCode.ts +0 -6
  390. package/src/utils/parseViyaDebugResponse.ts +0 -46
  391. package/src/utils/parseViyaLogDebugResponse.ts +0 -22
  392. package/src/utils/parseWeboutResponse.ts +0 -20
  393. package/src/utils/sas9/extractUserLongNameSas9.ts +0 -31
  394. package/src/utils/serialize.ts +0 -15
  395. package/src/utils/splitChunks.ts +0 -12
  396. package/src/utils/validateInput.ts +0 -93
  397. package/test/ContextManager.spec.d.ts +0 -1
  398. package/test/FileUploader.spec.d.ts +0 -4
  399. package/test/FolderOperations.spec.d.ts +0 -1
  400. package/test/RequestClient.spec.d.ts +0 -1
  401. package/test/SAS_server_app.d.ts +0 -10
  402. package/test/SessionManager.spec.d.ts +0 -1
  403. package/test/getJobsInFolder.spec.d.ts +0 -1
  404. package/test/utils/formatDataForRequest.spec.d.ts +0 -1
  405. package/test/utils/getValidJson.spec.d.ts +0 -1
  406. package/test/utils/isUrl.spec.d.ts +0 -1
  407. package/test/utils/parseGeneratedCode.spec.d.ts +0 -1
  408. package/test/utils/parseSourceCode.spec.d.ts +0 -1
  409. package/types/Tables.spec.d.ts +0 -1
  410. package/types/errors/RootFolderNotFoundError.spec.d.ts +0 -1
  411. package/types/errors/spec/SAS9AuthError.spec.d.ts +0 -1
  412. package/utils/spec/convertToCsv.spec.d.ts +0 -1
  413. package/utils/spec/extractUserLongNameSas9.spec.d.ts +0 -1
  414. package/utils/spec/getFormData.spec.d.ts +0 -1
  415. package/utils/spec/parseSasViyaLog.spec.d.ts +0 -1
  416. package/utils/spec/parseViyaDebugResponse.spec.d.ts +0 -1
  417. package/utils/spec/parseViyaLogDebugResponse.spec.d.ts +0 -1
  418. package/utils/spec/validateInput.spec.d.ts +0 -1
package/src/SASjs.ts DELETED
@@ -1,1268 +0,0 @@
1
- import { compareTimestamps, asyncForEach, validateInput } from './utils'
2
- import {
3
- SASjsConfig,
4
- UploadFile,
5
- EditContextInput,
6
- PollOptions,
7
- LoginMechanism,
8
- VerboseMode,
9
- ErrorResponse,
10
- LoginOptions,
11
- LoginResult,
12
- ExecutionQuery,
13
- Tables
14
- } from './types'
15
- import { SASViyaApiClient } from './SASViyaApiClient'
16
- import { SAS9ApiClient } from './SAS9ApiClient'
17
- import { SASjsApiClient, SASjsAuthResponse } from './SASjsApiClient'
18
- import { AuthManager } from './auth'
19
- import { OnTokensRefreshed } from './auth/getTokens'
20
- import {
21
- ServerType,
22
- MacroVar,
23
- AuthConfig,
24
- ExtraResponseAttributes,
25
- SasAuthResponse,
26
- AuthConfigSas9
27
- } from '@sasjs/utils/types'
28
- import { RequestClient } from './request/RequestClient'
29
- import { SasjsRequestClient } from './request/SasjsRequestClient'
30
- import {
31
- JobExecutor,
32
- WebJobExecutor,
33
- SasjsJobExecutor,
34
- ComputeJobExecutor,
35
- JesJobExecutor,
36
- Sas9JobExecutor,
37
- FileUploader
38
- } from './job-execution'
39
- import { AxiosResponse, AxiosError } from 'axios'
40
-
41
- interface ExecuteScriptParams {
42
- linesOfCode: string[]
43
- fileName?: string
44
- contextName?: string
45
- runTime?: string
46
- authConfig?: AuthConfig
47
- authConfigSas9?: AuthConfigSas9
48
- debug?: boolean
49
- onTokensRefreshed?: OnTokensRefreshed
50
- }
51
-
52
- const defaultConfig: SASjsConfig = {
53
- serverUrl: '',
54
- pathSASJS: '/SASjsApi/stp/execute',
55
- pathSAS9: '/SASStoredProcess/do',
56
- pathSASViya: '/SASJobExecution',
57
- appLoc: '/Public/seedapp',
58
- serverType: ServerType.SasViya,
59
- debug: false,
60
- contextName: 'SAS Job Execution compute context',
61
- useComputeApi: null,
62
- loginMechanism: LoginMechanism.Default
63
- }
64
-
65
- /**
66
- * SASjs is a JavaScript adapter for SAS.
67
- *
68
- */
69
- export default class SASjs {
70
- private sasjsConfig: SASjsConfig = new SASjsConfig()
71
- private jobsPath: string = ''
72
- private sasViyaApiClient: SASViyaApiClient | null = null
73
- private sas9ApiClient: SAS9ApiClient | null = null
74
- private sasJSApiClient: SASjsApiClient | null = null
75
- private fileUploader: FileUploader | null = null
76
- private authManager: AuthManager | null = null
77
- private requestClient: RequestClient | null = null
78
- private webJobExecutor: JobExecutor | null = null
79
- private sasjsJobExecutor: JobExecutor | null = null
80
- private computeJobExecutor: JobExecutor | null = null
81
- private jesJobExecutor: JobExecutor | null = null
82
- private sas9JobExecutor: JobExecutor | null = null
83
-
84
- constructor(config?: Partial<SASjsConfig>) {
85
- this.sasjsConfig = {
86
- ...defaultConfig,
87
- ...config
88
- }
89
-
90
- this.setupConfiguration()
91
- }
92
-
93
- public getCsrfToken(type: 'general' | 'file' = 'general') {
94
- return this.requestClient?.getCsrfToken(type)
95
- }
96
-
97
- /**
98
- * Executes code on a SAS server.
99
- * @param linesOfCode - lines of code to run.
100
- * @param fileName - (required for server type sas viya) name of the file to run. It will be converted to path to the file being submitted for execution.
101
- * @param contextName - (required for server type sas viya) context name on which code will be run on the server.
102
- * @param runTime - (required for server type sasjs) a string to represent runTime for code execution.
103
- * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
104
- * @param authConfigSas9 - (required for server type sas9) a valid username and password that are authorised to execute scripts.
105
- * @param debug - (optional) if true, global debug config will be overriden
106
- * @param onTokensRefreshed - (optional, SAS Viya only) callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
107
- */
108
- public async executeScript({
109
- linesOfCode,
110
- fileName,
111
- contextName,
112
- runTime,
113
- authConfig,
114
- authConfigSas9,
115
- debug,
116
- onTokensRefreshed
117
- }: ExecuteScriptParams) {
118
- this.isMethodSupported('executeScript', [
119
- ServerType.Sas9,
120
- ServerType.Sasjs,
121
- ServerType.SasViya
122
- ])
123
-
124
- if (this.sasjsConfig.serverType === ServerType.Sas9) {
125
- if (!authConfigSas9)
126
- throw new Error('Auth config for sas9 is not provided')
127
-
128
- return await this.sas9ApiClient?.executeScript(
129
- linesOfCode,
130
- authConfigSas9.userName,
131
- authConfigSas9.password
132
- )
133
- }
134
-
135
- if (this.sasjsConfig.serverType === ServerType.Sasjs) {
136
- return await this.sasJSApiClient?.executeScript(
137
- linesOfCode.join('\n'),
138
- runTime,
139
- authConfig
140
- )
141
- }
142
-
143
- if (this.sasjsConfig.serverType === ServerType.SasViya) {
144
- contextName = contextName || this.sasjsConfig.contextName
145
-
146
- if (!contextName) {
147
- throw new Error(
148
- 'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
149
- )
150
- }
151
-
152
- if (!fileName) {
153
- throw new Error(
154
- 'File name is required in case of SAS VIYA. Please provide a `fileName`.'
155
- )
156
- }
157
-
158
- return await this.sasViyaApiClient!.executeScript(
159
- fileName,
160
- linesOfCode,
161
- contextName,
162
- authConfig,
163
- null,
164
- debug ? debug : this.sasjsConfig.debug,
165
- false,
166
- true,
167
- undefined,
168
- false,
169
- undefined,
170
- onTokensRefreshed
171
- )
172
- }
173
- }
174
-
175
- /**
176
- * Executes job on SASJS server.
177
- * @param query - an object containing job path and debug level.
178
- * @param appLoc - an application path.
179
- * @param authConfig - an object for authentication.
180
- * @returns a promise that resolves into job execution result and log.
181
- */
182
- public async executeJob(
183
- query: ExecutionQuery,
184
- appLoc: string,
185
- authConfig?: AuthConfig
186
- ) {
187
- this.isMethodSupported('executeScript', [ServerType.Sasjs])
188
-
189
- return await this.sasJSApiClient?.executeJob(query, appLoc, authConfig)
190
- }
191
-
192
- /**
193
- * Gets compute contexts.
194
- * @param accessToken - an access token for an authorised user.
195
- */
196
- public async getComputeContexts(accessToken: string) {
197
- this.isMethodSupported('getComputeContexts', [ServerType.SasViya])
198
-
199
- return await this.sasViyaApiClient!.getComputeContexts(accessToken)
200
- }
201
-
202
- /**
203
- * Gets launcher contexts.
204
- * @param accessToken - an access token for an authorised user.
205
- */
206
- public async getLauncherContexts(accessToken: string) {
207
- this.isMethodSupported('getLauncherContexts', [ServerType.SasViya])
208
-
209
- return await this.sasViyaApiClient!.getLauncherContexts(accessToken)
210
- }
211
-
212
- /**
213
- * Gets default(system) launcher contexts.
214
- */
215
- public getDefaultComputeContexts() {
216
- this.isMethodSupported('getDefaultComputeContexts', [ServerType.SasViya])
217
-
218
- return this.sasViyaApiClient!.getDefaultComputeContexts()
219
- }
220
-
221
- /**
222
- * Gets executable compute contexts.
223
- * @param authConfig - an access token, refresh token, client and secret for an authorised user.
224
- */
225
- public async getExecutableContexts(authConfig: AuthConfig) {
226
- this.isMethodSupported('getExecutableContexts', [ServerType.SasViya])
227
-
228
- return await this.sasViyaApiClient!.getExecutableContexts(authConfig)
229
- }
230
-
231
- /**
232
- * Creates a compute context on the given server.
233
- * @param contextName - the name of the context to be created.
234
- * @param launchContextName - the name of the launcher context used by the compute service.
235
- * @param sharedAccountId - the ID of the account to run the servers for this context as.
236
- * @param autoExecLines - the lines of code to execute during session initialization.
237
- * @param accessToken - an access token for an authorised user.
238
- * @param authorisedUsers - an optional list of authorised user IDs.
239
- */
240
- public async createComputeContext(
241
- contextName: string,
242
- launchContextName: string,
243
- sharedAccountId: string,
244
- autoExecLines: string[],
245
- accessToken: string,
246
- authorisedUsers?: string[]
247
- ) {
248
- this.isMethodSupported('createComputeContext', [ServerType.SasViya])
249
-
250
- return await this.sasViyaApiClient!.createComputeContext(
251
- contextName,
252
- launchContextName,
253
- sharedAccountId,
254
- autoExecLines,
255
- accessToken,
256
- authorisedUsers
257
- )
258
- }
259
-
260
- /**
261
- * Creates a launcher context on the given server.
262
- * @param contextName - the name of the context to be created.
263
- * @param description - the description of the context to be created.
264
- * @param launchType - launch type of the context to be created.
265
- * @param accessToken - an access token for an authorised user.
266
- */
267
- public async createLauncherContext(
268
- contextName: string,
269
- description: string,
270
- launchType: string,
271
- accessToken: string
272
- ) {
273
- this.isMethodSupported('createLauncherContext', [ServerType.SasViya])
274
-
275
- return await this.sasViyaApiClient!.createLauncherContext(
276
- contextName,
277
- description,
278
- launchType,
279
- accessToken
280
- )
281
- }
282
-
283
- /**
284
- * Updates a compute context on the given server.
285
- * @param contextName - the original name of the context to be deleted.
286
- * @param editedContext - an object with the properties to be updated.
287
- * @param accessToken - an access token for an authorised user.
288
- */
289
- public async editComputeContext(
290
- contextName: string,
291
- editedContext: EditContextInput,
292
- accessToken?: string
293
- ) {
294
- this.isMethodSupported('editComputeContext', [ServerType.SasViya])
295
-
296
- return await this.sasViyaApiClient!.editComputeContext(
297
- contextName,
298
- editedContext,
299
- accessToken
300
- )
301
- }
302
-
303
- /**
304
- * Deletes a compute context on the given server.
305
- * @param contextName - the name of the context to be deleted.
306
- * @param accessToken - an access token for an authorised user.
307
- */
308
- public async deleteComputeContext(contextName: string, accessToken?: string) {
309
- this.isMethodSupported('deleteComputeContext', [ServerType.SasViya])
310
-
311
- return await this.sasViyaApiClient!.deleteComputeContext(
312
- contextName,
313
- accessToken
314
- )
315
- }
316
-
317
- /**
318
- * Returns a JSON representation of a compute context.
319
- * @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
320
- * @param contextName - the name of the context to return.
321
- * @param accessToken - an access token for an authorised user.
322
- */
323
- public async getComputeContextByName(
324
- contextName: string,
325
- accessToken?: string
326
- ) {
327
- this.isMethodSupported('getComputeContextByName', [ServerType.SasViya])
328
-
329
- return await this.sasViyaApiClient!.getComputeContextByName(
330
- contextName,
331
- accessToken
332
- )
333
- }
334
-
335
- /**
336
- * Returns a JSON representation of a compute context.
337
- * @param contextId - an id of the context to return.
338
- * @param accessToken - an access token for an authorised user.
339
- */
340
- public async getComputeContextById(contextId: string, accessToken?: string) {
341
- this.isMethodSupported('getComputeContextById', [ServerType.SasViya])
342
-
343
- return await this.sasViyaApiClient!.getComputeContextById(
344
- contextId,
345
- accessToken
346
- )
347
- }
348
-
349
- public async createSession(contextName: string, accessToken: string) {
350
- this.isMethodSupported('createSession', [ServerType.SasViya])
351
-
352
- return await this.sasViyaApiClient!.createSession(contextName, accessToken)
353
- }
354
-
355
- /**
356
- * Creates a folder in the logical SAS folder tree
357
- * @param folderName - name of the folder to be created.
358
- * @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder.
359
- * @param parentFolderUri - the URI of the parent folder.
360
- * @param accessToken - the access token to authorizing the request.
361
- * @param sasApiClient - a client for interfacing with SAS API.
362
- * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted. Applicable for SAS VIYA only.
363
- */
364
- public async createFolder(
365
- folderName: string,
366
- parentFolderPath: string,
367
- parentFolderUri?: string,
368
- accessToken?: string,
369
- sasApiClient?: SASViyaApiClient,
370
- isForced?: boolean
371
- ) {
372
- if (sasApiClient) {
373
- return await sasApiClient.createFolder(
374
- folderName,
375
- parentFolderPath,
376
- parentFolderUri,
377
- accessToken,
378
- isForced
379
- )
380
- }
381
-
382
- return await this.sasViyaApiClient!.createFolder(
383
- folderName,
384
- parentFolderPath,
385
- parentFolderUri,
386
- accessToken,
387
- isForced
388
- )
389
- }
390
-
391
- /**
392
- * Creates a file in the logical SAS folder tree
393
- * @param fileName - name of the file to be created.
394
- * @param content - content of the file to be created.
395
- * @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder.
396
- * @param parentFolderUri - the URI of the parent folder.
397
- * @param accessToken - the access token to authorizing the request.
398
- * @param sasApiClient - a client for interfacing with SAS API.
399
- */
400
- public async createFile(
401
- fileName: string,
402
- content: Buffer,
403
- parentFolderPath: string,
404
- parentFolderUri?: string,
405
- accessToken?: string,
406
- sasApiClient?: SASViyaApiClient
407
- ) {
408
- if (sasApiClient)
409
- return await sasApiClient.createFile(
410
- fileName,
411
- content,
412
- parentFolderPath,
413
- parentFolderUri,
414
- accessToken
415
- )
416
- return await this.sasViyaApiClient!.createFile(
417
- fileName,
418
- content,
419
- parentFolderPath,
420
- parentFolderUri,
421
- accessToken
422
- )
423
- }
424
-
425
- /**
426
- * Fetches the file content for a file in the specified folder.
427
- *
428
- * @param folderPath - the full path to the folder containing the file. eg: /Public/folder1/folder2
429
- * @param fileName - the name of the file in the `folderPath`
430
- * @param accessToken - an access token for authorizing the request
431
- */
432
- public async getFileContent(
433
- folderPath: string,
434
- fileName: string,
435
- accessToken?: string
436
- ) {
437
- this.isMethodSupported('getFileContent', [ServerType.SasViya])
438
-
439
- return await this.sasViyaApiClient!.getFileContent(
440
- folderPath,
441
- fileName,
442
- accessToken
443
- )
444
- }
445
-
446
- /**
447
- * Updates the file content for a file in the specified folder.
448
- *
449
- * @param folderPath - the full path to the folder containing the file. eg: /Public/folder1/folder2
450
- * @param fileName - the name of the file in the `folderPath`
451
- * @param content - the new content to be written to the file
452
- * @param accessToken - an access token for authorizing the request
453
- */
454
- public async updateFileContent(
455
- folderPath: string,
456
- fileName: string,
457
- content: string,
458
- accessToken?: string
459
- ) {
460
- this.isMethodSupported('updateFileContent', [ServerType.SasViya])
461
-
462
- return await this.sasViyaApiClient!.updateFileContent(
463
- folderPath,
464
- fileName,
465
- content,
466
- accessToken
467
- )
468
- }
469
-
470
- /**
471
- * Fetches a folder from the SAS file system.
472
- * @param folderPath - path of the folder to be fetched.
473
- * @param accessToken - the access token to authorize the request.
474
- */
475
- public async getFolder(folderPath: string, accessToken?: string) {
476
- this.isMethodSupported('getFolder', [ServerType.SasViya])
477
- return await this.sasViyaApiClient!.getFolder(folderPath, accessToken)
478
- }
479
-
480
- /**
481
- * For performance (and in case of accidental error) the `deleteFolder` function does not actually delete the folder (and all its content and subfolder content). Instead the folder is simply moved to the recycle bin. Deletion time will be added to the folder name.
482
- * @param folderPath - the full path (eg `/Public/example/deleteThis`) of the folder to be deleted.
483
- * @param accessToken - an access token for authorizing the request.
484
- */
485
- public async deleteFolder(folderPath: string, accessToken: string) {
486
- this.isMethodSupported('deleteFolder', [ServerType.SasViya])
487
-
488
- return await this.sasViyaApiClient?.deleteFolder(folderPath, accessToken)
489
- }
490
-
491
- /**
492
- * Lists children folders for given Viya folder.
493
- * @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder listed. Providing URI instead of path will save one extra request.
494
- * @param accessToken - an access token for authorizing the request.
495
- * @param returnDetails - when set to true, the function will return an array of objects with member details, otherwise it will return an array of member names.
496
- */
497
- public async listFolder(
498
- sourceFolder: string,
499
- accessToken?: string,
500
- limit?: number,
501
- returnDetails = false
502
- ) {
503
- this.isMethodSupported('listFolder', [ServerType.SasViya])
504
-
505
- return await this.sasViyaApiClient?.listFolder(
506
- sourceFolder,
507
- accessToken,
508
- limit,
509
- {
510
- returnDetails
511
- }
512
- )
513
- }
514
-
515
- /**
516
- * Moves folder to a new location. The folder may be renamed at the same time.
517
- * @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.
518
- * @param targetParentFolder - the full path or URI of the _parent_ folder to which the `sourceFolder` will be moved (eg `/Public/newDestination`). To move a folder, a user has to have write permissions in targetParentFolder. Providing URI instead of path will save one extra request.
519
- * @param targetFolderName - the name of the "moved" folder. If left blank, the original folder name will be used (eg `myFolder` in `/Public/newDestination/myFolder` for the example above). Optional field.
520
- * @param accessToken - an access token for authorizing the request.
521
- */
522
- public async moveFolder(
523
- sourceFolder: string,
524
- targetParentFolder: string,
525
- targetFolderName: string,
526
- accessToken: string
527
- ) {
528
- this.isMethodSupported('moveFolder', [ServerType.SasViya])
529
-
530
- return await this.sasViyaApiClient?.moveFolder(
531
- sourceFolder,
532
- targetParentFolder,
533
- targetFolderName,
534
- accessToken
535
- )
536
- }
537
-
538
- public async createJobDefinition(
539
- jobName: string,
540
- code: string,
541
- parentFolderPath?: string,
542
- parentFolderUri?: string,
543
- accessToken?: string,
544
- sasApiClient?: SASViyaApiClient
545
- ) {
546
- this.isMethodSupported('createJobDefinition', [ServerType.SasViya])
547
-
548
- if (sasApiClient)
549
- return await sasApiClient!.createJobDefinition(
550
- jobName,
551
- code,
552
- parentFolderPath,
553
- parentFolderUri,
554
- accessToken
555
- )
556
- return await this.sasViyaApiClient!.createJobDefinition(
557
- jobName,
558
- code,
559
- parentFolderPath,
560
- parentFolderUri,
561
- accessToken
562
- )
563
- }
564
-
565
- public async getAuthCode(clientId: string) {
566
- this.isMethodSupported('getAuthCode', [ServerType.SasViya])
567
-
568
- return await this.sasViyaApiClient!.getAuthCode(clientId)
569
- }
570
-
571
- /**
572
- * Exchanges the auth code for an access token for the given client.
573
- * @param clientId - the client ID to authenticate with.
574
- * @param clientSecret - the client secret to authenticate with.
575
- * @param authCode - the auth code received from the server.
576
- */
577
- public async getAccessToken(
578
- clientId: string,
579
- clientSecret: string,
580
- authCode: string
581
- ): Promise<SasAuthResponse | SASjsAuthResponse> {
582
- this.isMethodSupported('getAccessToken', [
583
- ServerType.SasViya,
584
- ServerType.Sasjs
585
- ])
586
-
587
- if (this.sasjsConfig.serverType === ServerType.Sasjs)
588
- return await this.sasJSApiClient!.getAccessToken(clientId, authCode)
589
-
590
- return await this.sasViyaApiClient!.getAccessToken(
591
- clientId,
592
- clientSecret,
593
- authCode
594
- )
595
- }
596
-
597
- /**
598
- * Exchanges the refresh token for an access token for the given client.
599
- * @param clientId - the client ID to authenticate with.
600
- * @param clientSecret - the client secret to authenticate with.
601
- * @param refreshToken - the refresh token received from the server.
602
- */
603
- public async refreshTokens(
604
- clientId: string,
605
- clientSecret: string,
606
- refreshToken: string
607
- ): Promise<SasAuthResponse | SASjsAuthResponse> {
608
- this.isMethodSupported('refreshTokens', [
609
- ServerType.SasViya,
610
- ServerType.Sasjs
611
- ])
612
-
613
- if (this.sasjsConfig.serverType === ServerType.Sasjs)
614
- return await this.sasJSApiClient!.refreshTokens(refreshToken)
615
-
616
- return await this.sasViyaApiClient!.refreshTokens(
617
- clientId,
618
- clientSecret,
619
- refreshToken
620
- )
621
- }
622
-
623
- public async deleteClient(clientId: string, accessToken: string) {
624
- this.isMethodSupported('deleteClient', [ServerType.SasViya])
625
-
626
- return await this.sasViyaApiClient!.deleteClient(clientId, accessToken)
627
- }
628
-
629
- /**
630
- * Returns the current SASjs configuration.
631
- *
632
- */
633
- public getSasjsConfig() {
634
- return this.sasjsConfig
635
- }
636
-
637
- /**
638
- * Returns the username of the user currently logged in.
639
- *
640
- */
641
- public getUserName() {
642
- return this.authManager!.userName
643
- }
644
-
645
- /**
646
- * Sets the SASjs configuration.
647
- * @param config - SASjs configuration.
648
- */
649
- public async setSASjsConfig(config: SASjsConfig) {
650
- this.sasjsConfig = {
651
- ...this.sasjsConfig,
652
- ...config
653
- }
654
- this.setupConfiguration()
655
- }
656
-
657
- /**
658
- * Sets the debug state. Turning this on will enable additional logging in the adapter.
659
- * @param value - boolean indicating debug state (on/off).
660
- */
661
- public setDebugState(value: boolean) {
662
- this.sasjsConfig.debug = value
663
- if (this.sasViyaApiClient) {
664
- this.sasViyaApiClient.debug = value
665
- }
666
- }
667
-
668
- /**
669
- * Checks whether a session is active, or login is required.
670
- * @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
671
- */
672
- public async checkSession() {
673
- return this.authManager!.checkSession()
674
- }
675
-
676
- /**
677
- * Logs into the SAS server with the supplied credentials.
678
- * @param username - a string representing the username.
679
- * @param password - a string representing the password.
680
- * @param clientId - a string representing the client ID.
681
- */
682
- public async logIn(
683
- username?: string,
684
- password?: string,
685
- clientId?: string,
686
- options: LoginOptions = {}
687
- ): Promise<LoginResult> {
688
- if (this.sasjsConfig.loginMechanism === LoginMechanism.Default) {
689
- if (!username || !password)
690
- throw new Error(
691
- 'A username and password are required when using the default login mechanism.'
692
- )
693
-
694
- return this.authManager!.logIn(username, password)
695
- }
696
-
697
- if (typeof window === typeof undefined) {
698
- throw new Error(
699
- 'The redirected login mechanism is only available for use in the browser.'
700
- )
701
- }
702
-
703
- return this.authManager!.redirectedLogIn(options)
704
- }
705
-
706
- /**
707
- * Logs out of the configured SAS server.
708
- */
709
- public logOut() {
710
- return this.authManager!.logOut()
711
- }
712
-
713
- /**
714
- * Uploads a file to the given service.
715
- * @param sasJob - the path to the SAS program (ultimately resolves to
716
- * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
717
- * Process). Is prepended at runtime with the value of `appLoc`.
718
- * @param files - array of files to be uploaded, including File object and file name.
719
- * @param params - request URL parameters.
720
- * @param config - provide any changes to the config here, for instance to
721
- * enable/disable `debug`. Any change provided will override the global config,
722
- * for that particular function call.
723
- * @param loginRequiredCallback - a function that is called if the
724
- * user is not logged in (eg to display a login form). The request will be
725
- * resubmitted after successful login.
726
- */
727
- public async uploadFile(
728
- sasJob: string,
729
- files: UploadFile[],
730
- params: { [key: string]: any } | null,
731
- config: { [key: string]: any } = {},
732
- loginRequiredCallback?: () => any
733
- ) {
734
- config = {
735
- ...this.sasjsConfig,
736
- ...config
737
- }
738
- const data = { files, params }
739
-
740
- return await this.fileUploader!.execute(
741
- sasJob,
742
- data,
743
- config,
744
- loginRequiredCallback
745
- )
746
- }
747
-
748
- /**
749
- * Makes a request to program specified in `SASjob` (could be a Viya Job, a
750
- * SAS 9 Stored Process, or a SASjs Server Stored Program). The response
751
- * object will always contain table names in lowercase, and column names in
752
- * uppercase. Values are returned formatted by default, unformatted
753
- * values can be configured as an option in the `%webout` macro.
754
- *
755
- * @param sasJob - the path to the SAS program (ultimately resolves to
756
- * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
757
- * Process). Is prepended at runtime with the value of `appLoc`.
758
- * @param data - a JSON object containing one or more tables to be sent to
759
- * SAS. For an example of the table structure, see the project README. This
760
- * value can be `null` if no inputs are required.
761
- * @param config - provide any changes to the config here, for instance to
762
- * enable/disable `debug`. Any change provided will override the global config,
763
- * for that particular function call.
764
- * @param loginRequiredCallback - a function that is called if the
765
- * user is not logged in (eg to display a login form). The request will be
766
- * resubmitted after successful login.
767
- * When using a `loginRequiredCallback`, the call to the request will look, for example, like so:
768
- * `await request(sasJobPath, data, config, () => setIsLoggedIn(false))`
769
- * If you are not passing in any data and configuration, it will look like so:
770
- * `await request(sasJobPath, {}, {}, () => setIsLoggedIn(false))`
771
- * @param extraResponseAttributes - a array of predefined values that are used
772
- * to provide extra attributes (same names as those values) to be added in response
773
- * Supported values are declared in ExtraResponseAttributes type.
774
- */
775
- public async request(
776
- sasJob: string,
777
- data: { [key: string]: any } | null,
778
- config: { [key: string]: any } = {},
779
- loginRequiredCallback?: () => any,
780
- authConfig?: AuthConfig,
781
- extraResponseAttributes: ExtraResponseAttributes[] = []
782
- ) {
783
- config = {
784
- ...this.sasjsConfig,
785
- ...config
786
- }
787
-
788
- const validationResult = validateInput(data)
789
-
790
- // status is true if the data passes validation checks above
791
- if (validationResult.status) {
792
- if (config.serverType === ServerType.Sasjs) {
793
- return await this.sasjsJobExecutor!.execute(
794
- sasJob,
795
- data,
796
- config,
797
- loginRequiredCallback,
798
- authConfig,
799
- extraResponseAttributes
800
- )
801
- } else if (
802
- config.serverType === ServerType.SasViya &&
803
- config.useComputeApi !== undefined &&
804
- config.useComputeApi !== null
805
- ) {
806
- if (config.useComputeApi) {
807
- return await this.computeJobExecutor!.execute(
808
- sasJob,
809
- data,
810
- config,
811
- loginRequiredCallback,
812
- authConfig
813
- )
814
- } else {
815
- if (!config.contextName)
816
- config = {
817
- ...config,
818
- contextName: 'SAS Job Execution compute context'
819
- }
820
- return await this.jesJobExecutor!.execute(
821
- sasJob,
822
- data,
823
- config,
824
- loginRequiredCallback,
825
- authConfig,
826
- extraResponseAttributes
827
- )
828
- }
829
- } else if (
830
- config.serverType === ServerType.Sas9 &&
831
- config.username &&
832
- config.password
833
- ) {
834
- return await this.sas9JobExecutor!.execute(sasJob, data, config)
835
- } else {
836
- return await this.webJobExecutor!.execute(
837
- sasJob,
838
- data,
839
- config,
840
- loginRequiredCallback,
841
- authConfig,
842
- extraResponseAttributes
843
- )
844
- }
845
- } else {
846
- return Promise.reject(new ErrorResponse(validationResult.msg))
847
- }
848
- }
849
-
850
- /**
851
- * Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
852
- * @param serviceJson - the JSON specifying the folders and services to be created.
853
- * @param appLoc - the base folder in which to create the new folders and
854
- * services. If not provided, is taken from SASjsConfig.
855
- * @param serverUrl - the server on which to deploy the folders and services.
856
- * If not provided, is taken from SASjsConfig.
857
- * @param accessToken - an optional access token to be passed in when
858
- * using this function from the command line.
859
- * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted.
860
- */
861
- public async deployServicePack(
862
- serviceJson: any,
863
- appLoc?: string,
864
- serverUrl?: string,
865
- accessToken?: string,
866
- isForced = false
867
- ) {
868
- this.isMethodSupported('deployServicePack', [ServerType.SasViya])
869
-
870
- let sasApiClient: any = null
871
-
872
- if (serverUrl || appLoc) {
873
- if (!serverUrl) serverUrl = this.sasjsConfig.serverUrl
874
- if (!appLoc) appLoc = this.sasjsConfig.appLoc
875
-
876
- if (this.sasjsConfig.serverType === ServerType.SasViya) {
877
- sasApiClient = new SASViyaApiClient(
878
- serverUrl,
879
- appLoc,
880
- this.sasjsConfig.contextName,
881
- this.requestClient!
882
- )
883
- sasApiClient.debug = this.sasjsConfig.debug
884
- } else if (this.sasjsConfig.serverType === ServerType.Sas9) {
885
- sasApiClient = new SAS9ApiClient(
886
- serverUrl,
887
- this.jobsPath,
888
- this.sasjsConfig.httpsAgentOptions
889
- )
890
- }
891
- } else {
892
- let sasClientConfig: any = null
893
-
894
- if (this.sasjsConfig.serverType === ServerType.SasViya) {
895
- sasClientConfig = this.sasViyaApiClient!.getConfig()
896
- } else if (this.sasjsConfig.serverType === ServerType.Sas9) {
897
- sasClientConfig = this.sas9ApiClient!.getConfig()
898
- }
899
-
900
- serverUrl = sasClientConfig.serverUrl
901
- appLoc = sasClientConfig.rootFolderName as string
902
- }
903
-
904
- // members of type 'folder' should be processed first
905
- if (serviceJson.members[0].members) {
906
- serviceJson.members[0].members.sort((member: { type: string }) =>
907
- member.type === 'folder' ? -1 : 1
908
- )
909
- }
910
-
911
- const members = serviceJson.members
912
-
913
- await this.createFoldersAndServices(
914
- appLoc,
915
- members,
916
- accessToken,
917
- sasApiClient,
918
- isForced
919
- )
920
- }
921
-
922
- /**
923
- * Kicks off execution of the given job via the compute API.
924
- * @returns an object representing the compute session created for the given job.
925
- * @param sasJob - the path to the SAS program (ultimately resolves to
926
- * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
927
- * Process). Is prepended at runtime with the value of `appLoc`.
928
- * @param data - a JSON object containing one or more tables to be sent to
929
- * SAS. Can be `null` if no inputs required.
930
- * @param config - provide any changes to the config here, for instance to
931
- * enable/disable `debug`. Any change provided will override the global config,
932
- * for that particular function call.
933
- * @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
934
- * The access token is not required when the user is authenticated via the browser.
935
- * @param waitForResult - a boolean that indicates whether the function needs to wait for execution to complete.
936
- * @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { maxPollCount: 24 * 60 * 60, pollInterval: 1000 }. More information available at src/api/viya/pollJobState.ts.
937
- * @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
938
- * @param variables - an object that represents macro variables.
939
- * @param verboseMode - boolean or a string equal to 'bleached' to enable verbose mode (log every HTTP response).
940
- * @param onTokensRefreshed - (optional, SAS Viya only) callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
941
- */
942
- public async startComputeJob(
943
- sasJob: string,
944
- data: any,
945
- config: any = {},
946
- authConfig?: AuthConfig,
947
- waitForResult?: boolean,
948
- pollOptions?: PollOptions,
949
- printPid = false,
950
- variables?: MacroVar,
951
- verboseMode?: VerboseMode,
952
- onTokensRefreshed?: OnTokensRefreshed
953
- ) {
954
- config = {
955
- ...this.sasjsConfig,
956
- ...config
957
- }
958
-
959
- this.isMethodSupported('startComputeJob', [ServerType.SasViya])
960
- if (!config.contextName) {
961
- throw new Error(
962
- 'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
963
- )
964
- }
965
-
966
- if (verboseMode) {
967
- this.requestClient?.setVerboseMode(verboseMode)
968
- this.requestClient?.enableVerboseMode()
969
- } else if (verboseMode === false) this.requestClient?.disableVerboseMode()
970
-
971
- return this.sasViyaApiClient?.executeComputeJob(
972
- sasJob,
973
- config.contextName,
974
- config.debug,
975
- data,
976
- authConfig,
977
- !!waitForResult,
978
- false,
979
- pollOptions,
980
- printPid,
981
- variables,
982
- onTokensRefreshed
983
- )
984
- }
985
-
986
- private resendWaitingRequests = async () => {
987
- await this.webJobExecutor?.resendWaitingRequests()
988
- await this.computeJobExecutor?.resendWaitingRequests()
989
- await this.jesJobExecutor?.resendWaitingRequests()
990
- await this.fileUploader?.resendWaitingRequests()
991
- await this.sasjsJobExecutor?.resendWaitingRequests()
992
- }
993
-
994
- /**
995
- * Fetches content of the log file
996
- * @param logUrl - url of the log file.
997
- * @param accessToken - an access token for an authorised user.
998
- */
999
- public async fetchLogFileContent(logUrl: string, accessToken?: string) {
1000
- return await this.requestClient!.get(logUrl, accessToken).then((res) => {
1001
- if (!res)
1002
- return Promise.reject(
1003
- new ErrorResponse(
1004
- 'Error while fetching log. Response was not provided.'
1005
- )
1006
- )
1007
-
1008
- try {
1009
- const result = JSON.stringify(res.result)
1010
-
1011
- return result
1012
- } catch (err) {
1013
- return Promise.reject(
1014
- new ErrorResponse(
1015
- 'Error while fetching log. The result is not valid.',
1016
- err
1017
- )
1018
- )
1019
- }
1020
- })
1021
- }
1022
-
1023
- /**
1024
- * this method returns an array of SASjsRequest
1025
- * @returns SASjsRequest[]
1026
- */
1027
- public getSasRequests() {
1028
- const requests = [...this.requestClient!.getRequests()]
1029
- const sortedRequests = requests.sort(compareTimestamps)
1030
- return sortedRequests
1031
- }
1032
-
1033
- public clearSasRequests() {
1034
- this.requestClient!.clearRequests()
1035
- }
1036
-
1037
- private setupConfiguration() {
1038
- if (
1039
- this.sasjsConfig.serverUrl === undefined ||
1040
- this.sasjsConfig.serverUrl === ''
1041
- ) {
1042
- if (typeof location !== 'undefined') {
1043
- let url = `${location.protocol}//${location.hostname}`
1044
-
1045
- if (location.port) url = `${url}:${location.port}`
1046
-
1047
- this.sasjsConfig.serverUrl = url
1048
- } else {
1049
- this.sasjsConfig.serverUrl = ''
1050
- }
1051
- }
1052
-
1053
- if (this.sasjsConfig.serverUrl.slice(-1) === '/') {
1054
- this.sasjsConfig.serverUrl = this.sasjsConfig.serverUrl.slice(0, -1)
1055
- }
1056
-
1057
- if (!this.requestClient) {
1058
- const RequestClientClass =
1059
- this.sasjsConfig.serverType === ServerType.Sasjs
1060
- ? SasjsRequestClient
1061
- : RequestClient
1062
- this.requestClient = new RequestClientClass(
1063
- this.sasjsConfig.serverUrl,
1064
- this.sasjsConfig.httpsAgentOptions,
1065
- this.sasjsConfig.requestHistoryLimit,
1066
- this.sasjsConfig.verbose
1067
- )
1068
- } else {
1069
- this.requestClient.setConfig(
1070
- this.sasjsConfig.serverUrl,
1071
- this.sasjsConfig.httpsAgentOptions
1072
- )
1073
- }
1074
-
1075
- this.jobsPath =
1076
- this.sasjsConfig.serverType === ServerType.SasViya
1077
- ? this.sasjsConfig.pathSASViya
1078
- : this.sasjsConfig.serverType === ServerType.Sas9
1079
- ? this.sasjsConfig.pathSAS9
1080
- : this.sasjsConfig.pathSASJS
1081
-
1082
- this.authManager = new AuthManager(
1083
- this.sasjsConfig.serverUrl,
1084
- this.sasjsConfig.serverType!,
1085
- this.requestClient,
1086
- this.resendWaitingRequests
1087
- )
1088
-
1089
- if (this.sasjsConfig.serverType === ServerType.SasViya) {
1090
- if (this.sasViyaApiClient) {
1091
- this.sasViyaApiClient!.setConfig(
1092
- this.sasjsConfig.serverUrl,
1093
- this.sasjsConfig.appLoc
1094
- )
1095
- } else {
1096
- this.sasViyaApiClient = new SASViyaApiClient(
1097
- this.sasjsConfig.serverUrl,
1098
- this.sasjsConfig.appLoc,
1099
- this.sasjsConfig.contextName,
1100
- this.requestClient
1101
- )
1102
- }
1103
-
1104
- this.sasViyaApiClient.debug = this.sasjsConfig.debug
1105
- }
1106
-
1107
- if (this.sasjsConfig.serverType === ServerType.Sas9) {
1108
- if (this.sas9ApiClient) {
1109
- this.sas9ApiClient!.setConfig(this.sasjsConfig.serverUrl)
1110
- } else {
1111
- this.sas9ApiClient = new SAS9ApiClient(
1112
- this.sasjsConfig.serverUrl,
1113
- this.jobsPath,
1114
- this.sasjsConfig.httpsAgentOptions
1115
- )
1116
- }
1117
- }
1118
-
1119
- if (this.sasjsConfig.serverType === ServerType.Sasjs) {
1120
- if (!this.sasJSApiClient) {
1121
- this.sasJSApiClient = new SASjsApiClient(this.requestClient)
1122
- }
1123
- }
1124
-
1125
- this.fileUploader = new FileUploader(
1126
- this.sasjsConfig.serverUrl,
1127
- this.sasjsConfig.serverType!,
1128
- this.jobsPath,
1129
- this.requestClient
1130
- )
1131
-
1132
- this.webJobExecutor = new WebJobExecutor(
1133
- this.sasjsConfig.serverUrl,
1134
- this.sasjsConfig.serverType!,
1135
- this.jobsPath,
1136
- this.requestClient,
1137
- this.sasViyaApiClient!
1138
- )
1139
-
1140
- this.sasjsJobExecutor = new SasjsJobExecutor(
1141
- this.sasjsConfig.serverUrl,
1142
- this.jobsPath,
1143
- this.requestClient
1144
- )
1145
-
1146
- this.sas9JobExecutor = new Sas9JobExecutor(
1147
- this.sasjsConfig.serverUrl,
1148
- this.sasjsConfig.serverType!,
1149
- this.jobsPath,
1150
- this.requestClient,
1151
- this.sasjsConfig.httpsAgentOptions
1152
- )
1153
-
1154
- this.computeJobExecutor = new ComputeJobExecutor(
1155
- this.sasjsConfig.serverUrl,
1156
- this.sasViyaApiClient!
1157
- )
1158
-
1159
- this.jesJobExecutor = new JesJobExecutor(
1160
- this.sasjsConfig.serverUrl,
1161
- this.sasViyaApiClient!
1162
- )
1163
- }
1164
-
1165
- private async createFoldersAndServices(
1166
- parentFolder: string,
1167
- membersJson: any[],
1168
- accessToken?: string,
1169
- sasApiClient?: SASViyaApiClient,
1170
- isForced?: boolean
1171
- ) {
1172
- await asyncForEach(membersJson, async (member: any) => {
1173
- switch (member.type) {
1174
- case 'folder':
1175
- await this.createFolder(
1176
- member.name,
1177
- parentFolder,
1178
- undefined,
1179
- accessToken,
1180
- sasApiClient,
1181
- isForced
1182
- )
1183
- break
1184
- case 'file':
1185
- await this.createFile(
1186
- member.name,
1187
- member.code,
1188
- parentFolder,
1189
- undefined,
1190
- accessToken,
1191
- sasApiClient
1192
- )
1193
- break
1194
- case 'service':
1195
- await this.createJobDefinition(
1196
- member.name,
1197
- member.code,
1198
- parentFolder,
1199
- undefined,
1200
- accessToken,
1201
- sasApiClient
1202
- )
1203
- break
1204
- default:
1205
- throw new Error(`Unidentified member '${member.name}' provided.`)
1206
- }
1207
- if (member.type === 'folder' && member.members && member.members.length)
1208
- await this.createFoldersAndServices(
1209
- `${parentFolder}/${member.name}`,
1210
- member.members,
1211
- accessToken,
1212
- sasApiClient,
1213
- isForced
1214
- )
1215
- })
1216
- }
1217
-
1218
- private isMethodSupported(method: string, serverTypes: ServerType[]) {
1219
- if (
1220
- !this.sasjsConfig.serverType ||
1221
- !serverTypes.includes(this.sasjsConfig.serverType)
1222
- ) {
1223
- throw new Error(
1224
- `Method '${method}' is only supported on ${serverTypes.join(
1225
- ', '
1226
- )} servers.`
1227
- )
1228
- }
1229
- }
1230
-
1231
- /**
1232
- * Enables verbose mode that will log a summary of every HTTP response.
1233
- * @param successCallBack - function that should be triggered on every HTTP response with the status 2**.
1234
- * @param errorCallBack - function that should be triggered on every HTTP response with the status different from 2**.
1235
- */
1236
- public enableVerboseMode(
1237
- successCallBack?: (response: AxiosResponse) => AxiosResponse,
1238
- errorCallBack?: (response: AxiosError) => AxiosError
1239
- ) {
1240
- this.requestClient?.enableVerboseMode(successCallBack, errorCallBack)
1241
- }
1242
-
1243
- /**
1244
- * Turns off verbose mode to log every HTTP response.
1245
- */
1246
- public disableVerboseMode() {
1247
- this.requestClient?.disableVerboseMode()
1248
- }
1249
-
1250
- /**
1251
- * Sets verbose mode.
1252
- * @param verboseMode - value of the verbose mode, can be true, false or bleached(without extra colors).
1253
- */
1254
- public setVerboseMode = (verboseMode: VerboseMode) => {
1255
- this.requestClient?.setVerboseMode(verboseMode)
1256
- }
1257
-
1258
- /**
1259
- * Create a tables class containing one or more tables to be sent to
1260
- * SAS.
1261
- * @param table - initial table data
1262
- * @param macroName - macro name
1263
- * @returns Tables class
1264
- */
1265
- Tables(table: Record<string, any>, macroName: string) {
1266
- return new Tables(table, macroName)
1267
- }
1268
- }