@api-client/core 0.9.21 → 0.9.23
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.
- package/build/browser.d.ts +11 -11
- package/build/browser.js +13 -16
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +11 -11
- package/build/index.js +13 -16
- package/build/index.js.map +1 -1
- package/build/src/data/DataExtractor.d.ts +66 -0
- package/build/src/data/DataExtractor.js +177 -0
- package/build/src/data/DataExtractor.js.map +1 -0
- package/build/src/data/RequestDataExtractor.d.ts +4 -1
- package/build/src/data/RequestDataExtractor.js +13 -26
- package/build/src/data/RequestDataExtractor.js.map +1 -1
- package/build/src/models/Request.d.ts +2 -2
- package/build/src/models/Request.js +1 -1
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestLog.d.ts +1 -1
- package/build/src/models/{http-actions → http-flows}/AssertionError.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/AssertionError.js +0 -0
- package/build/src/models/http-flows/AssertionError.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/HttpAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/HttpAssertion.js +0 -0
- package/build/src/models/http-flows/HttpAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/HttpFlows.d.ts +5 -38
- package/build/src/models/{http-actions → http-flows}/HttpFlows.js +4 -0
- package/build/src/models/http-flows/HttpFlows.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/HttpStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/HttpStep.js +0 -0
- package/build/src/models/http-flows/HttpStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/LegacyTranslator.d.ts +2 -2
- package/build/src/models/{http-actions → http-flows}/LegacyTranslator.js +92 -46
- package/build/src/models/http-flows/LegacyTranslator.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/EqualAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/EqualAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/EqualAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/GreaterThanAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/GreaterThanAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/GreaterThanAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/IncludesAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/IncludesAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/IncludesAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/IsEmptyAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/IsEmptyAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/IsEmptyAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/IsNotEmptyAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/IsNotEmptyAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/IsNotEmptyAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/LengthOfAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/LengthOfAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/LengthOfAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/LessThanAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/LessThanAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/LessThanAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/MatchesAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/MatchesAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/MatchesAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/MatchesSchemaAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/MatchesSchemaAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/MatchesSchemaAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/NotEqualAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/NotEqualAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/NotEqualAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/NotIncludesAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/NotIncludesAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/NotIncludesAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/NotOkAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/NotOkAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/NotOkAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/NotToBeAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/NotToBeAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/NotToBeAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/OkAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/OkAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/OkAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/ToBeAssertion.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/ToBeAssertion.js +0 -0
- package/build/src/models/http-flows/steps/assertion/ToBeAssertion.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/index.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/assertion/index.js +0 -0
- package/build/src/models/http-flows/steps/assertion/index.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/DeleteCookieStep.d.ts +5 -1
- package/build/src/models/{http-actions → http-flows}/steps/data/DeleteCookieStep.js +6 -1
- package/build/src/models/http-flows/steps/data/DeleteCookieStep.js.map +1 -0
- package/build/src/models/http-flows/steps/data/DeleteVariableStep.d.ts +36 -0
- package/build/src/models/http-flows/steps/data/DeleteVariableStep.js +44 -0
- package/build/src/models/http-flows/steps/data/DeleteVariableStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/ReadDataSourceStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/ReadDataSourceStep.js +0 -0
- package/build/src/models/http-flows/steps/data/ReadDataSourceStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/ReadDataStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/ReadDataStep.js +0 -0
- package/build/src/models/http-flows/steps/data/ReadDataStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/ReadValueStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/ReadValueStep.js +0 -0
- package/build/src/models/http-flows/steps/data/ReadValueStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/SetCookieStep.d.ts +2 -1
- package/build/src/models/{http-actions → http-flows}/steps/data/SetCookieStep.js +2 -1
- package/build/src/models/http-flows/steps/data/SetCookieStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/SetDataStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/SetDataStep.js +0 -0
- package/build/src/models/http-flows/steps/data/SetDataStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/SetVariableStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/SetVariableStep.js +0 -0
- package/build/src/models/http-flows/steps/data/SetVariableStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/index.d.ts +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/data/index.js +1 -0
- package/build/src/models/http-flows/steps/data/index.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/AsLowerCaseStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/AsLowerCaseStep.js +0 -0
- package/build/src/models/http-flows/steps/transformation/AsLowerCaseStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/AsNumberStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/AsNumberStep.js +0 -0
- package/build/src/models/http-flows/steps/transformation/AsNumberStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/AsUpperCaseStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/AsUpperCaseStep.js +0 -0
- package/build/src/models/http-flows/steps/transformation/AsUpperCaseStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/RoundStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/RoundStep.js +0 -0
- package/build/src/models/http-flows/steps/transformation/RoundStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/SubstringStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/SubstringStep.js +0 -0
- package/build/src/models/http-flows/steps/transformation/SubstringStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/TrimStep.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/TrimStep.js +0 -0
- package/build/src/models/http-flows/steps/transformation/TrimStep.js.map +1 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/index.d.ts +0 -0
- package/build/src/models/{http-actions → http-flows}/steps/transformation/index.js +0 -0
- package/build/src/models/http-flows/steps/transformation/index.js.map +1 -0
- package/build/src/proxy/HttpProjectProxy.d.ts +4 -0
- package/build/src/proxy/HttpProjectProxy.js.map +1 -1
- package/build/src/proxy/RequestProxy.d.ts +6 -2
- package/build/src/proxy/RequestProxy.js.map +1 -1
- package/build/src/runtime/http-runner/ConditionCheck.d.ts +1 -1
- package/build/src/runtime/http-runner/HttpAssertionRunner.d.ts +7 -57
- package/build/src/runtime/http-runner/HttpAssertionRunner.js +24 -382
- package/build/src/runtime/http-runner/HttpAssertionRunner.js.map +1 -1
- package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +10 -57
- package/build/src/runtime/http-runner/HttpFlowRunner.js +45 -203
- package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -1
- package/build/src/runtime/http-runner/HttpFlows.d.ts +119 -0
- package/build/src/runtime/http-runner/HttpFlows.js +541 -0
- package/build/src/runtime/http-runner/HttpFlows.js.map +1 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +2 -2
- package/package.json +1 -1
- package/src/data/DataExtractor.ts +188 -0
- package/src/data/RequestDataExtractor.ts +14 -26
- package/src/models/Request.ts +3 -3
- package/src/models/RequestLog.ts +1 -1
- package/src/models/{http-actions → http-flows}/AssertionError.ts +0 -0
- package/src/models/{http-actions → http-flows}/HttpAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/HttpFlows.ts +5 -39
- package/src/models/{http-actions → http-flows}/HttpStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/LegacyTranslator.ts +89 -31
- package/src/models/{http-actions → http-flows}/steps/assertion/EqualAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/GreaterThanAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/IncludesAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/IsEmptyAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/IsNotEmptyAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/LengthOfAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/LessThanAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/MatchesAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/MatchesSchemaAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/NotEqualAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/NotIncludesAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/NotOkAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/NotToBeAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/OkAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/assertion/ToBeAssertion.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/data/DeleteCookieStep.ts +6 -1
- package/src/models/http-flows/steps/data/DeleteVariableStep.ts +78 -0
- package/src/models/{http-actions → http-flows}/steps/data/ReadDataSourceStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/data/ReadDataStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/data/ReadValueStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/data/SetCookieStep.ts +4 -2
- package/src/models/{http-actions → http-flows}/steps/data/SetDataStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/data/SetVariableStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/transformation/AsLowerCaseStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/transformation/AsNumberStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/transformation/AsUpperCaseStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/transformation/RoundStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/transformation/SubstringStep.ts +0 -0
- package/src/models/{http-actions → http-flows}/steps/transformation/TrimStep.ts +0 -0
- package/src/proxy/HttpProjectProxy.ts +4 -0
- package/src/proxy/RequestProxy.ts +6 -2
- package/src/runtime/http-runner/ConditionCheck.ts +1 -1
- package/src/runtime/http-runner/HttpAssertionRunner.ts +28 -410
- package/src/runtime/http-runner/HttpFlowRunner.ts +47 -212
- package/src/runtime/http-runner/HttpFlows.ts +576 -0
- package/src/runtime/http-runner/HttpRequestRunner.ts +2 -2
- package/build/src/data/DataUtils.d.ts +0 -40
- package/build/src/data/DataUtils.js +0 -106
- package/build/src/data/DataUtils.js.map +0 -1
- package/build/src/models/http-actions/AssertionError.js.map +0 -1
- package/build/src/models/http-actions/HttpAssertion.js.map +0 -1
- package/build/src/models/http-actions/HttpFlows.js.map +0 -1
- package/build/src/models/http-actions/HttpStep.js.map +0 -1
- package/build/src/models/http-actions/LegacyTranslator.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/EqualAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/IncludesAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/LessThanAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/MatchesAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/NotOkAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/OkAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/ToBeAssertion.js.map +0 -1
- package/build/src/models/http-actions/steps/assertion/index.js.map +0 -1
- package/build/src/models/http-actions/steps/data/DeleteCookieStep.js.map +0 -1
- package/build/src/models/http-actions/steps/data/ReadDataSourceStep.js.map +0 -1
- package/build/src/models/http-actions/steps/data/ReadDataStep.js.map +0 -1
- package/build/src/models/http-actions/steps/data/ReadValueStep.js.map +0 -1
- package/build/src/models/http-actions/steps/data/SetCookieStep.js.map +0 -1
- package/build/src/models/http-actions/steps/data/SetDataStep.js.map +0 -1
- package/build/src/models/http-actions/steps/data/SetVariableStep.js.map +0 -1
- package/build/src/models/http-actions/steps/data/index.js.map +0 -1
- package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.js.map +0 -1
- package/build/src/models/http-actions/steps/transformation/AsNumberStep.js.map +0 -1
- package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.js.map +0 -1
- package/build/src/models/http-actions/steps/transformation/RoundStep.js.map +0 -1
- package/build/src/models/http-actions/steps/transformation/SubstringStep.js.map +0 -1
- package/build/src/models/http-actions/steps/transformation/TrimStep.js.map +0 -1
- package/build/src/models/http-actions/steps/transformation/index.js.map +0 -1
- package/src/data/DataUtils.ts +0 -108
|
@@ -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 {
|
|
7
|
-
import {
|
|
8
|
-
|
|
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
|
-
*
|
|
27
|
-
* The
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
85
|
-
|
|
86
|
-
|
|
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 (
|
|
131
|
-
return
|
|
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
|
-
|
|
226
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
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
|
}
|