@api-client/core 0.6.31 → 0.7.2

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 (324) hide show
  1. package/build/browser.d.ts +6 -14
  2. package/build/browser.js +11 -16
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +8 -20
  5. package/build/index.js +13 -25
  6. package/build/index.js.map +1 -1
  7. package/build/src/amf/ApiSchemaValues.d.ts +2 -0
  8. package/build/src/amf/ApiSchemaValues.js +29 -23
  9. package/build/src/amf/ApiSchemaValues.js.map +1 -1
  10. package/build/src/authorization/lib/Utils.d.ts +1 -1
  11. package/build/src/cookies/CookieJar.d.ts +23 -0
  12. package/build/src/cookies/CookieJar.js +3 -0
  13. package/build/src/cookies/CookieJar.js.map +1 -0
  14. package/build/src/cookies/CookieParser.d.ts +67 -0
  15. package/build/src/cookies/CookieParser.js +316 -0
  16. package/build/src/cookies/CookieParser.js.map +1 -0
  17. package/build/src/cookies/InMemoryCookieJar.d.ts +12 -0
  18. package/build/src/cookies/InMemoryCookieJar.js +68 -0
  19. package/build/src/cookies/InMemoryCookieJar.js.map +1 -0
  20. package/build/src/cookies/Punycode.d.ts +12 -0
  21. package/build/src/cookies/Punycode.js +124 -0
  22. package/build/src/cookies/Punycode.js.map +1 -0
  23. package/build/src/data/RequestDataExtractor.d.ts +8 -7
  24. package/build/src/data/RequestDataExtractor.js +8 -10
  25. package/build/src/data/RequestDataExtractor.js.map +1 -1
  26. package/build/src/events/CustomEvent.js +5 -0
  27. package/build/src/events/CustomEvent.js.map +1 -1
  28. package/build/src/events/EventTypes.d.ts +43 -43
  29. package/build/src/events/amf/AmfEventTypes.d.ts +4 -4
  30. package/build/src/events/authorization/AuthorizationEventTypes.d.ts +4 -4
  31. package/build/src/events/cookies/CookieEventTypes.d.ts +9 -9
  32. package/build/src/events/encryption/EncryptionEventTypes.d.ts +2 -2
  33. package/build/src/events/environment/EnvironmentEventTypes.d.ts +1 -1
  34. package/build/src/events/models/ModelEventTypes.d.ts +7 -7
  35. package/build/src/events/process/ProcessEventTypes.d.ts +3 -3
  36. package/build/src/events/reporting/ReportingEventTypes.d.ts +1 -1
  37. package/build/src/events/telemetry/TelemetryEventTypes.d.ts +6 -6
  38. package/build/src/events/transport/TransportEventTypes.d.ts +6 -6
  39. package/build/src/events/transport/TransportEvents.d.ts +2 -2
  40. package/build/src/mocking/ProjectMock.d.ts +3 -2
  41. package/build/src/mocking/ProjectMock.js +3 -3
  42. package/build/src/mocking/ProjectMock.js.map +1 -1
  43. package/build/src/mocking/lib/App.d.ts +36 -0
  44. package/build/src/mocking/lib/App.js +70 -0
  45. package/build/src/mocking/lib/App.js.map +1 -0
  46. package/build/src/models/{arc/ArcProject.d.ts → AppProject.d.ts} +296 -134
  47. package/build/src/models/{arc/ArcProject.js → AppProject.js} +436 -79
  48. package/build/src/models/AppProject.js.map +1 -0
  49. package/build/src/models/AppRequest.d.ts +69 -0
  50. package/build/src/models/{arc/ArcHttpRequest.js → AppRequest.js} +53 -17
  51. package/build/src/models/AppRequest.js.map +1 -0
  52. package/build/src/models/ClientCertificate.d.ts +2 -2
  53. package/build/src/models/Environment.d.ts +8 -1
  54. package/build/src/models/Environment.js +21 -0
  55. package/build/src/models/Environment.js.map +1 -1
  56. package/build/src/models/HostRule.d.ts +2 -2
  57. package/build/src/models/HttpCookie.d.ts +63 -12
  58. package/build/src/models/HttpCookie.js +178 -44
  59. package/build/src/models/HttpCookie.js.map +1 -1
  60. package/build/src/models/HttpHistory.d.ts +8 -3
  61. package/build/src/models/HttpHistory.js +3 -3
  62. package/build/src/models/HttpHistory.js.map +1 -1
  63. package/build/src/models/HttpProject.d.ts +34 -1
  64. package/build/src/models/HttpProject.js +104 -8
  65. package/build/src/models/HttpProject.js.map +1 -1
  66. package/build/src/models/ProjectFolder.d.ts +2 -0
  67. package/build/src/models/ProjectFolder.js +14 -0
  68. package/build/src/models/ProjectFolder.js.map +1 -1
  69. package/build/src/models/ProjectItem.d.ts +2 -0
  70. package/build/src/models/ProjectItem.js +20 -0
  71. package/build/src/models/ProjectItem.js.map +1 -1
  72. package/build/src/models/ProjectParent.js.map +1 -1
  73. package/build/src/models/ProjectRequest.d.ts +3 -2
  74. package/build/src/models/ProjectRequest.js.map +1 -1
  75. package/build/src/models/Property.d.ts +2 -2
  76. package/build/src/models/Property.js +2 -2
  77. package/build/src/models/Property.js.map +1 -1
  78. package/build/src/models/Request.d.ts +16 -8
  79. package/build/src/models/Request.js +20 -15
  80. package/build/src/models/Request.js.map +1 -1
  81. package/build/src/models/RequestAuthorization.js.map +1 -1
  82. package/build/src/models/RequestUiMeta.d.ts +0 -14
  83. package/build/src/models/RequestUiMeta.js +1 -10
  84. package/build/src/models/RequestUiMeta.js.map +1 -1
  85. package/build/src/models/Server.d.ts +1 -2
  86. package/build/src/models/Server.js.map +1 -1
  87. package/build/src/models/http-actions/HttpActions.d.ts +256 -0
  88. package/build/src/models/http-actions/HttpActions.js +46 -0
  89. package/build/src/models/http-actions/HttpActions.js.map +1 -0
  90. package/build/src/models/http-actions/LegacyTranslator.d.ts +17 -0
  91. package/build/src/models/http-actions/LegacyTranslator.js +222 -0
  92. package/build/src/models/http-actions/LegacyTranslator.js.map +1 -0
  93. package/build/src/models/store/Backend.d.ts +136 -1
  94. package/build/src/models/store/File.d.ts +1 -1
  95. package/build/src/models/store/File.js +2 -0
  96. package/build/src/models/store/File.js.map +1 -1
  97. package/build/src/models/store/User.d.ts +3 -3
  98. package/build/src/runtime/http-engine/CoreEngine.d.ts +2 -0
  99. package/build/src/runtime/http-engine/CoreEngine.js +1 -0
  100. package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
  101. package/build/src/runtime/http-engine/HttpEngine.d.ts +13 -0
  102. package/build/src/runtime/http-engine/HttpEngine.js +39 -31
  103. package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
  104. package/build/src/runtime/{actions/ConditionRunner.d.ts → http-runner/ConditionCheck.d.ts} +2 -2
  105. package/build/src/runtime/{actions/ConditionRunner.js → http-runner/ConditionCheck.js} +2 -2
  106. package/build/src/runtime/http-runner/ConditionCheck.js.map +1 -0
  107. package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +62 -0
  108. package/build/src/runtime/http-runner/HttpFlowRunner.js +217 -0
  109. package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -0
  110. package/build/src/runtime/{node/RequestFactory.d.ts → http-runner/HttpRequestRunner.d.ts} +40 -54
  111. package/build/src/runtime/http-runner/HttpRequestRunner.js +316 -0
  112. package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -0
  113. package/build/src/runtime/http-runner/HttpRuntimeEnvironment.d.ts +25 -0
  114. package/build/src/runtime/http-runner/HttpRuntimeEnvironment.js +2 -0
  115. package/build/src/runtime/http-runner/HttpRuntimeEnvironment.js.map +1 -0
  116. package/build/src/runtime/http-runner/RequestAuthorizationProcessor.d.ts +56 -0
  117. package/build/src/runtime/http-runner/RequestAuthorizationProcessor.js +143 -0
  118. package/build/src/runtime/http-runner/RequestAuthorizationProcessor.js.map +1 -0
  119. package/build/src/runtime/http-runner/RequestCookiesProcessor.d.ts +24 -0
  120. package/build/src/runtime/http-runner/RequestCookiesProcessor.js +65 -0
  121. package/build/src/runtime/http-runner/RequestCookiesProcessor.js.map +1 -0
  122. package/build/src/runtime/node/InteropInterfaces.d.ts +21 -6
  123. package/build/src/runtime/node/ProjectParallelRunner.js +3 -1
  124. package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
  125. package/build/src/runtime/node/ProjectRequestRunner.d.ts +24 -10
  126. package/build/src/runtime/node/ProjectRequestRunner.js +116 -45
  127. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
  128. package/build/src/runtime/node/ProjectRunner.d.ts +5 -7
  129. package/build/src/runtime/node/ProjectRunner.js +30 -14
  130. package/build/src/runtime/node/ProjectRunner.js.map +1 -1
  131. package/build/src/runtime/node/ProjectRunnerWorker.js +3 -0
  132. package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
  133. package/build/src/runtime/reporters/Reporter.d.ts +5 -0
  134. package/build/src/runtime/reporters/Reporter.js.map +1 -1
  135. package/build/src/runtime/store/AppSdk.d.ts +185 -0
  136. package/build/src/runtime/store/AppSdk.js +704 -0
  137. package/build/src/runtime/store/AppSdk.js.map +1 -0
  138. package/build/src/runtime/store/FilesSdk.js +4 -4
  139. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  140. package/build/src/runtime/store/HistorySdk.js +2 -2
  141. package/build/src/runtime/store/HistorySdk.js.map +1 -1
  142. package/build/src/runtime/store/RouteBuilder.d.ts +17 -2
  143. package/build/src/runtime/store/RouteBuilder.js +60 -3
  144. package/build/src/runtime/store/RouteBuilder.js.map +1 -1
  145. package/build/src/runtime/store/Sdk.d.ts +5 -0
  146. package/build/src/runtime/store/Sdk.js +5 -0
  147. package/build/src/runtime/store/Sdk.js.map +1 -1
  148. package/build/src/runtime/store/SharedSdk.js +1 -1
  149. package/build/src/runtime/store/SharedSdk.js.map +1 -1
  150. package/build/src/runtime/store/UsersSdk.js +1 -1
  151. package/build/src/runtime/store/UsersSdk.js.map +1 -1
  152. package/package.json +2 -2
  153. package/src/amf/ApiSchemaValues.ts +41 -33
  154. package/src/cookies/CookieJar.ts +26 -0
  155. package/src/cookies/CookieParser.ts +327 -0
  156. package/src/cookies/InMemoryCookieJar.ts +70 -0
  157. package/src/cookies/Punycode.ts +133 -0
  158. package/src/data/RequestDataExtractor.ts +14 -15
  159. package/src/events/CustomEvent.ts +4 -0
  160. package/src/mocking/ProjectMock.ts +4 -3
  161. package/src/mocking/lib/App.ts +101 -0
  162. package/src/models/{arc/ArcProject.ts → AppProject.ts} +671 -225
  163. package/src/models/AppRequest.ts +176 -0
  164. package/src/models/ClientCertificate.ts +2 -2
  165. package/src/models/Environment.ts +24 -2
  166. package/src/models/HostRule.ts +2 -2
  167. package/src/models/HttpCookie.ts +210 -48
  168. package/src/models/HttpHistory.ts +12 -5
  169. package/src/models/HttpProject.ts +113 -10
  170. package/src/models/ProjectFolder.ts +16 -0
  171. package/src/models/ProjectItem.ts +18 -0
  172. package/src/models/ProjectParent.ts +4 -1
  173. package/src/models/ProjectRequest.ts +4 -3
  174. package/src/models/Property.ts +4 -4
  175. package/src/models/Request.ts +29 -19
  176. package/src/models/RequestAuthorization.ts +4 -4
  177. package/src/models/RequestUiMeta.ts +1 -21
  178. package/src/models/Server.ts +1 -2
  179. package/src/models/http-actions/HttpActions.ts +270 -0
  180. package/src/models/http-actions/LegacyTranslator.ts +223 -0
  181. package/src/models/store/Backend.ts +148 -2
  182. package/src/models/store/File.ts +3 -1
  183. package/src/models/store/User.ts +3 -3
  184. package/src/runtime/http-engine/CoreEngine.ts +3 -2
  185. package/src/runtime/http-engine/HttpEngine.ts +48 -30
  186. package/src/runtime/{actions/ConditionRunner.ts → http-runner/ConditionCheck.ts} +3 -3
  187. package/src/runtime/http-runner/HttpFlowRunner.ts +232 -0
  188. package/src/runtime/http-runner/HttpRequestRunner.ts +353 -0
  189. package/src/runtime/http-runner/HttpRuntimeEnvironment.ts +27 -0
  190. package/src/runtime/http-runner/RequestAuthorizationProcessor.ts +144 -0
  191. package/src/runtime/http-runner/RequestCookiesProcessor.ts +74 -0
  192. package/src/runtime/node/InteropInterfaces.ts +24 -6
  193. package/src/runtime/node/ProjectParallelRunner.ts +4 -2
  194. package/src/runtime/node/ProjectRequestRunner.ts +130 -60
  195. package/src/runtime/node/ProjectRunner.ts +37 -22
  196. package/src/runtime/node/ProjectRunnerWorker.ts +3 -0
  197. package/src/runtime/reporters/Reporter.ts +5 -0
  198. package/src/runtime/store/AppSdk.ts +709 -0
  199. package/src/runtime/store/FilesSdk.ts +4 -4
  200. package/src/runtime/store/HistorySdk.ts +2 -2
  201. package/src/runtime/store/RouteBuilder.ts +75 -3
  202. package/src/runtime/store/Sdk.ts +6 -0
  203. package/src/runtime/store/SharedSdk.ts +1 -1
  204. package/src/runtime/store/UsersSdk.ts +1 -1
  205. package/build/src/lib/cookies/Cookie.d.ts +0 -123
  206. package/build/src/lib/cookies/Cookie.js +0 -257
  207. package/build/src/lib/cookies/Cookie.js.map +0 -1
  208. package/build/src/lib/cookies/Cookies.d.ts +0 -90
  209. package/build/src/lib/cookies/Cookies.js +0 -310
  210. package/build/src/lib/cookies/Cookies.js.map +0 -1
  211. package/build/src/lib/cookies/Utils.d.ts +0 -47
  212. package/build/src/lib/cookies/Utils.js +0 -163
  213. package/build/src/lib/cookies/Utils.js.map +0 -1
  214. package/build/src/mocking/lib/Arc.d.ts +0 -9
  215. package/build/src/mocking/lib/Arc.js +0 -24
  216. package/build/src/mocking/lib/Arc.js.map +0 -1
  217. package/build/src/models/RequestActions.d.ts +0 -65
  218. package/build/src/models/RequestActions.js +0 -114
  219. package/build/src/models/RequestActions.js.map +0 -1
  220. package/build/src/models/actions/Action.d.ts +0 -75
  221. package/build/src/models/actions/Action.js +0 -188
  222. package/build/src/models/actions/Action.js.map +0 -1
  223. package/build/src/models/actions/ActionView.d.ts +0 -15
  224. package/build/src/models/actions/ActionView.js +0 -33
  225. package/build/src/models/actions/ActionView.js.map +0 -1
  226. package/build/src/models/actions/Condition.d.ts +0 -81
  227. package/build/src/models/actions/Condition.js +0 -185
  228. package/build/src/models/actions/Condition.js.map +0 -1
  229. package/build/src/models/actions/ConditionView.d.ts +0 -17
  230. package/build/src/models/actions/ConditionView.js +0 -34
  231. package/build/src/models/actions/ConditionView.js.map +0 -1
  232. package/build/src/models/actions/Enums.d.ts +0 -26
  233. package/build/src/models/actions/Enums.js +0 -31
  234. package/build/src/models/actions/Enums.js.map +0 -1
  235. package/build/src/models/actions/RunnableAction.d.ts +0 -59
  236. package/build/src/models/actions/RunnableAction.js +0 -106
  237. package/build/src/models/actions/RunnableAction.js.map +0 -1
  238. package/build/src/models/actions/runnable/DeleteCookieAction.d.ts +0 -44
  239. package/build/src/models/actions/runnable/DeleteCookieAction.js +0 -92
  240. package/build/src/models/actions/runnable/DeleteCookieAction.js.map +0 -1
  241. package/build/src/models/actions/runnable/Runnable.d.ts +0 -8
  242. package/build/src/models/actions/runnable/Runnable.js +0 -4
  243. package/build/src/models/actions/runnable/Runnable.js.map +0 -1
  244. package/build/src/models/actions/runnable/SetCookieAction.d.ts +0 -87
  245. package/build/src/models/actions/runnable/SetCookieAction.js +0 -176
  246. package/build/src/models/actions/runnable/SetCookieAction.js.map +0 -1
  247. package/build/src/models/actions/runnable/SetVariableAction.d.ts +0 -31
  248. package/build/src/models/actions/runnable/SetVariableAction.js +0 -63
  249. package/build/src/models/actions/runnable/SetVariableAction.js.map +0 -1
  250. package/build/src/models/actions/runnable/index.d.ts +0 -7
  251. package/build/src/models/actions/runnable/index.js +0 -2
  252. package/build/src/models/actions/runnable/index.js.map +0 -1
  253. package/build/src/models/arc/ArcHttpRequest.d.ts +0 -40
  254. package/build/src/models/arc/ArcHttpRequest.js.map +0 -1
  255. package/build/src/models/arc/ArcProject.js.map +0 -1
  256. package/build/src/runtime/actions/ActionRunner.d.ts +0 -17
  257. package/build/src/runtime/actions/ActionRunner.js +0 -74
  258. package/build/src/runtime/actions/ActionRunner.js.map +0 -1
  259. package/build/src/runtime/actions/ConditionRunner.js.map +0 -1
  260. package/build/src/runtime/actions/RunnableCondition.d.ts +0 -27
  261. package/build/src/runtime/actions/RunnableCondition.js +0 -50
  262. package/build/src/runtime/actions/RunnableCondition.js.map +0 -1
  263. package/build/src/runtime/actions/runnable/ActionRunnable.d.ts +0 -13
  264. package/build/src/runtime/actions/runnable/ActionRunnable.js +0 -13
  265. package/build/src/runtime/actions/runnable/ActionRunnable.js.map +0 -1
  266. package/build/src/runtime/actions/runnable/DeleteCookieRunnable.d.ts +0 -7
  267. package/build/src/runtime/actions/runnable/DeleteCookieRunnable.js +0 -36
  268. package/build/src/runtime/actions/runnable/DeleteCookieRunnable.js.map +0 -1
  269. package/build/src/runtime/actions/runnable/SetCookieRunnable.d.ts +0 -10
  270. package/build/src/runtime/actions/runnable/SetCookieRunnable.js +0 -89
  271. package/build/src/runtime/actions/runnable/SetCookieRunnable.js.map +0 -1
  272. package/build/src/runtime/actions/runnable/SetVariableRunnable.d.ts +0 -10
  273. package/build/src/runtime/actions/runnable/SetVariableRunnable.js +0 -49
  274. package/build/src/runtime/actions/runnable/SetVariableRunnable.js.map +0 -1
  275. package/build/src/runtime/modules/BasicAuthCache.d.ts +0 -39
  276. package/build/src/runtime/modules/BasicAuthCache.js +0 -122
  277. package/build/src/runtime/modules/BasicAuthCache.js.map +0 -1
  278. package/build/src/runtime/modules/ExecutionResponse.d.ts +0 -4
  279. package/build/src/runtime/modules/ExecutionResponse.js +0 -6
  280. package/build/src/runtime/modules/ExecutionResponse.js.map +0 -1
  281. package/build/src/runtime/modules/ModulesRegistry.d.ts +0 -93
  282. package/build/src/runtime/modules/ModulesRegistry.js +0 -69
  283. package/build/src/runtime/modules/ModulesRegistry.js.map +0 -1
  284. package/build/src/runtime/modules/RequestAuthorization.d.ts +0 -6
  285. package/build/src/runtime/modules/RequestAuthorization.js +0 -110
  286. package/build/src/runtime/modules/RequestAuthorization.js.map +0 -1
  287. package/build/src/runtime/modules/RequestCookies.d.ts +0 -17
  288. package/build/src/runtime/modules/RequestCookies.js +0 -134
  289. package/build/src/runtime/modules/RequestCookies.js.map +0 -1
  290. package/build/src/runtime/node/RequestFactory.js +0 -406
  291. package/build/src/runtime/node/RequestFactory.js.map +0 -1
  292. package/build/src/runtime/node/VariablesStore.d.ts +0 -9
  293. package/build/src/runtime/node/VariablesStore.js +0 -19
  294. package/build/src/runtime/node/VariablesStore.js.map +0 -1
  295. package/src/lib/cookies/Cookie.ts +0 -312
  296. package/src/lib/cookies/Cookies.ts +0 -326
  297. package/src/lib/cookies/Utils.ts +0 -168
  298. package/src/mocking/lib/Arc.ts +0 -28
  299. package/src/models/RequestActions.ts +0 -161
  300. package/src/models/actions/Action.ts +0 -213
  301. package/src/models/actions/ActionView.ts +0 -40
  302. package/src/models/actions/Condition.ts +0 -207
  303. package/src/models/actions/ConditionView.ts +0 -42
  304. package/src/models/actions/Enums.ts +0 -29
  305. package/src/models/actions/RunnableAction.ts +0 -144
  306. package/src/models/actions/runnable/DeleteCookieAction.ts +0 -113
  307. package/src/models/actions/runnable/Runnable.ts +0 -9
  308. package/src/models/actions/runnable/SetCookieAction.ts +0 -216
  309. package/src/models/actions/runnable/SetVariableAction.ts +0 -81
  310. package/src/models/arc/ArcHttpRequest.ts +0 -129
  311. package/src/models/arc/readme.md +0 -3
  312. package/src/runtime/actions/ActionRunner.ts +0 -83
  313. package/src/runtime/actions/RunnableCondition.ts +0 -56
  314. package/src/runtime/actions/runnable/ActionRunnable.ts +0 -19
  315. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +0 -39
  316. package/src/runtime/actions/runnable/SetCookieRunnable.ts +0 -92
  317. package/src/runtime/actions/runnable/SetVariableRunnable.ts +0 -53
  318. package/src/runtime/modules/BasicAuthCache.ts +0 -129
  319. package/src/runtime/modules/ExecutionResponse.ts +0 -4
  320. package/src/runtime/modules/ModulesRegistry.ts +0 -136
  321. package/src/runtime/modules/RequestAuthorization.ts +0 -106
  322. package/src/runtime/modules/RequestCookies.ts +0 -146
  323. package/src/runtime/node/RequestFactory.ts +0 -432
  324. package/src/runtime/node/VariablesStore.ts +0 -25
@@ -3,15 +3,17 @@
3
3
  /* eslint-disable @typescript-eslint/no-this-alias */
4
4
  /* eslint-disable max-classes-per-file */
5
5
  // import { ARCHistoryRequest, ARCSavedRequest } from "@api-client/core/build/legacy.js";
6
- import v4 from "../../lib/uuid.js";
7
- import { HttpRequest } from "../HttpRequest.js";
8
- import { Request } from "../Request.js";
9
- import { Thing } from "../Thing.js";
10
- export const ArcProjectKind = 'ARC#HttpProject';
11
- export const ArcProjectFolderKind = 'ARC#HttpProjectFolder';
12
- export const ArcProjectRequestKind = 'ARC#HttpProjectRequest';
13
- export class ArcProjectRequest extends Request {
14
- kind = ArcProjectRequestKind;
6
+ import v4 from "../lib/uuid.js";
7
+ import { HttpRequest } from "./HttpRequest.js";
8
+ import { Request } from "./Request.js";
9
+ import { Environment, Kind as EnvironmentKind } from './Environment.js';
10
+ import { Thing } from "./Thing.js";
11
+ import { Certificate } from "./ClientCertificate.js";
12
+ export const AppProjectKind = 'Core#AppProject';
13
+ export const AppProjectFolderKind = 'Core#AppProjectFolder';
14
+ export const AppProjectRequestKind = 'Core#AppProjectRequest';
15
+ export class AppProjectRequest extends Request {
16
+ kind = AppProjectRequestKind;
15
17
  /**
16
18
  * The identifier of the request.
17
19
  */
@@ -32,9 +34,9 @@ export class ArcProjectRequest extends Request {
32
34
  throw new Error(`The project is required.`);
33
35
  }
34
36
  const now = Date.now();
35
- const request = new ArcProjectRequest(project, {
37
+ const request = new AppProjectRequest(project, {
36
38
  key: v4(),
37
- kind: ArcProjectRequestKind,
39
+ kind: AppProjectRequestKind,
38
40
  created: now,
39
41
  updated: now,
40
42
  expects: HttpRequest.fromBaseValues({ url, method: 'GET' }).toJSON(),
@@ -54,9 +56,9 @@ export class ArcProjectRequest extends Request {
54
56
  throw new Error(`The project is required.`);
55
57
  }
56
58
  const now = Date.now();
57
- const request = new ArcProjectRequest(project, {
59
+ const request = new AppProjectRequest(project, {
58
60
  key: v4(),
59
- kind: ArcProjectRequestKind,
61
+ kind: AppProjectRequestKind,
60
62
  created: now,
61
63
  updated: now,
62
64
  expects: new HttpRequest().toJSON(),
@@ -76,9 +78,9 @@ export class ArcProjectRequest extends Request {
76
78
  throw new Error(`The project is required.`);
77
79
  }
78
80
  const now = Date.now();
79
- const request = new ArcProjectRequest(project, {
81
+ const request = new AppProjectRequest(project, {
80
82
  key: v4(),
81
- kind: ArcProjectRequestKind,
83
+ kind: AppProjectRequestKind,
82
84
  created: now,
83
85
  updated: now,
84
86
  expects: HttpRequest.fromBaseValues({ method: info.method, url: info.url, headers: info.headers, payload: info.payload }).toJSON(),
@@ -91,8 +93,8 @@ export class ArcProjectRequest extends Request {
91
93
  */
92
94
  static fromRequest(request, project) {
93
95
  const key = v4();
94
- const init = { ...request, key, kind: ArcProjectRequestKind };
95
- const result = new ArcProjectRequest(project, init);
96
+ const init = { ...request, key, kind: AppProjectRequestKind };
97
+ const result = new AppProjectRequest(project, init);
96
98
  return result;
97
99
  }
98
100
  constructor(project, input) {
@@ -108,17 +110,17 @@ export class ArcProjectRequest extends Request {
108
110
  if (init) {
109
111
  this.key = init.key || v4();
110
112
  }
111
- this.kind = ArcProjectRequestKind;
113
+ this.kind = AppProjectRequestKind;
112
114
  }
113
115
  new(init) {
114
116
  super.new(init);
115
117
  const { key = v4() } = init;
116
118
  this.key = key;
117
- this.kind = ArcProjectRequestKind;
119
+ this.kind = AppProjectRequestKind;
118
120
  }
119
121
  toJSON() {
120
122
  const request = super.toJSON();
121
- const result = { ...request, key: this.key, kind: ArcProjectRequestKind };
123
+ const result = { ...request, key: this.key, kind: AppProjectRequestKind };
122
124
  return result;
123
125
  }
124
126
  /**
@@ -146,7 +148,7 @@ export class ArcProjectRequest extends Request {
146
148
  * Use the options dictionary to control this behavior.
147
149
  */
148
150
  clone(opts = {}) {
149
- const copy = new ArcProjectRequest(this.project, this.toJSON());
151
+ const copy = new AppProjectRequest(this.project, this.toJSON());
150
152
  if (!opts.withoutRevalidate) {
151
153
  copy.key = v4();
152
154
  }
@@ -168,15 +170,15 @@ export class ArcProjectRequest extends Request {
168
170
  * @returns The copied request.
169
171
  */
170
172
  static clone(request, project, opts = {}) {
171
- const obj = new ArcProjectRequest(project, request);
173
+ const obj = new AppProjectRequest(project, request);
172
174
  return obj.clone(opts);
173
175
  }
174
176
  }
175
- export class ArcProjectItem {
177
+ export class AppProjectItem {
176
178
  /**
177
179
  * The kind of the item.
178
180
  */
179
- kind = ArcProjectRequestKind;
181
+ kind = AppProjectRequestKind;
180
182
  /**
181
183
  * The identifier of the object in the `definitions` array of the project.
182
184
  */
@@ -190,7 +192,7 @@ export class ArcProjectItem {
190
192
  */
191
193
  static isProjectItem(input) {
192
194
  const typed = input;
193
- if (!input || ![ArcProjectFolderKind, ArcProjectRequestKind].includes(typed.kind)) {
195
+ if (!input || ![AppProjectFolderKind, AppProjectRequestKind, EnvironmentKind].includes(typed.kind)) {
194
196
  return false;
195
197
  }
196
198
  return true;
@@ -199,8 +201,8 @@ export class ArcProjectItem {
199
201
  * @return An instance that represents a request item
200
202
  */
201
203
  static projectRequest(project, key) {
202
- const item = new ArcProjectItem(project, {
203
- kind: ArcProjectRequestKind,
204
+ const item = new AppProjectItem(project, {
205
+ kind: AppProjectRequestKind,
204
206
  key,
205
207
  });
206
208
  return item;
@@ -209,8 +211,18 @@ export class ArcProjectItem {
209
211
  * @return An instance that represents a folder item
210
212
  */
211
213
  static projectFolder(project, key) {
212
- const item = new ArcProjectItem(project, {
213
- kind: ArcProjectFolderKind,
214
+ const item = new AppProjectItem(project, {
215
+ kind: AppProjectFolderKind,
216
+ key,
217
+ });
218
+ return item;
219
+ }
220
+ /**
221
+ * @return An instance that represents an environment item
222
+ */
223
+ static projectEnvironment(project, key) {
224
+ const item = new AppProjectItem(project, {
225
+ kind: EnvironmentKind,
214
226
  key,
215
227
  });
216
228
  return item;
@@ -225,13 +237,19 @@ export class ArcProjectItem {
225
237
  if (typeof input === 'string') {
226
238
  if (input === 'http-request') {
227
239
  init = {
228
- kind: ArcProjectRequestKind,
240
+ kind: AppProjectRequestKind,
229
241
  key: '',
230
242
  };
231
243
  }
232
244
  else if (input === 'folder') {
233
245
  init = {
234
- kind: ArcProjectFolderKind,
246
+ kind: AppProjectFolderKind,
247
+ key: '',
248
+ };
249
+ }
250
+ else if (input === 'environment') {
251
+ init = {
252
+ kind: EnvironmentKind,
235
253
  key: '',
236
254
  };
237
255
  }
@@ -253,7 +271,7 @@ export class ArcProjectItem {
253
271
  * Note, this throws an error when the project item is not a project item.
254
272
  */
255
273
  new(init) {
256
- if (!ArcProjectItem.isProjectItem(init)) {
274
+ if (!AppProjectItem.isProjectItem(init)) {
257
275
  throw new Error(`Not a project item.`);
258
276
  }
259
277
  const { kind, key } = init;
@@ -273,12 +291,15 @@ export class ArcProjectItem {
273
291
  getItem() {
274
292
  const { project, key, kind } = this;
275
293
  const { definitions } = project;
276
- if (kind === ArcProjectRequestKind) {
294
+ if (kind === AppProjectRequestKind) {
277
295
  return definitions.requests.find(i => i.key === key);
278
296
  }
279
- if (kind === ArcProjectFolderKind) {
297
+ if (kind === AppProjectFolderKind) {
280
298
  return definitions.folders.find(i => i.key === key);
281
299
  }
300
+ if (kind === EnvironmentKind) {
301
+ return definitions.environments.find(i => i.key === key);
302
+ }
282
303
  return undefined;
283
304
  }
284
305
  /**
@@ -289,7 +310,7 @@ export class ArcProjectItem {
289
310
  return project.findParent(key);
290
311
  }
291
312
  }
292
- export class ArcProjectParent {
313
+ export class AppProjectParent {
293
314
  /**
294
315
  * The auto-generated key for the folder object.
295
316
  * For the project root this is the same as the `_id`.
@@ -363,17 +384,17 @@ export class ArcProjectParent {
363
384
  */
364
385
  listFolderItems() {
365
386
  const { items = [] } = this;
366
- return items.filter(i => i.kind === ArcProjectFolderKind);
387
+ return items.filter(i => i.kind === AppProjectFolderKind);
367
388
  }
368
389
  /**
369
390
  * Lists items (not the actual definitions!) that are requests.
370
391
  */
371
392
  listRequestItems() {
372
393
  const { items = [] } = this;
373
- return items.filter(i => i.kind === ArcProjectRequestKind);
394
+ return items.filter(i => i.kind === AppProjectRequestKind);
374
395
  }
375
396
  }
376
- export class ArcProjectFolder extends ArcProjectParent {
397
+ export class AppProjectFolder extends AppProjectParent {
377
398
  project;
378
399
  /**
379
400
  * Creates a new ArcProjectFolder object from a name.
@@ -384,18 +405,18 @@ export class ArcProjectFolder extends ArcProjectParent {
384
405
  const now = Date.now();
385
406
  const key = v4();
386
407
  const info = Thing.fromName(name);
387
- const definition = new ArcProjectFolder(project, {
408
+ const definition = new AppProjectFolder(project, {
388
409
  key,
389
410
  created: now,
390
411
  updated: now,
391
412
  items: [],
392
- kind: ArcProjectFolderKind,
413
+ kind: AppProjectFolderKind,
393
414
  info: info.toJSON(),
394
415
  });
395
416
  return definition;
396
417
  }
397
418
  constructor(project, input) {
398
- super(ArcProjectFolderKind, input);
419
+ super(AppProjectFolderKind, input);
399
420
  this.project = project;
400
421
  let init;
401
422
  if (typeof input === 'string') {
@@ -407,11 +428,11 @@ export class ArcProjectFolder extends ArcProjectParent {
407
428
  if (init) {
408
429
  this.key = init.key || v4();
409
430
  }
410
- this.kind = ArcProjectFolderKind;
431
+ this.kind = AppProjectFolderKind;
411
432
  }
412
433
  toJSON() {
413
434
  const result = {
414
- kind: ArcProjectFolderKind,
435
+ kind: AppProjectFolderKind,
415
436
  info: this.info.toJSON(),
416
437
  key: this.key,
417
438
  created: this.created,
@@ -425,7 +446,7 @@ export class ArcProjectFolder extends ArcProjectParent {
425
446
  }
426
447
  setItems(items) {
427
448
  if (Array.isArray(items)) {
428
- this.items = items.map(i => new ArcProjectItem(this.project, i));
449
+ this.items = items.map(i => new AppProjectItem(this.project, i));
429
450
  }
430
451
  else {
431
452
  this.items = [];
@@ -481,7 +502,7 @@ export class ArcProjectFolder extends ArcProjectParent {
481
502
  */
482
503
  clone(opts = {}) {
483
504
  const { targetProject = this.project, targetFolder } = opts;
484
- const copy = new ArcProjectFolder(targetProject, this.toJSON());
505
+ const copy = new AppProjectFolder(targetProject, this.toJSON());
485
506
  copy.key = v4();
486
507
  const extProject = targetProject !== this.project;
487
508
  if (extProject) {
@@ -522,7 +543,7 @@ export class ArcProjectFolder extends ArcProjectParent {
522
543
  * @param project The originating project where the definitions are stored
523
544
  */
524
545
  cloneRequests(folder, project) {
525
- const requests = this.items.filter(i => i.kind === ArcProjectRequestKind);
546
+ const requests = this.items.filter(i => i.kind === AppProjectRequestKind);
526
547
  requests.forEach(r => {
527
548
  const request = project.findRequest(r.key, { keyOnly: true });
528
549
  if (!request) {
@@ -548,13 +569,13 @@ export class ArcProjectFolder extends ArcProjectParent {
548
569
  * @param withRequests Whether to clone requests with the folder.
549
570
  */
550
571
  cloneSubFolders(folder, project, withRequests = true) {
551
- const folders = this.items.filter(i => i.kind === ArcProjectFolderKind);
572
+ const folders = this.items.filter(i => i.kind === AppProjectFolderKind);
552
573
  folders.forEach(f => {
553
574
  const definition = project.findFolder(f.key, { keyOnly: true });
554
575
  if (!definition) {
555
576
  return;
556
577
  }
557
- const copy = new ArcProjectFolder(folder.getProject(), definition.toJSON());
578
+ const copy = new AppProjectFolder(folder.getProject(), definition.toJSON());
558
579
  copy.key = v4();
559
580
  copy.items = [];
560
581
  folder.addFolder(copy);
@@ -584,11 +605,45 @@ export class ArcProjectFolder extends ArcProjectParent {
584
605
  */
585
606
  async addLegacyRequest(legacy) {
586
607
  const request = await Request.fromLegacy(legacy);
587
- const projectRequest = ArcProjectRequest.fromRequest(request.toJSON(), this.project);
608
+ const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), this.project);
588
609
  return this.addRequest(projectRequest);
589
610
  }
611
+ /**
612
+ * Adds an environment to the project.
613
+ * @returns The same or created environment.
614
+ */
615
+ addEnvironment(env, opts = {}) {
616
+ const newOptions = { ...opts, parent: this.key };
617
+ return this.project.addEnvironment(env, newOptions);
618
+ }
619
+ /**
620
+ * @param key The environment key to read.
621
+ */
622
+ getEnvironment(key) {
623
+ return this.project.getEnvironment(key, { parent: this.key });
624
+ }
625
+ /**
626
+ * Removes an environment from the folder or a sub-folder.
627
+ *
628
+ * @param key the key of the environment to remove
629
+ * @returns The removed environment, if any.
630
+ */
631
+ removeEnvironment(key) {
632
+ return this.project.removeEnvironment(key, { parent: this.key });
633
+ }
634
+ /**
635
+ * This is a link to the `getEnvironments()`. The difference is that on the
636
+ * project level it won't return environments defined with the class initialization.
637
+ */
638
+ listEnvironments() {
639
+ return this.project.listEnvironments({ parent: this.key });
640
+ }
590
641
  }
591
- export class ArcProject extends ArcProjectParent {
642
+ /**
643
+ * An app project is similar to the HttpProject but stored for a single application
644
+ * and has no sharing options. The AppProject can be upgraded to an HttpProject.
645
+ */
646
+ export class AppProject extends AppProjectParent {
592
647
  /**
593
648
  * Timestamp when the project was last updated.
594
649
  */
@@ -603,7 +658,7 @@ export class ArcProject extends ArcProjectParent {
603
658
  * @param name The name to set.
604
659
  */
605
660
  static fromName(name) {
606
- const project = new ArcProject();
661
+ const project = new AppProject();
607
662
  const info = Thing.fromName(name);
608
663
  project.info = info;
609
664
  return project;
@@ -615,7 +670,7 @@ export class ArcProject extends ArcProjectParent {
615
670
  */
616
671
  static async fromLegacyProject(project, requests) {
617
672
  const { name = 'Unnamed project', description, requests: ids } = project;
618
- const result = ArcProject.fromName(name);
673
+ const result = AppProject.fromName(name);
619
674
  if (project._id) {
620
675
  result.key = project._id;
621
676
  }
@@ -629,7 +684,7 @@ export class ArcProject extends ArcProjectParent {
629
684
  return;
630
685
  }
631
686
  const request = await Request.fromLegacy(old);
632
- const projectRequest = ArcProjectRequest.fromRequest(request.toJSON(), result);
687
+ const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), result);
633
688
  if (old._id) {
634
689
  projectRequest.key = old._id;
635
690
  }
@@ -640,10 +695,12 @@ export class ArcProject extends ArcProjectParent {
640
695
  return result;
641
696
  }
642
697
  constructor(input) {
643
- super(ArcProjectKind);
698
+ super(AppProjectKind);
644
699
  this.definitions = {
645
700
  folders: [],
646
701
  requests: [],
702
+ environments: [],
703
+ certificates: [],
647
704
  };
648
705
  let init;
649
706
  if (typeof input === 'string') {
@@ -652,13 +709,13 @@ export class ArcProject extends ArcProjectParent {
652
709
  else if (typeof input === 'object') {
653
710
  init = input;
654
711
  if (!init.kind) {
655
- init.kind = ArcProjectKind;
712
+ init.kind = AppProjectKind;
656
713
  }
657
714
  }
658
715
  else {
659
716
  const now = Date.now();
660
717
  init = {
661
- kind: ArcProjectKind,
718
+ kind: AppProjectKind,
662
719
  key: v4(),
663
720
  definitions: {},
664
721
  items: [],
@@ -687,23 +744,31 @@ export class ArcProject extends ArcProjectParent {
687
744
  this.definitions = {
688
745
  folders: [],
689
746
  requests: [],
747
+ environments: [],
748
+ certificates: [],
690
749
  };
691
750
  if (Array.isArray(definitions.requests)) {
692
751
  this.definitions.requests = definitions.requests.map(i => {
693
- const instance = new ArcProjectRequest(this, i);
752
+ const instance = new AppProjectRequest(this, i);
694
753
  return instance;
695
754
  });
696
755
  }
697
756
  if (Array.isArray(definitions.folders)) {
698
757
  this.definitions.folders = definitions.folders.map(i => {
699
- const instance = new ArcProjectFolder(this, i);
758
+ const instance = new AppProjectFolder(this, i);
700
759
  return instance;
701
760
  });
702
761
  }
762
+ if (Array.isArray(definitions.environments)) {
763
+ this.definitions.environments = definitions.environments.map(i => new Environment(i));
764
+ }
765
+ if (Array.isArray(definitions.certificates)) {
766
+ this.definitions.certificates = definitions.certificates.map(i => new Certificate(i));
767
+ }
703
768
  }
704
769
  toJSON() {
705
770
  const result = {
706
- kind: ArcProjectKind,
771
+ kind: AppProjectKind,
707
772
  key: this.key,
708
773
  definitions: {},
709
774
  items: [],
@@ -717,6 +782,12 @@ export class ArcProject extends ArcProjectParent {
717
782
  if (Array.isArray(this.definitions.folders) && this.definitions.folders.length) {
718
783
  result.definitions.folders = this.definitions.folders.map(i => i.toJSON());
719
784
  }
785
+ if (Array.isArray(this.definitions.environments) && this.definitions.environments.length) {
786
+ result.definitions.environments = this.definitions.environments.map(i => i.toJSON());
787
+ }
788
+ if (Array.isArray(this.definitions.certificates) && this.definitions.certificates.length) {
789
+ result.definitions.certificates = this.definitions.certificates.map(i => i.toJSON());
790
+ }
720
791
  if (Array.isArray(this.items) && this.items.length) {
721
792
  result.items = this.items.map(i => i.toJSON());
722
793
  }
@@ -724,7 +795,7 @@ export class ArcProject extends ArcProjectParent {
724
795
  }
725
796
  setItems(items) {
726
797
  if (Array.isArray(items)) {
727
- this.items = items.map(i => new ArcProjectItem(this, i));
798
+ this.items = items.map(i => new AppProjectItem(this, i));
728
799
  }
729
800
  else {
730
801
  this.items = [];
@@ -779,13 +850,13 @@ export class ArcProject extends ArcProjectParent {
779
850
  }
780
851
  let definition;
781
852
  if (typeof init === 'string') {
782
- definition = ArcProjectFolder.fromName(this, init);
853
+ definition = AppProjectFolder.fromName(this, init);
783
854
  }
784
- else if (init instanceof ArcProjectFolder) {
855
+ else if (init instanceof AppProjectFolder) {
785
856
  definition = init;
786
857
  }
787
858
  else {
788
- definition = new ArcProjectFolder(this, init);
859
+ definition = new AppProjectFolder(this, init);
789
860
  }
790
861
  if (skipExisting) {
791
862
  const folders = root.listFolderItems();
@@ -797,7 +868,7 @@ export class ArcProject extends ArcProjectParent {
797
868
  }
798
869
  }
799
870
  this.definitions.folders.push(definition);
800
- const item = ArcProjectItem.projectFolder(this, definition.key);
871
+ const item = AppProjectItem.projectFolder(this, definition.key);
801
872
  if (!Array.isArray(root.items)) {
802
873
  root.items = [];
803
874
  }
@@ -819,7 +890,7 @@ export class ArcProject extends ArcProjectParent {
819
890
  findFolder(nameOrKey, opts = {}) {
820
891
  const { definitions } = this;
821
892
  const item = definitions.folders.find((i) => {
822
- if (i.kind !== ArcProjectFolderKind) {
893
+ if (i.kind !== AppProjectFolderKind) {
823
894
  return false;
824
895
  }
825
896
  const folder = i;
@@ -932,7 +1003,7 @@ export class ArcProject extends ArcProjectParent {
932
1003
  if (item.key === child) {
933
1004
  return true;
934
1005
  }
935
- if (item.kind === ArcProjectFolderKind) {
1006
+ if (item.kind === AppProjectFolderKind) {
936
1007
  const hasChild = this.hasChild(child, item.key);
937
1008
  if (hasChild) {
938
1009
  return true;
@@ -963,14 +1034,14 @@ export class ArcProject extends ArcProjectParent {
963
1034
  // if we got here, it means that we are adding a new request object to the project.
964
1035
  let finalRequest;
965
1036
  if (typeof request === 'string') {
966
- finalRequest = ArcProjectRequest.fromUrl(request, this);
1037
+ finalRequest = AppProjectRequest.fromUrl(request, this);
967
1038
  }
968
- else if (request instanceof ArcProjectRequest) {
1039
+ else if (request instanceof AppProjectRequest) {
969
1040
  finalRequest = request;
970
1041
  finalRequest.project = this;
971
1042
  }
972
1043
  else {
973
- finalRequest = new ArcProjectRequest(this, request);
1044
+ finalRequest = new AppProjectRequest(this, request);
974
1045
  }
975
1046
  if (!finalRequest.key) {
976
1047
  finalRequest.key = v4();
@@ -996,7 +1067,7 @@ export class ArcProject extends ArcProjectParent {
996
1067
  }
997
1068
  }
998
1069
  this.definitions.requests.push(finalRequest);
999
- const item = ArcProjectItem.projectRequest(this, finalRequest.key);
1070
+ const item = AppProjectItem.projectRequest(this, finalRequest.key);
1000
1071
  if (typeof opts.index === 'number') {
1001
1072
  root.items.splice(opts.index, 0, item);
1002
1073
  }
@@ -1013,7 +1084,7 @@ export class ArcProject extends ArcProjectParent {
1013
1084
  */
1014
1085
  async addLegacyRequest(legacy) {
1015
1086
  const request = await Request.fromLegacy(legacy);
1016
- const projectRequest = ArcProjectRequest.fromRequest(request.toJSON(), this);
1087
+ const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), this);
1017
1088
  return this.addRequest(projectRequest);
1018
1089
  }
1019
1090
  /**
@@ -1114,14 +1185,14 @@ export class ArcProject extends ArcProjectParent {
1114
1185
  */
1115
1186
  listFolderItems() {
1116
1187
  const { items = [] } = this;
1117
- return items.filter(i => i.kind === ArcProjectFolderKind);
1188
+ return items.filter(i => i.kind === AppProjectFolderKind);
1118
1189
  }
1119
1190
  /**
1120
1191
  * Lists items (not the actual definitions!) that are requests.
1121
1192
  */
1122
1193
  listRequestItems() {
1123
1194
  const { items = [] } = this;
1124
- return items.filter(i => i.kind === ArcProjectRequestKind);
1195
+ return items.filter(i => i.kind === AppProjectRequestKind);
1125
1196
  }
1126
1197
  /**
1127
1198
  * Lists folders from the project or a sub-folder.
@@ -1198,12 +1269,15 @@ export class ArcProject extends ArcProjectParent {
1198
1269
  const { definitions } = this;
1199
1270
  items.forEach((item) => {
1200
1271
  let definition;
1201
- if (item.kind === ArcProjectFolderKind) {
1272
+ if (item.kind === AppProjectFolderKind) {
1202
1273
  definition = definitions.folders.find(d => item.key === d.key);
1203
1274
  }
1204
- else if (item.kind === ArcProjectRequestKind) {
1275
+ else if (item.kind === AppProjectRequestKind) {
1205
1276
  definition = definitions.requests.find(d => item.key === d.key);
1206
1277
  }
1278
+ else if (item.kind === EnvironmentKind) {
1279
+ definition = definitions.environments.find(d => item.key === d.key);
1280
+ }
1207
1281
  if (definition) {
1208
1282
  result.push(definition);
1209
1283
  }
@@ -1223,15 +1297,15 @@ export class ArcProject extends ArcProjectParent {
1223
1297
  * Makes a copy of this project.
1224
1298
  */
1225
1299
  clone(opts = {}) {
1226
- const copy = new ArcProject(this.toJSON());
1300
+ const copy = new AppProject(this.toJSON());
1227
1301
  if (!opts.withoutRevalidate) {
1228
1302
  copy.key = v4();
1229
- ArcProject.regenerateKeys(copy);
1303
+ AppProject.regenerateKeys(copy);
1230
1304
  }
1231
1305
  return copy;
1232
1306
  }
1233
1307
  static clone(project, opts = {}) {
1234
- const obj = new ArcProject(project);
1308
+ const obj = new AppProject(project);
1235
1309
  return obj.clone(opts);
1236
1310
  }
1237
1311
  /**
@@ -1273,6 +1347,289 @@ export class ArcProject extends ArcProjectParent {
1273
1347
  indexObject.key = newKey;
1274
1348
  request.key = newKey;
1275
1349
  });
1350
+ (definitions.environments || []).forEach((environment) => {
1351
+ const oldKey = environment.key;
1352
+ const indexObject = flatItems.find(i => i.key === oldKey);
1353
+ if (!indexObject) {
1354
+ return;
1355
+ }
1356
+ const newKey = v4();
1357
+ indexObject.key = newKey;
1358
+ environment.key = newKey;
1359
+ });
1360
+ (definitions.certificates || []).forEach((cert) => {
1361
+ cert.key = v4();
1362
+ });
1363
+ }
1364
+ /**
1365
+ * Adds an environment to the project.
1366
+ * @returns The same or created environment.
1367
+ */
1368
+ addEnvironment(env, opts = {}) {
1369
+ const environment = this._createEnv(env);
1370
+ const root = this._getRoot(opts);
1371
+ const project = this.getProject();
1372
+ if (!project.definitions.environments) {
1373
+ project.definitions.environments = [];
1374
+ }
1375
+ project.definitions.environments.push(environment);
1376
+ const item = AppProjectItem.projectEnvironment(project, environment.key);
1377
+ this._insertItem(item, root, opts);
1378
+ return environment;
1379
+ }
1380
+ _createEnv(env) {
1381
+ let finalEnv;
1382
+ if (env instanceof Environment) {
1383
+ finalEnv = env;
1384
+ }
1385
+ else if (typeof env === 'string') {
1386
+ finalEnv = Environment.fromName(env);
1387
+ }
1388
+ else {
1389
+ finalEnv = new Environment(env);
1390
+ }
1391
+ if (!finalEnv.key) {
1392
+ finalEnv.key = v4();
1393
+ }
1394
+ return finalEnv;
1395
+ }
1396
+ /**
1397
+ * @param key The environment key to read.
1398
+ */
1399
+ getEnvironment(key, opts = {}) {
1400
+ const root = this._getRoot(opts);
1401
+ const item = root.items.find(i => i.key === key);
1402
+ if (!item) {
1403
+ return undefined;
1404
+ }
1405
+ const project = this.getProject();
1406
+ if (!Array.isArray(project.definitions.environments)) {
1407
+ project.definitions.environments = [];
1408
+ }
1409
+ return project.definitions.environments.find(e => e.key === key);
1410
+ }
1411
+ /**
1412
+ * Removes an environment from the folder or a sub-folder.
1413
+ *
1414
+ * @param key the key of the environment to remove
1415
+ * @returns The removed environment, if any.
1416
+ */
1417
+ removeEnvironment(key, opts = {}) {
1418
+ const root = this._getRoot(opts);
1419
+ const itemIndex = root.items.findIndex(i => i.key === key);
1420
+ if (itemIndex < 0) {
1421
+ return undefined;
1422
+ }
1423
+ root.items.splice(itemIndex, 1);
1424
+ const project = this.getProject();
1425
+ if (!Array.isArray(project.definitions.environments)) {
1426
+ project.definitions.environments = [];
1427
+ }
1428
+ const defIndex = project.definitions.environments.findIndex(i => i.key === key);
1429
+ if (defIndex < 0) {
1430
+ return undefined;
1431
+ }
1432
+ const env = project.definitions.environments[defIndex];
1433
+ project.definitions.environments.splice(defIndex, 1);
1434
+ return env;
1435
+ }
1436
+ /**
1437
+ * This is a link to the `getEnvironments()`. The difference is that on the
1438
+ * project level it won't return environments defined with the class initialization.
1439
+ */
1440
+ listEnvironments(opts = {}) {
1441
+ const root = this._getRoot(opts);
1442
+ const items = root.items.filter(i => i.kind === EnvironmentKind).map(i => i.key);
1443
+ const project = this.getProject();
1444
+ if (!Array.isArray(project.definitions.environments)) {
1445
+ project.definitions.environments = [];
1446
+ }
1447
+ return project.definitions.environments.filter(e => items.includes(e.key));
1448
+ }
1449
+ /**
1450
+ * Reads the list of environments from then selected folder up to the project root.
1451
+ * It stops going up in the project structure when selected environment has the `encapsulated`
1452
+ * property set to true.
1453
+ * The environments are ordered from the top-most level to the selected folder.
1454
+ *
1455
+ * @param opts The environment read options
1456
+ */
1457
+ readEnvironments(opts = {}) {
1458
+ const result = [];
1459
+ const { parent, nameOrKey } = opts;
1460
+ const root = parent ? this.findFolder(parent, { keyOnly: true }) : this;
1461
+ if (!root) {
1462
+ return result;
1463
+ }
1464
+ let current = root;
1465
+ while (current) {
1466
+ const environments = current.listEnvironments();
1467
+ if (environments.length) {
1468
+ const selected = nameOrKey ? environments.find(i => i.key === nameOrKey || i.info.name === nameOrKey) : environments[0];
1469
+ if (selected) {
1470
+ result.push(selected);
1471
+ if (selected.encapsulated) {
1472
+ break;
1473
+ }
1474
+ }
1475
+ }
1476
+ current = current.getParent();
1477
+ }
1478
+ return result.reverse();
1479
+ }
1480
+ /**
1481
+ * Finds a definition for an environment regardless of its parent.
1482
+ *
1483
+ * @param key The Key of the environment to find.
1484
+ * @returns The environment definition or undefined if not found.
1485
+ */
1486
+ findEnvironment(key) {
1487
+ return this.definitions.environments.find(i => i.key === key);
1488
+ }
1489
+ /**
1490
+ * Depending on the options returns a project or a folder.
1491
+ * It throws when parent folder cannot ber found.
1492
+ */
1493
+ _getRoot(opts) {
1494
+ const project = this.getProject();
1495
+ if (opts.parent) {
1496
+ const parent = project.findFolder(opts.parent);
1497
+ if (!parent) {
1498
+ throw new Error(`Unable to find the parent folder ${opts.parent}.`);
1499
+ }
1500
+ return parent;
1501
+ }
1502
+ return project;
1503
+ }
1504
+ _insertItem(item, root, opts) {
1505
+ if (!Array.isArray(root.items)) {
1506
+ root.items = [];
1507
+ }
1508
+ if (typeof opts.index === 'number') {
1509
+ root.items.splice(opts.index, 0, item);
1510
+ }
1511
+ else {
1512
+ root.items.push(item);
1513
+ }
1514
+ }
1515
+ /**
1516
+ * Finds a definition for a certificate.
1517
+ *
1518
+ * @param key The key of the certificate to find.
1519
+ * @returns The certificate definition or undefined if not found.
1520
+ */
1521
+ findCertificate(key) {
1522
+ return this.definitions.certificates.find(i => i.key === key);
1523
+ }
1524
+ /**
1525
+ * Adds a certificate to the project.
1526
+ *
1527
+ * @param init Either an instance of a certificate or its definition.
1528
+ * @returns The inserted certificate.
1529
+ */
1530
+ addCertificate(init) {
1531
+ let finalCert;
1532
+ if (init instanceof Certificate) {
1533
+ finalCert = init;
1534
+ }
1535
+ else {
1536
+ finalCert = new Certificate(init);
1537
+ }
1538
+ if (!this.definitions.certificates) {
1539
+ this.definitions.certificates = [];
1540
+ }
1541
+ this.definitions.certificates.push(finalCert);
1542
+ return finalCert;
1543
+ }
1544
+ /**
1545
+ * Removes a certificate from the project.
1546
+ *
1547
+ * @param key the key of the certificate to remove
1548
+ * @returns The removed certificate, if any.
1549
+ */
1550
+ removeCertificate(key) {
1551
+ if (!Array.isArray(this.definitions.certificates)) {
1552
+ return undefined;
1553
+ }
1554
+ const defIndex = this.definitions.certificates.findIndex(i => i.key === key);
1555
+ if (defIndex < 0) {
1556
+ return undefined;
1557
+ }
1558
+ const cert = this.definitions.certificates[defIndex];
1559
+ this.definitions.certificates.splice(defIndex, 1);
1560
+ return cert;
1561
+ }
1562
+ /**
1563
+ * Finds the requests that are using the certificate identified by the key.
1564
+ *
1565
+ * @param key The key of the certificate to find the usage for.
1566
+ * @returns The list of requests that use this certificate.
1567
+ */
1568
+ findCertificateRequests(key) {
1569
+ return this.definitions.requests.filter((request) => {
1570
+ if (!Array.isArray(request.authorization)) {
1571
+ return false;
1572
+ }
1573
+ const ccAuth = request.authorization.find(auth => auth.type === 'client certificate');
1574
+ if (!ccAuth) {
1575
+ return false;
1576
+ }
1577
+ const cnf = ccAuth.config;
1578
+ return !!cnf && !!cnf.certificate && cnf.certificate.key === key;
1579
+ });
1580
+ }
1581
+ /**
1582
+ * Iterates over requests in the project.
1583
+ */
1584
+ *requestIterator(opts = {}) {
1585
+ const { definitions } = this;
1586
+ const { ignore = [], parent, recursive, requests = [] } = opts;
1587
+ const root = parent ? this.findFolder(parent) : this;
1588
+ if (!root) {
1589
+ throw new Error(`The parent folder not found: ${parent}.`);
1590
+ }
1591
+ const items = root.items;
1592
+ if (!items || !items.length) {
1593
+ return;
1594
+ }
1595
+ for (const item of items) {
1596
+ if (ignore.includes(item.key)) {
1597
+ continue;
1598
+ }
1599
+ if (item.kind === AppProjectRequestKind) {
1600
+ const request = definitions.requests.find(i => i.key === item.key);
1601
+ if (!request) {
1602
+ continue;
1603
+ }
1604
+ const name = request.info.name || '';
1605
+ if (ignore.includes(name)) {
1606
+ continue;
1607
+ }
1608
+ if (requests.length && !requests.includes(item.key) && !requests.includes(name)) {
1609
+ continue;
1610
+ }
1611
+ yield request;
1612
+ }
1613
+ else if (recursive && item.kind === AppProjectFolderKind) {
1614
+ const folder = definitions.folders.find(i => i.key === item.key);
1615
+ if (!folder) {
1616
+ continue;
1617
+ }
1618
+ const name = folder.info.name || '';
1619
+ if (ignore.includes(name)) {
1620
+ continue;
1621
+ }
1622
+ const it = this.requestIterator({
1623
+ parent: item.key,
1624
+ recursive,
1625
+ ignore,
1626
+ requests,
1627
+ });
1628
+ for (const request of it) {
1629
+ yield request;
1630
+ }
1631
+ }
1632
+ }
1276
1633
  }
1277
1634
  }
1278
- //# sourceMappingURL=ArcProject.js.map
1635
+ //# sourceMappingURL=AppProject.js.map