@api-client/core 0.9.4 → 0.9.5

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 (224) hide show
  1. package/build/browser.d.ts +12 -2
  2. package/build/browser.js +15 -2
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +13 -3
  5. package/build/index.js +16 -3
  6. package/build/index.js.map +1 -1
  7. package/build/src/data/{JmesparthReader.d.ts → JmespathReader.d.ts} +1 -1
  8. package/build/src/data/{JmesparthReader.js → JmespathReader.js} +2 -2
  9. package/build/src/data/JmespathReader.js.map +1 -0
  10. package/build/src/data/RequestDataExtractor.d.ts +5 -5
  11. package/build/src/data/RequestDataExtractor.js.map +1 -1
  12. package/build/src/data/XmlReader.js +14 -1
  13. package/build/src/data/XmlReader.js.map +1 -1
  14. package/build/src/models/ClientCertificate.d.ts +9 -0
  15. package/build/src/models/ClientCertificate.js.map +1 -1
  16. package/build/src/models/Environment.d.ts +3 -2
  17. package/build/src/models/Environment.js +11 -6
  18. package/build/src/models/Environment.js.map +1 -1
  19. package/build/src/models/ErrorResponse.js.map +1 -1
  20. package/build/src/models/HttpRequest.d.ts +2 -7
  21. package/build/src/models/HttpRequest.js +1 -6
  22. package/build/src/models/HttpRequest.js.map +1 -1
  23. package/build/src/models/HttpResponse.d.ts +2 -7
  24. package/build/src/models/HttpResponse.js +1 -3
  25. package/build/src/models/HttpResponse.js.map +1 -1
  26. package/build/src/models/ProjectRequest.d.ts +19 -0
  27. package/build/src/models/ProjectRequest.js +50 -0
  28. package/build/src/models/ProjectRequest.js.map +1 -1
  29. package/build/src/models/Request.d.ts +12 -3
  30. package/build/src/models/Request.js +14 -1
  31. package/build/src/models/Request.js.map +1 -1
  32. package/build/src/models/RequestAuthorization.js.map +1 -1
  33. package/build/src/models/RequestLog.d.ts +11 -0
  34. package/build/src/models/RequestLog.js +15 -1
  35. package/build/src/models/RequestLog.js.map +1 -1
  36. package/build/src/models/SerializablePayload.d.ts +6 -1
  37. package/build/src/models/SerializablePayload.js +10 -6
  38. package/build/src/models/SerializablePayload.js.map +1 -1
  39. package/build/src/models/http-actions/AssertionError.d.ts +36 -0
  40. package/build/src/models/http-actions/AssertionError.js +35 -0
  41. package/build/src/models/http-actions/AssertionError.js.map +1 -0
  42. package/build/src/models/http-actions/HttpAssertion.d.ts +84 -0
  43. package/build/src/models/http-actions/HttpAssertion.js +52 -0
  44. package/build/src/models/http-actions/HttpAssertion.js.map +1 -0
  45. package/build/src/models/http-actions/HttpFlows.d.ts +109 -0
  46. package/build/src/models/http-actions/HttpFlows.js +31 -0
  47. package/build/src/models/http-actions/HttpFlows.js.map +1 -0
  48. package/build/src/models/http-actions/HttpStep.d.ts +29 -0
  49. package/build/src/models/http-actions/HttpStep.js +30 -0
  50. package/build/src/models/http-actions/HttpStep.js.map +1 -0
  51. package/build/src/models/http-actions/LegacyTranslator.d.ts +8 -7
  52. package/build/src/models/http-actions/LegacyTranslator.js +18 -13
  53. package/build/src/models/http-actions/LegacyTranslator.js.map +1 -1
  54. package/build/src/models/http-actions/steps/assertion/EqualAssertion.d.ts +76 -0
  55. package/build/src/models/http-actions/steps/assertion/EqualAssertion.js +79 -0
  56. package/build/src/models/http-actions/steps/assertion/EqualAssertion.js.map +1 -0
  57. package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.d.ts +36 -0
  58. package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.js +59 -0
  59. package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.js.map +1 -0
  60. package/build/src/models/http-actions/steps/assertion/IncludesAssertion.d.ts +28 -0
  61. package/build/src/models/http-actions/steps/assertion/IncludesAssertion.js +45 -0
  62. package/build/src/models/http-actions/steps/assertion/IncludesAssertion.js.map +1 -0
  63. package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.d.ts +18 -0
  64. package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.js +29 -0
  65. package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.js.map +1 -0
  66. package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.d.ts +18 -0
  67. package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.js +29 -0
  68. package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.js.map +1 -0
  69. package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.d.ts +28 -0
  70. package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.js +45 -0
  71. package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.js.map +1 -0
  72. package/build/src/models/http-actions/steps/assertion/LessThanAssertion.d.ts +36 -0
  73. package/build/src/models/http-actions/steps/assertion/LessThanAssertion.js +59 -0
  74. package/build/src/models/http-actions/steps/assertion/LessThanAssertion.js.map +1 -0
  75. package/build/src/models/http-actions/steps/assertion/MatchesAssertion.d.ts +28 -0
  76. package/build/src/models/http-actions/steps/assertion/MatchesAssertion.js +45 -0
  77. package/build/src/models/http-actions/steps/assertion/MatchesAssertion.js.map +1 -0
  78. package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.d.ts +36 -0
  79. package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.js +59 -0
  80. package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.js.map +1 -0
  81. package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.d.ts +76 -0
  82. package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.js +79 -0
  83. package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.js.map +1 -0
  84. package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.d.ts +28 -0
  85. package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.js +45 -0
  86. package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.js.map +1 -0
  87. package/build/src/models/http-actions/steps/assertion/NotOkAssertion.d.ts +18 -0
  88. package/build/src/models/http-actions/steps/assertion/NotOkAssertion.js +29 -0
  89. package/build/src/models/http-actions/steps/assertion/NotOkAssertion.js.map +1 -0
  90. package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.d.ts +29 -0
  91. package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.js +45 -0
  92. package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.js.map +1 -0
  93. package/build/src/models/http-actions/steps/assertion/OkAssertion.d.ts +18 -0
  94. package/build/src/models/http-actions/steps/assertion/OkAssertion.js +29 -0
  95. package/build/src/models/http-actions/steps/assertion/OkAssertion.js.map +1 -0
  96. package/build/src/models/http-actions/steps/assertion/ToBeAssertion.d.ts +35 -0
  97. package/build/src/models/http-actions/steps/assertion/ToBeAssertion.js +53 -0
  98. package/build/src/models/http-actions/steps/assertion/ToBeAssertion.js.map +1 -0
  99. package/build/src/models/http-actions/steps/assertion/index.d.ts +15 -0
  100. package/build/src/models/http-actions/steps/assertion/index.js +16 -0
  101. package/build/src/models/http-actions/steps/assertion/index.js.map +1 -0
  102. package/build/src/models/http-actions/steps/data/DeleteCookieStep.d.ts +44 -0
  103. package/build/src/models/http-actions/steps/data/DeleteCookieStep.js +67 -0
  104. package/build/src/models/http-actions/steps/data/DeleteCookieStep.js.map +1 -0
  105. package/build/src/models/http-actions/steps/data/ReadDataSourceStep.d.ts +53 -0
  106. package/build/src/models/http-actions/steps/data/ReadDataSourceStep.js +60 -0
  107. package/build/src/models/http-actions/steps/data/ReadDataSourceStep.js.map +1 -0
  108. package/build/src/models/http-actions/steps/data/ReadDataStep.d.ts +67 -0
  109. package/build/src/models/http-actions/steps/data/ReadDataStep.js +77 -0
  110. package/build/src/models/http-actions/steps/data/ReadDataStep.js.map +1 -0
  111. package/build/src/models/http-actions/steps/data/ReadValueStep.d.ts +45 -0
  112. package/build/src/models/http-actions/steps/data/ReadValueStep.js +52 -0
  113. package/build/src/models/http-actions/steps/data/ReadValueStep.js.map +1 -0
  114. package/build/src/models/http-actions/steps/data/SetCookieStep.d.ts +100 -0
  115. package/build/src/models/http-actions/steps/data/SetCookieStep.js +138 -0
  116. package/build/src/models/http-actions/steps/data/SetCookieStep.js.map +1 -0
  117. package/build/src/models/http-actions/steps/data/SetDataStep.d.ts +77 -0
  118. package/build/src/models/http-actions/steps/data/SetDataStep.js +69 -0
  119. package/build/src/models/http-actions/steps/data/SetDataStep.js.map +1 -0
  120. package/build/src/models/http-actions/steps/data/SetVariableStep.d.ts +40 -0
  121. package/build/src/models/http-actions/steps/data/SetVariableStep.js +44 -0
  122. package/build/src/models/http-actions/steps/data/SetVariableStep.js.map +1 -0
  123. package/build/src/models/http-actions/steps/data/index.d.ts +7 -0
  124. package/build/src/models/http-actions/steps/data/index.js +8 -0
  125. package/build/src/models/http-actions/steps/data/index.js.map +1 -0
  126. package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.d.ts +18 -0
  127. package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.js +29 -0
  128. package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.js.map +1 -0
  129. package/build/src/models/http-actions/steps/transformation/AsNumberStep.d.ts +18 -0
  130. package/build/src/models/http-actions/steps/transformation/AsNumberStep.js +29 -0
  131. package/build/src/models/http-actions/steps/transformation/AsNumberStep.js.map +1 -0
  132. package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.d.ts +18 -0
  133. package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.js +29 -0
  134. package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.js.map +1 -0
  135. package/build/src/models/http-actions/steps/transformation/RoundStep.d.ts +43 -0
  136. package/build/src/models/http-actions/steps/transformation/RoundStep.js +52 -0
  137. package/build/src/models/http-actions/steps/transformation/RoundStep.js.map +1 -0
  138. package/build/src/models/http-actions/steps/transformation/SubstringStep.d.ts +38 -0
  139. package/build/src/models/http-actions/steps/transformation/SubstringStep.js +65 -0
  140. package/build/src/models/http-actions/steps/transformation/SubstringStep.js.map +1 -0
  141. package/build/src/models/http-actions/steps/transformation/TrimStep.d.ts +20 -0
  142. package/build/src/models/http-actions/steps/transformation/TrimStep.js +30 -0
  143. package/build/src/models/http-actions/steps/transformation/TrimStep.js.map +1 -0
  144. package/build/src/models/http-actions/steps/transformation/index.d.ts +6 -0
  145. package/build/src/models/http-actions/steps/transformation/index.js +7 -0
  146. package/build/src/models/http-actions/steps/transformation/index.js.map +1 -0
  147. package/build/src/proxy/RequestProxy.d.ts +7 -2
  148. package/build/src/proxy/RequestProxy.js +4 -1
  149. package/build/src/proxy/RequestProxy.js.map +1 -1
  150. package/build/src/runtime/http-runner/ConditionCheck.d.ts +10 -10
  151. package/build/src/runtime/http-runner/ConditionCheck.js.map +1 -1
  152. package/build/src/runtime/http-runner/HttpAssertionRunner.d.ts +75 -0
  153. package/build/src/runtime/http-runner/HttpAssertionRunner.js +538 -0
  154. package/build/src/runtime/http-runner/HttpAssertionRunner.js.map +1 -0
  155. package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +11 -6
  156. package/build/src/runtime/http-runner/HttpFlowRunner.js +24 -15
  157. package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -1
  158. package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +14 -3
  159. package/build/src/runtime/http-runner/HttpRequestRunner.js +44 -0
  160. package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -1
  161. package/build/src/runtime/node/ProjectParallelRunner.d.ts +1 -1
  162. package/build/src/runtime/node/ProjectParallelRunner.js +2 -2
  163. package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
  164. package/build/src/runtime/node/ProjectRequestRunner.js +6 -2
  165. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
  166. package/package.json +3 -2
  167. package/src/data/{JmesparthReader.ts → JmespathReader.ts} +2 -2
  168. package/src/data/RequestDataExtractor.ts +5 -5
  169. package/src/data/XmlReader.ts +16 -2
  170. package/src/models/ClientCertificate.ts +9 -0
  171. package/src/models/Environment.ts +11 -7
  172. package/src/models/ErrorResponse.ts +1 -1
  173. package/src/models/HttpRequest.ts +4 -14
  174. package/src/models/HttpResponse.ts +5 -11
  175. package/src/models/ProjectRequest.ts +54 -0
  176. package/src/models/Request.ts +23 -4
  177. package/src/models/RequestAuthorization.ts +1 -1
  178. package/src/models/RequestLog.ts +21 -1
  179. package/src/models/SerializablePayload.ts +18 -1
  180. package/src/models/http-actions/AssertionError.ts +57 -0
  181. package/src/models/http-actions/HttpAssertion.ts +89 -0
  182. package/src/models/http-actions/HttpFlows.ts +115 -0
  183. package/src/models/http-actions/HttpStep.ts +50 -0
  184. package/src/models/http-actions/LegacyTranslator.ts +42 -30
  185. package/src/models/http-actions/steps/assertion/EqualAssertion.ts +130 -0
  186. package/src/models/http-actions/steps/assertion/GreaterThanAssertion.ts +87 -0
  187. package/src/models/http-actions/steps/assertion/IncludesAssertion.ts +68 -0
  188. package/src/models/http-actions/steps/assertion/IsEmptyAssertion.ts +41 -0
  189. package/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.ts +41 -0
  190. package/src/models/http-actions/steps/assertion/LengthOfAssertion.ts +68 -0
  191. package/src/models/http-actions/steps/assertion/LessThanAssertion.ts +87 -0
  192. package/src/models/http-actions/steps/assertion/MatchesAssertion.ts +68 -0
  193. package/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.ts +85 -0
  194. package/src/models/http-actions/steps/assertion/NotEqualAssertion.ts +130 -0
  195. package/src/models/http-actions/steps/assertion/NotIncludesAssertion.ts +68 -0
  196. package/src/models/http-actions/steps/assertion/NotOkAssertion.ts +41 -0
  197. package/src/models/http-actions/steps/assertion/NotToBeAssertion.ts +69 -0
  198. package/src/models/http-actions/steps/assertion/OkAssertion.ts +41 -0
  199. package/src/models/http-actions/steps/assertion/ToBeAssertion.ts +76 -0
  200. package/src/models/http-actions/steps/data/DeleteCookieStep.ts +102 -0
  201. package/src/models/http-actions/steps/data/ReadDataSourceStep.ts +103 -0
  202. package/src/models/http-actions/steps/data/ReadDataStep.ts +128 -0
  203. package/src/models/http-actions/steps/data/ReadValueStep.ts +88 -0
  204. package/src/models/http-actions/steps/data/SetCookieStep.ts +206 -0
  205. package/src/models/http-actions/steps/data/SetDataStep.ts +124 -0
  206. package/src/models/http-actions/steps/data/SetVariableStep.ts +82 -0
  207. package/src/models/http-actions/steps/transformation/AsLowerCaseStep.ts +41 -0
  208. package/src/models/http-actions/steps/transformation/AsNumberStep.ts +41 -0
  209. package/src/models/http-actions/steps/transformation/AsUpperCaseStep.ts +41 -0
  210. package/src/models/http-actions/steps/transformation/RoundStep.ts +86 -0
  211. package/src/models/http-actions/steps/transformation/SubstringStep.ts +93 -0
  212. package/src/models/http-actions/steps/transformation/TrimStep.ts +43 -0
  213. package/src/proxy/RequestProxy.ts +11 -3
  214. package/src/runtime/http-runner/ConditionCheck.ts +13 -14
  215. package/src/runtime/http-runner/HttpAssertionRunner.ts +540 -0
  216. package/src/runtime/http-runner/HttpFlowRunner.ts +33 -19
  217. package/src/runtime/http-runner/HttpRequestRunner.ts +53 -5
  218. package/src/runtime/node/ProjectParallelRunner.ts +4 -4
  219. package/src/runtime/node/ProjectRequestRunner.ts +6 -2
  220. package/build/src/data/JmesparthReader.js.map +0 -1
  221. package/build/src/models/http-actions/HttpActions.d.ts +0 -256
  222. package/build/src/models/http-actions/HttpActions.js +0 -46
  223. package/build/src/models/http-actions/HttpActions.js.map +0 -1
  224. package/src/models/http-actions/HttpActions.ts +0 -270
@@ -4,13 +4,22 @@ import { ISentRequest } from "../../models/SentRequest.js";
4
4
  import { IResponse } from "../../models/Response.js";
5
5
  import { IErrorResponse } from "../../models/ErrorResponse.js";
6
6
  import { HttpCookie } from "../../models/HttpCookie.js";
7
- import { ActionSourceEnum, DeleteCookieStepKind, IActionStep, IDeleteCookieStep, IHttpAction, IHttpActionFlow, IHttpCondition, IReadDataStep, ISetCookieStep, ISetDataStep, ISetVariableStep, ReadDataStepKind, SetCookieStepKind, SetDataStepKind, SetVariableStepKind } from '../../models/http-actions/HttpActions.js';
7
+ import {
8
+ FlowSourceEnum, IHttpAction,
9
+ IHttpFlow, IHttpCondition,
10
+ } from '../../models/http-actions/HttpFlows.js';
8
11
  import { RequestDataExtractor } from "../../data/RequestDataExtractor.js";
9
12
  import { checkCondition } from "./ConditionCheck.js";
10
13
  import { ApiSchemaValues } from "../../amf/ApiSchemaValues.js";
11
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";
12
21
 
13
- type FlowValue = string | number | boolean | null | undefined;
22
+ export type FlowValue = string | number | boolean | null | undefined | unknown;
14
23
 
15
24
  export class HttpFlowRunner {
16
25
  /**
@@ -27,7 +36,7 @@ export class HttpFlowRunner {
27
36
  */
28
37
  cookies?: CookieJar;
29
38
 
30
- async request(request: IHttpRequest, flows?: IHttpActionFlow[]): Promise<void> {
39
+ async request(request: IHttpRequest, flows?: IHttpFlow[]): Promise<void> {
31
40
  if (!flows || !flows.length) {
32
41
  return;
33
42
  }
@@ -38,7 +47,7 @@ export class HttpFlowRunner {
38
47
  }
39
48
  }
40
49
 
41
- async response(request: IHttpRequest | ISentRequest, response: IResponse | IErrorResponse, flows?: IHttpActionFlow[]): Promise<void> {
50
+ async response(request: IHttpRequest | ISentRequest, response: IResponse | IErrorResponse, flows?: IHttpFlow[]): Promise<void> {
42
51
  if (!flows || !flows.length) {
43
52
  return;
44
53
  }
@@ -78,7 +87,7 @@ export class HttpFlowRunner {
78
87
  return checkCondition(readValue, operator, value);
79
88
  }
80
89
 
81
- async _runStep(step: IActionStep, input: FlowValue, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<FlowValue> {
90
+ async _runStep(step: IHttpStep, input: FlowValue, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<FlowValue> {
82
91
  switch (step.kind) {
83
92
  case ReadDataStepKind: return this._runReadDataStep(step as IReadDataStep, request, response);
84
93
  case SetDataStepKind: return this._runSetDataStep(step as ISetDataStep);
@@ -98,21 +107,23 @@ export class HttpFlowRunner {
98
107
  * @returns The read value or undefined.
99
108
  */
100
109
  async _runReadDataStep(step: IReadDataStep, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<string | number | undefined> {
101
- const { source, data, enabled, path } = step;
102
- if (enabled === false) {
110
+ const instance = new ReadDataStep(step);
111
+
112
+ if (instance.enabled === false || !instance.checkValidity()) {
103
113
  return undefined;
104
114
  }
105
- if (source === ActionSourceEnum.request) {
115
+ const { source, data, path } = step;
116
+ if (source === FlowSourceEnum.request) {
106
117
  const extractor = new RequestDataExtractor(request);
107
118
  return extractor.extract(source, data, path);
108
119
  }
109
120
 
110
- if (source === ActionSourceEnum.response) {
121
+ if (source === FlowSourceEnum.response) {
111
122
  const extractor = new RequestDataExtractor(request, response);
112
123
  return extractor.extract(source, data, path);
113
124
  }
114
125
 
115
- if (source === ActionSourceEnum.variable && path && this.variables) {
126
+ if (source === FlowSourceEnum.variable && path && this.variables) {
116
127
  return this.variables[path];
117
128
  }
118
129
 
@@ -126,10 +137,11 @@ export class HttpFlowRunner {
126
137
  * @returns The read value with applied data type.
127
138
  */
128
139
  _runSetDataStep(step: ISetDataStep): FlowValue {
129
- const { value, dataType, enabled } = step;
130
- if (enabled === false) {
140
+ const instance = new SetDataStep(step);
141
+ if (instance.enabled === false || !instance.checkValidity()) {
131
142
  return undefined;
132
143
  }
144
+ const { value, dataType } = step;
133
145
  if (value === null || value === undefined) {
134
146
  return undefined;
135
147
  }
@@ -143,10 +155,11 @@ export class HttpFlowRunner {
143
155
  * @param value The value to set. A value that is `null` or `undefined` deletes the variable.
144
156
  */
145
157
  _runSetVariableStep(step: ISetVariableStep, value: FlowValue): FlowValue {
146
- const { name, enabled } = step;
147
- if (enabled === false || !name || !this.variables) {
158
+ const instance = new SetVariableStep(step);
159
+ if (instance.enabled === false || !instance.checkValidity() || !this.variables) {
148
160
  return undefined;
149
161
  }
162
+ const { name } = step;
150
163
  if (value === null || typeof value === undefined) {
151
164
  delete this.variables[name];
152
165
  } else {
@@ -163,14 +176,15 @@ export class HttpFlowRunner {
163
176
  * @param request The request object.
164
177
  */
165
178
  async _runSetCookieStep(step: ISetCookieStep, value: FlowValue, request: IHttpRequest | ISentRequest): Promise<FlowValue> {
166
- const { name, enabled, expires, hostOnly, httpOnly, sameSite, secure, session } = step;
179
+ const instance = new SetCookieStep(step);
167
180
  const { cookies } = this;
168
- if (enabled === false || !name || !cookies ) {
181
+ if (instance.enabled === false || !instance.checkValidity() || !cookies ) {
169
182
  return undefined;
170
183
  }
171
184
  if (value === null || typeof value === undefined) {
172
185
  return undefined;
173
186
  }
187
+ const { name, expires, hostOnly, httpOnly, sameSite, secure, session } = step;
174
188
  const typedValue = String(value);
175
189
  let url: string;
176
190
  if (step.url) {
@@ -215,9 +229,9 @@ export class HttpFlowRunner {
215
229
  * A step to delete cookies from the cookie jar.
216
230
  */
217
231
  async _runDeleteCookieStep(step: IDeleteCookieStep, request: IHttpRequest | ISentRequest): Promise<FlowValue> {
218
- const { name, enabled } = step;
232
+ const instance = new DeleteCookieStep(step);
219
233
  const { cookies } = this;
220
- if (enabled === false || !cookies ) {
234
+ if (instance.enabled === false || !instance.checkValidity() || !cookies ) {
221
235
  return undefined;
222
236
  }
223
237
  let url: string;
@@ -226,7 +240,7 @@ export class HttpFlowRunner {
226
240
  } else {
227
241
  url = request.url;
228
242
  }
229
- await cookies.deleteCookies(url, name);
243
+ await cookies.deleteCookies(url, step.name);
230
244
  return undefined;
231
245
  }
232
246
  }
@@ -4,7 +4,8 @@ import { IRequestConfig } from '../../models/RequestConfig.js';
4
4
  import { IRequestAuthorization } from '../../models/RequestAuthorization.js';
5
5
  import { IRequestLog } from '../../models/RequestLog.js';
6
6
  import { VariablesProcessor } from '../variables/VariablesProcessor.js';
7
- import { IHttpActionFlow } from '../../models/http-actions/HttpActions.js';
7
+ import { IHttpFlow } from '../../models/http-actions/HttpFlows.js';
8
+ import { AssertionResult, IHttpAssertion } from '../../models/http-actions/HttpAssertion.js';
8
9
  import { HttpEngineOptions } from '../http-engine/HttpEngine.js';
9
10
  import { CoreEngine } from '../http-engine/CoreEngine.js';
10
11
  import { Logger } from '../../lib/logging/Logger.js';
@@ -16,6 +17,7 @@ import { ISentRequest } from "../../models/SentRequest.js";
16
17
  import { IResponse } from "../../models/Response.js";
17
18
  import { IErrorResponse } from "../../models/ErrorResponse.js";
18
19
  import { HttpCertificate } from '../../models/ClientCertificate.js';
20
+ import { HttpAssertionRunner } from './HttpAssertionRunner.js';
19
21
 
20
22
  /**
21
23
  * A class that takes a single HttpRequest definition and executes it.
@@ -45,7 +47,7 @@ export class HttpRequestRunner {
45
47
  /**
46
48
  * Actions to be performed when the request is executed.
47
49
  */
48
- flows?: IHttpActionFlow[];
50
+ flows?: IHttpFlow[];
49
51
 
50
52
  /**
51
53
  * The cumulative list of all variables to be applied to the request and other properties.
@@ -80,6 +82,8 @@ export class HttpRequestRunner {
80
82
  */
81
83
  certificates?: HttpCertificate[]
82
84
 
85
+ assertions?: IHttpAssertion[];
86
+
83
87
  /**
84
88
  * Creates an instance from the IRequest object with setting the corresponding variables.
85
89
  * @param request The request object to use.
@@ -89,6 +93,7 @@ export class HttpRequestRunner {
89
93
  instance.flows = request.flows;
90
94
  instance.authorization = request.authorization;
91
95
  instance.config = request.config;
96
+ instance.assertions = request.assertions;
92
97
  return instance;
93
98
  }
94
99
 
@@ -215,8 +220,8 @@ export class HttpRequestRunner {
215
220
  *
216
221
  * @param trigger The trigger name to read the flows for.
217
222
  */
218
- protected async readFlows(trigger: 'request' | 'response'): Promise<IHttpActionFlow[]> {
219
- const result: IHttpActionFlow[] = [];
223
+ protected async readFlows(trigger: 'request' | 'response'): Promise<IHttpFlow[]> {
224
+ const result: IHttpFlow[] = [];
220
225
  const { flows, variables = {}, variablesProcessor } = this;
221
226
  if (!Array.isArray(flows) || !flows.length) {
222
227
  return result;
@@ -228,7 +233,7 @@ export class HttpRequestRunner {
228
233
  if (!Array.isArray(flow.actions) || !flow.actions.length) {
229
234
  continue;
230
235
  }
231
- const copy = { ...flow } as IHttpActionFlow;
236
+ const copy = { ...flow } as IHttpFlow;
232
237
  const actions = copy.actions.map(async (action) => {
233
238
  const actionCopy = { ...action };
234
239
  if (actionCopy.condition) {
@@ -339,6 +344,10 @@ export class HttpRequestRunner {
339
344
  }
340
345
  }
341
346
  await this.runResponseFlows(request, response);
347
+ const assertions = await this.runAssertions(request, response);
348
+ if (assertions) {
349
+ log.assertions = assertions;
350
+ }
342
351
  }
343
352
 
344
353
  get sessionCookies(): boolean {
@@ -369,4 +378,43 @@ export class HttpRequestRunner {
369
378
  }
370
379
  return `${baseUri}/${currentUrl}`;
371
380
  }
381
+
382
+ /**
383
+ * Prepares and runs assertions on the response.
384
+ * It changes the response object by setting the assertions result.
385
+ */
386
+ async runAssertions(request: ISentRequest, response: IResponse | IErrorResponse): Promise<AssertionResult[] | undefined> {
387
+ const assertions = await this.readAssertions();
388
+ if (!assertions.length) {
389
+ return;
390
+ }
391
+ const factory = new HttpAssertionRunner();
392
+ return factory.run(request, response, assertions);
393
+ }
394
+
395
+ /**
396
+ * @returns Prepared (evaluated with variables) assertions. Only not disabled assertions are returned.
397
+ */
398
+ protected async readAssertions(): Promise<IHttpAssertion[]> {
399
+ const { assertions, variablesProcessor, variables = {} } = this;
400
+ if (!Array.isArray(assertions) || !assertions.length) {
401
+ return [];
402
+ }
403
+ const result: IHttpAssertion[] = [];
404
+ for (const assertion of assertions) {
405
+ if (assertion.enabled === false) {
406
+ continue;
407
+ }
408
+ if (!Array.isArray(assertion.steps) || !assertion.steps.length) {
409
+ continue;
410
+ }
411
+ const copy = { ...assertion } as IHttpAssertion;
412
+ const stepsPromises = copy.steps.map(async (step) => {
413
+ return variablesProcessor.evaluateVariablesWithContext(step, variables);
414
+ });
415
+ copy.steps = await Promise.all(stepsPromises);
416
+ result.push(copy);
417
+ }
418
+ return result;
419
+ }
372
420
  }
@@ -33,7 +33,7 @@ export interface IWorkerInfo {
33
33
  }
34
34
 
35
35
  interface WorkerInfoInternal extends IWorkerInfo {
36
- worker: Worker;
36
+ worker?: Worker;
37
37
  }
38
38
 
39
39
  export interface IWorkerMessage {
@@ -133,7 +133,7 @@ export class ProjectParallelRunner extends BaseRunner {
133
133
  workers.forEach((info) => {
134
134
  if (info.status !== 'error') {
135
135
  try {
136
- info.worker.destroy();
136
+ info.worker?.destroy();
137
137
  } catch (e) {
138
138
  // ...
139
139
  }
@@ -185,7 +185,7 @@ export class ProjectParallelRunner extends BaseRunner {
185
185
  const { workers } = this;
186
186
  const result: IWorkerInfo[] = [];
187
187
  workers.forEach((info) => {
188
- const cp = { ...info } as any;
188
+ const cp = { ...info };
189
189
  delete cp.worker;
190
190
  result.push(cp);
191
191
  });
@@ -266,7 +266,7 @@ export class ProjectParallelRunner extends BaseRunner {
266
266
  const opts: IProjectParallelWorkerOptions = { ...this.options, project: this.project.toJSON() };
267
267
  opts.iterations = info.iterations;
268
268
  info.status = 'running';
269
- info.worker.send({
269
+ info.worker?.send({
270
270
  cmd: 'run',
271
271
  data: opts,
272
272
  });
@@ -229,12 +229,16 @@ export class ProjectRequestRunner extends EventEmitter {
229
229
  const config = request.getConfig();
230
230
  const factory = new HttpRequestRunner();
231
231
  factory.variables = variables;
232
- if (request.authorization) {
233
- factory.authorization = request.authorization.map(i => i.toJSON());
232
+ const auth = request.readAuthorization();
233
+ if (auth.length) {
234
+ factory.authorization = auth.map(i => i.toJSON());
234
235
  }
235
236
  if (request.flows) {
236
237
  factory.flows = request.flows;
237
238
  }
239
+ if (request.assertions) {
240
+ factory.assertions = request.assertions;
241
+ }
238
242
  if (request.clientCertificate) {
239
243
  factory.certificates = [request.clientCertificate.toJSON()];
240
244
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"JmesparthReader.js","sourceRoot":"","sources":["../../../src/data/JmesparthReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAC7C,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE;YACT,OAAO,SAAS,CAAC;SAClB;QACD,IAAI,GAAQ,CAAC;QACb,IAAI;YACF,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SACxB;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;CACF"}
@@ -1,256 +0,0 @@
1
- import { SameSiteValue } from '../../cookies/CookieParser.js';
2
- export declare const ReadDataStepKind = "HttpAction#ReadData";
3
- export declare const SetDataStepKind = "HttpAction#SetData";
4
- export declare const SetVariableStepKind = "HttpAction#SetVariable";
5
- export declare const SetCookieStepKind = "HttpAction#SetCookie";
6
- export declare const DeleteCookieStepKind = "HttpAction#DeleteCookie";
7
- export declare enum ActionSourceEnum {
8
- /**
9
- * The request object.
10
- */
11
- request = "request",
12
- /**
13
- * The response object.
14
- */
15
- response = "response",
16
- /**
17
- * A variable from the current environment.
18
- */
19
- variable = "variable"
20
- }
21
- export declare enum ActionOperatorEnum {
22
- equal = "equal",
23
- notEqual = "not-equal",
24
- greaterThan = "greater-than",
25
- greaterThanEqual = "greater-than-equal",
26
- lessThan = "less-than",
27
- lessThanEqual = "less-than-equal",
28
- contains = "contains",
29
- regex = "regex"
30
- }
31
- export declare enum ActionRequestDataEnum {
32
- url = "url",
33
- method = "method",
34
- headers = "headers",
35
- body = "body"
36
- }
37
- export declare enum ActionResponseDataEnum {
38
- url = "url",
39
- status = "status",
40
- headers = "headers",
41
- body = "body"
42
- }
43
- /**
44
- * A flow represents a series of actions to be performed one-by-one after the HTTP request is sent or when the response
45
- * is ready.
46
- */
47
- export interface IHttpActionFlow {
48
- /**
49
- * The description of the flow
50
- */
51
- description?: string;
52
- /**
53
- * Describes when the flow is executed.
54
- * The `request` means the flow is executed before the request is sent to the HTTP engine.
55
- * The `response` means the flow is executed after the response has been received in full, but before reporting
56
- * the response to the UI.
57
- */
58
- trigger: 'request' | 'response';
59
- /**
60
- * The ordered list of actions to execute.
61
- */
62
- actions: IHttpAction[];
63
- }
64
- /**
65
- * Describes a single action in a flow.
66
- * An action can have a condition that is checked against the current context.
67
- * Action is not executed when the condition is not meet.
68
- *
69
- * Each action has one or more steps (when 0 items then the action is ignored). Each step performs a task.
70
- * The result of a task is passed to the next step as an input. The result of a task may be `void`, `null`, or `undefined` which is treated as `void`.
71
- */
72
- export interface IHttpAction {
73
- /**
74
- * The description of the action
75
- */
76
- description?: string;
77
- /**
78
- * A condition to check before performing the action.
79
- */
80
- condition?: IHttpCondition;
81
- /**
82
- * The list of steps to perform. This is an ordered list of action tasks.
83
- * Each step is described by the `kind` property which tells the runner what action to perform.
84
- */
85
- steps: IActionStep[];
86
- }
87
- /**
88
- * A condition to execute for an action.
89
- */
90
- export interface IHttpCondition {
91
- /**
92
- * The main data source.
93
- * In the legacy actions this was `type`.
94
- */
95
- source?: ActionSourceEnum;
96
- /**
97
- * Source of the data.
98
- * In the legacy actions this was `source`.
99
- * This is not required when the source is not `request` or `response`.
100
- */
101
- data?: ActionRequestDataEnum | ActionResponseDataEnum;
102
- /**
103
- * The path to the data.
104
- * For JSON value use https://jmespath.org/ syntax.
105
- * For XML use xpath.
106
- * For any other use a simple path to the data separated by dot (e.g. headers.content-type)
107
- */
108
- path?: string;
109
- /**
110
- * The comparison operator.
111
- */
112
- operator?: ActionOperatorEnum;
113
- /**
114
- * The value to compare the read result.
115
- * In runtime, the type is casted to the same type as read value.
116
- *
117
- * When this is not set it compares to an empty string value or `0`.
118
- *
119
- * In ARC actions this was the `predictedValue`.
120
- */
121
- value?: string;
122
- }
123
- export interface IActionStep {
124
- /**
125
- * The kind of the action to perform.
126
- */
127
- kind: string;
128
- /**
129
- * Whether the step is disabled in the flow.
130
- */
131
- enabled?: boolean;
132
- }
133
- /**
134
- * Reads the data from various sources.
135
- */
136
- export interface IReadDataStep extends IActionStep {
137
- kind: typeof ReadDataStepKind;
138
- /**
139
- * The main data source.
140
- * In the legacy actions this was `type`.
141
- */
142
- source?: ActionSourceEnum;
143
- /**
144
- * Source of the data.
145
- * In the legacy actions this was `source`.
146
- * This is not required when the source is not `request` or `response`.
147
- */
148
- data?: ActionRequestDataEnum | ActionResponseDataEnum;
149
- /**
150
- * The path to the data.
151
- * For JSON value use https://jmespath.org/ syntax.
152
- * For XML use xpath.
153
- * For any other use a simple path to the data separated by dot (e.g. headers.content-type)
154
- */
155
- path?: string;
156
- }
157
- /**
158
- * Sets a manually defined value that can be passed to the next step.
159
- */
160
- export interface ISetDataStep extends IActionStep {
161
- kind: typeof SetDataStepKind;
162
- /**
163
- * The value to return to the next step.
164
- * This is always a string. Use the `dataType` to determine the correct data type.
165
- */
166
- value: string;
167
- /**
168
- * The data type of the value. This is a value prefixed with
169
- * `http://www.w3.org/2001/XMLSchema#` or `http://a.ml/vocabularies/shapes#`.
170
- *
171
- * Examples:
172
- *
173
- * - `http://www.w3.org/2001/XMLSchema#boolean`
174
- * - `http://www.w3.org/2001/XMLSchema#string`
175
- * - `http://www.w3.org/2001/XMLSchema#number`
176
- * - `http://www.w3.org/2001/XMLSchema#integer`
177
- * - `http://www.w3.org/2001/XMLSchema#long`
178
- * - `http://a.ml/vocabularies/shapes#number`
179
- * - `http://a.ml/vocabularies/shapes#integer`
180
- * - `http://a.ml/vocabularies/shapes#double`
181
- * - ...
182
- *
183
- * @default `http://www.w3.org/2001/XMLSchema#string`
184
- */
185
- dataType?: string;
186
- }
187
- /**
188
- * A step that accepts an input from the previous step and sets a variable in the current environment
189
- * with this value. If the value is `void`, `null`, or `undefined` then the variable is removed from the
190
- * environment.
191
- *
192
- * All variables are strings.
193
- */
194
- export interface ISetVariableStep extends IActionStep {
195
- kind: typeof SetVariableStepKind;
196
- /**
197
- * The name of the variable to set
198
- */
199
- name: string;
200
- }
201
- /**
202
- * A step that allows to set a cookie with the value returned by a previous step.
203
- */
204
- export interface ISetCookieStep extends IActionStep {
205
- kind: typeof SetCookieStepKind;
206
- /**
207
- * Name of the cookie
208
- */
209
- name: string;
210
- /**
211
- * The URL associated with the cookie. When not set it uses the request URL or the request URL of the last redirect.
212
- */
213
- url?: string;
214
- /**
215
- * The cookie expiration time. It can be a valid cookie date or a string representing a relative time to "now"
216
- * like `4d`, `600s`, etc.
217
- */
218
- expires?: string;
219
- /**
220
- * Whether the cookie is host only
221
- */
222
- hostOnly?: boolean;
223
- /**
224
- * Whether the cookie is HTTP only
225
- */
226
- httpOnly?: boolean;
227
- /**
228
- * Whether the cookie is HTTPS only
229
- */
230
- secure?: boolean;
231
- /**
232
- * Whether the cookie is a session cookie
233
- */
234
- session?: boolean;
235
- /**
236
- * The SameSite parameter of the cookie.
237
- * https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#creating_cookies
238
- */
239
- sameSite?: SameSiteValue;
240
- }
241
- /**
242
- * A step allowing to delete a cookie for the given configuration.
243
- * This step does not require an input.
244
- */
245
- export interface IDeleteCookieStep extends IActionStep {
246
- kind: typeof DeleteCookieStepKind;
247
- /**
248
- * The URL associated with the cookie. When not set it uses the request URL or the request URL of the last redirect.
249
- */
250
- url?: string;
251
- /**
252
- * Name of the cookie to remove.
253
- * When not set it removes all cookies for the URL.
254
- */
255
- name?: string;
256
- }
@@ -1,46 +0,0 @@
1
- export const ReadDataStepKind = 'HttpAction#ReadData';
2
- export const SetDataStepKind = 'HttpAction#SetData';
3
- export const SetVariableStepKind = 'HttpAction#SetVariable';
4
- export const SetCookieStepKind = 'HttpAction#SetCookie';
5
- export const DeleteCookieStepKind = 'HttpAction#DeleteCookie';
6
- export var ActionSourceEnum;
7
- (function (ActionSourceEnum) {
8
- /**
9
- * The request object.
10
- */
11
- ActionSourceEnum["request"] = "request";
12
- /**
13
- * The response object.
14
- */
15
- ActionSourceEnum["response"] = "response";
16
- /**
17
- * A variable from the current environment.
18
- */
19
- ActionSourceEnum["variable"] = "variable";
20
- })(ActionSourceEnum || (ActionSourceEnum = {}));
21
- export var ActionOperatorEnum;
22
- (function (ActionOperatorEnum) {
23
- ActionOperatorEnum["equal"] = "equal";
24
- ActionOperatorEnum["notEqual"] = "not-equal";
25
- ActionOperatorEnum["greaterThan"] = "greater-than";
26
- ActionOperatorEnum["greaterThanEqual"] = "greater-than-equal";
27
- ActionOperatorEnum["lessThan"] = "less-than";
28
- ActionOperatorEnum["lessThanEqual"] = "less-than-equal";
29
- ActionOperatorEnum["contains"] = "contains";
30
- ActionOperatorEnum["regex"] = "regex";
31
- })(ActionOperatorEnum || (ActionOperatorEnum = {}));
32
- export var ActionRequestDataEnum;
33
- (function (ActionRequestDataEnum) {
34
- ActionRequestDataEnum["url"] = "url";
35
- ActionRequestDataEnum["method"] = "method";
36
- ActionRequestDataEnum["headers"] = "headers";
37
- ActionRequestDataEnum["body"] = "body";
38
- })(ActionRequestDataEnum || (ActionRequestDataEnum = {}));
39
- export var ActionResponseDataEnum;
40
- (function (ActionResponseDataEnum) {
41
- ActionResponseDataEnum["url"] = "url";
42
- ActionResponseDataEnum["status"] = "status";
43
- ActionResponseDataEnum["headers"] = "headers";
44
- ActionResponseDataEnum["body"] = "body";
45
- })(ActionResponseDataEnum || (ActionResponseDataEnum = {}));
46
- //# sourceMappingURL=HttpActions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpActions.js","sourceRoot":"","sources":["../../../../src/models/http-actions/HttpActions.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AACtD,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AAC5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,yBAAyB,CAAC;AAE9D,MAAM,CAAN,IAAY,gBAaX;AAbD,WAAY,gBAAgB;IAC1B;;OAEG;IACH,uCAAmB,CAAA;IACnB;;OAEG;IACH,yCAAqB,CAAA;IACrB;;OAEG;IACH,yCAAqB,CAAA;AACvB,CAAC,EAbW,gBAAgB,KAAhB,gBAAgB,QAa3B;AAED,MAAM,CAAN,IAAY,kBASX;AATD,WAAY,kBAAkB;IAC5B,qCAAe,CAAA;IACf,4CAAsB,CAAA;IACtB,kDAA4B,CAAA;IAC5B,6DAAuC,CAAA;IACvC,4CAAsB,CAAA;IACtB,uDAAiC,CAAA;IACjC,2CAAqB,CAAA;IACrB,qCAAe,CAAA;AACjB,CAAC,EATW,kBAAkB,KAAlB,kBAAkB,QAS7B;AAED,MAAM,CAAN,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B,oCAAW,CAAA;IACX,0CAAiB,CAAA;IACjB,4CAAmB,CAAA;IACnB,sCAAa,CAAA;AACf,CAAC,EALW,qBAAqB,KAArB,qBAAqB,QAKhC;AAED,MAAM,CAAN,IAAY,sBAKX;AALD,WAAY,sBAAsB;IAChC,qCAAW,CAAA;IACX,2CAAiB,CAAA;IACjB,6CAAmB,CAAA;IACnB,uCAAa,CAAA;AACf,CAAC,EALW,sBAAsB,KAAtB,sBAAsB,QAKjC"}