@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
@@ -0,0 +1,188 @@
1
+ import { IHttpRequest, HttpRequest } from '../models/HttpRequest.js';
2
+ import { ISentRequest, SentRequest } from '../models/SentRequest.js';
3
+ import { IHttpResponse, HttpResponse } from '../models/HttpResponse.js';
4
+ import { IErrorResponse, ErrorResponse } from '../models/ErrorResponse.js';
5
+ import { Headers } from '../lib/headers/Headers.js';
6
+ import { DataReader } from './DataReader.js';
7
+ import { JmespathReader } from './JmespathReader.js';
8
+ import { XmlReader } from './XmlReader.js';
9
+ import { UrlEncodedReader } from './UrlEncodedReader.js';
10
+ import { CookieParser } from '../cookies/CookieParser.js';
11
+
12
+ type DataInput = HttpRequest | SentRequest | IHttpRequest | ISentRequest | IHttpResponse | HttpResponse | IErrorResponse | ErrorResponse | undefined;
13
+
14
+ /**
15
+ * This is a factory class for the `RequestDataExtractor`.
16
+ */
17
+ export class DataExtractor {
18
+ /**
19
+ * Reads the value of a cookie.
20
+ * @param name The name of the cookie to read.
21
+ * @param input The response object.
22
+ */
23
+ static readCookieValue(name: string, input: IHttpResponse | HttpResponse | IErrorResponse | ErrorResponse | undefined): string | undefined {
24
+ const headers = this.readHeaders(input);
25
+ if (!headers) {
26
+ return undefined;
27
+ }
28
+ const parsed = new Headers(headers);
29
+ const header = parsed.get('set-cookie');
30
+ if (!header) {
31
+ return undefined;
32
+ }
33
+ const cookies = CookieParser.parseRelaxed(header);
34
+ const cookie = cookies.find(i => i.name === name);
35
+ if (cookie) {
36
+ return cookie.value;
37
+ }
38
+ return undefined;
39
+ }
40
+
41
+ static readHeaders(obj: DataInput): string {
42
+ if (!obj) {
43
+ return '';
44
+ }
45
+ const typedInstance = obj as HttpRequest | SentRequest;
46
+ if (typedInstance.headersModel && typeof typedInstance.headersModel.toRawString === 'function') {
47
+ return typedInstance.headersModel.toString();
48
+ }
49
+ const typedSchema = obj as IHttpRequest | ISentRequest;
50
+ if (Array.isArray(typedSchema.headersModel)) {
51
+ const headers = Headers.fromPropertyArray(typedSchema.headersModel);
52
+ return headers.toString();
53
+ }
54
+ return obj.headers || '';
55
+ }
56
+
57
+ /**
58
+ * Reads value from the body.
59
+ * @param value The read body value as string
60
+ * @param mime The body mime
61
+ * @param path THe path to read.
62
+ * @returns The extracted value.
63
+ */
64
+ static async extractBody(value: string, mime: string, path: string): Promise<string | undefined> {
65
+ let reader: DataReader | undefined;
66
+ if (mime.includes('json')) {
67
+ // reader = new JsonReader();
68
+ reader = new JmespathReader();
69
+ } else if (mime.includes('xml')) {
70
+ reader = new XmlReader();
71
+ } else if (mime.includes('x-www-form-urlencoded')) {
72
+ reader = new UrlEncodedReader();
73
+ }
74
+ if (!reader) {
75
+ return undefined;
76
+ }
77
+ await reader.writePayload(value);
78
+ return reader.getValue(path) as Promise<string>;
79
+ }
80
+
81
+ /**
82
+ * Returns the value for path for given source object
83
+ *
84
+ * @param url An url to parse.
85
+ * @param path Path to the data
86
+ * @return Value for the path.
87
+ */
88
+ static getDataUrl(url: string, path: string[]): string | number | undefined {
89
+ if (!path || path.length === 0 || !url) {
90
+ return url;
91
+ }
92
+ let value: URL | undefined;
93
+ try {
94
+ value = new URL(url);
95
+ } catch (e) {
96
+ //
97
+ }
98
+ if (!value) {
99
+ return undefined;
100
+ }
101
+ switch (path[0]) {
102
+ case 'host':
103
+ return value.host;
104
+ case 'protocol':
105
+ return value.protocol;
106
+ case 'path':
107
+ return value.pathname;
108
+ case 'query':
109
+ return DataExtractor.readUrlQueryValue(value, path[1]) || undefined;
110
+ case 'hash':
111
+ return DataExtractor.readUrlHashValue(value, path[1]) || undefined;
112
+ default:
113
+ throw new Error(`Unknown path in the URL: ${path}`);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Reads value of the URL query parameters.
119
+ *
120
+ * The `?` at the beginning of the query string is removed.
121
+ *
122
+ * @param url The URL object instance
123
+ * @param param Param name to return. If not set then it returns whole query string value.
124
+ * @return Full query string value if `param` is not set or parameter
125
+ * value. This function does not returns `null` values.
126
+ */
127
+ static readUrlQueryValue(url: URL, param?: string): string | null {
128
+ if (!param) {
129
+ let v = url.search || '';
130
+ if (v[0] === '?') {
131
+ v = v.substring(1);
132
+ }
133
+ return v;
134
+ }
135
+ let value = url.searchParams.get(param);
136
+ if (!value && value !== '') {
137
+ value = null;
138
+ }
139
+ return value;
140
+ }
141
+
142
+ /**
143
+ * Reads value of the URL hash.
144
+ *
145
+ * The `#` at the beginning of the hash string is removed.
146
+ *
147
+ * If the `param` argument is set then it treats hahs value as a query
148
+ * parameters string and parses it to get the value.
149
+ *
150
+ * @param url The URL object instance
151
+ * @param param Param name to return. If not set then it returns whole hash string value.
152
+ * @return Hash parameter or whole hash value.
153
+ */
154
+ static readUrlHashValue(url: URL, param?: string): string | undefined {
155
+ let value: string | undefined = (url.hash || '').substring(1);
156
+ if (!param) {
157
+ return value;
158
+ }
159
+ const obj = new URLSearchParams(value);
160
+ value = obj.get(param) || undefined;
161
+ if (!value && value !== '') {
162
+ value = undefined;
163
+ }
164
+ return value;
165
+ }
166
+
167
+
168
+ /**
169
+ * Returns a value for the headers.
170
+ *
171
+ * @param source HTTP headers string
172
+ * @param path The path to the object
173
+ * @returns The value for the path.
174
+ */
175
+ static getDataHeaders(source: string, path: string[]): string | undefined {
176
+ if (!path || !path.length || !path[0]) {
177
+ return source;
178
+ }
179
+ const headers = new Headers(source);
180
+ const lowerName = path[0].toLowerCase();
181
+ for (const [name, value] of headers) {
182
+ if (name.toLowerCase() === lowerName) {
183
+ return value;
184
+ }
185
+ }
186
+ return undefined;
187
+ }
188
+ }
@@ -1,14 +1,10 @@
1
- import * as DataUtils from './DataUtils.js';
2
1
  import { IHttpRequest, HttpRequest } from '../models/HttpRequest.js';
3
2
  import { ISentRequest, SentRequest } from '../models/SentRequest.js';
4
3
  import { IHttpResponse, HttpResponse } from '../models/HttpResponse.js';
5
4
  import { IErrorResponse, ErrorResponse } from '../models/ErrorResponse.js';
6
- import { FlowRequestDataEnum, FlowResponseDataEnum, FlowSourceEnum } from '../models/http-actions/HttpFlows.js';
5
+ import { FlowRequestDataEnum, FlowResponseDataEnum, FlowSourceEnum } from '../models/http-flows/HttpFlows.js';
7
6
  import { Headers } from '../lib/headers/Headers.js';
8
- import { JsonReader } from './JsonReader.js';
9
- import { XmlReader } from './XmlReader.js';
10
- import { UrlEncodedReader } from './UrlEncodedReader.js';
11
- import { DataReader } from './DataReader.js';
7
+ import { DataExtractor } from './DataExtractor.js';
12
8
 
13
9
  /**
14
10
  * A class to extract data from the request or the response.
@@ -47,15 +43,19 @@ export class RequestDataExtractor {
47
43
  const args = path ? path.split('.') : [];
48
44
  switch (data) {
49
45
  case 'url':
50
- return DataUtils.getDataUrl(this.getUrl(), args);
46
+ return DataExtractor.getDataUrl(this.getUrl(), args);
51
47
  case 'headers':
52
- return DataUtils.getDataHeaders(this.getHeaders(source), args);
48
+ return DataExtractor.getDataHeaders(this.getHeaders(source), args);
53
49
  case 'status':
54
50
  return this.response && this.response.status;
51
+ case 'statusText':
52
+ return this.response && this.response.statusText;
55
53
  case 'method':
56
54
  return this.request.method;
57
55
  case 'body':
58
56
  return this.processBody(path, source);
57
+ case 'cookie':
58
+ return DataExtractor.readCookieValue(args[0], this.response);
59
59
  default:
60
60
  throw new Error(`Unknown data ${data} for ${source} data`);
61
61
  }
@@ -74,10 +74,7 @@ export class RequestDataExtractor {
74
74
  * @returns The headers from the request / response
75
75
  */
76
76
  getHeaders(source?: FlowSourceEnum): string {
77
- if (source === 'request') {
78
- return this.request.headers || '';
79
- }
80
- return this.response && this.response.headers || '';
77
+ return DataExtractor.readHeaders(source === 'request' ? this.request : this.response);
81
78
  }
82
79
 
83
80
  async processBody(path?: string, source?: FlowSourceEnum): Promise<string | undefined> {
@@ -97,7 +94,7 @@ export class RequestDataExtractor {
97
94
  if (!mime) {
98
95
  return undefined;
99
96
  }
100
- return this.extractBody(value, mime, path);
97
+ return DataExtractor.extractBody(value, mime, path);
101
98
  }
102
99
 
103
100
  /**
@@ -114,19 +111,10 @@ export class RequestDataExtractor {
114
111
  return undefined;
115
112
  }
116
113
 
114
+ /**
115
+ * @deprecated Use `DataExtractor.extractBody()` instead.
116
+ */
117
117
  async extractBody(value: string, mime: string, path: string): Promise<string | undefined> {
118
- let reader: DataReader | undefined;
119
- if (mime.includes('json')) {
120
- reader = new JsonReader();
121
- } else if (mime.includes('xml')) {
122
- reader = new XmlReader();
123
- } else if (mime.includes('x-www-form-urlencoded')) {
124
- reader = new UrlEncodedReader();
125
- }
126
- if (!reader) {
127
- return undefined;
128
- }
129
- await reader.writePayload(value);
130
- return reader.getValue(path) as Promise<string>;
118
+ return DataExtractor.extractBody(value, mime, path)
131
119
  }
132
120
  }
package/src/lib/Buffer.ts CHANGED
@@ -1,48 +1,76 @@
1
+ import { hasBuffer } from "../Platform.js";
2
+
1
3
  /**
2
4
  * Converts base64 string to Uint8Array.
3
5
  *
4
6
  * @returns The restored array view.
5
7
  */
6
- export function base64ToBuffer(str: string): Uint8Array {
8
+ export function base64ToBuffer(str: string): Uint8Array | Buffer {
9
+ if (hasBuffer) {
10
+ return Buffer.from(str, 'base64');
11
+ }
7
12
  const asciiString = atob(str);
8
13
  return new Uint8Array([...asciiString].map((char) => char.charCodeAt(0)));
9
14
  }
10
15
 
16
+ function uint8ArrayToBase64(view: Uint8Array): string {
17
+ if (hasBuffer) {
18
+ const buffer = Buffer.from(view);
19
+ return buffer.toString('base64');
20
+ }
21
+ return btoa(String.fromCharCode(...view))
22
+ }
23
+
24
+ function arrayBufferToBase64(buffer: ArrayBuffer): string {
25
+ if (hasBuffer) {
26
+ const nodeBuffer = Buffer.from(buffer);
27
+ return nodeBuffer.toString('base64');
28
+ }
29
+ return btoa(String.fromCharCode(...new Uint8Array(buffer)));
30
+ }
31
+
11
32
  /**
12
33
  * Converts incoming data to base64 string.
13
34
  *
14
35
  * @returns Safe to store string.
15
36
  */
16
- export function bufferToBase64(view: Buffer | Uint8Array): string {
17
- const str = view.reduce(
18
- (data, byte) => data + String.fromCharCode(byte),
19
- ''
20
- );
21
- return btoa(str);
37
+ export function bufferToBase64(view: Buffer | ArrayBuffer | Uint8Array): string {
38
+ const name = view[Symbol.toStringTag];
39
+ if (name === 'Uint8Array') {
40
+ return uint8ArrayToBase64(view as Uint8Array);
41
+ }
42
+ if (name === 'ArrayBuffer') {
43
+ return arrayBufferToBase64(view as ArrayBuffer);
44
+ }
45
+ const buffer = view as Buffer;
46
+ return buffer.toString('base64');
22
47
  }
23
48
 
24
49
  /**
25
50
  * Reads file as ArrayBuffer
26
51
  */
27
- export function fileToBuffer(blob: Blob): Promise<Uint8Array> {
28
- return new Promise((resolve, reject) => {
29
- const reader = new FileReader();
30
- reader.onload = (): void => { resolve(new Uint8Array(reader.result as ArrayBuffer)); };
31
- /* istanbul ignore next */
32
- reader.onerror = (): void => { reject(new Error('Unable to read file')); };
33
- reader.readAsArrayBuffer(blob);
34
- });
52
+ export async function fileToBuffer(blob: Blob): Promise<Uint8Array> {
53
+ const ab = await blob.arrayBuffer();
54
+ return new Uint8Array(ab);
55
+ // return new Promise((resolve, reject) => {
56
+ // const reader = new FileReader();
57
+ // reader.onload = (): void => { resolve(new Uint8Array(reader.result as ArrayBuffer)); };
58
+ // /* istanbul ignore next */
59
+ // reader.onerror = (): void => { reject(new Error('Unable to read file')); };
60
+ // reader.readAsArrayBuffer(blob);
61
+ // });
35
62
  }
36
63
 
37
64
  /**
38
65
  * Reads file as string
39
66
  */
40
- export function fileToString(blob: Blob): Promise<string> {
41
- return new Promise((resolve, reject) => {
42
- const reader = new FileReader();
43
- reader.onload = (): void => { resolve(reader.result as string); };
44
- /* istanbul ignore next */
45
- reader.onerror = (): void => { reject(new Error('Unable to read file')); };
46
- reader.readAsText(blob);
47
- });
67
+ export async function fileToString(blob: Blob): Promise<string> {
68
+ return blob.text();
69
+ // return new Promise((resolve, reject) => {
70
+ // const reader = new FileReader();
71
+ // reader.onload = (): void => { resolve(reader.result as string); };
72
+ // /* istanbul ignore next */
73
+ // reader.onerror = (): void => { reject(new Error('Unable to read file')); };
74
+ // reader.readAsText(blob);
75
+ // });
48
76
  }
@@ -292,7 +292,7 @@ export class Certificate {
292
292
  }
293
293
  if (typeof data.data !== 'string') {
294
294
  data.type = 'buffer';
295
- const buff = data.data as Buffer;
295
+ const buff = data.data as Buffer | ArrayBuffer | Uint8Array;
296
296
  data.data = bufferToBase64(buff);
297
297
  }
298
298
  return data;
@@ -13,9 +13,9 @@ import { ARCSavedRequest, ARCHistoryRequest } from './legacy/request/ArcRequest.
13
13
  import { ErrorResponse as LegacyErrorResponse, Response as LegacyResponse } from './legacy/request/ArcResponse.js';
14
14
  import { PayloadSerializer } from '../lib/transformers/PayloadSerializer.js';
15
15
  import { Normalizer } from './legacy/Normalizer.js';
16
- import { IHttpFlow } from './http-actions/HttpFlows.js';
17
- import { IHttpAssertion } from './http-actions/HttpAssertion.js';
18
- import { LegacyTranslator } from './http-actions/LegacyTranslator.js';
16
+ import { IHttpFlow } from './http-flows/HttpFlows.js';
17
+ import { IHttpAssertion } from './http-flows/HttpAssertion.js';
18
+ import { LegacyTranslator } from './http-flows/LegacyTranslator.js';
19
19
 
20
20
  export const Kind = 'Core#Request';
21
21
  export const createdSymbol = Symbol('created');
@@ -4,7 +4,7 @@ import { IErrorResponse, ErrorResponse } from './ErrorResponse.js';
4
4
  import { IResponse, Response } from './Response.js';
5
5
  import { IRequestsSize, RequestsSize } from './RequestsSize.js';
6
6
  import { ResponseRedirect as LegacyRedirect } from './legacy/request/ArcResponse.js';
7
- import { AssertionResult } from './http-actions/HttpAssertion.js';
7
+ import { AssertionResult } from './http-flows/HttpAssertion.js';
8
8
 
9
9
  export const Kind = 'Core#ResponseLog';
10
10
 
@@ -1,4 +1,3 @@
1
- import { AssertionEnum } from './HttpAssertion.js';
2
1
  import { IHttpStep } from './HttpStep.js';
3
2
 
4
3
  export enum FlowSourceEnum {
@@ -28,6 +27,10 @@ export enum FlowResponseDataEnum {
28
27
  status = "status",
29
28
  statusText = "statusText",
30
29
  headers = "headers",
30
+ /**
31
+ * Reads the value of a cookie in the `set-cookie` header.
32
+ */
33
+ cookie = "cookie",
31
34
  body = "body"
32
35
  }
33
36
 
@@ -54,7 +57,7 @@ export interface IHttpFlow {
54
57
  /**
55
58
  * A condition to check before running the flow.
56
59
  */
57
- condition?: IHttpCondition;
60
+ condition?: IHttpAction;
58
61
  }
59
62
 
60
63
  /**
@@ -76,40 +79,3 @@ export interface IHttpAction {
76
79
  */
77
80
  steps: IHttpStep[];
78
81
  }
79
-
80
- /**
81
- * A condition to execute for an action.
82
- */
83
- export interface IHttpCondition {
84
- /**
85
- * The main data source.
86
- * In the legacy actions this was `type`.
87
- */
88
- source?: FlowSourceEnum;
89
- /**
90
- * Source of the data.
91
- * In the legacy actions this was `source`.
92
- * This is not required when the source is not `request` or `response`.
93
- */
94
- data?: FlowRequestDataEnum | FlowResponseDataEnum;
95
- /**
96
- * The path to the data.
97
- * For JSON value use https://jmespath.org/ syntax.
98
- * For XML use xpath.
99
- * For any other use a simple path to the data separated by dot (e.g. headers.content-type)
100
- */
101
- path?: string;
102
- /**
103
- * The comparison operator.
104
- */
105
- operator?: AssertionEnum;
106
- /**
107
- * The value to compare the read result.
108
- * In runtime, the type is casted to the same type as read value.
109
- *
110
- * When this is not set it compares to an empty string value or `0`.
111
- *
112
- * In ARC actions this was the `predictedValue`.
113
- */
114
- value?: string;
115
- }
@@ -4,16 +4,21 @@ import {
4
4
  SetCookieConfig, SetVariableConfig, DeleteCookieConfig, DataSourceConfiguration
5
5
  } from '../../models/legacy/actions/Actions.js';
6
6
  import {
7
- IHttpFlow, IHttpAction, IHttpCondition, FlowSourceEnum, FlowRequestDataEnum,
7
+ IHttpFlow, IHttpAction, FlowSourceEnum, FlowRequestDataEnum,
8
8
  FlowResponseDataEnum,
9
9
  } from './HttpFlows.js';
10
10
  import { AmfNamespace } from '../../amf/definitions/Namespace.js';
11
- import { AssertionEnum } from './HttpAssertion.js';
12
11
  import { IHttpStep } from './HttpStep.js';
13
- import { IReadDataStep, ReadDataStepKind } from './steps/data/ReadDataStep.js';
12
+ import { IReadDataStep, ReadDataStep, ReadDataStepKind } from './steps/data/ReadDataStep.js';
14
13
  import { ISetDataStep, SetDataStepKind } from './steps/data/SetDataStep.js';
15
14
  import { ISetCookieStep, SetCookieStepKind } from './steps/data/SetCookieStep.js';
16
15
  import { DeleteCookieStepKind, IDeleteCookieStep } from './steps/data/DeleteCookieStep.js';
16
+ import { IncludesAssertion } from './steps/assertion/IncludesAssertion.js';
17
+ import { EqualAssertion } from './steps/assertion/EqualAssertion.js';
18
+ import { GreaterThanAssertion } from './steps/assertion/GreaterThanAssertion.js';
19
+ import { LessThanAssertion } from './steps/assertion/LessThanAssertion.js';
20
+ import { NotEqualAssertion } from './steps/assertion/NotEqualAssertion.js';
21
+ import { MatchesAssertion } from './steps/assertion/MatchesAssertion.js';
17
22
 
18
23
  /**
19
24
  * Allows to translate the old ARC actions into Action flows.
@@ -64,45 +69,98 @@ export class LegacyTranslator {
64
69
  return flow;
65
70
  }
66
71
 
67
- protected static _translateCondition(runnable: LegacyCondition): IHttpCondition | undefined {
72
+ protected static _translateCondition(runnable: LegacyCondition): IHttpAction | undefined {
68
73
  const { source, alwaysPass, operator, path, predictedValue, type } = runnable;
69
74
  if (alwaysPass) {
70
75
  // in the flow, if there's no condition the steps are always executed.
71
76
  return undefined
72
77
  }
73
-
74
- const result: IHttpCondition = {};
75
- if (typeof path === 'string') {
76
- result.path = path;
78
+ if (!path || !type) {
79
+ return undefined;
77
80
  }
78
- if (type) {
79
- switch (type) {
80
- case 'request': result.source = FlowSourceEnum.request; break;
81
- case 'response': result.source = FlowSourceEnum.response; break;
82
- }
81
+ if (!['request', 'response'].includes(type)) {
82
+ return;
83
83
  }
84
- if (type && source) {
84
+
85
+ const result: IHttpAction = {
86
+ steps: [],
87
+ };
88
+ const readData = new ReadDataStep();
89
+ readData.source = type === 'request' ? FlowSourceEnum.request : FlowSourceEnum.response;
90
+ readData.path = path;
91
+ if (source) {
85
92
  if (type === 'request') {
86
- result.data = source as FlowRequestDataEnum;
87
- }
88
- if (type === 'response') {
89
- result.data = source as FlowResponseDataEnum;
93
+ readData.data = source as FlowRequestDataEnum;
94
+ } else if (type === 'response') {
95
+ readData.data = source as FlowResponseDataEnum;
90
96
  }
91
97
  }
92
- if (predictedValue) {
93
- result.value = String(predictedValue);
94
- }
95
- if (operator) {
96
- switch (operator) {
97
- case 'contains': result.operator = AssertionEnum.contains; break;
98
- case 'equal': result.operator = AssertionEnum.equal; break;
99
- case 'greater-than': result.operator = AssertionEnum.greaterThan; break;
100
- case 'greater-than-equal': result.operator = AssertionEnum.greaterThanEqual; break;
101
- case 'less-than': result.operator = AssertionEnum.lessThan; break;
102
- case 'less-than-equal': result.operator = AssertionEnum.lessThanEqual; break;
103
- case 'not-equal': result.operator = AssertionEnum.notEqual; break;
104
- case 'regex': result.operator = AssertionEnum.regex; break;
98
+ result.steps.push(readData.toJSON());
99
+ if (!operator) {
100
+ return result;
101
+ }
102
+ if (operator === 'contains') {
103
+ const assertion = new IncludesAssertion();
104
+ if (predictedValue) {
105
+ assertion.value = String(predictedValue);
106
+ }
107
+ result.steps.push(assertion.toJSON());
108
+ } else if (operator === 'equal') {
109
+ const assertion = new EqualAssertion();
110
+ if (predictedValue) {
111
+ assertion.value = String(predictedValue);
112
+ }
113
+ result.steps.push(assertion.toJSON());
114
+ } else if (operator === 'not-equal') {
115
+ const assertion = new NotEqualAssertion();
116
+ if (predictedValue) {
117
+ assertion.value = String(predictedValue);
118
+ }
119
+ result.steps.push(assertion.toJSON());
120
+ } else if (operator === 'greater-than') {
121
+ const assertion = new GreaterThanAssertion();
122
+ if (predictedValue) {
123
+ const typed = Number(predictedValue);
124
+ if (!Number.isNaN(typed)) {
125
+ assertion.value = typed;
126
+ }
127
+ }
128
+ result.steps.push(assertion.toJSON());
129
+ } else if (operator === 'greater-than-equal') {
130
+ const assertion = new GreaterThanAssertion();
131
+ assertion.equal = true;
132
+ if (predictedValue) {
133
+ const typed = Number(predictedValue);
134
+ if (!Number.isNaN(typed)) {
135
+ assertion.value = typed;
136
+ }
137
+ }
138
+ result.steps.push(assertion.toJSON());
139
+ } else if (operator === 'less-than') {
140
+ const assertion = new LessThanAssertion();
141
+ if (predictedValue) {
142
+ const typed = Number(predictedValue);
143
+ if (!Number.isNaN(typed)) {
144
+ assertion.value = typed;
145
+ }
146
+ }
147
+ result.steps.push(assertion.toJSON());
148
+ } else if (operator === 'less-than-equal') {
149
+ const assertion = new LessThanAssertion();
150
+ assertion.equal = true;
151
+ if (predictedValue) {
152
+ const typed = Number(predictedValue);
153
+ if (!Number.isNaN(typed)) {
154
+ assertion.value = typed;
155
+ }
156
+ }
157
+ result.steps.push(assertion.toJSON());
158
+ } else if (operator === 'regex') {
159
+ const assertion = new MatchesAssertion();
160
+ if (predictedValue) {
161
+ assertion.value = String(predictedValue);
105
162
  }
163
+ result.steps.push(assertion.toJSON());
106
164
  }
107
165
  return result;
108
166
  }
@@ -33,11 +33,16 @@ export class DeleteCookieStep extends HttpStep {
33
33
  */
34
34
  name?: string;
35
35
 
36
- static byName(name: string): DeleteCookieStep {
36
+ /**
37
+ * @param name The name of the cookie
38
+ * @param url Optionally, the URL of the cookie.
39
+ */
40
+ static byName(name: string, url?: string): DeleteCookieStep {
37
41
  return new DeleteCookieStep({
38
42
  kind: DeleteCookieStepKind,
39
43
  enabled: true,
40
44
  name,
45
+ url,
41
46
  });
42
47
  }
43
48