@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
@@ -1,1417 +0,0 @@
1
- import { isRelativePath, isUri, isUrl } from './utils'
2
- import NodeFormData from 'form-data'
3
- import {
4
- Job,
5
- Session,
6
- Context,
7
- ContextAllAttributes,
8
- Folder,
9
- File,
10
- EditContextInput,
11
- JobDefinition,
12
- PollOptions
13
- } from './types'
14
- import {
15
- CertificateError,
16
- JobExecutionError,
17
- RootFolderNotFoundError
18
- } from './types/errors'
19
- import { SessionManager } from './SessionManager'
20
- import { ContextManager } from './ContextManager'
21
- import {
22
- SasAuthResponse,
23
- MacroVar,
24
- AuthConfig,
25
- ServerType
26
- } from '@sasjs/utils/types'
27
- import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
28
- import { RequestClient } from './request/RequestClient'
29
- import { prefixMessage } from '@sasjs/utils/error'
30
- import { pollJobState } from './api/viya/pollJobState'
31
- import { getTokens, OnTokensRefreshed } from './auth/getTokens'
32
- import { uploadTables } from './api/viya/uploadTables'
33
- import { executeOnComputeApi } from './api/viya/executeOnComputeApi'
34
- import { getAccessTokenForViya } from './auth/getAccessTokenForViya'
35
- import { refreshTokensForViya } from './auth/refreshTokensForViya'
36
- import { FileResource } from './types/FileResource'
37
-
38
- interface JobExecutionResult {
39
- result?: { result: object }
40
- log?: string
41
- error?: object
42
- }
43
- /* Viya /types/types?limit=999999 response structure */
44
- interface IViyaTypesResponse {
45
- accept: string
46
- count: number
47
- items: IViyaTypesItem[]
48
- limit: number
49
- links: IViyaTypesLink[]
50
- name: string
51
- start: number
52
- version: number
53
- }
54
-
55
- /* Item element within the Viya types response */
56
- interface IViyaTypesItem {
57
- description?: string
58
- extensions?: string[]
59
- iconUri?: string
60
- label: string
61
- links: IViyaTypesLink[]
62
- mappedTypes?: string[]
63
- mediaType?: string
64
- mediaTypes?: string[]
65
- name?: string | undefined
66
- pluralLabel?: string
67
- properties?: IViyaTypesProperties
68
- resourceUri?: string
69
- serviceRootUri?: string
70
- tags?: string[]
71
- version: number
72
- }
73
-
74
- /**
75
- * Generic structure for a link
76
- * in the links array of a Viya
77
- * types/types api response
78
- */
79
- type IViyaTypesLink = Record<string, string>
80
-
81
- /**
82
- * Generic structure for a type's
83
- * 'properties' object from the Viya
84
- * types/types api response
85
- */
86
- type IViyaTypesProperties = Record<string, string>
87
-
88
- /**
89
- * Arbitrary interface for storing
90
- * sufficient additional detail to
91
- * create and patch a new file.
92
- */
93
- interface IViyaTypesExtensionInfo {
94
- typeDefName: string | undefined
95
- properties: IViyaTypesProperties | undefined
96
- }
97
-
98
- /**
99
- * A client for interfacing with the SAS Viya REST API.
100
- *
101
- */
102
- export class SASViyaApiClient {
103
- constructor(
104
- private serverUrl: string,
105
- private rootFolderName: string,
106
- private contextName: string,
107
- private requestClient: RequestClient
108
- ) {
109
- if (serverUrl) isUrl(serverUrl)
110
- }
111
-
112
- private _debug = false
113
- private sessionManager = new SessionManager(
114
- this.serverUrl,
115
- this.contextName,
116
- this.requestClient
117
- )
118
- private contextManager = new ContextManager(
119
- this.serverUrl,
120
- this.requestClient
121
- )
122
- private folderMap = new Map<string, Job[]>()
123
- private fileExtensionMap = new Map<string, IViyaTypesExtensionInfo>()
124
- private boolExtensionMap = false // required in case the map has zero entries
125
- // after an attempt to populate it.
126
-
127
- /**
128
- * A helper method used to call appendRequest method of RequestClient
129
- * @param response - response from sasjs request
130
- * @param program - name of program
131
- * @param debug - a boolean that indicates whether debug was enabled or not
132
- */
133
- public appendRequest(response: any, program: string, debug: boolean) {
134
- this.requestClient!.appendRequest(response, program, debug)
135
- }
136
-
137
- public get debug() {
138
- return this._debug
139
- }
140
-
141
- public set debug(value: boolean) {
142
- this._debug = value
143
- if (this.sessionManager) {
144
- this.sessionManager.debug = value
145
- }
146
- }
147
-
148
- /**
149
- * Returns a list of jobs in the currently set root folder.
150
- */
151
- public async getJobsInFolder(folderPath: string) {
152
- const path = isRelativePath(folderPath)
153
- ? `${this.rootFolderName}/${folderPath}`
154
- : folderPath
155
- if (this.folderMap.get(path)) {
156
- return this.folderMap.get(path)
157
- }
158
-
159
- await this.populateFolderMap(path)
160
- return this.folderMap.get(path)
161
- }
162
-
163
- /**
164
- * Returns an object containing the server URL and root folder name.
165
- */
166
- public getConfig() {
167
- return {
168
- serverUrl: this.serverUrl,
169
- rootFolderName: this.rootFolderName
170
- }
171
- }
172
-
173
- /**
174
- * Updates server URL and root folder name, if it was not set.
175
- * @param serverUrl - the URL of the server.
176
- * @param rootFolderName - the name for root folder.
177
- */
178
- public setConfig(serverUrl: string, rootFolderName: string) {
179
- if (serverUrl) this.serverUrl = serverUrl
180
- if (rootFolderName) this.rootFolderName = rootFolderName
181
- }
182
-
183
- /**
184
- * Returns all available compute contexts on this server.
185
- * @param accessToken - an access token for an authorized user.
186
- */
187
- public async getComputeContexts(accessToken?: string) {
188
- return await this.contextManager.getComputeContexts(accessToken)
189
- }
190
-
191
- /**
192
- * Returns default(system) compute contexts.
193
- */
194
- public getDefaultComputeContexts() {
195
- return this.contextManager.getDefaultComputeContexts
196
- }
197
-
198
- /**
199
- * Returns all available launcher contexts on this server.
200
- * @param accessToken - an access token for an authorized user.
201
- */
202
- public async getLauncherContexts(accessToken?: string) {
203
- return await this.contextManager.getLauncherContexts(accessToken)
204
- }
205
-
206
- /**
207
- * Returns all compute contexts on this server that the user has access to.
208
- * @param authConfig - an access token, refresh token, client and secret for an authorized user.
209
- */
210
- public async getExecutableContexts(authConfig?: AuthConfig) {
211
- const bindedExecuteScript = this.executeScript.bind(this)
212
-
213
- return await this.contextManager.getExecutableContexts(
214
- bindedExecuteScript,
215
- authConfig
216
- )
217
- }
218
-
219
- /**
220
- * Creates a session on the given context.
221
- * @param contextName - the name of the context to create a session on.
222
- * @param accessToken - an access token for an authorized user.
223
- */
224
- public async createSession(contextName: string, accessToken?: string) {
225
- const headers: any = {
226
- 'Content-Type': 'application/json'
227
- }
228
-
229
- if (accessToken) {
230
- headers.Authorization = `Bearer ${accessToken}`
231
- }
232
-
233
- const { result: contexts } = await this.requestClient.get<{
234
- items: Context[]
235
- }>(`/compute/contexts?limit=10000`, accessToken)
236
-
237
- const executionContext =
238
- contexts.items && contexts.items.length
239
- ? contexts.items.find((c: any) => c.name === contextName)
240
- : null
241
- if (!executionContext) {
242
- throw new Error(`Execution context ${contextName} not found.`)
243
- }
244
-
245
- const { result: createdSession } = await this.requestClient.post<Session>(
246
- `/compute/contexts/${executionContext.id}/sessions`,
247
- {},
248
- accessToken
249
- )
250
-
251
- return createdSession
252
- }
253
-
254
- /**
255
- * Creates a compute context on the given server.
256
- * @param contextName - the name of the context to be created.
257
- * @param launchContextName - the name of the launcher context used by the compute service.
258
- * @param sharedAccountId - the ID of the account to run the servers for this context.
259
- * @param autoExecLines - the lines of code to execute during session initialization.
260
- * @param accessToken - an access token for an authorized user.
261
- * @param authorizedUsers - an optional list of authorized user IDs.
262
- */
263
- public async createComputeContext(
264
- contextName: string,
265
- launchContextName: string,
266
- sharedAccountId: string,
267
- autoExecLines: string[],
268
- accessToken?: string,
269
- authorizedUsers?: string[]
270
- ) {
271
- return await this.contextManager.createComputeContext(
272
- contextName,
273
- launchContextName,
274
- sharedAccountId,
275
- autoExecLines,
276
- accessToken,
277
- authorizedUsers
278
- )
279
- }
280
-
281
- /**
282
- * Creates a launcher context on the given server.
283
- * @param contextName - the name of the context to be created.
284
- * @param description - the description of the context to be created.
285
- * @param launchType - launch type of the context to be created.
286
- * @param accessToken - an access token for an authorized user.
287
- */
288
- public async createLauncherContext(
289
- contextName: string,
290
- description: string,
291
- launchType = 'direct',
292
- accessToken?: string
293
- ) {
294
- return await this.contextManager.createLauncherContext(
295
- contextName,
296
- description,
297
- launchType,
298
- accessToken
299
- )
300
- }
301
-
302
- /**
303
- * Updates a compute context on the given server.
304
- * @param contextName - the original name of the context to be updated.
305
- * @param editedContext - an object with the properties to be updated.
306
- * @param accessToken - an access token for an authorized user.
307
- */
308
- public async editComputeContext(
309
- contextName: string,
310
- editedContext: EditContextInput,
311
- accessToken?: string
312
- ) {
313
- return await this.contextManager.editComputeContext(
314
- contextName,
315
- editedContext,
316
- accessToken
317
- )
318
- }
319
-
320
- /**
321
- * Deletes a compute context on the given server.
322
- * @param contextName - the name of the context to be deleted.
323
- * @param accessToken - an access token for an authorized user.
324
- */
325
- public async deleteComputeContext(contextName: string, accessToken?: string) {
326
- return await this.contextManager.deleteComputeContext(
327
- contextName,
328
- accessToken
329
- )
330
- }
331
-
332
- /**
333
- * Executes code on the current SAS Viya server.
334
- * @param jobPath - the path to the file being submitted for execution.
335
- * @param linesOfCode - an array of code lines to execute.
336
- * @param contextName - the context to execute the code in.
337
- * @param authConfig - an object containing an access token, refresh token, client ID and secret.
338
- * @param data - execution data.
339
- * @param debug - when set to true, the log will be returned.
340
- * @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
341
- * @param waitForResult - when set to true, function will return the session
342
- * @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.
343
- * @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
344
- * @param variables - an object that represents macro variables.
345
- * @param onTokensRefreshed - optional callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
346
- */
347
- public async executeScript(
348
- jobPath: string,
349
- linesOfCode: string[],
350
- contextName: string,
351
- authConfig?: AuthConfig,
352
- data = null,
353
- debug: boolean = false,
354
- expectWebout = false,
355
- waitForResult = true,
356
- pollOptions?: PollOptions,
357
- printPid = false,
358
- variables?: MacroVar,
359
- onTokensRefreshed?: OnTokensRefreshed
360
- ): Promise<any> {
361
- return executeOnComputeApi(
362
- this.requestClient,
363
- this.sessionManager,
364
- this.rootFolderName,
365
- jobPath,
366
- linesOfCode,
367
- contextName,
368
- authConfig,
369
- data,
370
- debug,
371
- expectWebout,
372
- waitForResult,
373
- pollOptions,
374
- printPid,
375
- variables,
376
- onTokensRefreshed
377
- )
378
- }
379
-
380
- /**
381
- * Fetches the file content for a file in the specified folder.
382
- *
383
- * @param folderPath - the full path to the folder containing the file. eg: /Public/folder1/folder2
384
- * @param fileName - the name of the file in the `folderPath`
385
- * @param accessToken - an access token for authorizing the request
386
- */
387
- public async getFileContent(
388
- folderPath: string,
389
- fileName: string,
390
- accessToken?: string
391
- ) {
392
- const fileUri = await this.getFileUri(
393
- folderPath,
394
- fileName,
395
- accessToken
396
- ).catch((err) => {
397
- throw prefixMessage(
398
- err,
399
- `Error while getting file URI for: ${fileName} in folder: ${folderPath}. `
400
- )
401
- })
402
-
403
- return await this.requestClient
404
- .get<string>(`${this.serverUrl}${fileUri}/content`, accessToken)
405
- .then((res) => res.result)
406
- }
407
-
408
- /**
409
- * Updates the file content for a file in the specified folder.
410
- *
411
- * @param folderPath - the full path to the folder containing the file. eg: /Public/folder1/folder2
412
- * @param fileName - the name of the file in the `folderPath`
413
- * @param content - the new content to be written to the file
414
- * @param accessToken - an access token for authorizing the request
415
- */
416
- public async updateFileContent(
417
- folderPath: string,
418
- fileName: string,
419
- content: string,
420
- accessToken?: string
421
- ) {
422
- const fileUri = await this.getFileUri(
423
- folderPath,
424
- fileName,
425
- accessToken
426
- ).catch((err) => {
427
- throw prefixMessage(
428
- err,
429
- `Error while getting file URI for: ${fileName} in folder: ${folderPath}. `
430
- )
431
- })
432
-
433
- // Fetch the file resource details to get the Etag and content type
434
- const { result: originalFileResource, etag } =
435
- await this.requestClient.get<FileResource>(
436
- `${this.serverUrl}${fileUri}`,
437
- accessToken
438
- )
439
-
440
- if (!originalFileResource || !etag)
441
- throw new Error(
442
- `File ${fileName} does not have an ETag, or request failed.`
443
- )
444
-
445
- return await this.requestClient
446
- .put<FileResource>(
447
- `${this.serverUrl}${fileUri}/content`,
448
- content,
449
- accessToken,
450
- {
451
- 'If-Match': etag,
452
- 'Content-Type': originalFileResource.contentType
453
- }
454
- )
455
- .then((res) => res.result)
456
- }
457
-
458
- /**
459
- * Fetches a folder. Path to the folder is required.
460
- * @param folderPath - the absolute path to the folder.
461
- * @param accessToken - an access token for authorizing the request.
462
- */
463
- public async getFolder(folderPath: string, accessToken?: string) {
464
- return await this.requestClient
465
- .get(`/folders/folders/@item?path=${folderPath}`, accessToken)
466
- .then((res) => res.result)
467
- }
468
-
469
- /**
470
- * Creates a file. Path to or URI of the parent folder is required.
471
- * @param fileName - the name of the new file.
472
- * @param contentBuffer - the content of the new file in Buffer.
473
- * @param parentFolderPath - the full path to the parent folder. If not
474
- * provided, the parentFolderUri must be provided.
475
- * @param parentFolderUri - the URI (eg /folders/folders/UUID) of the parent
476
- * folder. If not provided, the parentFolderPath must be provided.
477
- * @param accessToken - an access token for authorizing the request.
478
- */
479
- public async createFile(
480
- fileName: string,
481
- contentBuffer: Buffer,
482
- parentFolderPath?: string,
483
- parentFolderUri?: string,
484
- accessToken?: string
485
- ): Promise<File> {
486
- if (!parentFolderPath && !parentFolderUri) {
487
- throw new Error('Path or URI of the parent folder is required.')
488
- }
489
-
490
- if (!parentFolderUri && parentFolderPath) {
491
- parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
492
- }
493
-
494
- const headers = {
495
- Accept: 'application/vnd.sas.file+json',
496
- 'Content-Disposition': `filename="${fileName}";`
497
- }
498
-
499
- const formData = new NodeFormData()
500
- formData.append('file', contentBuffer, fileName)
501
-
502
- /** Query Viya for file metadata based on extension type. */
503
-
504
- // typeDefName - Viya accepts this property during the file creation
505
- let typeDefName: string | undefined = undefined
506
- // Additional properties are supplied by a patch.
507
- let filePatch:
508
- | {
509
- name: string
510
- properties: IViyaTypesProperties | undefined
511
- }
512
- | undefined = undefined
513
-
514
- // The patching process requires properties related to the file-extension
515
- const fileExtension: string | undefined = fileName
516
- .split('.')
517
- .pop()
518
- ?.toLowerCase()
519
-
520
- if (fileExtension) {
521
- if (!this.boolExtensionMap) {
522
- // Populate the file extension map
523
- // 1. Get Viya's response to this api call
524
- const typesQueryUrl = `/types/types?limit=999999`
525
- const response = (
526
- await this.requestClient.get(typesQueryUrl, accessToken)
527
- ).result as IViyaTypesResponse
528
- // 2. Filter the returned items that have file extensions into a map
529
- // using forEach as an item may relate to multiple file extensions.
530
- response.items
531
- .filter((e) => e.extensions)
532
- .forEach((e) => {
533
- e.extensions?.forEach((ext) => {
534
- this.fileExtensionMap.set(ext, {
535
- // `name` becomes the typeDefName value at file creation time.
536
- // `name` is ignored here if it is not populated in the map, or
537
- // has a blank/empty value.
538
- typeDefName: e.name
539
- ? e.name.trim().length
540
- ? e.name.trim()
541
- : undefined
542
- : undefined,
543
- properties: e.properties
544
- })
545
- })
546
- })
547
- // 3. Toggle the flag to avoid repeating this step
548
- this.boolExtensionMap = true
549
- }
550
-
551
- // Query the map for the current file extension
552
- const fileExtInfo = this.fileExtensionMap.get(fileExtension)
553
- if (fileExtInfo) {
554
- // If the extension was found in the map, record the typeDefName and
555
- // create a patch if a properties object was returned.
556
- typeDefName = fileExtInfo.typeDefName
557
- if (fileExtInfo.properties)
558
- filePatch = { name: fileName, properties: fileExtInfo.properties }
559
- }
560
- }
561
-
562
- // Create the file
563
- const createFileResponse = await this.requestClient.post<File>(
564
- `/files/files?parentFolderUri=${parentFolderUri}&typeDefName=${
565
- typeDefName ?? 'file'
566
- }#rawUpload`,
567
- formData,
568
- accessToken,
569
- 'multipart/form-data; boundary=' + (formData as any)._boundary,
570
- headers
571
- )
572
-
573
- // If a patch was created...
574
- if (filePatch) {
575
- try {
576
- const patchHeaders = {
577
- Accept: 'application/json',
578
- 'If-Match': '*'
579
- }
580
- // Get the URI of the newly created file
581
- const fileUri = createFileResponse.result.links.filter(
582
- (e) => e.method == 'PATCH' && e.rel == 'patch'
583
- )[0].uri
584
- // and apply the patch
585
- return (
586
- await this.requestClient.patch<File>(
587
- `${fileUri}`,
588
- filePatch,
589
- accessToken,
590
- patchHeaders
591
- )
592
- ).result
593
- } catch (e: any) {
594
- throw new Error(`Error patching file ${fileName}.\n${e.message}`)
595
- }
596
- }
597
- return createFileResponse.result
598
- }
599
-
600
- /**
601
- * Creates a folder. Path to or URI of the parent folder is required.
602
- * @param folderName - the name of the new folder.
603
- * @param parentFolderPath - the full path to the parent folder. If not
604
- * provided, the parentFolderUri must be provided.
605
- * @param parentFolderUri - the URI (eg /folders/folders/UUID) of the parent
606
- * folder. If not provided, the parentFolderPath must be provided.
607
- * @param accessToken - an access token for authorizing the request.
608
- * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted.
609
- */
610
- public async createFolder(
611
- folderName: string,
612
- parentFolderPath?: string,
613
- parentFolderUri?: string,
614
- accessToken?: string,
615
- isForced?: boolean
616
- ): Promise<Folder> {
617
- const logger = process.logger || console
618
-
619
- if (!parentFolderPath && !parentFolderUri) {
620
- throw new Error('Path or URI of the parent folder is required.')
621
- }
622
-
623
- if (!parentFolderUri && parentFolderPath) {
624
- parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
625
-
626
- if (!parentFolderUri) {
627
- logger.info(
628
- `Parent folder at path '${parentFolderPath}' is not present.`
629
- )
630
-
631
- const newParentFolderPath = parentFolderPath.substring(
632
- 0,
633
- parentFolderPath.lastIndexOf('/')
634
- )
635
- const newFolderName = `${parentFolderPath.split('/').pop()}`
636
-
637
- if (newParentFolderPath === '') {
638
- throw new RootFolderNotFoundError(
639
- parentFolderPath,
640
- this.serverUrl,
641
- accessToken
642
- )
643
- }
644
-
645
- logger.info(
646
- `Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
647
- )
648
-
649
- const parentFolder = await this.createFolder(
650
- newFolderName,
651
- newParentFolderPath,
652
- undefined,
653
- accessToken
654
- )
655
-
656
- logger.info(
657
- `Parent folder '${newFolderName}' has been successfully created.`
658
- )
659
-
660
- parentFolderUri = `/folders/folders/${parentFolder.id}`
661
- } else if (isForced) {
662
- const folderPath = parentFolderPath + '/' + folderName
663
- const folderUri = await this.getFolderUri(folderPath, accessToken)
664
-
665
- if (folderUri) {
666
- await this.deleteFolder(
667
- parentFolderPath + '/' + folderName,
668
- accessToken
669
- )
670
- }
671
- }
672
- }
673
-
674
- const { result: createFolderResponse } = await this.requestClient
675
- .post<Folder>(
676
- `/folders/folders?parentFolderUri=${parentFolderUri}`,
677
- {
678
- name: folderName,
679
- type: 'folder'
680
- },
681
- accessToken
682
- )
683
- .catch((err) => {
684
- const { message, response } = err
685
-
686
- if (message && response && response.data && response.data.message) {
687
- const { status } = response
688
- const { message: responseMessage } = response.data
689
- const messages = [message, responseMessage].map((mes: string) =>
690
- /\.$/.test(mes) ? mes : `${mes}.`
691
- )
692
-
693
- if (!isForced && status === 409) {
694
- messages.push(`To override, please set "isForced" to "true".`)
695
- }
696
-
697
- const errMessage = messages.join(' ')
698
-
699
- throw errMessage
700
- }
701
-
702
- throw err
703
- })
704
-
705
- // update folder map with newly created folder.
706
- await this.populateFolderMap(
707
- `${parentFolderPath}/${folderName}`,
708
- accessToken
709
- )
710
-
711
- return createFolderResponse
712
- }
713
-
714
- /**
715
- * Creates a Job in the specified folder (or folder uri).
716
- * @param parentFolderPath - the location of the new job.
717
- * @param parentFolderUri - the URI location of the new job. The function is a
718
- * little faster if the folder URI is supplied instead of the path.
719
- * @param jobName - the name of the new job to be created.
720
- * @param code - the SAS code for the new job.
721
- */
722
- public async createJobDefinition(
723
- jobName: string,
724
- code: string,
725
- parentFolderPath?: string,
726
- parentFolderUri?: string,
727
- accessToken?: string
728
- ) {
729
- if (!parentFolderPath && !parentFolderUri) {
730
- throw new Error(`Path to or URI of the parent folder is required.`)
731
- }
732
-
733
- if (!parentFolderUri && parentFolderPath) {
734
- parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
735
- }
736
-
737
- return await this.requestClient.post<Job>(
738
- `${this.serverUrl}/jobDefinitions/definitions?parentFolderUri=${parentFolderUri}`,
739
- {
740
- name: jobName,
741
- parameters: [
742
- {
743
- name: '_addjesbeginendmacros',
744
- type: 'CHARACTER',
745
- defaultValue: 'false'
746
- }
747
- ],
748
- type: 'Compute',
749
- code
750
- },
751
- accessToken
752
- )
753
- }
754
-
755
- /**
756
- * Performs a login redirect and returns an auth code for the given client.
757
- * @param clientId - the client ID to authenticate with.
758
- */
759
- public async getAuthCode(clientId: string) {
760
- const authUrl = `${this.serverUrl}/SASLogon/oauth/authorize?client_id=${clientId}&response_type=code`
761
-
762
- const authCode = await this.requestClient
763
- .get<string>(authUrl, undefined, 'text/plain')
764
- .then((response) => response.result)
765
- .then(async (response) => {
766
- let code = ''
767
- if (isAuthorizeFormRequired(response)) {
768
- const formResponse: any = await this.requestClient.authorize(response)
769
-
770
- const responseBody = formResponse
771
- .split('<body>')[1]
772
- .split('</body>')[0]
773
- const bodyElement: any = document.createElement('div')
774
- bodyElement.innerHTML = responseBody
775
-
776
- code = bodyElement.querySelector('.infobox h4').innerText
777
-
778
- return code
779
- } else {
780
- const responseBody = response.split('<body>')[1].split('</body>')[0]
781
- const bodyElement: any = document.createElement('div')
782
- bodyElement.innerHTML = responseBody
783
-
784
- if (bodyElement) {
785
- code = bodyElement.querySelector('.infobox h4').innerText
786
- }
787
-
788
- return code
789
- }
790
- })
791
- .catch(() => null)
792
-
793
- return authCode
794
- }
795
-
796
- /**
797
- * Exchanges the auth code for an access token for the given client.
798
- * @param clientId - the client ID to authenticate with.
799
- * @param clientSecret - the client secret to authenticate with.
800
- * @param authCode - the auth code received from the server.
801
- */
802
- public async getAccessToken(
803
- clientId: string,
804
- clientSecret: string,
805
- authCode: string
806
- ): Promise<SasAuthResponse> {
807
- return getAccessTokenForViya(
808
- this.requestClient,
809
- clientId,
810
- clientSecret,
811
- authCode
812
- )
813
- }
814
-
815
- /**
816
- * Exchanges the refresh token for an access token for the given client.
817
- * This method can only be used by Node.
818
- * @param clientId - the client ID to authenticate with.
819
- * @param clientSecret - the client secret to authenticate with.
820
- * @param refreshToken - the refresh token received from the server.
821
- */
822
- public async refreshTokens(
823
- clientId: string,
824
- clientSecret: string,
825
- refreshToken: string
826
- ) {
827
- return refreshTokensForViya(
828
- this.requestClient,
829
- clientId,
830
- clientSecret,
831
- refreshToken
832
- )
833
- }
834
-
835
- /**
836
- * Deletes the client representing the supplied ID.
837
- * @param clientId - the client ID to authenticate with.
838
- * @param accessToken - an access token for authorizing the request.
839
- */
840
- public async deleteClient(clientId: string, accessToken?: string) {
841
- const url = this.serverUrl + `/oauth/clients/${clientId}`
842
- const headers: any = {}
843
- if (accessToken) {
844
- headers.Authorization = `Bearer ${accessToken}`
845
- }
846
-
847
- const deleteResponse = await this.requestClient.delete(url, accessToken)
848
-
849
- return deleteResponse.result
850
- }
851
-
852
- /**
853
- * Executes a job via the SAS Viya Compute API.
854
- * @param sasJob - the relative path to the job.
855
- * @param contextName - the name of the context where the job is to be executed.
856
- * @param debug - sets the _debug flag in the job arguments.
857
- * @param data - any data to be passed in as input to the job.
858
- * @param accessToken - an optional access token for an authorized user.
859
- * @param waitForResult - a boolean indicating if the function should wait for a result.
860
- * @param expectWebout - a boolean indicating whether to expect a _webout response.
861
- * @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.
862
- * @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
863
- * @param variables - an object that represents macro variables.
864
- */
865
- public async executeComputeJob(
866
- sasJob: string,
867
- contextName: string,
868
- debug?: boolean,
869
- data?: any,
870
- authConfig?: AuthConfig,
871
- waitForResult = true,
872
- expectWebout = false,
873
- pollOptions?: PollOptions,
874
- printPid = false,
875
- variables?: MacroVar,
876
- onTokensRefreshed?: OnTokensRefreshed
877
- ) {
878
- let access_token = (authConfig || {}).access_token
879
- if (authConfig) {
880
- ;({ access_token } = await getTokens(
881
- this.requestClient,
882
- authConfig,
883
- ServerType.SasViya,
884
- onTokensRefreshed
885
- ))
886
- }
887
-
888
- if (isRelativePath(sasJob) && !this.rootFolderName) {
889
- throw new Error(
890
- 'Relative paths cannot be used without specifying a root folder name'
891
- )
892
- }
893
-
894
- const folderPathParts = sasJob.split('/')
895
- const jobName = folderPathParts.pop()
896
- const folderPath = folderPathParts.join('/')
897
- const fullFolderPath = isRelativePath(sasJob)
898
- ? `${this.rootFolderName}/${folderPath}`
899
- : folderPath
900
-
901
- await this.populateFolderMap(fullFolderPath, access_token).catch((err) => {
902
- throw prefixMessage(err, 'Error while populating folder map. ')
903
- })
904
-
905
- const jobFolder = this.folderMap.get(fullFolderPath)
906
-
907
- if (!jobFolder) {
908
- throw new Error(
909
- `The folder '${fullFolderPath}' was not found on '${this.serverUrl}'`
910
- )
911
- }
912
-
913
- const jobToExecute = jobFolder?.find((item) => item.name === jobName)
914
-
915
- if (!jobToExecute) {
916
- throw new Error(`Job was not found.`)
917
- }
918
-
919
- let code = jobToExecute?.code
920
-
921
- if (!code) {
922
- const jobDefinitionLink = jobToExecute?.links.find(
923
- (l) => l.rel === 'getResource'
924
- )
925
-
926
- if (!jobDefinitionLink) {
927
- throw new Error(`URI of job definition was not found.`)
928
- }
929
-
930
- const { result: jobDefinition } = await this.requestClient
931
- .get<JobDefinition>(
932
- `${this.serverUrl}${jobDefinitionLink.href}`,
933
- access_token
934
- )
935
- .catch((err) => {
936
- throw prefixMessage(err, 'Error while getting job definition. ')
937
- })
938
-
939
- code = jobDefinition.code
940
-
941
- // Adds code to existing job definition
942
- jobToExecute.code = code
943
- }
944
-
945
- if (!code) code = ''
946
-
947
- const linesToExecute = code.replace(/\r\n/g, '\n').split('\n')
948
-
949
- return await this.executeScript(
950
- sasJob,
951
- linesToExecute,
952
- contextName,
953
- authConfig,
954
- data,
955
- debug,
956
- expectWebout,
957
- waitForResult,
958
- pollOptions,
959
- printPid,
960
- variables,
961
- onTokensRefreshed
962
- )
963
- }
964
-
965
- /**
966
- * Executes a job via the SAS Viya Job Execution API
967
- * @param sasJob - the relative or absolute path to the job.
968
- * @param contextName - the name of the context where the job is to be executed.
969
- * @param debug - sets the _debug flag in the job arguments.
970
- * @param data - any data to be passed in as input to the job.
971
- * @param accessToken - an optional access token for an authorized user.
972
- * @param onTokensRefreshed - optional callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
973
- */
974
- public async executeJob(
975
- sasJob: string,
976
- contextName: string,
977
- debug: boolean,
978
- data?: any,
979
- authConfig?: AuthConfig,
980
- onTokensRefreshed?: OnTokensRefreshed
981
- ): Promise<JobExecutionResult> {
982
- let access_token = (authConfig || {}).access_token
983
-
984
- if (authConfig) {
985
- ;({ access_token } = await getTokens(
986
- this.requestClient,
987
- authConfig,
988
- ServerType.SasViya,
989
- onTokensRefreshed
990
- ))
991
- }
992
-
993
- if (isRelativePath(sasJob) && !this.rootFolderName) {
994
- throw new Error(
995
- 'Relative paths cannot be used without specifying a root folder name.'
996
- )
997
- }
998
-
999
- const folderPathParts = sasJob.split('/')
1000
- const jobName = folderPathParts.pop()
1001
- const folderPath = folderPathParts.join('/')
1002
- const fullFolderPath = isRelativePath(sasJob)
1003
- ? `${this.rootFolderName}/${folderPath}`
1004
- : folderPath
1005
-
1006
- await this.populateFolderMap(fullFolderPath, access_token)
1007
-
1008
- const jobFolder = this.folderMap.get(fullFolderPath)
1009
- if (!jobFolder) {
1010
- throw new Error(
1011
- `The folder '${fullFolderPath}' was not found on '${this.serverUrl}'.`
1012
- )
1013
- }
1014
-
1015
- const jobToExecute = jobFolder?.find((item) => item.name === jobName)
1016
-
1017
- let files: any[] = []
1018
- if (data && Object.keys(data).length) {
1019
- files = await this.uploadTables(data, access_token)
1020
- }
1021
-
1022
- if (!jobToExecute) throw new Error(`Job was not found.`)
1023
-
1024
- const jobDefinitionLink = jobToExecute?.links.find(
1025
- (l) => l.rel === 'getResource'
1026
- )?.href
1027
-
1028
- const { result: jobDefinition } = await this.requestClient.get<Job>(
1029
- `${this.serverUrl}${jobDefinitionLink}`,
1030
- access_token
1031
- )
1032
-
1033
- const jobArguments: { [key: string]: any } = {
1034
- _contextName: contextName,
1035
- _program: `${fullFolderPath}/${jobName}`,
1036
- _webin_file_count: files.length,
1037
- _OMITJSONLISTING: true,
1038
- _OMITJSONLOG: true,
1039
- _omitSessionResults: false,
1040
- _OMITTEXTLISTING: true,
1041
- _OMITTEXTLOG: true
1042
- }
1043
-
1044
- if (debug) {
1045
- jobArguments['_OMITTEXTLOG'] = 'false'
1046
- jobArguments['_omitSessionResults'] = 'false'
1047
- jobArguments['_DEBUG'] = 131
1048
- }
1049
-
1050
- files.forEach((fileInfo, index) => {
1051
- jobArguments[`_webin_fileuri${index + 1}`] =
1052
- `/files/files/${fileInfo.file.id}`
1053
- jobArguments[`_webin_name${index + 1}`] = fileInfo.tableName
1054
- })
1055
-
1056
- // Viya JES requires arguments to be Map<String,String>; coerce booleans/numbers.
1057
- const stringifiedArguments: { [key: string]: string } = {}
1058
- for (const k of Object.keys(jobArguments)) {
1059
- stringifiedArguments[k] = String(jobArguments[k])
1060
- }
1061
-
1062
- const postJobRequestBody = {
1063
- name: `exec-${jobName}`,
1064
- description: 'Powered by SASjs',
1065
- jobDefinition,
1066
- arguments: stringifiedArguments
1067
- }
1068
-
1069
- const { result: postedJob } = await this.requestClient.post<Job>(
1070
- `${this.serverUrl}/jobExecution/jobs?_action=wait`,
1071
- postJobRequestBody,
1072
- access_token
1073
- )
1074
-
1075
- const jobStatus = await this.pollJobState(
1076
- postedJob,
1077
- authConfig,
1078
- undefined,
1079
- onTokensRefreshed
1080
- ).catch((err) => {
1081
- throw prefixMessage(err, 'Error while polling job status. ')
1082
- })
1083
-
1084
- const { result: currentJob } = await this.requestClient.get<Job>(
1085
- `${this.serverUrl}/jobExecution/jobs/${postedJob.id}`,
1086
- access_token
1087
- )
1088
-
1089
- let jobResult
1090
- let log
1091
-
1092
- const resultLink = currentJob.results['_webout.json']
1093
- const logLink = currentJob.links.find((l) => l.rel === 'log')
1094
-
1095
- if (resultLink) {
1096
- jobResult = await this.requestClient.get<any>(
1097
- `${this.serverUrl}${resultLink}/content`,
1098
- access_token,
1099
- 'text/plain'
1100
- )
1101
- }
1102
-
1103
- if (debug && logLink) {
1104
- log = await this.requestClient
1105
- .get<any>(`${this.serverUrl}${logLink.href}/content`, access_token)
1106
- .then((res: any) => res.result.items.map((i: any) => i.line).join('\n'))
1107
- }
1108
-
1109
- if (jobStatus === 'failed') {
1110
- throw new JobExecutionError(
1111
- currentJob.error?.errorCode,
1112
- currentJob.error?.message,
1113
- log
1114
- )
1115
- }
1116
-
1117
- const executionResult: JobExecutionResult = {
1118
- result: jobResult?.result,
1119
- log
1120
- }
1121
-
1122
- const { error } = currentJob
1123
- if (error) executionResult.error = error
1124
-
1125
- return executionResult
1126
- }
1127
-
1128
- private async populateFolderMap(folderPath: string, accessToken?: string) {
1129
- const path = isRelativePath(folderPath)
1130
- ? `${this.rootFolderName}/${folderPath}`
1131
- : folderPath
1132
- if (this.folderMap.get(path)) {
1133
- return
1134
- }
1135
-
1136
- const url = '/folders/folders/@item?path=' + path
1137
- const { result: folder } = await this.requestClient
1138
- .get<Folder>(`${url}`, accessToken)
1139
- .catch((err) => {
1140
- throw prefixMessage(err, 'Error while getting folder. ')
1141
- })
1142
-
1143
- if (!folder) {
1144
- throw new Error(`The path ${path} does not exist on ${this.serverUrl}`)
1145
- }
1146
-
1147
- const { result: members } = await this.requestClient
1148
- .get<{ items: any[] }>(
1149
- `/folders/folders/${folder.id}/members?limit=${
1150
- folder.memberCount < 500 ? 500 : folder.memberCount
1151
- }`, // this is a fix for https://github.com/sasjs/adapter/issues/669
1152
- accessToken
1153
- )
1154
- .catch((err) => {
1155
- throw prefixMessage(err, 'Error while getting members. ')
1156
- })
1157
-
1158
- const itemsAtRoot = members.items
1159
-
1160
- this.folderMap.set(path, itemsAtRoot)
1161
- }
1162
-
1163
- private async pollJobState(
1164
- postedJob: Job,
1165
- authConfig?: AuthConfig,
1166
- pollOptions?: PollOptions,
1167
- onTokensRefreshed?: OnTokensRefreshed
1168
- ) {
1169
- return pollJobState(
1170
- this.requestClient,
1171
- postedJob,
1172
- this.debug,
1173
- authConfig,
1174
- pollOptions,
1175
- undefined,
1176
- onTokensRefreshed
1177
- )
1178
- }
1179
-
1180
- private async uploadTables(data: any, accessToken?: string) {
1181
- return uploadTables(this.requestClient, data, accessToken)
1182
- }
1183
-
1184
- private async getFolderDetails(
1185
- folderPath: string,
1186
- accessToken?: string
1187
- ): Promise<Folder | undefined> {
1188
- const url = isUri(folderPath)
1189
- ? folderPath
1190
- : `/folders/folders/@item?path=${folderPath}`
1191
-
1192
- const { result: folder } = await this.requestClient
1193
- .get<Folder>(`${this.serverUrl}${url}`, accessToken)
1194
- .catch((err) => {
1195
- if (err instanceof CertificateError) throw err
1196
- return { result: null }
1197
- })
1198
-
1199
- if (!folder) return undefined
1200
-
1201
- return folder
1202
- }
1203
-
1204
- private async getFolderUri(folderPath: string, accessToken?: string) {
1205
- const folderDetails = await this.getFolderDetails(folderPath, accessToken)
1206
-
1207
- if (!folderDetails) return undefined
1208
-
1209
- return `/folders/folders/${folderDetails.id}`
1210
- }
1211
-
1212
- private async getFileUri(
1213
- folderPath: string,
1214
- fileName: string,
1215
- accessToken?: string
1216
- ): Promise<string> {
1217
- const folderMembers = await this.listFolder(folderPath, accessToken, 1000, {
1218
- returnDetails: true
1219
- }).catch((err) => {
1220
- throw prefixMessage(err, `Error while listing folder: ${folderPath}. `)
1221
- })
1222
-
1223
- if (!folderMembers || !folderMembers.length)
1224
- throw new Error(`No members found in folder: ${folderPath}`)
1225
-
1226
- const fileUri = folderMembers.find(
1227
- (member) => member.name === fileName
1228
- )?.uri
1229
-
1230
- if (!fileUri)
1231
- throw new Error(`File ${fileName} not found in folder: ${folderPath}`)
1232
-
1233
- return fileUri
1234
- }
1235
-
1236
- private async getRecycleBinUri(accessToken?: string) {
1237
- const url = '/folders/folders/@myRecycleBin'
1238
-
1239
- const { result: folder } = await this.requestClient
1240
- .get<Folder>(`${this.serverUrl}${url}`, accessToken)
1241
- .catch((err) => {
1242
- if (err instanceof CertificateError) throw err
1243
- return { result: null }
1244
- })
1245
-
1246
- if (!folder) return undefined
1247
-
1248
- return `/folders/folders/${folder.id}`
1249
- }
1250
-
1251
- /**
1252
- * Returns a JSON representation of a compute context.
1253
- * @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
1254
- * @param contextName - the name of the context to return.
1255
- * @param accessToken - an access token for an authorized user.
1256
- */
1257
- public async getComputeContextByName(
1258
- contextName: string,
1259
- accessToken?: string
1260
- ): Promise<Context> {
1261
- return await this.contextManager.getComputeContextByName(
1262
- contextName,
1263
- accessToken
1264
- )
1265
- }
1266
-
1267
- /**
1268
- * Returns a JSON representation of a compute context.
1269
- * @param contextId - an id of the context to return.
1270
- * @param accessToken - an access token for an authorized user.
1271
- */
1272
- public async getComputeContextById(
1273
- contextId: string,
1274
- accessToken?: string
1275
- ): Promise<ContextAllAttributes> {
1276
- return await this.contextManager.getComputeContextById(
1277
- contextId,
1278
- accessToken
1279
- )
1280
- }
1281
-
1282
- /**
1283
- * Lists children folders/files for given Viya folder.
1284
- * @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.
1285
- * @param accessToken - an access token for authorizing the request.
1286
- * @param {Object} [options] - Additional options.
1287
- * @param {boolean} [options.returnDetails=false] - when set to true, the function will return an array of objects with member details, otherwise it will return an array of member names.
1288
- */
1289
- public async listFolder(
1290
- sourceFolder: string,
1291
- accessToken?: string,
1292
- limit: number = 20,
1293
- options?: {
1294
- returnDetails?: boolean
1295
- }
1296
- ) {
1297
- // checks if 'sourceFolder' is already a URI
1298
- const sourceFolderUri = isUri(sourceFolder)
1299
- ? sourceFolder
1300
- : await this.getFolderUri(sourceFolder, accessToken)
1301
-
1302
- const { result: members } = await this.requestClient.get<{ items: any[] }>(
1303
- `${this.serverUrl}${sourceFolderUri}/members?limit=${limit}`,
1304
- accessToken
1305
- )
1306
-
1307
- let membersToReturn = []
1308
-
1309
- if (members && members.items) {
1310
- // If returnDetails is true, return full member details
1311
- if (options?.returnDetails) {
1312
- membersToReturn = members.items
1313
- } else {
1314
- // If returnDetails is false, return only member names
1315
- membersToReturn = members.items.map((item: any) => item.name)
1316
- }
1317
- }
1318
-
1319
- // Return members without Etag
1320
- return membersToReturn
1321
- }
1322
-
1323
- /**
1324
- * Moves Viya folder to a new location. The folder may be renamed at the same time.
1325
- * @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.
1326
- * @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 the path will save one extra request.
1327
- * @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.
1328
- * @param accessToken - an access token for authorizing the request.
1329
- */
1330
- public async moveFolder(
1331
- sourceFolder: string,
1332
- targetParentFolder: string,
1333
- targetFolderName: string,
1334
- accessToken?: string
1335
- ) {
1336
- // If target path is an existing folder, than keep source folder name, othervise rename it with given target folder name
1337
- const sourceFolderName = sourceFolder.split('/').pop() as string
1338
- const targetFolderDetails = await this.getFolderDetails(
1339
- targetParentFolder,
1340
- accessToken
1341
- )
1342
-
1343
- if (!targetFolderDetails) {
1344
- let targetParentFolderArr = targetParentFolder.split('/')
1345
- targetParentFolderArr.splice(targetParentFolderArr.length - 1, 1)
1346
- targetParentFolder = targetParentFolderArr.join('/')
1347
- } else {
1348
- targetFolderName = sourceFolderName
1349
- }
1350
-
1351
- // checks if 'sourceFolder' is already an URI
1352
- const sourceFolderUri = await this.getFolderUri(sourceFolder, accessToken)
1353
-
1354
- // checks if 'targetParentFolder' is already a URI
1355
- const targetParentFolderUri = await this.getFolderUri(
1356
- targetParentFolder,
1357
- accessToken
1358
- )
1359
-
1360
- if (!sourceFolderUri) {
1361
- return undefined
1362
- }
1363
- const sourceFolderId = sourceFolderUri?.split('/').pop()
1364
-
1365
- const { result: folder } = await this.requestClient
1366
- .patch<Folder>(
1367
- `${this.serverUrl}${sourceFolderUri}`,
1368
- {
1369
- id: sourceFolderId,
1370
- name: targetFolderName,
1371
- parentFolderUri: targetParentFolderUri
1372
- },
1373
- accessToken
1374
- )
1375
- .catch((err) => {
1376
- if (err.code && err.code === 'ENOTFOUND') {
1377
- const notFoundError = {
1378
- body: {
1379
- message: `Folder '${sourceFolder
1380
- .split('/')
1381
- .pop()}' was not found.`
1382
- }
1383
- }
1384
-
1385
- throw notFoundError
1386
- }
1387
-
1388
- throw err
1389
- })
1390
-
1391
- if (!folder) return undefined
1392
-
1393
- return folder
1394
- }
1395
-
1396
- /**
1397
- * 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.
1398
- * @param folderPath - the full path (eg `/Public/example/deleteThis`) of the folder to be deleted.
1399
- * @param accessToken - an access token for authorizing the request.
1400
- */
1401
- public async deleteFolder(folderPath: string, accessToken?: string) {
1402
- const recycleBinUri = await this.getRecycleBinUri(accessToken)
1403
- const folderName = folderPath.split('/').pop() || ''
1404
- const date = new Date()
1405
- const timeMark = date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
1406
- const deletedFolderName = folderName + ' ' + timeMark
1407
-
1408
- const movedFolder = await this.moveFolder(
1409
- folderPath,
1410
- recycleBinUri!,
1411
- deletedFolderName,
1412
- accessToken
1413
- )
1414
-
1415
- return movedFolder
1416
- }
1417
- }