@api-client/core 0.3.11 → 0.4.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 (356) hide show
  1. package/build/browser.d.ts +10 -8
  2. package/build/browser.js +11 -7
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +12 -11
  5. package/build/index.js +9 -9
  6. package/build/index.js.map +1 -1
  7. package/build/src/data/JmesparthReader.d.ts +1 -1
  8. package/build/src/data/JmesparthReader.js +1 -1
  9. package/build/src/events/models/ProjectEvents.d.ts +1 -1
  10. package/build/src/events/models/ProjectEvents.js +1 -2
  11. package/build/src/events/models/ProjectEvents.js.map +1 -1
  12. package/build/src/lib/transformers/PayloadSerializer.d.ts +2 -2
  13. package/build/src/lib/transformers/PayloadSerializer.js +3 -3
  14. package/build/src/lib/transformers/PayloadSerializer.js.map +1 -1
  15. package/build/src/mocking/ProjectMock.d.ts +7 -1
  16. package/build/src/mocking/ProjectMock.js +6 -0
  17. package/build/src/mocking/ProjectMock.js.map +1 -1
  18. package/build/src/mocking/lib/History.d.ts +70 -0
  19. package/build/src/mocking/lib/History.js +120 -0
  20. package/build/src/mocking/lib/History.js.map +1 -0
  21. package/build/src/mocking/lib/Request.d.ts +2 -2
  22. package/build/src/mocking/lib/Request.js +3 -2
  23. package/build/src/mocking/lib/Request.js.map +1 -1
  24. package/build/src/mocking/lib/Response.d.ts +6 -6
  25. package/build/src/mocking/lib/Response.js +6 -6
  26. package/build/src/mocking/lib/Response.js.map +1 -1
  27. package/build/src/mocking/lib/User.d.ts +20 -0
  28. package/build/src/mocking/lib/User.js +54 -0
  29. package/build/src/mocking/lib/User.js.map +1 -0
  30. package/build/src/models/AuthorizationData.d.ts +2 -2
  31. package/build/src/models/AuthorizationData.js +2 -2
  32. package/build/src/models/Backend.d.ts +85 -0
  33. package/build/src/models/ClientCertificate.d.ts +1 -1
  34. package/build/src/models/Environment.d.ts +3 -3
  35. package/build/src/models/Environment.js +3 -3
  36. package/build/src/models/Environment.js.map +1 -1
  37. package/build/src/models/ErrorResponse.d.ts +1 -1
  38. package/build/src/models/ErrorResponse.js +1 -1
  39. package/build/src/models/HostRule.d.ts +4 -4
  40. package/build/src/models/HostRule.js +4 -4
  41. package/build/src/models/HostRule.js.map +1 -1
  42. package/build/src/models/HttpHistory.d.ts +64 -18
  43. package/build/src/models/HttpHistory.js +43 -19
  44. package/build/src/models/HttpHistory.js.map +1 -1
  45. package/build/src/models/HttpProject.d.ts +4 -5
  46. package/build/src/models/HttpProject.js +3 -3
  47. package/build/src/models/HttpProject.js.map +1 -1
  48. package/build/src/models/HttpProjectListItem.d.ts +1 -1
  49. package/build/src/models/HttpProjectListItem.js +1 -1
  50. package/build/src/models/HttpProjectListItem.js.map +1 -1
  51. package/build/src/models/HttpRequest.d.ts +2 -2
  52. package/build/src/models/HttpRequest.js +2 -2
  53. package/build/src/models/HttpRequest.js.map +1 -1
  54. package/build/src/models/HttpResponse.d.ts +2 -2
  55. package/build/src/models/HttpResponse.js +3 -3
  56. package/build/src/models/HttpResponse.js.map +1 -1
  57. package/build/src/models/License.d.ts +3 -3
  58. package/build/src/models/License.js +3 -3
  59. package/build/src/models/License.js.map +1 -1
  60. package/build/src/models/ProjectFolder.d.ts +2 -2
  61. package/build/src/models/ProjectFolder.js +3 -3
  62. package/build/src/models/ProjectFolder.js.map +1 -1
  63. package/build/src/models/ProjectItem.d.ts +1 -1
  64. package/build/src/models/ProjectItem.js +2 -2
  65. package/build/src/models/ProjectItem.js.map +1 -1
  66. package/build/src/models/ProjectRequest.d.ts +2 -2
  67. package/build/src/models/ProjectRequest.js +1 -1
  68. package/build/src/models/ProjectRequest.js.map +1 -1
  69. package/build/src/models/ProjectSchema.d.ts +2 -2
  70. package/build/src/models/ProjectSchema.js +1 -1
  71. package/build/src/models/ProjectSchema.js.map +1 -1
  72. package/build/src/models/Property.d.ts +4 -4
  73. package/build/src/models/Property.js +4 -4
  74. package/build/src/models/Property.js.map +1 -1
  75. package/build/src/models/Provider.d.ts +3 -3
  76. package/build/src/models/Provider.js +3 -3
  77. package/build/src/models/Provider.js.map +1 -1
  78. package/build/src/models/Request.d.ts +2 -2
  79. package/build/src/models/Request.js +3 -3
  80. package/build/src/models/Request.js.map +1 -1
  81. package/build/src/models/RequestActions.d.ts +2 -4
  82. package/build/src/models/RequestActions.js +2 -4
  83. package/build/src/models/RequestActions.js.map +1 -1
  84. package/build/src/models/RequestAuthorization.d.ts +3 -5
  85. package/build/src/models/RequestAuthorization.js +2 -4
  86. package/build/src/models/RequestAuthorization.js.map +1 -1
  87. package/build/src/models/RequestConfig.d.ts +3 -5
  88. package/build/src/models/RequestConfig.js +1 -3
  89. package/build/src/models/RequestConfig.js.map +1 -1
  90. package/build/src/models/RequestLog.d.ts +14 -8
  91. package/build/src/models/RequestLog.js +18 -7
  92. package/build/src/models/RequestLog.js.map +1 -1
  93. package/build/src/models/RequestTime.d.ts +4 -6
  94. package/build/src/models/RequestTime.js +2 -4
  95. package/build/src/models/RequestTime.js.map +1 -1
  96. package/build/src/models/RequestUiMeta.d.ts +5 -5
  97. package/build/src/models/RequestUiMeta.js +2 -2
  98. package/build/src/models/RequestUiMeta.js.map +1 -1
  99. package/build/src/models/RequestsSize.d.ts +1 -3
  100. package/build/src/models/RequestsSize.js +1 -3
  101. package/build/src/models/RequestsSize.js.map +1 -1
  102. package/build/src/models/{ArcResponse.d.ts → Response.d.ts} +7 -9
  103. package/build/src/models/{ArcResponse.js → Response.js} +4 -6
  104. package/build/src/models/Response.js.map +1 -0
  105. package/build/src/models/ResponseAuthorization.d.ts +3 -3
  106. package/build/src/models/ResponseAuthorization.js +3 -3
  107. package/build/src/models/ResponseAuthorization.js.map +1 -1
  108. package/build/src/models/ResponseRedirect.d.ts +3 -5
  109. package/build/src/models/ResponseRedirect.js +1 -3
  110. package/build/src/models/ResponseRedirect.js.map +1 -1
  111. package/build/src/models/RevisionInfo.d.ts +1 -1
  112. package/build/src/models/RevisionInfo.js +1 -1
  113. package/build/src/models/RevisionInfo.js.map +1 -1
  114. package/build/src/models/SentRequest.d.ts +2 -4
  115. package/build/src/models/SentRequest.js +1 -3
  116. package/build/src/models/SentRequest.js.map +1 -1
  117. package/build/src/models/Server.d.ts +3 -3
  118. package/build/src/models/Server.js +3 -3
  119. package/build/src/models/Server.js.map +1 -1
  120. package/build/src/models/Thing.d.ts +3 -3
  121. package/build/src/models/Thing.js +3 -3
  122. package/build/src/models/Thing.js.map +1 -1
  123. package/build/src/models/Url.d.ts +2 -4
  124. package/build/src/models/Url.js +2 -4
  125. package/build/src/models/Url.js.map +1 -1
  126. package/build/src/models/User.d.ts +2 -1
  127. package/build/src/models/User.js +1 -1
  128. package/build/src/models/User.js.map +1 -1
  129. package/build/src/models/WebApi.d.ts +1 -1
  130. package/build/src/models/WebApi.js +1 -1
  131. package/build/src/models/WebApi.js.map +1 -1
  132. package/build/src/models/WebApiIndex.d.ts +1 -1
  133. package/build/src/models/WebApiIndex.js +1 -1
  134. package/build/src/models/WebApiIndex.js.map +1 -1
  135. package/build/src/models/Workspace.d.ts +4 -4
  136. package/build/src/models/Workspace.js +4 -4
  137. package/build/src/models/Workspace.js.map +1 -1
  138. package/build/src/models/actions/Action.d.ts +2 -2
  139. package/build/src/models/actions/Action.js +1 -1
  140. package/build/src/models/actions/Action.js.map +1 -1
  141. package/build/src/models/actions/Condition.d.ts +2 -2
  142. package/build/src/models/actions/Condition.js +1 -1
  143. package/build/src/models/actions/Condition.js.map +1 -1
  144. package/build/src/models/actions/RunnableAction.d.ts +1 -1
  145. package/build/src/models/actions/RunnableAction.js +1 -1
  146. package/build/src/models/actions/RunnableAction.js.map +1 -1
  147. package/build/src/models/actions/runnable/DeleteCookieAction.d.ts +2 -2
  148. package/build/src/models/actions/runnable/DeleteCookieAction.js +1 -1
  149. package/build/src/models/actions/runnable/DeleteCookieAction.js.map +1 -1
  150. package/build/src/models/actions/runnable/SetCookieAction.d.ts +2 -2
  151. package/build/src/models/actions/runnable/SetCookieAction.js +1 -1
  152. package/build/src/models/actions/runnable/SetCookieAction.js.map +1 -1
  153. package/build/src/models/actions/runnable/SetVariableAction.d.ts +2 -2
  154. package/build/src/models/actions/runnable/SetVariableAction.js +1 -1
  155. package/build/src/models/actions/runnable/SetVariableAction.js.map +1 -1
  156. package/build/src/models/transformers/ImportUtils.d.ts +1 -1
  157. package/build/src/models/transformers/ImportUtils.js +1 -1
  158. package/build/src/models/transformers/PostmanBackupTransformer.js +2 -1
  159. package/build/src/models/transformers/PostmanBackupTransformer.js.map +1 -1
  160. package/build/src/models/transformers/PostmanV21Transformer.js +2 -1
  161. package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
  162. package/build/src/models/transformers/PostmanV2Transformer.js +2 -1
  163. package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
  164. package/build/src/runtime/actions/RunnableCondition.d.ts +6 -7
  165. package/build/src/runtime/actions/RunnableCondition.js +4 -5
  166. package/build/src/runtime/actions/RunnableCondition.js.map +1 -1
  167. package/build/src/runtime/http-engine/{ArcEngine.d.ts → CoreEngine.d.ts} +3 -3
  168. package/build/src/runtime/http-engine/{ArcEngine.js → CoreEngine.js} +8 -8
  169. package/build/src/runtime/http-engine/CoreEngine.js.map +1 -0
  170. package/build/src/runtime/http-engine/HttpEngine.d.ts +3 -3
  171. package/build/src/runtime/http-engine/HttpEngine.js +3 -20
  172. package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
  173. package/build/src/runtime/modules/BasicAuthCache.js +2 -5
  174. package/build/src/runtime/modules/BasicAuthCache.js.map +1 -1
  175. package/build/src/runtime/modules/RequestCookies.d.ts +1 -1
  176. package/build/src/runtime/modules/RequestCookies.js +3 -2
  177. package/build/src/runtime/modules/RequestCookies.js.map +1 -1
  178. package/build/src/runtime/node/InteropInterfaces.d.ts +115 -0
  179. package/build/src/runtime/node/InteropInterfaces.js +2 -0
  180. package/build/src/runtime/node/InteropInterfaces.js.map +1 -0
  181. package/build/src/runtime/node/ProjectParallelRunner.d.ts +2 -7
  182. package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
  183. package/build/src/runtime/node/ProjectRequestRunner.d.ts +17 -49
  184. package/build/src/runtime/node/ProjectRequestRunner.js +39 -10
  185. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
  186. package/build/src/runtime/node/ProjectRunner.d.ts +1 -59
  187. package/build/src/runtime/node/ProjectRunner.js.map +1 -1
  188. package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
  189. package/build/src/runtime/node/RequestFactory.d.ts +1 -1
  190. package/build/src/runtime/node/RequestFactory.js +3 -3
  191. package/build/src/runtime/node/RequestFactory.js.map +1 -1
  192. package/build/src/runtime/reporters/ProjectRunCliReporter.js.map +1 -1
  193. package/build/src/runtime/reporters/Reporter.js.map +1 -1
  194. package/build/src/runtime/store/AuthSdk.d.ts +28 -0
  195. package/build/src/runtime/store/AuthSdk.js +123 -0
  196. package/build/src/runtime/store/AuthSdk.js.map +1 -0
  197. package/build/src/runtime/store/BackendSdk.d.ts +8 -0
  198. package/build/src/runtime/store/BackendSdk.js +25 -0
  199. package/build/src/runtime/store/BackendSdk.js.map +1 -0
  200. package/build/src/runtime/store/HistorySdk.d.ts +48 -0
  201. package/build/src/runtime/store/HistorySdk.js +142 -0
  202. package/build/src/runtime/store/HistorySdk.js.map +1 -0
  203. package/build/src/runtime/store/Http.d.ts +14 -0
  204. package/build/src/runtime/store/Http.js +4 -0
  205. package/build/src/runtime/store/Http.js.map +1 -0
  206. package/build/src/runtime/store/HttpNode.d.ts +16 -0
  207. package/build/src/runtime/store/HttpNode.js +95 -0
  208. package/build/src/runtime/store/HttpNode.js.map +1 -0
  209. package/build/src/runtime/store/HttpWeb.d.ts +15 -0
  210. package/build/src/runtime/store/HttpWeb.js +83 -0
  211. package/build/src/runtime/store/HttpWeb.js.map +1 -0
  212. package/build/src/runtime/store/ProjectsSdk.d.ts +43 -0
  213. package/build/src/runtime/store/ProjectsSdk.js +144 -0
  214. package/build/src/runtime/store/ProjectsSdk.js.map +1 -0
  215. package/build/src/runtime/store/RouteBuilder.d.ts +42 -0
  216. package/build/src/runtime/store/RouteBuilder.js +75 -0
  217. package/build/src/runtime/store/RouteBuilder.js.map +1 -0
  218. package/build/src/runtime/store/Sdk.d.ts +79 -0
  219. package/build/src/runtime/store/Sdk.js +117 -0
  220. package/build/src/runtime/store/Sdk.js.map +1 -0
  221. package/build/src/runtime/store/SdkBase.d.ts +45 -0
  222. package/build/src/runtime/store/SdkBase.js +40 -0
  223. package/build/src/runtime/store/SdkBase.js.map +1 -0
  224. package/build/src/runtime/store/SpacesSdk.d.ts +50 -0
  225. package/build/src/runtime/store/SpacesSdk.js +185 -0
  226. package/build/src/runtime/store/SpacesSdk.js.map +1 -0
  227. package/build/src/runtime/store/StoreSdkNode.d.ts +10 -0
  228. package/build/src/runtime/store/StoreSdkNode.js +11 -0
  229. package/build/src/runtime/store/StoreSdkNode.js.map +1 -0
  230. package/build/src/runtime/store/StoreSdkWeb.d.ts +10 -0
  231. package/build/src/runtime/store/StoreSdkWeb.js +11 -0
  232. package/build/src/runtime/store/StoreSdkWeb.js.map +1 -0
  233. package/build/src/runtime/store/UsersSdk.d.ts +18 -0
  234. package/build/src/runtime/store/UsersSdk.js +88 -0
  235. package/build/src/runtime/store/UsersSdk.js.map +1 -0
  236. package/build/src/runtime/store/WsClient.d.ts +24 -0
  237. package/build/src/runtime/store/WsClient.js +4 -0
  238. package/build/src/runtime/store/WsClient.js.map +1 -0
  239. package/build/src/runtime/store/WsClientNode.d.ts +24 -0
  240. package/build/src/runtime/store/WsClientNode.js +66 -0
  241. package/build/src/runtime/store/WsClientNode.js.map +1 -0
  242. package/build/src/runtime/store/WsClientWeb.d.ts +23 -0
  243. package/build/src/runtime/store/WsClientWeb.js +73 -0
  244. package/build/src/runtime/store/WsClientWeb.js.map +1 -0
  245. package/package.json +6 -8
  246. package/readme.md +5 -5
  247. package/src/data/JmesparthReader.ts +1 -1
  248. package/src/events/models/ProjectEvents.ts +2 -2
  249. package/src/events/readme.md +1 -1
  250. package/src/lib/transformers/PayloadSerializer.ts +3 -3
  251. package/src/mocking/ProjectMock.ts +9 -1
  252. package/src/mocking/lib/History.ts +179 -0
  253. package/src/mocking/lib/Request.ts +5 -5
  254. package/src/mocking/lib/Response.ts +10 -10
  255. package/src/mocking/lib/User.ts +68 -0
  256. package/src/models/AuthorizationData.ts +2 -2
  257. package/src/models/Backend.ts +93 -0
  258. package/src/models/ClientCertificate.ts +1 -1
  259. package/src/models/Environment.ts +4 -4
  260. package/src/models/ErrorResponse.ts +1 -1
  261. package/src/models/HostRule.ts +5 -5
  262. package/src/models/HttpHistory.ts +89 -27
  263. package/src/models/HttpProject.ts +5 -6
  264. package/src/models/HttpProjectListItem.ts +1 -1
  265. package/src/models/HttpRequest.ts +2 -2
  266. package/src/models/HttpResponse.ts +3 -3
  267. package/src/models/License.ts +4 -4
  268. package/src/models/ProjectFolder.ts +3 -3
  269. package/src/models/ProjectItem.ts +2 -2
  270. package/src/models/ProjectRequest.ts +2 -2
  271. package/src/models/ProjectSchema.ts +2 -2
  272. package/src/models/Property.ts +5 -5
  273. package/src/models/Provider.ts +4 -4
  274. package/src/models/README.md +2 -2
  275. package/src/models/Request.ts +4 -4
  276. package/src/models/RequestActions.ts +2 -4
  277. package/src/models/RequestAuthorization.ts +3 -5
  278. package/src/models/RequestConfig.ts +3 -5
  279. package/src/models/RequestLog.ts +25 -11
  280. package/src/models/RequestTime.ts +4 -6
  281. package/src/models/RequestUiMeta.ts +5 -5
  282. package/src/models/RequestsSize.ts +1 -3
  283. package/src/models/{ArcResponse.ts → Response.ts} +12 -14
  284. package/src/models/ResponseAuthorization.ts +4 -4
  285. package/src/models/ResponseRedirect.ts +3 -5
  286. package/src/models/RevisionInfo.ts +1 -1
  287. package/src/models/SentRequest.ts +2 -4
  288. package/src/models/Server.ts +4 -4
  289. package/src/models/Thing.ts +4 -4
  290. package/src/models/Url.ts +2 -4
  291. package/src/models/User.ts +2 -1
  292. package/src/models/WebApi.ts +1 -1
  293. package/src/models/WebApiIndex.ts +1 -1
  294. package/src/models/Workspace.ts +5 -5
  295. package/src/models/actions/Action.ts +2 -2
  296. package/src/models/actions/Condition.ts +2 -2
  297. package/src/models/actions/RunnableAction.ts +1 -1
  298. package/src/models/actions/runnable/DeleteCookieAction.ts +2 -2
  299. package/src/models/actions/runnable/SetCookieAction.ts +2 -2
  300. package/src/models/actions/runnable/SetVariableAction.ts +2 -2
  301. package/src/models/transformers/ImportUtils.ts +1 -1
  302. package/src/models/transformers/PostmanBackupTransformer.ts +2 -1
  303. package/src/models/transformers/PostmanV21Transformer.ts +2 -1
  304. package/src/models/transformers/PostmanV2Transformer.ts +2 -1
  305. package/src/runtime/actions/RunnableCondition.ts +6 -7
  306. package/src/runtime/http-engine/{ArcEngine.ts → CoreEngine.ts} +7 -7
  307. package/src/runtime/http-engine/HttpEngine.ts +5 -24
  308. package/src/runtime/modules/BasicAuthCache.ts +2 -6
  309. package/src/runtime/modules/RequestCookies.ts +6 -5
  310. package/src/runtime/node/InteropInterfaces.ts +121 -0
  311. package/src/runtime/node/ProjectParallelRunner.ts +2 -9
  312. package/src/runtime/node/ProjectRequestRunner.ts +42 -61
  313. package/src/runtime/node/ProjectRunner.ts +1 -60
  314. package/src/runtime/node/ProjectRunnerWorker.ts +2 -1
  315. package/src/runtime/node/RequestFactory.ts +3 -3
  316. package/src/runtime/reporters/ProjectRunCliReporter.ts +2 -2
  317. package/src/runtime/reporters/Reporter.ts +4 -4
  318. package/src/runtime/store/AuthSdk.ts +126 -0
  319. package/src/runtime/store/BackendSdk.ts +25 -0
  320. package/src/runtime/store/HistorySdk.ts +157 -0
  321. package/src/runtime/store/Http.ts +18 -0
  322. package/src/runtime/store/HttpNode.ts +100 -0
  323. package/src/runtime/store/HttpWeb.ts +89 -0
  324. package/src/runtime/store/ProjectsSdk.ts +147 -0
  325. package/src/runtime/store/RouteBuilder.ts +89 -0
  326. package/src/runtime/store/Sdk.ts +131 -0
  327. package/src/runtime/store/SdkBase.ts +72 -0
  328. package/src/runtime/store/SpacesSdk.ts +190 -0
  329. package/src/runtime/store/StoreSdkNode.ts +13 -0
  330. package/src/runtime/store/StoreSdkWeb.ts +13 -0
  331. package/src/runtime/store/UsersSdk.ts +89 -0
  332. package/src/runtime/store/WsClient.ts +28 -0
  333. package/src/runtime/store/WsClientNode.ts +68 -0
  334. package/src/runtime/store/WsClientWeb.ts +75 -0
  335. package/build/src/models/ArcResponse.js.map +0 -1
  336. package/build/src/models/HistoryIndex.d.ts +0 -43
  337. package/build/src/models/HistoryIndex.js +0 -53
  338. package/build/src/models/HistoryIndex.js.map +0 -1
  339. package/build/src/models/HistoryRequest.d.ts +0 -13
  340. package/build/src/models/HistoryRequest.js +0 -25
  341. package/build/src/models/HistoryRequest.js.map +0 -1
  342. package/build/src/runtime/http-engine/ArcEngine.js.map +0 -1
  343. package/build/src/runtime/http-engine/NodeEngine.d.ts +0 -154
  344. package/build/src/runtime/http-engine/NodeEngine.js +0 -766
  345. package/build/src/runtime/http-engine/NodeEngine.js.map +0 -1
  346. package/build/src/runtime/http-engine/NodeEngineDirect.d.ts +0 -113
  347. package/build/src/runtime/http-engine/NodeEngineDirect.js +0 -449
  348. package/build/src/runtime/http-engine/NodeEngineDirect.js.map +0 -1
  349. package/build/src/runtime/store/StoreSdk.d.ts +0 -279
  350. package/build/src/runtime/store/StoreSdk.js +0 -840
  351. package/build/src/runtime/store/StoreSdk.js.map +0 -1
  352. package/src/models/HistoryIndex.ts +0 -76
  353. package/src/models/HistoryRequest.ts +0 -28
  354. package/src/runtime/http-engine/NodeEngine.ts +0 -792
  355. package/src/runtime/http-engine/NodeEngineDirect.ts +0 -482
  356. package/src/runtime/store/StoreSdk.ts +0 -895
@@ -1,5 +1,5 @@
1
1
  import { IRequestLog } from '../../models/RequestLog.js';
2
- import { IArcResponse } from '../../models/ArcResponse.js';
2
+ import { IResponse } from '../../models/Response.js';
3
3
  import { ErrorResponse } from '../../models/ErrorResponse.js';
4
4
 
5
5
  export interface IProjectExecutionIteration {
@@ -56,7 +56,7 @@ export abstract class Reporter {
56
56
  if (!log.response || ErrorResponse.isErrorResponse(log.response)) {
57
57
  return true;
58
58
  }
59
- const response = log.response as IArcResponse;
59
+ const response = log.response as IResponse;
60
60
  if (response.status >= 400) {
61
61
  return true;
62
62
  }
@@ -93,7 +93,7 @@ export abstract class Reporter {
93
93
  if (!log.response || ErrorResponse.isErrorResponse(log.response)) {
94
94
  return;
95
95
  }
96
- const response = log.response as IArcResponse;
96
+ const response = log.response as IResponse;
97
97
  if (response.status < 400) {
98
98
  result++;
99
99
  }
@@ -114,7 +114,7 @@ export abstract class Reporter {
114
114
  if (!log.response || ErrorResponse.isErrorResponse(log.response)) {
115
115
  return;
116
116
  }
117
- const response = log.response as IArcResponse;
117
+ const response = log.response as IResponse;
118
118
  if (response.loadingTime && response.loadingTime > 0) {
119
119
  result += response.loadingTime;
120
120
  }
@@ -0,0 +1,126 @@
1
+ import { SdkBase, IStoreTokenInfo } from './SdkBase.js';
2
+ import { RouteBuilder } from './RouteBuilder.js';
3
+ import { Headers } from '../../lib/headers/Headers.js';
4
+ import WebSocketNode from 'ws';
5
+
6
+ export class AuthSdk extends SdkBase {
7
+ protected getExpires(headers: Headers): number | undefined {
8
+ const expires = headers.get('expires');
9
+ if (!expires) {
10
+ return undefined;
11
+ }
12
+ const d = new Date(expires);
13
+ const time = d.getTime();
14
+ if (Number.isNaN(time)) {
15
+ console.warn(`Invalid session response: the expires header cannot be parsed.`);
16
+ return undefined;
17
+ }
18
+ return time;
19
+ }
20
+
21
+ /**
22
+ * Creates unauthenticated session in the backend.
23
+ * @returns The JWT for unauthenticated user.
24
+ */
25
+ async createSession(): Promise<IStoreTokenInfo> {
26
+ const url = this.sdk.getUrl(RouteBuilder.sessions());
27
+ // console.log('Create session: ', url);
28
+ const result = await this.sdk.http.post(url.toString());
29
+ this.inspectCommonStatusCodes(result.status);
30
+ if (result.status !== 200) {
31
+ throw new Error(`Unable to create the session. Invalid response status: ${result.status}`);
32
+ }
33
+ if (!result.body) {
34
+ throw new Error(`Unable to create the session. Response has no token.`);
35
+ }
36
+ const info: IStoreTokenInfo = {
37
+ token: result.body,
38
+ };
39
+ const expires = this.getExpires(result.headers);
40
+ if (expires) {
41
+ info.expires = expires;
42
+ }
43
+ return info;
44
+ }
45
+
46
+ /**
47
+ * Initializes the authentication session.
48
+ * @param token The unauthenticated session JWT. Required when not set on the class.
49
+ * @returns The location of the authorization endpoint.
50
+ */
51
+ async createAuthSession(token?: string, loginPath = '/auth/login'): Promise<string> {
52
+ const url = this.sdk.getUrl(loginPath);
53
+ const result = await this.sdk.http.post(url.toString(), { token });
54
+ this.inspectCommonStatusCodes(result.status);
55
+ const loc = result.headers.get('location');
56
+ if (!loc) {
57
+ throw new Error(`The location header not returned by the server.`);
58
+ }
59
+ return loc;
60
+ }
61
+
62
+ /**
63
+ * Listens to the first message coming to the client from the auth endpoint.
64
+ * @param authPath The authorization path returned by the server info or 401 response.
65
+ * @param token Optional token to use.
66
+ */
67
+ async listenAuth(authPath: string, token?: string): Promise<void> {
68
+ const url = this.sdk.getUrl(authPath);
69
+ const client = await this.sdk.ws.createAndConnect(url.toString(), token);
70
+ return new Promise((resolve, reject) => {
71
+ const { sdk } = this;
72
+ async function finishData(data: any): Promise<void> {
73
+ let message: any;
74
+ try {
75
+ message = JSON.parse(data.toString());
76
+ await sdk.ws.disconnect(client);
77
+ } catch (cause) {
78
+ reject(cause);
79
+ return;
80
+ }
81
+ if (message.status === 'OK') {
82
+ resolve();
83
+ } else {
84
+ reject(new Error(message.message || 'Unknown error'));
85
+ }
86
+ }
87
+ const typedNode = client as WebSocketNode;
88
+ if (typeof typedNode.on === 'function') {
89
+ typedNode.on('message', (data: Buffer) => {
90
+ finishData(data);
91
+ });
92
+ } else {
93
+ const typedWeb = client as WebSocket;
94
+ typedWeb.addEventListener('message', (event) => {
95
+ finishData(event.data);
96
+ });
97
+ }
98
+ });
99
+ }
100
+
101
+ /**
102
+ * Renews authenticated token to a new one when the token expires.
103
+ * @param token Optional token to use.
104
+ * @returns
105
+ */
106
+ async renewToken(token = this.sdk.token): Promise<IStoreTokenInfo> {
107
+ const authPath = RouteBuilder.sessionRenew();
108
+ const url = this.sdk.getUrl(authPath);
109
+ const result = await this.sdk.http.post(url.toString(), { token });
110
+ this.inspectCommonStatusCodes(result.status);
111
+ if (result.status !== 200) {
112
+ throw new Error(`Unable to renew the token. Invalid response status: ${result.status}`);
113
+ }
114
+ if (!result.body) {
115
+ throw new Error(`Unable to create the session. Response has no token.`);
116
+ }
117
+ const info: IStoreTokenInfo = {
118
+ token: result.body,
119
+ };
120
+ const expires = this.getExpires(result.headers);
121
+ if (expires) {
122
+ info.expires = expires;
123
+ }
124
+ return info;
125
+ }
126
+ }
@@ -0,0 +1,25 @@
1
+ import { SdkBase } from './SdkBase.js';
2
+ import { RouteBuilder } from './RouteBuilder.js';
3
+ import { IBackendInfo } from '../../models/Backend.js';
4
+
5
+ export class BackendSdk extends SdkBase {
6
+ /**
7
+ * @returns Client information about the store configuration.
8
+ */
9
+ async getInfo(): Promise<IBackendInfo> {
10
+ const url = this.sdk.getUrl(RouteBuilder.backend());
11
+ const result = await this.sdk.http.get(url.toString());
12
+ this.inspectCommonStatusCodes(result.status);
13
+ if (result.status !== 200) {
14
+ throw new Error(`Invalid store response. Expected 200 status and ${result.status} received.`);
15
+ }
16
+ const body = result.body as string;
17
+ let data;
18
+ try {
19
+ data = JSON.parse(body);
20
+ } catch (e) {
21
+ throw new Error(`The server returned invalid response. Unable to read store status.`);
22
+ }
23
+ return data as IBackendInfo;
24
+ }
25
+ }
@@ -0,0 +1,157 @@
1
+ import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
2
+ import { RouteBuilder } from './RouteBuilder.js';
3
+ import { IListResponse, HistoryListOptions } from '../../models/Backend.js';
4
+ import { IHttpHistory, IHttpHistoryBulkAdd, Kind as HttpHistoryKind } from '../../models/HttpHistory.js';
5
+
6
+ export class HistorySdk extends SdkBase {
7
+ /**
8
+ * Creates a history object.
9
+ * A history object can be created per app (type = app) or a store's space/[project/[request]].
10
+ *
11
+ * The user can always read their own history. If the history is created for a space/project then
12
+ * history records are shared as any other object in the space.
13
+ *
14
+ * Note, history objects cannot be updated. They can only be created or deleted.
15
+ *
16
+ * @param history The history to create
17
+ * @returns The key of the created history.
18
+ */
19
+ async create(history: IHttpHistory): Promise<string> {
20
+ const { token } = this.sdk;
21
+ const url = this.sdk.getUrl(RouteBuilder.history());
22
+ const body = JSON.stringify(history);
23
+ const result = await this.sdk.http.post(url.toString(), { token, body });
24
+ this.inspectCommonStatusCodes(result.status);
25
+ const E_PREFIX = 'Unable to create a history. ';
26
+ if (result.status !== 200) {
27
+ this.logInvalidResponse(result);
28
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
29
+ }
30
+ const location = result.headers.get('location');
31
+ if (!location) {
32
+ throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
33
+ }
34
+ const id = location.split('/').pop();
35
+ return id as string;
36
+ }
37
+
38
+ /**
39
+ * Creates a multiple history objects in a batch operation.
40
+ *
41
+ * @param info The bulk create info object.
42
+ */
43
+ async createBulk(info: IHttpHistoryBulkAdd): Promise<string[]> {
44
+ const { token } = this.sdk;
45
+ const url = this.sdk.getUrl(RouteBuilder.historyBatchCreate());
46
+ const body = JSON.stringify(info);
47
+ const result = await this.sdk.http.post(url.toString(), { token, body });
48
+ this.inspectCommonStatusCodes(result.status);
49
+ const E_PREFIX = 'Unable to create a bulk history. ';
50
+ if (result.status !== 200) {
51
+ this.logInvalidResponse(result);
52
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
53
+ }
54
+ if (!result.body) {
55
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
56
+ }
57
+ let data: string[];
58
+ try {
59
+ data = JSON.parse(result.body);
60
+ } catch (e) {
61
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
62
+ }
63
+ return data;
64
+ }
65
+
66
+ /**
67
+ * Lists the history.
68
+ *
69
+ * @param options Optional query options.
70
+ */
71
+ async list(options: HistoryListOptions): Promise<IListResponse> {
72
+ const { token } = this.sdk;
73
+ const url = this.sdk.getUrl(RouteBuilder.history());
74
+ this.sdk.appendListOptions(url, options);
75
+ const result = await this.sdk.http.get(url.toString(), { token });
76
+ this.inspectCommonStatusCodes(result.status);
77
+ const E_PREFIX = 'Unable to list history. ';
78
+ if (result.status !== 200) {
79
+ this.logInvalidResponse(result);
80
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
81
+ }
82
+ if (!result.body) {
83
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
84
+ }
85
+ let data: IListResponse;
86
+ try {
87
+ data = JSON.parse(result.body);
88
+ } catch (e) {
89
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
90
+ }
91
+ if (!Array.isArray(data.data)) {
92
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
93
+ }
94
+ return data;
95
+ }
96
+
97
+ /**
98
+ * Deletes a history object form the store.
99
+ *
100
+ * @param key The key returned by the store when created the history. Also available via the `key` property on the history object.
101
+ */
102
+ delete(key: string): Promise<void>;
103
+ /**
104
+ * Deletes a list of history objects in a batch operation.
105
+ *
106
+ * @param keys The keys returned by the store when created the history. Also available via the `key` property on the history object.
107
+ */
108
+ delete(keys: string[]): Promise<void>;
109
+ /**
110
+ * Deletes a history or a list of history objects from the store.
111
+ * @param key A key or a list of keys.
112
+ */
113
+ async delete(key: string | string[]): Promise<void> {
114
+ const { token } = this.sdk;
115
+ const isArray = Array.isArray(key);
116
+ const path = isArray ? RouteBuilder.historyBatchDelete() : RouteBuilder.historyItem(key);
117
+ const url = this.sdk.getUrl(path);
118
+
119
+ const result = isArray ? await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(key) }) : await this.sdk.http.delete(url.toString(), { token });
120
+ this.inspectCommonStatusCodes(result.status);
121
+ const E_PREFIX = 'Unable to delete history. ';
122
+ if (result.status !== 204) {
123
+ this.logInvalidResponse(result);
124
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Reads a history definition from the store.
130
+ * @param key The history key
131
+ * @returns The history object
132
+ */
133
+ async read(key: string): Promise<IHttpHistory> {
134
+ const { token } = this.sdk;
135
+ const url = this.sdk.getUrl(RouteBuilder.historyItem(key));
136
+ const result = await this.sdk.http.get(url.toString(), { token });
137
+ this.inspectCommonStatusCodes(result.status);
138
+ const E_PREFIX = 'Unable to read a history. ';
139
+ if (result.status !== 200) {
140
+ this.logInvalidResponse(result);
141
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
142
+ }
143
+ if (!result.body) {
144
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
145
+ }
146
+ let data: IHttpHistory;
147
+ try {
148
+ data = JSON.parse(result.body);
149
+ } catch (e) {
150
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
151
+ }
152
+ if (data.kind !== HttpHistoryKind) {
153
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
154
+ }
155
+ return data;
156
+ }
157
+ }
@@ -0,0 +1,18 @@
1
+ import { SdkBase, IStoreRequestOptions, IStoreResponse } from './SdkBase.js';
2
+
3
+ export abstract class Http extends SdkBase {
4
+ /**
5
+ * Performs the GET request.
6
+ *
7
+ * @param url The request URL
8
+ * @param opts The request options
9
+ * @returns The response info.
10
+ */
11
+ abstract get(url: string, opts?: IStoreRequestOptions): Promise<IStoreResponse>;
12
+
13
+ abstract post(url: string, opts?: IStoreRequestOptions): Promise<IStoreResponse>;
14
+
15
+ abstract patch(url: string, opts?: IStoreRequestOptions): Promise<IStoreResponse>;
16
+
17
+ abstract delete(url: string, opts?: IStoreRequestOptions): Promise<IStoreResponse>;
18
+ }
@@ -0,0 +1,100 @@
1
+ import http from 'http';
2
+ import https from 'https';
3
+ import { Headers } from '../../lib/headers/Headers.js';
4
+ import { Http } from './Http.js';
5
+ import { IStoreRequestOptions, IStoreResponse } from './SdkBase.js';
6
+
7
+ export class HttpNode extends Http {
8
+ /**
9
+ * Performs the GET request.
10
+ *
11
+ * @param url The request URL
12
+ * @param opts The request options
13
+ * @returns The response info.
14
+ */
15
+ async get(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
16
+ const result = await this._get(url, opts);
17
+ if ([301, 302, 308, 307].includes(result.status)) {
18
+ const loc = result.headers.get('location');
19
+ if (!loc) {
20
+ throw new Error('Expected redirection but no "location" header.')
21
+ }
22
+ const newUrl = new URL(loc, url);
23
+ return this.get(newUrl.toString(), opts);
24
+ }
25
+ return result;
26
+ }
27
+
28
+ private _get(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
29
+ return new Promise((resolve, reject) => {
30
+ const { method='GET', headers={}, token = this.sdk.token } = opts;
31
+ if (token) {
32
+ headers.authorization = `Bearer ${token}`;
33
+ }
34
+ const isSsl = url.startsWith('https:');
35
+ const lib = isSsl ? https : http;
36
+ // console.log(`${method} ${url}`);
37
+ const request = lib.request(url, {
38
+ method,
39
+ headers,
40
+ rejectUnauthorized: false,
41
+ });
42
+ request.on('response', (response) => {
43
+ const ro: IStoreResponse = {
44
+ status: response.statusCode as number,
45
+ headers: new Headers(response.headers),
46
+ body: '',
47
+ };
48
+ response.on('data', (chunk) => {
49
+ ro.body += chunk;
50
+ });
51
+ response.on('end', () => resolve(ro));
52
+ });
53
+ request.on('error', (error) => reject(error));
54
+ request.end();
55
+ });
56
+ }
57
+
58
+ post(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
59
+ return new Promise((resolve, reject) => {
60
+ const { method='POST', headers={}, token = this.sdk.token } = opts;
61
+ if (token) {
62
+ headers.authorization = `Bearer ${token}`;
63
+ }
64
+ const isSsl = url.startsWith('https:');
65
+ const lib = isSsl ? https : http;
66
+ const request = lib.request(url, {
67
+ method,
68
+ headers,
69
+ });
70
+ request.on('response', (response) => {
71
+ const ro: IStoreResponse = {
72
+ status: response.statusCode as number,
73
+ headers: new Headers(response.headers),
74
+ body: '',
75
+ };
76
+ response.on('data', (chunk) => {
77
+ ro.body += chunk;
78
+ });
79
+ response.on('end', () => resolve(ro));
80
+ });
81
+ request.on('error', (error) => reject(error));
82
+ if (opts.body) {
83
+ request.write(opts.body);
84
+ }
85
+ request.end();
86
+ });
87
+ }
88
+
89
+ patch(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
90
+ const options = { ...opts };
91
+ options.method = 'PATCH';
92
+ return this.post(url, options);
93
+ }
94
+
95
+ delete(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
96
+ const options = { ...opts };
97
+ options.method = 'DELETE';
98
+ return this.post(url, options);
99
+ }
100
+ }
@@ -0,0 +1,89 @@
1
+ import { Http } from './Http.js';
2
+ import { IStoreRequestOptions, IStoreResponse } from './SdkBase.js';
3
+ import { Headers } from '../../lib/headers/Headers.js';
4
+
5
+ export class HttpWeb extends Http {
6
+ /**
7
+ * Performs the GET request.
8
+ *
9
+ * @param url The request URL
10
+ * @param opts The request options
11
+ * @returns The response info.
12
+ */
13
+ async get(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
14
+ const { method='GET', headers={}, token = this.sdk.token } = opts;
15
+ if (token) {
16
+ headers.authorization = `Bearer ${token}`;
17
+ }
18
+ // eslint-disable-next-line no-undef
19
+ const init: RequestInit = {
20
+ method,
21
+ headers,
22
+ redirect: 'follow',
23
+ };
24
+ const response = await fetch(url, init);
25
+ let body: string | undefined;
26
+ try {
27
+ body = await response.text();
28
+ } catch (e) {
29
+ // ...
30
+ }
31
+
32
+ const responseHeaders = new Headers();
33
+ response.headers.forEach((value: string, key: string) => {
34
+ responseHeaders.append(key, value);
35
+ });
36
+
37
+ const result: IStoreResponse = {
38
+ status: response.status,
39
+ headers: responseHeaders,
40
+ body,
41
+ };
42
+ return result;
43
+ }
44
+
45
+ async post(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
46
+ const { method='POST', headers={}, token = this.sdk.token } = opts;
47
+ if (token) {
48
+ headers.authorization = `Bearer ${token}`;
49
+ }
50
+ // eslint-disable-next-line no-undef
51
+ const init: RequestInit = {
52
+ method,
53
+ headers,
54
+ redirect: 'follow',
55
+ };
56
+ if (opts.body) {
57
+ init.body = opts.body.toString();
58
+ }
59
+ const response = await fetch(url, init);
60
+ let body: string | undefined;
61
+ try {
62
+ body = await response.text();
63
+ } catch (e) {
64
+ // ...
65
+ }
66
+
67
+ const responseHeaders = new Headers();
68
+ response.headers.forEach((value: string, key: string) => {
69
+ responseHeaders.append(key, value);
70
+ });
71
+
72
+ const result: IStoreResponse = {
73
+ status: response.status,
74
+ headers: responseHeaders,
75
+ body,
76
+ };
77
+ return result;
78
+ }
79
+
80
+ patch(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
81
+ const options: IStoreRequestOptions = { ...opts, method: 'PATCH' };
82
+ return this.post(url, options);
83
+ }
84
+
85
+ delete(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
86
+ const options: IStoreRequestOptions = { ...opts, method: 'DELETE' };
87
+ return this.post(url, options);
88
+ }
89
+ }
@@ -0,0 +1,147 @@
1
+ import { JsonPatch } from 'json8-patch';
2
+ import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
3
+ import { RouteBuilder } from './RouteBuilder.js';
4
+ import { IListOptions, IListResponse } from '../../models/Backend.js';
5
+ import { HttpProject, IHttpProject, Kind as HttpProjectKind } from '../../models/HttpProject.js';
6
+
7
+ export class ProjectsSdk extends SdkBase {
8
+ /**
9
+ * Creates a project in a user space.
10
+ *
11
+ * @param space The user space key
12
+ * @param project THe project to create
13
+ * @returns The key of the created project.
14
+ */
15
+ async create(space: string, project: IHttpProject | HttpProject): Promise<string> {
16
+ const { token } = this.sdk;
17
+ const url = this.sdk.getUrl(RouteBuilder.spaceProjects(space));
18
+ const body = JSON.stringify(project);
19
+ const result = await this.sdk.http.post(url.toString(), { token, body });
20
+ this.inspectCommonStatusCodes(result.status);
21
+ const E_PREFIX = 'Unable to create a project. ';
22
+ if (result.status !== 204) {
23
+ this.logInvalidResponse(result);
24
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
25
+ }
26
+ const location = result.headers.get('location');
27
+ if (!location) {
28
+ throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
29
+ }
30
+ const id = location.split('/').pop();
31
+ return id as string;
32
+ }
33
+
34
+ /**
35
+ * Reads a project definition from the store.
36
+ * @param space The user space key
37
+ * @param project The project key
38
+ * @returns The definition of the project.
39
+ */
40
+ async read(space: string, project: string): Promise<IHttpProject> {
41
+ const { token } = this.sdk;
42
+ const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
43
+ const result = await this.sdk.http.get(url.toString(), { token });
44
+ this.inspectCommonStatusCodes(result.status);
45
+ const E_PREFIX = 'Unable to read a project. ';
46
+ if (result.status !== 200) {
47
+ this.logInvalidResponse(result);
48
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
49
+ }
50
+ if (!result.body) {
51
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
52
+ }
53
+ let data: IHttpProject;
54
+ try {
55
+ data = JSON.parse(result.body);
56
+ } catch (e) {
57
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
58
+ }
59
+ if (data.kind !== HttpProjectKind) {
60
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
61
+ }
62
+ return data;
63
+ }
64
+
65
+ /**
66
+ * Lists projects in the space
67
+ *
68
+ * @param space The user space key
69
+ * @param options Optional query options.
70
+ */
71
+ async list(space: string, options?: IListOptions): Promise<IListResponse> {
72
+ const { token } = this.sdk;
73
+ const url = this.sdk.getUrl(RouteBuilder.spaceProjects(space));
74
+ this.sdk.appendListOptions(url, options);
75
+ const result = await this.sdk.http.get(url.toString(), { token });
76
+ this.inspectCommonStatusCodes(result.status);
77
+ const E_PREFIX = 'Unable to list projects. ';
78
+ if (result.status !== 200) {
79
+ this.logInvalidResponse(result);
80
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
81
+ }
82
+ if (!result.body) {
83
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
84
+ }
85
+ let data: IListResponse;
86
+ try {
87
+ data = JSON.parse(result.body);
88
+ } catch (e) {
89
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
90
+ }
91
+ if (!Array.isArray(data.data)) {
92
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
93
+ }
94
+ return data;
95
+ }
96
+
97
+ /**
98
+ * Deletes a project form the store.
99
+ *
100
+ * @param space The key of the parent space.
101
+ * @param project The key of the project to delete.
102
+ */
103
+ async delete(space: string, project: string): Promise<void> {
104
+ const { token } = this.sdk;
105
+ const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
106
+ const result = await this.sdk.http.delete(url.toString(), { token });
107
+ this.inspectCommonStatusCodes(result.status);
108
+ const E_PREFIX = 'Unable to delete a project. ';
109
+ if (result.status !== 204) {
110
+ this.logInvalidResponse(result);
111
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Patches a project in the store.
117
+ * @param space The key of the parent user space
118
+ * @param project The key of project to patch.
119
+ * @param value The JSON patch to be processed.
120
+ * @returns The JSON patch to revert the change using the `json8-patch` library
121
+ */
122
+ async patch(space: string, project: string, value: JsonPatch): Promise<JsonPatch> {
123
+ const { token } = this.sdk;
124
+ const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
125
+ const body = JSON.stringify(value);
126
+ const result = await this.sdk.http.patch(url.toString(), { token, body });
127
+ this.inspectCommonStatusCodes(result.status);
128
+ const E_PREFIX = 'Unable to patch a project. ';
129
+ if (result.status !== 200) {
130
+ this.logInvalidResponse(result);
131
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
132
+ }
133
+ if (!result.body) {
134
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
135
+ }
136
+ let data: any;
137
+ try {
138
+ data = JSON.parse(result.body);
139
+ } catch (e) {
140
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
141
+ }
142
+ if (!data.revert) {
143
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
144
+ }
145
+ return data.revert as JsonPatch;
146
+ }
147
+ }