@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/SASjs.js ADDED
@@ -0,0 +1,794 @@
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 SASViyaApiClient_1 = require("./SASViyaApiClient");
15
+ const SAS9ApiClient_1 = require("./SAS9ApiClient");
16
+ const SASjsApiClient_1 = require("./SASjsApiClient");
17
+ const auth_1 = require("./auth");
18
+ const types_2 = require("@sasjs/utils/types");
19
+ const RequestClient_1 = require("./request/RequestClient");
20
+ const SasjsRequestClient_1 = require("./request/SasjsRequestClient");
21
+ const job_execution_1 = require("./job-execution");
22
+ const defaultConfig = {
23
+ serverUrl: '',
24
+ pathSASJS: '/SASjsApi/stp/execute',
25
+ pathSAS9: '/SASStoredProcess/do',
26
+ pathSASViya: '/SASJobExecution',
27
+ appLoc: '/Public/seedapp',
28
+ serverType: types_2.ServerType.SasViya,
29
+ debug: false,
30
+ contextName: 'SAS Job Execution compute context',
31
+ useComputeApi: null,
32
+ loginMechanism: types_1.LoginMechanism.Default
33
+ };
34
+ /**
35
+ * SASjs is a JavaScript adapter for SAS.
36
+ *
37
+ */
38
+ class SASjs {
39
+ constructor(config) {
40
+ this.sasjsConfig = new types_1.SASjsConfig();
41
+ this.jobsPath = '';
42
+ this.sasViyaApiClient = null;
43
+ this.sas9ApiClient = null;
44
+ this.sasJSApiClient = null;
45
+ this.fileUploader = null;
46
+ this.authManager = null;
47
+ this.requestClient = null;
48
+ this.webJobExecutor = null;
49
+ this.sasjsJobExecutor = null;
50
+ this.computeJobExecutor = null;
51
+ this.jesJobExecutor = null;
52
+ this.sas9JobExecutor = null;
53
+ this.resendWaitingRequests = () => __awaiter(this, void 0, void 0, function* () {
54
+ var _a, _b, _c, _d, _e;
55
+ yield ((_a = this.webJobExecutor) === null || _a === void 0 ? void 0 : _a.resendWaitingRequests());
56
+ yield ((_b = this.computeJobExecutor) === null || _b === void 0 ? void 0 : _b.resendWaitingRequests());
57
+ yield ((_c = this.jesJobExecutor) === null || _c === void 0 ? void 0 : _c.resendWaitingRequests());
58
+ yield ((_d = this.fileUploader) === null || _d === void 0 ? void 0 : _d.resendWaitingRequests());
59
+ yield ((_e = this.sasjsJobExecutor) === null || _e === void 0 ? void 0 : _e.resendWaitingRequests());
60
+ });
61
+ /**
62
+ * Sets verbose mode.
63
+ * @param verboseMode - value of the verbose mode, can be true, false or bleached(without extra colors).
64
+ */
65
+ this.setVerboseMode = (verboseMode) => {
66
+ var _a;
67
+ (_a = this.requestClient) === null || _a === void 0 ? void 0 : _a.setVerboseMode(verboseMode);
68
+ };
69
+ this.sasjsConfig = Object.assign(Object.assign({}, defaultConfig), config);
70
+ this.setupConfiguration();
71
+ }
72
+ getCsrfToken(type = 'general') {
73
+ var _a;
74
+ return (_a = this.requestClient) === null || _a === void 0 ? void 0 : _a.getCsrfToken(type);
75
+ }
76
+ /**
77
+ * Executes code on a SAS server.
78
+ * @param linesOfCode - lines of code to run.
79
+ * @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.
80
+ * @param contextName - (required for server type sas viya) context name on which code will be run on the server.
81
+ * @param runTime - (required for server type sasjs) a string to represent runTime for code execution.
82
+ * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
83
+ * @param authConfigSas9 - (required for server type sas9) a valid username and password that are authorised to execute scripts.
84
+ * @param debug - (optional) if true, global debug config will be overriden
85
+ * @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.
86
+ */
87
+ executeScript({ linesOfCode, fileName, contextName, runTime, authConfig, authConfigSas9, debug, onTokensRefreshed }) {
88
+ var _a, _b;
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ this.isMethodSupported('executeScript', [
91
+ types_2.ServerType.Sas9,
92
+ types_2.ServerType.Sasjs,
93
+ types_2.ServerType.SasViya
94
+ ]);
95
+ if (this.sasjsConfig.serverType === types_2.ServerType.Sas9) {
96
+ if (!authConfigSas9)
97
+ throw new Error('Auth config for sas9 is not provided');
98
+ return yield ((_a = this.sas9ApiClient) === null || _a === void 0 ? void 0 : _a.executeScript(linesOfCode, authConfigSas9.userName, authConfigSas9.password));
99
+ }
100
+ if (this.sasjsConfig.serverType === types_2.ServerType.Sasjs) {
101
+ return yield ((_b = this.sasJSApiClient) === null || _b === void 0 ? void 0 : _b.executeScript(linesOfCode.join('\n'), runTime, authConfig));
102
+ }
103
+ if (this.sasjsConfig.serverType === types_2.ServerType.SasViya) {
104
+ contextName = contextName || this.sasjsConfig.contextName;
105
+ if (!contextName) {
106
+ throw new Error('Context name is undefined. Please set a `contextName` in your SASjs or override config.');
107
+ }
108
+ if (!fileName) {
109
+ throw new Error('File name is required in case of SAS VIYA. Please provide a `fileName`.');
110
+ }
111
+ return yield this.sasViyaApiClient.executeScript(fileName, linesOfCode, contextName, authConfig, null, debug ? debug : this.sasjsConfig.debug, false, true, undefined, false, undefined, onTokensRefreshed);
112
+ }
113
+ });
114
+ }
115
+ /**
116
+ * Executes job on SASJS server.
117
+ * @param query - an object containing job path and debug level.
118
+ * @param appLoc - an application path.
119
+ * @param authConfig - an object for authentication.
120
+ * @returns a promise that resolves into job execution result and log.
121
+ */
122
+ executeJob(query, appLoc, authConfig) {
123
+ var _a;
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ this.isMethodSupported('executeScript', [types_2.ServerType.Sasjs]);
126
+ return yield ((_a = this.sasJSApiClient) === null || _a === void 0 ? void 0 : _a.executeJob(query, appLoc, authConfig));
127
+ });
128
+ }
129
+ /**
130
+ * Gets compute contexts.
131
+ * @param accessToken - an access token for an authorised user.
132
+ */
133
+ getComputeContexts(accessToken) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ this.isMethodSupported('getComputeContexts', [types_2.ServerType.SasViya]);
136
+ return yield this.sasViyaApiClient.getComputeContexts(accessToken);
137
+ });
138
+ }
139
+ /**
140
+ * Gets launcher contexts.
141
+ * @param accessToken - an access token for an authorised user.
142
+ */
143
+ getLauncherContexts(accessToken) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ this.isMethodSupported('getLauncherContexts', [types_2.ServerType.SasViya]);
146
+ return yield this.sasViyaApiClient.getLauncherContexts(accessToken);
147
+ });
148
+ }
149
+ /**
150
+ * Gets default(system) launcher contexts.
151
+ */
152
+ getDefaultComputeContexts() {
153
+ this.isMethodSupported('getDefaultComputeContexts', [types_2.ServerType.SasViya]);
154
+ return this.sasViyaApiClient.getDefaultComputeContexts();
155
+ }
156
+ /**
157
+ * Gets executable compute contexts.
158
+ * @param authConfig - an access token, refresh token, client and secret for an authorised user.
159
+ */
160
+ getExecutableContexts(authConfig) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ this.isMethodSupported('getExecutableContexts', [types_2.ServerType.SasViya]);
163
+ return yield this.sasViyaApiClient.getExecutableContexts(authConfig);
164
+ });
165
+ }
166
+ /**
167
+ * Creates a compute context on the given server.
168
+ * @param contextName - the name of the context to be created.
169
+ * @param launchContextName - the name of the launcher context used by the compute service.
170
+ * @param sharedAccountId - the ID of the account to run the servers for this context as.
171
+ * @param autoExecLines - the lines of code to execute during session initialization.
172
+ * @param accessToken - an access token for an authorised user.
173
+ * @param authorisedUsers - an optional list of authorised user IDs.
174
+ */
175
+ createComputeContext(contextName, launchContextName, sharedAccountId, autoExecLines, accessToken, authorisedUsers) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ this.isMethodSupported('createComputeContext', [types_2.ServerType.SasViya]);
178
+ return yield this.sasViyaApiClient.createComputeContext(contextName, launchContextName, sharedAccountId, autoExecLines, accessToken, authorisedUsers);
179
+ });
180
+ }
181
+ /**
182
+ * Creates a launcher context on the given server.
183
+ * @param contextName - the name of the context to be created.
184
+ * @param description - the description of the context to be created.
185
+ * @param launchType - launch type of the context to be created.
186
+ * @param accessToken - an access token for an authorised user.
187
+ */
188
+ createLauncherContext(contextName, description, launchType, accessToken) {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ this.isMethodSupported('createLauncherContext', [types_2.ServerType.SasViya]);
191
+ return yield this.sasViyaApiClient.createLauncherContext(contextName, description, launchType, accessToken);
192
+ });
193
+ }
194
+ /**
195
+ * Updates a compute context on the given server.
196
+ * @param contextName - the original name of the context to be deleted.
197
+ * @param editedContext - an object with the properties to be updated.
198
+ * @param accessToken - an access token for an authorised user.
199
+ */
200
+ editComputeContext(contextName, editedContext, accessToken) {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ this.isMethodSupported('editComputeContext', [types_2.ServerType.SasViya]);
203
+ return yield this.sasViyaApiClient.editComputeContext(contextName, editedContext, accessToken);
204
+ });
205
+ }
206
+ /**
207
+ * Deletes a compute context on the given server.
208
+ * @param contextName - the name of the context to be deleted.
209
+ * @param accessToken - an access token for an authorised user.
210
+ */
211
+ deleteComputeContext(contextName, accessToken) {
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ this.isMethodSupported('deleteComputeContext', [types_2.ServerType.SasViya]);
214
+ return yield this.sasViyaApiClient.deleteComputeContext(contextName, accessToken);
215
+ });
216
+ }
217
+ /**
218
+ * Returns a JSON representation of a compute context.
219
+ * @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
220
+ * @param contextName - the name of the context to return.
221
+ * @param accessToken - an access token for an authorised user.
222
+ */
223
+ getComputeContextByName(contextName, accessToken) {
224
+ return __awaiter(this, void 0, void 0, function* () {
225
+ this.isMethodSupported('getComputeContextByName', [types_2.ServerType.SasViya]);
226
+ return yield this.sasViyaApiClient.getComputeContextByName(contextName, accessToken);
227
+ });
228
+ }
229
+ /**
230
+ * Returns a JSON representation of a compute context.
231
+ * @param contextId - an id of the context to return.
232
+ * @param accessToken - an access token for an authorised user.
233
+ */
234
+ getComputeContextById(contextId, accessToken) {
235
+ return __awaiter(this, void 0, void 0, function* () {
236
+ this.isMethodSupported('getComputeContextById', [types_2.ServerType.SasViya]);
237
+ return yield this.sasViyaApiClient.getComputeContextById(contextId, accessToken);
238
+ });
239
+ }
240
+ createSession(contextName, accessToken) {
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ this.isMethodSupported('createSession', [types_2.ServerType.SasViya]);
243
+ return yield this.sasViyaApiClient.createSession(contextName, accessToken);
244
+ });
245
+ }
246
+ /**
247
+ * Creates a folder in the logical SAS folder tree
248
+ * @param folderName - name of the folder to be created.
249
+ * @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder.
250
+ * @param parentFolderUri - the URI of the parent folder.
251
+ * @param accessToken - the access token to authorizing the request.
252
+ * @param sasApiClient - a client for interfacing with SAS API.
253
+ * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted. Applicable for SAS VIYA only.
254
+ */
255
+ createFolder(folderName, parentFolderPath, parentFolderUri, accessToken, sasApiClient, isForced) {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ if (sasApiClient) {
258
+ return yield sasApiClient.createFolder(folderName, parentFolderPath, parentFolderUri, accessToken, isForced);
259
+ }
260
+ return yield this.sasViyaApiClient.createFolder(folderName, parentFolderPath, parentFolderUri, accessToken, isForced);
261
+ });
262
+ }
263
+ /**
264
+ * Creates a file in the logical SAS folder tree
265
+ * @param fileName - name of the file to be created.
266
+ * @param content - content of the file to be created.
267
+ * @param parentFolderPath - the full path (eg `/Public/example/myFolder`) of the parent folder.
268
+ * @param parentFolderUri - the URI of the parent folder.
269
+ * @param accessToken - the access token to authorizing the request.
270
+ * @param sasApiClient - a client for interfacing with SAS API.
271
+ */
272
+ createFile(fileName, content, parentFolderPath, parentFolderUri, accessToken, sasApiClient) {
273
+ return __awaiter(this, void 0, void 0, function* () {
274
+ if (sasApiClient)
275
+ return yield sasApiClient.createFile(fileName, content, parentFolderPath, parentFolderUri, accessToken);
276
+ return yield this.sasViyaApiClient.createFile(fileName, content, parentFolderPath, parentFolderUri, accessToken);
277
+ });
278
+ }
279
+ /**
280
+ * Fetches the file content for a file in the specified folder.
281
+ *
282
+ * @param folderPath - the full path to the folder containing the file. eg: /Public/folder1/folder2
283
+ * @param fileName - the name of the file in the `folderPath`
284
+ * @param accessToken - an access token for authorizing the request
285
+ */
286
+ getFileContent(folderPath, fileName, accessToken) {
287
+ return __awaiter(this, void 0, void 0, function* () {
288
+ this.isMethodSupported('getFileContent', [types_2.ServerType.SasViya]);
289
+ return yield this.sasViyaApiClient.getFileContent(folderPath, fileName, accessToken);
290
+ });
291
+ }
292
+ /**
293
+ * Updates the file content for a file in the specified folder.
294
+ *
295
+ * @param folderPath - the full path to the folder containing the file. eg: /Public/folder1/folder2
296
+ * @param fileName - the name of the file in the `folderPath`
297
+ * @param content - the new content to be written to the file
298
+ * @param accessToken - an access token for authorizing the request
299
+ */
300
+ updateFileContent(folderPath, fileName, content, accessToken) {
301
+ return __awaiter(this, void 0, void 0, function* () {
302
+ this.isMethodSupported('updateFileContent', [types_2.ServerType.SasViya]);
303
+ return yield this.sasViyaApiClient.updateFileContent(folderPath, fileName, content, accessToken);
304
+ });
305
+ }
306
+ /**
307
+ * Fetches a folder from the SAS file system.
308
+ * @param folderPath - path of the folder to be fetched.
309
+ * @param accessToken - the access token to authorize the request.
310
+ */
311
+ getFolder(folderPath, accessToken) {
312
+ return __awaiter(this, void 0, void 0, function* () {
313
+ this.isMethodSupported('getFolder', [types_2.ServerType.SasViya]);
314
+ return yield this.sasViyaApiClient.getFolder(folderPath, accessToken);
315
+ });
316
+ }
317
+ /**
318
+ * 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.
319
+ * @param folderPath - the full path (eg `/Public/example/deleteThis`) of the folder to be deleted.
320
+ * @param accessToken - an access token for authorizing the request.
321
+ */
322
+ deleteFolder(folderPath, accessToken) {
323
+ var _a;
324
+ return __awaiter(this, void 0, void 0, function* () {
325
+ this.isMethodSupported('deleteFolder', [types_2.ServerType.SasViya]);
326
+ return yield ((_a = this.sasViyaApiClient) === null || _a === void 0 ? void 0 : _a.deleteFolder(folderPath, accessToken));
327
+ });
328
+ }
329
+ /**
330
+ * Lists children folders for given Viya folder.
331
+ * @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.
332
+ * @param accessToken - an access token for authorizing the request.
333
+ * @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.
334
+ */
335
+ listFolder(sourceFolder, accessToken, limit, returnDetails = false) {
336
+ var _a;
337
+ return __awaiter(this, void 0, void 0, function* () {
338
+ this.isMethodSupported('listFolder', [types_2.ServerType.SasViya]);
339
+ return yield ((_a = this.sasViyaApiClient) === null || _a === void 0 ? void 0 : _a.listFolder(sourceFolder, accessToken, limit, {
340
+ returnDetails
341
+ }));
342
+ });
343
+ }
344
+ /**
345
+ * Moves folder to a new location. The folder may be renamed at the same time.
346
+ * @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.
347
+ * @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.
348
+ * @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.
349
+ * @param accessToken - an access token for authorizing the request.
350
+ */
351
+ moveFolder(sourceFolder, targetParentFolder, targetFolderName, accessToken) {
352
+ var _a;
353
+ return __awaiter(this, void 0, void 0, function* () {
354
+ this.isMethodSupported('moveFolder', [types_2.ServerType.SasViya]);
355
+ return yield ((_a = this.sasViyaApiClient) === null || _a === void 0 ? void 0 : _a.moveFolder(sourceFolder, targetParentFolder, targetFolderName, accessToken));
356
+ });
357
+ }
358
+ createJobDefinition(jobName, code, parentFolderPath, parentFolderUri, accessToken, sasApiClient) {
359
+ return __awaiter(this, void 0, void 0, function* () {
360
+ this.isMethodSupported('createJobDefinition', [types_2.ServerType.SasViya]);
361
+ if (sasApiClient)
362
+ return yield sasApiClient.createJobDefinition(jobName, code, parentFolderPath, parentFolderUri, accessToken);
363
+ return yield this.sasViyaApiClient.createJobDefinition(jobName, code, parentFolderPath, parentFolderUri, accessToken);
364
+ });
365
+ }
366
+ getAuthCode(clientId) {
367
+ return __awaiter(this, void 0, void 0, function* () {
368
+ this.isMethodSupported('getAuthCode', [types_2.ServerType.SasViya]);
369
+ return yield this.sasViyaApiClient.getAuthCode(clientId);
370
+ });
371
+ }
372
+ /**
373
+ * Exchanges the auth code for an access token for the given client.
374
+ * @param clientId - the client ID to authenticate with.
375
+ * @param clientSecret - the client secret to authenticate with.
376
+ * @param authCode - the auth code received from the server.
377
+ */
378
+ getAccessToken(clientId, clientSecret, authCode) {
379
+ return __awaiter(this, void 0, void 0, function* () {
380
+ this.isMethodSupported('getAccessToken', [
381
+ types_2.ServerType.SasViya,
382
+ types_2.ServerType.Sasjs
383
+ ]);
384
+ if (this.sasjsConfig.serverType === types_2.ServerType.Sasjs)
385
+ return yield this.sasJSApiClient.getAccessToken(clientId, authCode);
386
+ return yield this.sasViyaApiClient.getAccessToken(clientId, clientSecret, authCode);
387
+ });
388
+ }
389
+ /**
390
+ * Exchanges the refresh token for an access token for the given client.
391
+ * @param clientId - the client ID to authenticate with.
392
+ * @param clientSecret - the client secret to authenticate with.
393
+ * @param refreshToken - the refresh token received from the server.
394
+ */
395
+ refreshTokens(clientId, clientSecret, refreshToken) {
396
+ return __awaiter(this, void 0, void 0, function* () {
397
+ this.isMethodSupported('refreshTokens', [
398
+ types_2.ServerType.SasViya,
399
+ types_2.ServerType.Sasjs
400
+ ]);
401
+ if (this.sasjsConfig.serverType === types_2.ServerType.Sasjs)
402
+ return yield this.sasJSApiClient.refreshTokens(refreshToken);
403
+ return yield this.sasViyaApiClient.refreshTokens(clientId, clientSecret, refreshToken);
404
+ });
405
+ }
406
+ deleteClient(clientId, accessToken) {
407
+ return __awaiter(this, void 0, void 0, function* () {
408
+ this.isMethodSupported('deleteClient', [types_2.ServerType.SasViya]);
409
+ return yield this.sasViyaApiClient.deleteClient(clientId, accessToken);
410
+ });
411
+ }
412
+ /**
413
+ * Returns the current SASjs configuration.
414
+ *
415
+ */
416
+ getSasjsConfig() {
417
+ return this.sasjsConfig;
418
+ }
419
+ /**
420
+ * Returns the username of the user currently logged in.
421
+ *
422
+ */
423
+ getUserName() {
424
+ return this.authManager.userName;
425
+ }
426
+ /**
427
+ * Sets the SASjs configuration.
428
+ * @param config - SASjs configuration.
429
+ */
430
+ setSASjsConfig(config) {
431
+ return __awaiter(this, void 0, void 0, function* () {
432
+ this.sasjsConfig = Object.assign(Object.assign({}, this.sasjsConfig), config);
433
+ this.setupConfiguration();
434
+ });
435
+ }
436
+ /**
437
+ * Sets the debug state. Turning this on will enable additional logging in the adapter.
438
+ * @param value - boolean indicating debug state (on/off).
439
+ */
440
+ setDebugState(value) {
441
+ this.sasjsConfig.debug = value;
442
+ if (this.sasViyaApiClient) {
443
+ this.sasViyaApiClient.debug = value;
444
+ }
445
+ }
446
+ /**
447
+ * Checks whether a session is active, or login is required.
448
+ * @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
449
+ */
450
+ checkSession() {
451
+ return __awaiter(this, void 0, void 0, function* () {
452
+ return this.authManager.checkSession();
453
+ });
454
+ }
455
+ /**
456
+ * Logs into the SAS server with the supplied credentials.
457
+ * @param username - a string representing the username.
458
+ * @param password - a string representing the password.
459
+ * @param clientId - a string representing the client ID.
460
+ */
461
+ logIn(username, password, clientId, options = {}) {
462
+ return __awaiter(this, void 0, void 0, function* () {
463
+ if (this.sasjsConfig.loginMechanism === types_1.LoginMechanism.Default) {
464
+ if (!username || !password)
465
+ throw new Error('A username and password are required when using the default login mechanism.');
466
+ return this.authManager.logIn(username, password);
467
+ }
468
+ if (typeof window === typeof undefined) {
469
+ throw new Error('The redirected login mechanism is only available for use in the browser.');
470
+ }
471
+ return this.authManager.redirectedLogIn(options);
472
+ });
473
+ }
474
+ /**
475
+ * Logs out of the configured SAS server.
476
+ */
477
+ logOut() {
478
+ return this.authManager.logOut();
479
+ }
480
+ /**
481
+ * Uploads a file to the given service.
482
+ * @param sasJob - the path to the SAS program (ultimately resolves to
483
+ * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
484
+ * Process). Is prepended at runtime with the value of `appLoc`.
485
+ * @param files - array of files to be uploaded, including File object and file name.
486
+ * @param params - request URL parameters.
487
+ * @param config - provide any changes to the config here, for instance to
488
+ * enable/disable `debug`. Any change provided will override the global config,
489
+ * for that particular function call.
490
+ * @param loginRequiredCallback - a function that is called if the
491
+ * user is not logged in (eg to display a login form). The request will be
492
+ * resubmitted after successful login.
493
+ */
494
+ uploadFile(sasJob, files, params, config = {}, loginRequiredCallback) {
495
+ return __awaiter(this, void 0, void 0, function* () {
496
+ config = Object.assign(Object.assign({}, this.sasjsConfig), config);
497
+ const data = { files, params };
498
+ return yield this.fileUploader.execute(sasJob, data, config, loginRequiredCallback);
499
+ });
500
+ }
501
+ /**
502
+ * Makes a request to program specified in `SASjob` (could be a Viya Job, a
503
+ * SAS 9 Stored Process, or a SASjs Server Stored Program). The response
504
+ * object will always contain table names in lowercase, and column names in
505
+ * uppercase. Values are returned formatted by default, unformatted
506
+ * values can be configured as an option in the `%webout` macro.
507
+ *
508
+ * @param sasJob - the path to the SAS program (ultimately resolves to
509
+ * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
510
+ * Process). Is prepended at runtime with the value of `appLoc`.
511
+ * @param data - a JSON object containing one or more tables to be sent to
512
+ * SAS. For an example of the table structure, see the project README. This
513
+ * value can be `null` if no inputs are required.
514
+ * @param config - provide any changes to the config here, for instance to
515
+ * enable/disable `debug`. Any change provided will override the global config,
516
+ * for that particular function call.
517
+ * @param loginRequiredCallback - a function that is called if the
518
+ * user is not logged in (eg to display a login form). The request will be
519
+ * resubmitted after successful login.
520
+ * When using a `loginRequiredCallback`, the call to the request will look, for example, like so:
521
+ * `await request(sasJobPath, data, config, () => setIsLoggedIn(false))`
522
+ * If you are not passing in any data and configuration, it will look like so:
523
+ * `await request(sasJobPath, {}, {}, () => setIsLoggedIn(false))`
524
+ * @param extraResponseAttributes - a array of predefined values that are used
525
+ * to provide extra attributes (same names as those values) to be added in response
526
+ * Supported values are declared in ExtraResponseAttributes type.
527
+ */
528
+ request(sasJob, data, config = {}, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
529
+ return __awaiter(this, void 0, void 0, function* () {
530
+ config = Object.assign(Object.assign({}, this.sasjsConfig), config);
531
+ const validationResult = (0, utils_1.validateInput)(data);
532
+ // status is true if the data passes validation checks above
533
+ if (validationResult.status) {
534
+ if (config.serverType === types_2.ServerType.Sasjs) {
535
+ return yield this.sasjsJobExecutor.execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes);
536
+ }
537
+ else if (config.serverType === types_2.ServerType.SasViya &&
538
+ config.useComputeApi !== undefined &&
539
+ config.useComputeApi !== null) {
540
+ if (config.useComputeApi) {
541
+ return yield this.computeJobExecutor.execute(sasJob, data, config, loginRequiredCallback, authConfig);
542
+ }
543
+ else {
544
+ if (!config.contextName)
545
+ config = Object.assign(Object.assign({}, config), { contextName: 'SAS Job Execution compute context' });
546
+ return yield this.jesJobExecutor.execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes);
547
+ }
548
+ }
549
+ else if (config.serverType === types_2.ServerType.Sas9 &&
550
+ config.username &&
551
+ config.password) {
552
+ return yield this.sas9JobExecutor.execute(sasJob, data, config);
553
+ }
554
+ else {
555
+ return yield this.webJobExecutor.execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes);
556
+ }
557
+ }
558
+ else {
559
+ return Promise.reject(new types_1.ErrorResponse(validationResult.msg));
560
+ }
561
+ });
562
+ }
563
+ /**
564
+ * Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
565
+ * @param serviceJson - the JSON specifying the folders and services to be created.
566
+ * @param appLoc - the base folder in which to create the new folders and
567
+ * services. If not provided, is taken from SASjsConfig.
568
+ * @param serverUrl - the server on which to deploy the folders and services.
569
+ * If not provided, is taken from SASjsConfig.
570
+ * @param accessToken - an optional access token to be passed in when
571
+ * using this function from the command line.
572
+ * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted.
573
+ */
574
+ deployServicePack(serviceJson, appLoc, serverUrl, accessToken, isForced = false) {
575
+ return __awaiter(this, void 0, void 0, function* () {
576
+ this.isMethodSupported('deployServicePack', [types_2.ServerType.SasViya]);
577
+ let sasApiClient = null;
578
+ if (serverUrl || appLoc) {
579
+ if (!serverUrl)
580
+ serverUrl = this.sasjsConfig.serverUrl;
581
+ if (!appLoc)
582
+ appLoc = this.sasjsConfig.appLoc;
583
+ if (this.sasjsConfig.serverType === types_2.ServerType.SasViya) {
584
+ sasApiClient = new SASViyaApiClient_1.SASViyaApiClient(serverUrl, appLoc, this.sasjsConfig.contextName, this.requestClient);
585
+ sasApiClient.debug = this.sasjsConfig.debug;
586
+ }
587
+ else if (this.sasjsConfig.serverType === types_2.ServerType.Sas9) {
588
+ sasApiClient = new SAS9ApiClient_1.SAS9ApiClient(serverUrl, this.jobsPath, this.sasjsConfig.httpsAgentOptions);
589
+ }
590
+ }
591
+ else {
592
+ let sasClientConfig = null;
593
+ if (this.sasjsConfig.serverType === types_2.ServerType.SasViya) {
594
+ sasClientConfig = this.sasViyaApiClient.getConfig();
595
+ }
596
+ else if (this.sasjsConfig.serverType === types_2.ServerType.Sas9) {
597
+ sasClientConfig = this.sas9ApiClient.getConfig();
598
+ }
599
+ serverUrl = sasClientConfig.serverUrl;
600
+ appLoc = sasClientConfig.rootFolderName;
601
+ }
602
+ // members of type 'folder' should be processed first
603
+ if (serviceJson.members[0].members) {
604
+ serviceJson.members[0].members.sort((member) => member.type === 'folder' ? -1 : 1);
605
+ }
606
+ const members = serviceJson.members;
607
+ yield this.createFoldersAndServices(appLoc, members, accessToken, sasApiClient, isForced);
608
+ });
609
+ }
610
+ /**
611
+ * Kicks off execution of the given job via the compute API.
612
+ * @returns an object representing the compute session created for the given job.
613
+ * @param sasJob - the path to the SAS program (ultimately resolves to
614
+ * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
615
+ * Process). Is prepended at runtime with the value of `appLoc`.
616
+ * @param data - a JSON object containing one or more tables to be sent to
617
+ * SAS. Can be `null` if no inputs required.
618
+ * @param config - provide any changes to the config here, for instance to
619
+ * enable/disable `debug`. Any change provided will override the global config,
620
+ * for that particular function call.
621
+ * @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
622
+ * The access token is not required when the user is authenticated via the browser.
623
+ * @param waitForResult - a boolean that indicates whether the function needs to wait for execution to complete.
624
+ * @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.
625
+ * @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
626
+ * @param variables - an object that represents macro variables.
627
+ * @param verboseMode - boolean or a string equal to 'bleached' to enable verbose mode (log every HTTP response).
628
+ * @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.
629
+ */
630
+ startComputeJob(sasJob, data, config = {}, authConfig, waitForResult, pollOptions, printPid = false, variables, verboseMode, onTokensRefreshed) {
631
+ var _a, _b, _c, _d;
632
+ return __awaiter(this, void 0, void 0, function* () {
633
+ config = Object.assign(Object.assign({}, this.sasjsConfig), config);
634
+ this.isMethodSupported('startComputeJob', [types_2.ServerType.SasViya]);
635
+ if (!config.contextName) {
636
+ throw new Error('Context name is undefined. Please set a `contextName` in your SASjs or override config.');
637
+ }
638
+ if (verboseMode) {
639
+ (_a = this.requestClient) === null || _a === void 0 ? void 0 : _a.setVerboseMode(verboseMode);
640
+ (_b = this.requestClient) === null || _b === void 0 ? void 0 : _b.enableVerboseMode();
641
+ }
642
+ else if (verboseMode === false)
643
+ (_c = this.requestClient) === null || _c === void 0 ? void 0 : _c.disableVerboseMode();
644
+ return (_d = this.sasViyaApiClient) === null || _d === void 0 ? void 0 : _d.executeComputeJob(sasJob, config.contextName, config.debug, data, authConfig, !!waitForResult, false, pollOptions, printPid, variables, onTokensRefreshed);
645
+ });
646
+ }
647
+ /**
648
+ * Fetches content of the log file
649
+ * @param logUrl - url of the log file.
650
+ * @param accessToken - an access token for an authorised user.
651
+ */
652
+ fetchLogFileContent(logUrl, accessToken) {
653
+ return __awaiter(this, void 0, void 0, function* () {
654
+ return yield this.requestClient.get(logUrl, accessToken).then((res) => {
655
+ if (!res)
656
+ return Promise.reject(new types_1.ErrorResponse('Error while fetching log. Response was not provided.'));
657
+ try {
658
+ const result = JSON.stringify(res.result);
659
+ return result;
660
+ }
661
+ catch (err) {
662
+ return Promise.reject(new types_1.ErrorResponse('Error while fetching log. The result is not valid.', err));
663
+ }
664
+ });
665
+ });
666
+ }
667
+ /**
668
+ * this method returns an array of SASjsRequest
669
+ * @returns SASjsRequest[]
670
+ */
671
+ getSasRequests() {
672
+ const requests = [...this.requestClient.getRequests()];
673
+ const sortedRequests = requests.sort(utils_1.compareTimestamps);
674
+ return sortedRequests;
675
+ }
676
+ clearSasRequests() {
677
+ this.requestClient.clearRequests();
678
+ }
679
+ setupConfiguration() {
680
+ if (this.sasjsConfig.serverUrl === undefined ||
681
+ this.sasjsConfig.serverUrl === '') {
682
+ if (typeof location !== 'undefined') {
683
+ let url = `${location.protocol}//${location.hostname}`;
684
+ if (location.port)
685
+ url = `${url}:${location.port}`;
686
+ this.sasjsConfig.serverUrl = url;
687
+ }
688
+ else {
689
+ this.sasjsConfig.serverUrl = '';
690
+ }
691
+ }
692
+ if (this.sasjsConfig.serverUrl.slice(-1) === '/') {
693
+ this.sasjsConfig.serverUrl = this.sasjsConfig.serverUrl.slice(0, -1);
694
+ }
695
+ if (!this.requestClient) {
696
+ const RequestClientClass = this.sasjsConfig.serverType === types_2.ServerType.Sasjs
697
+ ? SasjsRequestClient_1.SasjsRequestClient
698
+ : RequestClient_1.RequestClient;
699
+ this.requestClient = new RequestClientClass(this.sasjsConfig.serverUrl, this.sasjsConfig.httpsAgentOptions, this.sasjsConfig.requestHistoryLimit, this.sasjsConfig.verbose);
700
+ }
701
+ else {
702
+ this.requestClient.setConfig(this.sasjsConfig.serverUrl, this.sasjsConfig.httpsAgentOptions);
703
+ }
704
+ this.jobsPath =
705
+ this.sasjsConfig.serverType === types_2.ServerType.SasViya
706
+ ? this.sasjsConfig.pathSASViya
707
+ : this.sasjsConfig.serverType === types_2.ServerType.Sas9
708
+ ? this.sasjsConfig.pathSAS9
709
+ : this.sasjsConfig.pathSASJS;
710
+ this.authManager = new auth_1.AuthManager(this.sasjsConfig.serverUrl, this.sasjsConfig.serverType, this.requestClient, this.resendWaitingRequests);
711
+ if (this.sasjsConfig.serverType === types_2.ServerType.SasViya) {
712
+ if (this.sasViyaApiClient) {
713
+ this.sasViyaApiClient.setConfig(this.sasjsConfig.serverUrl, this.sasjsConfig.appLoc);
714
+ }
715
+ else {
716
+ this.sasViyaApiClient = new SASViyaApiClient_1.SASViyaApiClient(this.sasjsConfig.serverUrl, this.sasjsConfig.appLoc, this.sasjsConfig.contextName, this.requestClient);
717
+ }
718
+ this.sasViyaApiClient.debug = this.sasjsConfig.debug;
719
+ }
720
+ if (this.sasjsConfig.serverType === types_2.ServerType.Sas9) {
721
+ if (this.sas9ApiClient) {
722
+ this.sas9ApiClient.setConfig(this.sasjsConfig.serverUrl);
723
+ }
724
+ else {
725
+ this.sas9ApiClient = new SAS9ApiClient_1.SAS9ApiClient(this.sasjsConfig.serverUrl, this.jobsPath, this.sasjsConfig.httpsAgentOptions);
726
+ }
727
+ }
728
+ if (this.sasjsConfig.serverType === types_2.ServerType.Sasjs) {
729
+ if (!this.sasJSApiClient) {
730
+ this.sasJSApiClient = new SASjsApiClient_1.SASjsApiClient(this.requestClient);
731
+ }
732
+ }
733
+ this.fileUploader = new job_execution_1.FileUploader(this.sasjsConfig.serverUrl, this.sasjsConfig.serverType, this.jobsPath, this.requestClient);
734
+ this.webJobExecutor = new job_execution_1.WebJobExecutor(this.sasjsConfig.serverUrl, this.sasjsConfig.serverType, this.jobsPath, this.requestClient, this.sasViyaApiClient);
735
+ this.sasjsJobExecutor = new job_execution_1.SasjsJobExecutor(this.sasjsConfig.serverUrl, this.jobsPath, this.requestClient);
736
+ this.sas9JobExecutor = new job_execution_1.Sas9JobExecutor(this.sasjsConfig.serverUrl, this.sasjsConfig.serverType, this.jobsPath, this.requestClient, this.sasjsConfig.httpsAgentOptions);
737
+ this.computeJobExecutor = new job_execution_1.ComputeJobExecutor(this.sasjsConfig.serverUrl, this.sasViyaApiClient);
738
+ this.jesJobExecutor = new job_execution_1.JesJobExecutor(this.sasjsConfig.serverUrl, this.sasViyaApiClient);
739
+ }
740
+ createFoldersAndServices(parentFolder, membersJson, accessToken, sasApiClient, isForced) {
741
+ return __awaiter(this, void 0, void 0, function* () {
742
+ yield (0, utils_1.asyncForEach)(membersJson, (member) => __awaiter(this, void 0, void 0, function* () {
743
+ switch (member.type) {
744
+ case 'folder':
745
+ yield this.createFolder(member.name, parentFolder, undefined, accessToken, sasApiClient, isForced);
746
+ break;
747
+ case 'file':
748
+ yield this.createFile(member.name, member.code, parentFolder, undefined, accessToken, sasApiClient);
749
+ break;
750
+ case 'service':
751
+ yield this.createJobDefinition(member.name, member.code, parentFolder, undefined, accessToken, sasApiClient);
752
+ break;
753
+ default:
754
+ throw new Error(`Unidentified member '${member.name}' provided.`);
755
+ }
756
+ if (member.type === 'folder' && member.members && member.members.length)
757
+ yield this.createFoldersAndServices(`${parentFolder}/${member.name}`, member.members, accessToken, sasApiClient, isForced);
758
+ }));
759
+ });
760
+ }
761
+ isMethodSupported(method, serverTypes) {
762
+ if (!this.sasjsConfig.serverType ||
763
+ !serverTypes.includes(this.sasjsConfig.serverType)) {
764
+ throw new Error(`Method '${method}' is only supported on ${serverTypes.join(', ')} servers.`);
765
+ }
766
+ }
767
+ /**
768
+ * Enables verbose mode that will log a summary of every HTTP response.
769
+ * @param successCallBack - function that should be triggered on every HTTP response with the status 2**.
770
+ * @param errorCallBack - function that should be triggered on every HTTP response with the status different from 2**.
771
+ */
772
+ enableVerboseMode(successCallBack, errorCallBack) {
773
+ var _a;
774
+ (_a = this.requestClient) === null || _a === void 0 ? void 0 : _a.enableVerboseMode(successCallBack, errorCallBack);
775
+ }
776
+ /**
777
+ * Turns off verbose mode to log every HTTP response.
778
+ */
779
+ disableVerboseMode() {
780
+ var _a;
781
+ (_a = this.requestClient) === null || _a === void 0 ? void 0 : _a.disableVerboseMode();
782
+ }
783
+ /**
784
+ * Create a tables class containing one or more tables to be sent to
785
+ * SAS.
786
+ * @param table - initial table data
787
+ * @param macroName - macro name
788
+ * @returns Tables class
789
+ */
790
+ Tables(table, macroName) {
791
+ return new types_1.Tables(table, macroName);
792
+ }
793
+ }
794
+ exports.default = SASjs;