@api-client/core 0.9.22 → 0.9.24

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 (233) hide show
  1. package/build/browser.d.ts +11 -11
  2. package/build/browser.js +13 -16
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +11 -11
  5. package/build/index.js +13 -16
  6. package/build/index.js.map +1 -1
  7. package/build/src/data/DataExtractor.d.ts +66 -0
  8. package/build/src/data/DataExtractor.js +177 -0
  9. package/build/src/data/DataExtractor.js.map +1 -0
  10. package/build/src/data/RequestDataExtractor.d.ts +4 -1
  11. package/build/src/data/RequestDataExtractor.js +13 -26
  12. package/build/src/data/RequestDataExtractor.js.map +1 -1
  13. package/build/src/lib/Buffer.d.ts +2 -2
  14. package/build/src/lib/Buffer.js +46 -18
  15. package/build/src/lib/Buffer.js.map +1 -1
  16. package/build/src/models/ClientCertificate.js.map +1 -1
  17. package/build/src/models/Request.d.ts +2 -2
  18. package/build/src/models/Request.js +1 -1
  19. package/build/src/models/Request.js.map +1 -1
  20. package/build/src/models/RequestLog.d.ts +1 -1
  21. package/build/src/models/http-flows/AssertionError.js.map +1 -0
  22. package/build/src/models/http-flows/HttpAssertion.js.map +1 -0
  23. package/build/src/models/{http-actions → http-flows}/HttpFlows.d.ts +5 -38
  24. package/build/src/models/{http-actions → http-flows}/HttpFlows.js +4 -0
  25. package/build/src/models/http-flows/HttpFlows.js.map +1 -0
  26. package/build/src/models/http-flows/HttpStep.js.map +1 -0
  27. package/build/src/models/{http-actions → http-flows}/LegacyTranslator.d.ts +2 -2
  28. package/build/src/models/{http-actions → http-flows}/LegacyTranslator.js +92 -46
  29. package/build/src/models/http-flows/LegacyTranslator.js.map +1 -0
  30. package/build/src/models/http-flows/steps/assertion/EqualAssertion.js.map +1 -0
  31. package/build/src/models/http-flows/steps/assertion/GreaterThanAssertion.js.map +1 -0
  32. package/build/src/models/http-flows/steps/assertion/IncludesAssertion.js.map +1 -0
  33. package/build/src/models/http-flows/steps/assertion/IsEmptyAssertion.js.map +1 -0
  34. package/build/src/models/http-flows/steps/assertion/IsNotEmptyAssertion.js.map +1 -0
  35. package/build/src/models/http-flows/steps/assertion/LengthOfAssertion.js.map +1 -0
  36. package/build/src/models/http-flows/steps/assertion/LessThanAssertion.js.map +1 -0
  37. package/build/src/models/http-flows/steps/assertion/MatchesAssertion.js.map +1 -0
  38. package/build/src/models/http-flows/steps/assertion/MatchesSchemaAssertion.js.map +1 -0
  39. package/build/src/models/http-flows/steps/assertion/NotEqualAssertion.js.map +1 -0
  40. package/build/src/models/http-flows/steps/assertion/NotIncludesAssertion.js.map +1 -0
  41. package/build/src/models/http-flows/steps/assertion/NotOkAssertion.js.map +1 -0
  42. package/build/src/models/http-flows/steps/assertion/NotToBeAssertion.js.map +1 -0
  43. package/build/src/models/http-flows/steps/assertion/OkAssertion.js.map +1 -0
  44. package/build/src/models/http-flows/steps/assertion/ToBeAssertion.js.map +1 -0
  45. package/build/src/models/http-flows/steps/assertion/index.js.map +1 -0
  46. package/build/src/models/{http-actions → http-flows}/steps/data/DeleteCookieStep.d.ts +5 -1
  47. package/build/src/models/{http-actions → http-flows}/steps/data/DeleteCookieStep.js +6 -1
  48. package/build/src/models/http-flows/steps/data/DeleteCookieStep.js.map +1 -0
  49. package/build/src/models/http-flows/steps/data/DeleteVariableStep.d.ts +36 -0
  50. package/build/src/models/http-flows/steps/data/DeleteVariableStep.js +44 -0
  51. package/build/src/models/http-flows/steps/data/DeleteVariableStep.js.map +1 -0
  52. package/build/src/models/http-flows/steps/data/ReadDataSourceStep.js.map +1 -0
  53. package/build/src/models/http-flows/steps/data/ReadDataStep.js.map +1 -0
  54. package/build/src/models/http-flows/steps/data/ReadValueStep.js.map +1 -0
  55. package/build/src/models/{http-actions → http-flows}/steps/data/SetCookieStep.d.ts +2 -1
  56. package/build/src/models/{http-actions → http-flows}/steps/data/SetCookieStep.js +2 -1
  57. package/build/src/models/http-flows/steps/data/SetCookieStep.js.map +1 -0
  58. package/build/src/models/http-flows/steps/data/SetDataStep.js.map +1 -0
  59. package/build/src/models/http-flows/steps/data/SetVariableStep.js.map +1 -0
  60. package/build/src/models/{http-actions → http-flows}/steps/data/index.d.ts +1 -0
  61. package/build/src/models/{http-actions → http-flows}/steps/data/index.js +1 -0
  62. package/build/src/models/http-flows/steps/data/index.js.map +1 -0
  63. package/build/src/models/http-flows/steps/transformation/AsLowerCaseStep.js.map +1 -0
  64. package/build/src/models/http-flows/steps/transformation/AsNumberStep.js.map +1 -0
  65. package/build/src/models/http-flows/steps/transformation/AsUpperCaseStep.js.map +1 -0
  66. package/build/src/models/http-flows/steps/transformation/RoundStep.js.map +1 -0
  67. package/build/src/models/http-flows/steps/transformation/SubstringStep.js.map +1 -0
  68. package/build/src/models/http-flows/steps/transformation/TrimStep.js.map +1 -0
  69. package/build/src/models/http-flows/steps/transformation/index.js.map +1 -0
  70. package/build/src/proxy/RequestProxy.d.ts +2 -2
  71. package/build/src/proxy/RequestProxy.js.map +1 -1
  72. package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
  73. package/build/src/runtime/http-runner/ConditionCheck.d.ts +1 -1
  74. package/build/src/runtime/http-runner/HttpAssertionRunner.d.ts +7 -57
  75. package/build/src/runtime/http-runner/HttpAssertionRunner.js +24 -382
  76. package/build/src/runtime/http-runner/HttpAssertionRunner.js.map +1 -1
  77. package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +10 -57
  78. package/build/src/runtime/http-runner/HttpFlowRunner.js +45 -203
  79. package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -1
  80. package/build/src/runtime/http-runner/HttpFlows.d.ts +119 -0
  81. package/build/src/runtime/http-runner/HttpFlows.js +541 -0
  82. package/build/src/runtime/http-runner/HttpFlows.js.map +1 -0
  83. package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +2 -2
  84. package/package.json +1 -1
  85. package/src/data/DataExtractor.ts +188 -0
  86. package/src/data/RequestDataExtractor.ts +14 -26
  87. package/src/lib/Buffer.ts +51 -23
  88. package/src/models/ClientCertificate.ts +1 -1
  89. package/src/models/Request.ts +3 -3
  90. package/src/models/RequestLog.ts +1 -1
  91. package/src/models/{http-actions → http-flows}/HttpFlows.ts +5 -39
  92. package/src/models/{http-actions → http-flows}/LegacyTranslator.ts +89 -31
  93. package/src/models/{http-actions → http-flows}/steps/data/DeleteCookieStep.ts +6 -1
  94. package/src/models/http-flows/steps/data/DeleteVariableStep.ts +78 -0
  95. package/src/models/{http-actions → http-flows}/steps/data/SetCookieStep.ts +4 -2
  96. package/src/proxy/RequestProxy.ts +2 -2
  97. package/src/runtime/http-engine/HttpEngine.ts +3 -3
  98. package/src/runtime/http-runner/ConditionCheck.ts +1 -1
  99. package/src/runtime/http-runner/HttpAssertionRunner.ts +28 -410
  100. package/src/runtime/http-runner/HttpFlowRunner.ts +47 -212
  101. package/src/runtime/http-runner/HttpFlows.ts +576 -0
  102. package/src/runtime/http-runner/HttpRequestRunner.ts +2 -2
  103. package/build/src/data/DataUtils.d.ts +0 -40
  104. package/build/src/data/DataUtils.js +0 -106
  105. package/build/src/data/DataUtils.js.map +0 -1
  106. package/build/src/models/http-actions/AssertionError.js.map +0 -1
  107. package/build/src/models/http-actions/HttpAssertion.js.map +0 -1
  108. package/build/src/models/http-actions/HttpFlows.js.map +0 -1
  109. package/build/src/models/http-actions/HttpStep.js.map +0 -1
  110. package/build/src/models/http-actions/LegacyTranslator.js.map +0 -1
  111. package/build/src/models/http-actions/steps/assertion/EqualAssertion.js.map +0 -1
  112. package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.js.map +0 -1
  113. package/build/src/models/http-actions/steps/assertion/IncludesAssertion.js.map +0 -1
  114. package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.js.map +0 -1
  115. package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.js.map +0 -1
  116. package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.js.map +0 -1
  117. package/build/src/models/http-actions/steps/assertion/LessThanAssertion.js.map +0 -1
  118. package/build/src/models/http-actions/steps/assertion/MatchesAssertion.js.map +0 -1
  119. package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.js.map +0 -1
  120. package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.js.map +0 -1
  121. package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.js.map +0 -1
  122. package/build/src/models/http-actions/steps/assertion/NotOkAssertion.js.map +0 -1
  123. package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.js.map +0 -1
  124. package/build/src/models/http-actions/steps/assertion/OkAssertion.js.map +0 -1
  125. package/build/src/models/http-actions/steps/assertion/ToBeAssertion.js.map +0 -1
  126. package/build/src/models/http-actions/steps/assertion/index.js.map +0 -1
  127. package/build/src/models/http-actions/steps/data/DeleteCookieStep.js.map +0 -1
  128. package/build/src/models/http-actions/steps/data/ReadDataSourceStep.js.map +0 -1
  129. package/build/src/models/http-actions/steps/data/ReadDataStep.js.map +0 -1
  130. package/build/src/models/http-actions/steps/data/ReadValueStep.js.map +0 -1
  131. package/build/src/models/http-actions/steps/data/SetCookieStep.js.map +0 -1
  132. package/build/src/models/http-actions/steps/data/SetDataStep.js.map +0 -1
  133. package/build/src/models/http-actions/steps/data/SetVariableStep.js.map +0 -1
  134. package/build/src/models/http-actions/steps/data/index.js.map +0 -1
  135. package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.js.map +0 -1
  136. package/build/src/models/http-actions/steps/transformation/AsNumberStep.js.map +0 -1
  137. package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.js.map +0 -1
  138. package/build/src/models/http-actions/steps/transformation/RoundStep.js.map +0 -1
  139. package/build/src/models/http-actions/steps/transformation/SubstringStep.js.map +0 -1
  140. package/build/src/models/http-actions/steps/transformation/TrimStep.js.map +0 -1
  141. package/build/src/models/http-actions/steps/transformation/index.js.map +0 -1
  142. package/src/data/DataUtils.ts +0 -108
  143. /package/build/src/models/{http-actions → http-flows}/AssertionError.d.ts +0 -0
  144. /package/build/src/models/{http-actions → http-flows}/AssertionError.js +0 -0
  145. /package/build/src/models/{http-actions → http-flows}/HttpAssertion.d.ts +0 -0
  146. /package/build/src/models/{http-actions → http-flows}/HttpAssertion.js +0 -0
  147. /package/build/src/models/{http-actions → http-flows}/HttpStep.d.ts +0 -0
  148. /package/build/src/models/{http-actions → http-flows}/HttpStep.js +0 -0
  149. /package/build/src/models/{http-actions → http-flows}/steps/assertion/EqualAssertion.d.ts +0 -0
  150. /package/build/src/models/{http-actions → http-flows}/steps/assertion/EqualAssertion.js +0 -0
  151. /package/build/src/models/{http-actions → http-flows}/steps/assertion/GreaterThanAssertion.d.ts +0 -0
  152. /package/build/src/models/{http-actions → http-flows}/steps/assertion/GreaterThanAssertion.js +0 -0
  153. /package/build/src/models/{http-actions → http-flows}/steps/assertion/IncludesAssertion.d.ts +0 -0
  154. /package/build/src/models/{http-actions → http-flows}/steps/assertion/IncludesAssertion.js +0 -0
  155. /package/build/src/models/{http-actions → http-flows}/steps/assertion/IsEmptyAssertion.d.ts +0 -0
  156. /package/build/src/models/{http-actions → http-flows}/steps/assertion/IsEmptyAssertion.js +0 -0
  157. /package/build/src/models/{http-actions → http-flows}/steps/assertion/IsNotEmptyAssertion.d.ts +0 -0
  158. /package/build/src/models/{http-actions → http-flows}/steps/assertion/IsNotEmptyAssertion.js +0 -0
  159. /package/build/src/models/{http-actions → http-flows}/steps/assertion/LengthOfAssertion.d.ts +0 -0
  160. /package/build/src/models/{http-actions → http-flows}/steps/assertion/LengthOfAssertion.js +0 -0
  161. /package/build/src/models/{http-actions → http-flows}/steps/assertion/LessThanAssertion.d.ts +0 -0
  162. /package/build/src/models/{http-actions → http-flows}/steps/assertion/LessThanAssertion.js +0 -0
  163. /package/build/src/models/{http-actions → http-flows}/steps/assertion/MatchesAssertion.d.ts +0 -0
  164. /package/build/src/models/{http-actions → http-flows}/steps/assertion/MatchesAssertion.js +0 -0
  165. /package/build/src/models/{http-actions → http-flows}/steps/assertion/MatchesSchemaAssertion.d.ts +0 -0
  166. /package/build/src/models/{http-actions → http-flows}/steps/assertion/MatchesSchemaAssertion.js +0 -0
  167. /package/build/src/models/{http-actions → http-flows}/steps/assertion/NotEqualAssertion.d.ts +0 -0
  168. /package/build/src/models/{http-actions → http-flows}/steps/assertion/NotEqualAssertion.js +0 -0
  169. /package/build/src/models/{http-actions → http-flows}/steps/assertion/NotIncludesAssertion.d.ts +0 -0
  170. /package/build/src/models/{http-actions → http-flows}/steps/assertion/NotIncludesAssertion.js +0 -0
  171. /package/build/src/models/{http-actions → http-flows}/steps/assertion/NotOkAssertion.d.ts +0 -0
  172. /package/build/src/models/{http-actions → http-flows}/steps/assertion/NotOkAssertion.js +0 -0
  173. /package/build/src/models/{http-actions → http-flows}/steps/assertion/NotToBeAssertion.d.ts +0 -0
  174. /package/build/src/models/{http-actions → http-flows}/steps/assertion/NotToBeAssertion.js +0 -0
  175. /package/build/src/models/{http-actions → http-flows}/steps/assertion/OkAssertion.d.ts +0 -0
  176. /package/build/src/models/{http-actions → http-flows}/steps/assertion/OkAssertion.js +0 -0
  177. /package/build/src/models/{http-actions → http-flows}/steps/assertion/ToBeAssertion.d.ts +0 -0
  178. /package/build/src/models/{http-actions → http-flows}/steps/assertion/ToBeAssertion.js +0 -0
  179. /package/build/src/models/{http-actions → http-flows}/steps/assertion/index.d.ts +0 -0
  180. /package/build/src/models/{http-actions → http-flows}/steps/assertion/index.js +0 -0
  181. /package/build/src/models/{http-actions → http-flows}/steps/data/ReadDataSourceStep.d.ts +0 -0
  182. /package/build/src/models/{http-actions → http-flows}/steps/data/ReadDataSourceStep.js +0 -0
  183. /package/build/src/models/{http-actions → http-flows}/steps/data/ReadDataStep.d.ts +0 -0
  184. /package/build/src/models/{http-actions → http-flows}/steps/data/ReadDataStep.js +0 -0
  185. /package/build/src/models/{http-actions → http-flows}/steps/data/ReadValueStep.d.ts +0 -0
  186. /package/build/src/models/{http-actions → http-flows}/steps/data/ReadValueStep.js +0 -0
  187. /package/build/src/models/{http-actions → http-flows}/steps/data/SetDataStep.d.ts +0 -0
  188. /package/build/src/models/{http-actions → http-flows}/steps/data/SetDataStep.js +0 -0
  189. /package/build/src/models/{http-actions → http-flows}/steps/data/SetVariableStep.d.ts +0 -0
  190. /package/build/src/models/{http-actions → http-flows}/steps/data/SetVariableStep.js +0 -0
  191. /package/build/src/models/{http-actions → http-flows}/steps/transformation/AsLowerCaseStep.d.ts +0 -0
  192. /package/build/src/models/{http-actions → http-flows}/steps/transformation/AsLowerCaseStep.js +0 -0
  193. /package/build/src/models/{http-actions → http-flows}/steps/transformation/AsNumberStep.d.ts +0 -0
  194. /package/build/src/models/{http-actions → http-flows}/steps/transformation/AsNumberStep.js +0 -0
  195. /package/build/src/models/{http-actions → http-flows}/steps/transformation/AsUpperCaseStep.d.ts +0 -0
  196. /package/build/src/models/{http-actions → http-flows}/steps/transformation/AsUpperCaseStep.js +0 -0
  197. /package/build/src/models/{http-actions → http-flows}/steps/transformation/RoundStep.d.ts +0 -0
  198. /package/build/src/models/{http-actions → http-flows}/steps/transformation/RoundStep.js +0 -0
  199. /package/build/src/models/{http-actions → http-flows}/steps/transformation/SubstringStep.d.ts +0 -0
  200. /package/build/src/models/{http-actions → http-flows}/steps/transformation/SubstringStep.js +0 -0
  201. /package/build/src/models/{http-actions → http-flows}/steps/transformation/TrimStep.d.ts +0 -0
  202. /package/build/src/models/{http-actions → http-flows}/steps/transformation/TrimStep.js +0 -0
  203. /package/build/src/models/{http-actions → http-flows}/steps/transformation/index.d.ts +0 -0
  204. /package/build/src/models/{http-actions → http-flows}/steps/transformation/index.js +0 -0
  205. /package/src/models/{http-actions → http-flows}/AssertionError.ts +0 -0
  206. /package/src/models/{http-actions → http-flows}/HttpAssertion.ts +0 -0
  207. /package/src/models/{http-actions → http-flows}/HttpStep.ts +0 -0
  208. /package/src/models/{http-actions → http-flows}/steps/assertion/EqualAssertion.ts +0 -0
  209. /package/src/models/{http-actions → http-flows}/steps/assertion/GreaterThanAssertion.ts +0 -0
  210. /package/src/models/{http-actions → http-flows}/steps/assertion/IncludesAssertion.ts +0 -0
  211. /package/src/models/{http-actions → http-flows}/steps/assertion/IsEmptyAssertion.ts +0 -0
  212. /package/src/models/{http-actions → http-flows}/steps/assertion/IsNotEmptyAssertion.ts +0 -0
  213. /package/src/models/{http-actions → http-flows}/steps/assertion/LengthOfAssertion.ts +0 -0
  214. /package/src/models/{http-actions → http-flows}/steps/assertion/LessThanAssertion.ts +0 -0
  215. /package/src/models/{http-actions → http-flows}/steps/assertion/MatchesAssertion.ts +0 -0
  216. /package/src/models/{http-actions → http-flows}/steps/assertion/MatchesSchemaAssertion.ts +0 -0
  217. /package/src/models/{http-actions → http-flows}/steps/assertion/NotEqualAssertion.ts +0 -0
  218. /package/src/models/{http-actions → http-flows}/steps/assertion/NotIncludesAssertion.ts +0 -0
  219. /package/src/models/{http-actions → http-flows}/steps/assertion/NotOkAssertion.ts +0 -0
  220. /package/src/models/{http-actions → http-flows}/steps/assertion/NotToBeAssertion.ts +0 -0
  221. /package/src/models/{http-actions → http-flows}/steps/assertion/OkAssertion.ts +0 -0
  222. /package/src/models/{http-actions → http-flows}/steps/assertion/ToBeAssertion.ts +0 -0
  223. /package/src/models/{http-actions → http-flows}/steps/data/ReadDataSourceStep.ts +0 -0
  224. /package/src/models/{http-actions → http-flows}/steps/data/ReadDataStep.ts +0 -0
  225. /package/src/models/{http-actions → http-flows}/steps/data/ReadValueStep.ts +0 -0
  226. /package/src/models/{http-actions → http-flows}/steps/data/SetDataStep.ts +0 -0
  227. /package/src/models/{http-actions → http-flows}/steps/data/SetVariableStep.ts +0 -0
  228. /package/src/models/{http-actions → http-flows}/steps/transformation/AsLowerCaseStep.ts +0 -0
  229. /package/src/models/{http-actions → http-flows}/steps/transformation/AsNumberStep.ts +0 -0
  230. /package/src/models/{http-actions → http-flows}/steps/transformation/AsUpperCaseStep.ts +0 -0
  231. /package/src/models/{http-actions → http-flows}/steps/transformation/RoundStep.ts +0 -0
  232. /package/src/models/{http-actions → http-flows}/steps/transformation/SubstringStep.ts +0 -0
  233. /package/src/models/{http-actions → http-flows}/steps/transformation/TrimStep.ts +0 -0
@@ -1,250 +1,85 @@
1
- import { CookieJar } from "../../cookies/CookieJar.js";
2
1
  import { IHttpRequest } from "../../models/HttpRequest.js";
3
2
  import { ISentRequest } from "../../models/SentRequest.js";
4
3
  import { IResponse } from "../../models/Response.js";
5
4
  import { IErrorResponse } from "../../models/ErrorResponse.js";
6
- import { HttpCookie } from "../../models/HttpCookie.js";
7
- import {
8
- FlowSourceEnum, IHttpAction,
9
- IHttpFlow, IHttpCondition,
10
- } from '../../models/http-actions/HttpFlows.js';
11
- import { RequestDataExtractor } from "../../data/RequestDataExtractor.js";
12
- import { checkCondition } from "./ConditionCheck.js";
13
- import { ApiSchemaValues } from "../../amf/ApiSchemaValues.js";
14
- import { SameSiteValue } from "../../cookies/CookieParser.js";
15
- import { IHttpStep } from "../../models/http-actions/HttpStep.js";
16
- import { IReadDataStep, ReadDataStep, ReadDataStepKind } from "../../models/http-actions/steps/data/ReadDataStep.js";
17
- import { ISetDataStep, SetDataStep, SetDataStepKind } from "../../models/http-actions/steps/data/SetDataStep.js";
18
- import { ISetVariableStep, SetVariableStep, SetVariableStepKind } from "../../models/http-actions/steps/data/SetVariableStep.js";
19
- import { ISetCookieStep, SetCookieStep, SetCookieStepKind } from "../../models/http-actions/steps/data/SetCookieStep.js";
20
- import { DeleteCookieStep, DeleteCookieStepKind, IDeleteCookieStep } from "../../models/http-actions/steps/data/DeleteCookieStep.js";
5
+ import { IHttpAction, IHttpFlow } from '../../models/http-flows/HttpFlows.js';
6
+ import { IHttpStep } from "../../models/http-flows/HttpStep.js";
7
+ import { HttpFlows, IStepValue } from "./HttpFlows.js";
21
8
 
22
9
  export type FlowValue = string | number | boolean | null | undefined | unknown;
23
10
 
24
- export class HttpFlowRunner {
11
+ export class HttpFlowRunner extends HttpFlows {
25
12
  /**
26
- * The cumulative list of all variables to be applied to the request and other properties.
27
- * The variables must be already processed for variables in values (evaluated).
28
- *
29
- * These variables are passed by reference. Changes made anywhere to the variables will result
30
- * with updating this list.
13
+ * Runs flows before the HTTP request is sent to the remote machine.
14
+ * The request has to be pre-processed, that is, variables should already be applied to it.
31
15
  */
32
- variables?: Record<string, string>;
33
-
34
- /**
35
- * An instance of a cookie jar (store) to put/read cookies.
36
- */
37
- cookies?: CookieJar;
38
-
39
16
  async request(request: IHttpRequest, flows?: IHttpFlow[]): Promise<void> {
40
17
  if (!flows || !flows.length) {
41
18
  return;
42
19
  }
43
- for (const flow of flows) {
44
- const { condition, actions } = flow;
45
- if (condition) {
46
- try {
47
- const meet = await this._satisfied(condition, request);
48
- if (!meet) {
49
- continue;
50
- }
51
- } catch (_) {
52
- continue;
53
- }
54
- }
55
- for (const action of actions) {
56
- await this._runAction(action, request);
57
- }
58
- }
20
+ await this.runFlows(request, flows);
59
21
  }
60
22
 
61
23
  async response(request: IHttpRequest | ISentRequest, response: IResponse | IErrorResponse, flows?: IHttpFlow[]): Promise<void> {
62
24
  if (!flows || !flows.length) {
63
25
  return;
64
26
  }
27
+ await this.runFlows(request, flows, response);
28
+ }
29
+
30
+ protected async runFlows(request: IHttpRequest | ISentRequest, flows: IHttpFlow[], response?: IResponse | IErrorResponse): Promise<void> {
65
31
  for (const flow of flows) {
66
- for (const action of flow.actions) {
67
- await this._runAction(action, request, response);
32
+ const { condition, actions } = flow;
33
+ const passedCondition = await this.checkCondition(request, condition, response);
34
+ if (!passedCondition) {
35
+ continue;
36
+ }
37
+ for (const action of actions) {
38
+ try {
39
+ await this.runAction(action, request, response);
40
+ } catch (e) {
41
+ // eslint-disable-next-line no-console
42
+ console.warn(e);
43
+ // if the step fails then we stop execution.
44
+ // TODO: we should generate a report with the list of execution errors and present it in the UI.
45
+ break;
46
+ }
68
47
  }
69
48
  }
70
49
  }
71
50
 
72
- async _runAction(action: IHttpAction, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<void> {
51
+ async runAction(action: IHttpAction, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<void> {
73
52
  const { steps } = action;
74
53
  if (!Array.isArray(steps) || !steps.length) {
75
54
  return;
76
55
  }
77
- // this keeps a value from the last step to be passed to the next step.
78
- let lastResult: FlowValue;
79
- for (const step of steps) {
80
- lastResult = await this._runStep(step, lastResult, request, response);
81
- }
56
+ await this.runSteps(steps, request, response);
82
57
  }
83
58
 
84
- async _satisfied(condition: IHttpCondition, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<boolean> {
85
- const { source, data, path, operator, value } = condition;
86
- if (!source || !operator) {
87
- return false;
88
- }
89
- const extractor = new RequestDataExtractor(request, response);
90
- const readValue = await extractor.extract(source, data, path);
91
- return checkCondition(readValue, operator, value);
92
- }
93
-
94
- async _runStep(step: IHttpStep, input: FlowValue, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<FlowValue> {
95
- switch (step.kind) {
96
- case ReadDataStepKind: return this._runReadDataStep(step as IReadDataStep, request, response);
97
- case SetDataStepKind: return this._runSetDataStep(step as ISetDataStep);
98
- case SetVariableStepKind: return this._runSetVariableStep(step as ISetVariableStep, input);
99
- case SetCookieStepKind: return this._runSetCookieStep(step as ISetCookieStep, input, request);
100
- case DeleteCookieStepKind: return this._runDeleteCookieStep(step as IDeleteCookieStep, request);
101
- default: return undefined;
102
- }
103
- }
104
-
105
- /**
106
- * A step that reads data from the request, response, or variables.
107
- *
108
- * @param step The step configuration.
109
- * @param request The HttpRequest or the SentRequest (for responses)
110
- * @param response When available, the response data
111
- * @returns The read value or undefined.
112
- */
113
- async _runReadDataStep(step: IReadDataStep, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<string | number | undefined> {
114
- const instance = new ReadDataStep(step);
115
-
116
- if (instance.enabled === false || !instance.checkValidity()) {
117
- return undefined;
118
- }
119
- const { source, data, path } = step;
120
- if (source === FlowSourceEnum.request) {
121
- const extractor = new RequestDataExtractor(request);
122
- return extractor.extract(source, data, path);
123
- }
124
-
125
- if (source === FlowSourceEnum.response) {
126
- const extractor = new RequestDataExtractor(request, response);
127
- return extractor.extract(source, data, path);
59
+ async checkCondition(request: IHttpRequest | ISentRequest, condition?: IHttpAction, response?: IResponse | IErrorResponse): Promise<boolean> {
60
+ if (!condition) {
61
+ return true;
128
62
  }
129
-
130
- if (source === FlowSourceEnum.variable && path && this.variables) {
131
- return this.variables[path];
132
- }
133
-
134
- return undefined;
135
- }
136
-
137
- /**
138
- * A step that returns a pre-configured value.
139
- *
140
- * @param step The step configuration.
141
- * @returns The read value with applied data type.
142
- */
143
- _runSetDataStep(step: ISetDataStep): FlowValue {
144
- const instance = new SetDataStep(step);
145
- if (instance.enabled === false || !instance.checkValidity()) {
146
- return undefined;
147
- }
148
- const { value, dataType } = step;
149
- if (value === null || value === undefined) {
150
- return undefined;
151
- }
152
- return ApiSchemaValues.parseScalar(value, dataType);
153
- }
154
-
155
- /**
156
- * A step that sets a variable in the current environment.
157
- *
158
- * @param step The step configuration.
159
- * @param value The value to set. A value that is `null` or `undefined` deletes the variable.
160
- */
161
- _runSetVariableStep(step: ISetVariableStep, value: FlowValue): FlowValue {
162
- const instance = new SetVariableStep(step);
163
- if (instance.enabled === false || !instance.checkValidity() || !this.variables) {
164
- return undefined;
165
- }
166
- const { name } = step;
167
- if (value === null || typeof value === undefined) {
168
- delete this.variables[name];
169
- } else {
170
- this.variables[name] = String(value);
171
- }
172
- return undefined;
173
- }
174
-
175
- /**
176
- * A step that sets a cookie.
177
- *
178
- * @param step The step configuration.
179
- * @param value The value to sent on the cookie.
180
- * @param request The request object.
181
- */
182
- async _runSetCookieStep(step: ISetCookieStep, value: FlowValue, request: IHttpRequest | ISentRequest): Promise<FlowValue> {
183
- const instance = new SetCookieStep(step);
184
- const { cookies } = this;
185
- if (instance.enabled === false || !instance.checkValidity() || !cookies ) {
186
- return undefined;
187
- }
188
- if (value === null || typeof value === undefined) {
189
- return undefined;
190
- }
191
- const { name, expires, hostOnly, httpOnly, sameSite, secure, session } = step;
192
- const typedValue = String(value);
193
- let url: string;
194
- if (step.url) {
195
- url = step.url;
196
- } else {
197
- url = request.url;
198
- }
199
- const cookie = new HttpCookie({
200
- name: name,
201
- value: typedValue,
202
- sameSite: 'unspecified',
203
- });
204
-
205
- if (sameSite) {
206
- const typed = sameSite as SameSiteValue;
207
- switch (typed.toLowerCase()) {
208
- case 'lax': cookie.sameSite = 'lax'; break;
209
- case 'strict': cookie.sameSite = 'strict'; break;
210
- case 'none': cookie.sameSite = 'no_restriction'; break;
211
- }
212
- }
213
- if (expires) {
214
- cookie.expirationDate = expires;
215
- }
216
- if (typeof hostOnly === 'boolean') {
217
- cookie.hostOnly = hostOnly;
218
- }
219
- if (typeof httpOnly === 'boolean') {
220
- cookie.httpOnly = httpOnly;
221
- }
222
- if (typeof secure === 'boolean') {
223
- cookie.secure = secure;
63
+ const { steps = [] } = condition;
64
+ if (!Array.isArray(steps) || !steps.length) {
65
+ return true;
224
66
  }
225
- if (typeof session === 'boolean') {
226
- cookie.session = session;
67
+ // the condition works with assertions. If the condition throws then it is not satisfied.
68
+ try {
69
+ await this.runSteps(steps, request, response);
70
+ return true;
71
+ } catch (_) {
72
+ return false;
227
73
  }
228
- await cookies.setCookies(url, [cookie]);
229
- return undefined;
230
74
  }
231
75
 
232
- /**
233
- * A step to delete cookies from the cookie jar.
234
- */
235
- async _runDeleteCookieStep(step: IDeleteCookieStep, request: IHttpRequest | ISentRequest): Promise<FlowValue> {
236
- const instance = new DeleteCookieStep(step);
237
- const { cookies } = this;
238
- if (instance.enabled === false || !instance.checkValidity() || !cookies) {
239
- return undefined;
240
- }
241
- let url: string;
242
- if (step.url) {
243
- url = step.url;
244
- } else {
245
- url = request.url;
76
+ protected async runSteps(steps: IHttpStep[], request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<void> {
77
+ // this keeps a value from the last step to be passed to the next step.
78
+ let lastResult: IStepValue = {
79
+ value: undefined,
80
+ };
81
+ for (const step of steps) {
82
+ lastResult = await this.runStep(request, step, lastResult, response);
246
83
  }
247
- await cookies.deleteCookies(url, step.name);
248
- return undefined;
249
84
  }
250
85
  }