@api-client/core 0.3.1 → 0.3.4
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 +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js.map +1 -1
- package/build/src/models/Backend.d.ts +22 -0
- package/build/src/runtime/store/StoreSdk.d.ts +192 -12
- package/build/src/runtime/store/StoreSdk.js +592 -53
- package/build/src/runtime/store/StoreSdk.js.map +1 -1
- package/package.json +3 -1
- package/src/data/DataReader.ts +11 -0
- package/src/data/DataUtils.ts +108 -0
- package/src/data/JmesparthReader.ts +26 -0
- package/src/data/Json2Xml.ts +190 -0
- package/src/data/JsonReader.ts +41 -0
- package/src/data/PayloadPointer.ts +48 -0
- package/src/data/RequestDataExtractor.ts +133 -0
- package/src/data/UrlEncodedReader.ts +20 -0
- package/src/data/XmlReader.ts +103 -0
- package/src/events/BaseEvents.ts +259 -0
- package/src/events/CustomEvent.ts +27 -0
- package/src/events/EventTypes.ts +19 -0
- package/src/events/Events.ts +19 -0
- package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
- package/src/events/authorization/AuthorizationEvents.ts +61 -0
- package/src/events/cookies/CookieEventTypes.ts +13 -0
- package/src/events/cookies/CookieEvents.ts +157 -0
- package/src/events/encryption/EncryptionEventTypes.ts +4 -0
- package/src/events/encryption/EncryptionEvents.ts +51 -0
- package/src/events/environment/EnvironmentEventTypes.ts +3 -0
- package/src/events/environment/EnvironmentEvents.ts +24 -0
- package/src/events/models/ClientCertificateEvents.ts +87 -0
- package/src/events/models/ModelEventTypes.ts +47 -0
- package/src/events/models/ModelEvents.ts +7 -0
- package/src/events/models/ProjectEvents.ts +331 -0
- package/src/events/process/ProcessEventTypes.ts +5 -0
- package/src/events/process/ProcessEvents.ts +76 -0
- package/src/events/readme.md +22 -0
- package/src/events/reporting/ReportingEventTypes.ts +3 -0
- package/src/events/reporting/ReportingEvents.ts +28 -0
- package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
- package/src/events/telemetry/TelemetryEvents.ts +156 -0
- package/src/lib/cookies/Cookie.ts +312 -0
- package/src/lib/cookies/Cookies.ts +326 -0
- package/src/lib/cookies/Utils.ts +168 -0
- package/src/lib/headers/Headers.ts +219 -0
- package/src/lib/logging/DefaultLogger.ts +19 -0
- package/src/lib/logging/DummyLogger.ts +21 -0
- package/src/lib/logging/Logger.ts +16 -0
- package/src/lib/transformers/PayloadSerializer.ts +332 -0
- package/src/lib/transformers/Utils.ts +18 -0
- package/src/lib/uuid.ts +40 -0
- package/src/mocking/LegacyInterfaces.ts +52 -0
- package/src/mocking/LegacyMock.ts +37 -0
- package/src/mocking/legacy/Authorization.ts +39 -0
- package/src/mocking/legacy/Certificates.ts +145 -0
- package/src/mocking/legacy/Cookies.ts +51 -0
- package/src/mocking/legacy/HostRules.ts +43 -0
- package/src/mocking/legacy/Http.ts +236 -0
- package/src/mocking/legacy/HttpResponse.ts +106 -0
- package/src/mocking/legacy/RestApi.ts +68 -0
- package/src/mocking/legacy/Urls.ts +44 -0
- package/src/mocking/legacy/Variables.ts +53 -0
- package/src/models/ArcResponse.ts +166 -0
- package/src/models/Authorization.ts +481 -0
- package/src/models/AuthorizationData.ts +60 -0
- package/src/models/Backend.ts +107 -0
- package/src/models/ClientCertificate.ts +68 -0
- package/src/models/Environment.ts +279 -0
- package/src/models/ErrorResponse.ts +101 -0
- package/src/models/HistoryIndex.ts +76 -0
- package/src/models/HistoryRequest.ts +28 -0
- package/src/models/HostRule.ts +163 -0
- package/src/models/HttpCookie.ts +285 -0
- package/src/models/HttpProject.ts +1294 -0
- package/src/models/HttpProjectListItem.ts +23 -0
- package/src/models/HttpRequest.ts +124 -0
- package/src/models/HttpResponse.ts +143 -0
- package/src/models/License.ts +113 -0
- package/src/models/ProjectDefinitionProperty.ts +40 -0
- package/src/models/ProjectFolder.ts +439 -0
- package/src/models/ProjectItem.ts +135 -0
- package/src/models/ProjectParent.ts +113 -0
- package/src/models/ProjectRequest.ts +277 -0
- package/src/models/ProjectSchema.ts +202 -0
- package/src/models/Property.ts +423 -0
- package/src/models/Provider.ts +98 -0
- package/src/models/README.md +20 -0
- package/src/models/Request.ts +452 -0
- package/src/models/RequestActions.ts +163 -0
- package/src/models/RequestAuthorization.ts +115 -0
- package/src/models/RequestConfig.ts +317 -0
- package/src/models/RequestLog.ts +159 -0
- package/src/models/RequestTime.ts +108 -0
- package/src/models/RequestUiMeta.ts +258 -0
- package/src/models/RequestsSize.ts +65 -0
- package/src/models/ResponseAuthorization.ts +104 -0
- package/src/models/ResponseRedirect.ts +158 -0
- package/src/models/RevisionInfo.ts +37 -0
- package/src/models/SentRequest.ts +125 -0
- package/src/models/SerializablePayload.ts +68 -0
- package/src/models/Server.ts +153 -0
- package/src/models/Thing.ts +110 -0
- package/src/models/Url.ts +90 -0
- package/src/models/User.ts +120 -0
- package/src/models/WebApi.ts +234 -0
- package/src/models/WebApiIndex.ts +122 -0
- package/src/models/Workspace.ts +182 -0
- package/src/models/actions/Action.ts +213 -0
- package/src/models/actions/ActionView.ts +40 -0
- package/src/models/actions/Condition.ts +207 -0
- package/src/models/actions/ConditionView.ts +42 -0
- package/src/models/actions/Enums.ts +29 -0
- package/src/models/actions/RunnableAction.ts +144 -0
- package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
- package/src/models/actions/runnable/Runnable.ts +9 -0
- package/src/models/actions/runnable/SetCookieAction.ts +216 -0
- package/src/models/actions/runnable/SetVariableAction.ts +81 -0
- package/src/models/legacy/DataExport.ts +172 -0
- package/src/models/legacy/Normalizer.ts +110 -0
- package/src/models/legacy/actions/Actions.ts +269 -0
- package/src/models/legacy/authorization/Authorization.ts +572 -0
- package/src/models/legacy/models/ApiTypes.ts +202 -0
- package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
- package/src/models/legacy/models/AuthData.ts +17 -0
- package/src/models/legacy/models/ClientCertificate.ts +95 -0
- package/src/models/legacy/models/Cookies.ts +52 -0
- package/src/models/legacy/models/HostRule.ts +35 -0
- package/src/models/legacy/models/RestApi.ts +49 -0
- package/src/models/legacy/models/UrlHistory.ts +37 -0
- package/src/models/legacy/models/Variable.ts +43 -0
- package/src/models/legacy/models/base.d.ts +95 -0
- package/src/models/legacy/request/ArcRequest.ts +405 -0
- package/src/models/legacy/request/ArcResponse.ts +177 -0
- package/src/models/legacy/request/HistoryData.ts +47 -0
- package/src/models/legacy/request/Legacy.ts +45 -0
- package/src/models/legacy/request/RequestBody.ts +87 -0
- package/src/models/transformers/ArcDexieTransformer.ts +323 -0
- package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
- package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
- package/src/models/transformers/ArcPouchTransformer.ts +184 -0
- package/src/models/transformers/BaseTransformer.ts +116 -0
- package/src/models/transformers/ImportUtils.ts +141 -0
- package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
- package/src/models/transformers/LegacyExportProcessor.ts +252 -0
- package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
- package/src/models/transformers/PostmanDataTransformer.ts +50 -0
- package/src/models/transformers/PostmanTransformer.ts +106 -0
- package/src/models/transformers/PostmanV21Transformer.ts +311 -0
- package/src/models/transformers/PostmanV2Transformer.ts +308 -0
- package/src/models/transformers/har.ts +865 -0
- package/src/runtime/actions/ActionRunner.ts +83 -0
- package/src/runtime/actions/ConditionRunner.ts +194 -0
- package/src/runtime/actions/RunnableCondition.ts +57 -0
- package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
- package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
- package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
- package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
- package/src/runtime/http-engine/ArcEngine.ts +1064 -0
- package/src/runtime/http-engine/Errors.ts +13 -0
- package/src/runtime/http-engine/FormData.ts +85 -0
- package/src/runtime/http-engine/HttpEngine.ts +874 -0
- package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
- package/src/runtime/http-engine/NodeEngine.ts +787 -0
- package/src/runtime/http-engine/NodeEngineDirect.ts +476 -0
- package/src/runtime/http-engine/PayloadSupport.ts +84 -0
- package/src/runtime/http-engine/RequestUtils.ts +164 -0
- package/src/runtime/http-engine/ntlm/Des.ts +345 -0
- package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
- package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
- package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
- package/src/runtime/modules/BasicAuthCache.ts +133 -0
- package/src/runtime/modules/ExecutionResponse.ts +4 -0
- package/src/runtime/modules/ModulesRegistry.ts +136 -0
- package/src/runtime/modules/RequestAuthorization.ts +110 -0
- package/src/runtime/modules/RequestCookies.ts +145 -0
- package/src/runtime/node/ProjectRunner.ts +275 -0
- package/src/runtime/node/RequestFactory.ts +422 -0
- package/src/runtime/node/VariablesStore.ts +25 -0
- package/src/runtime/store/StoreSdk.ts +838 -0
- package/src/runtime/variables/Cache.ts +53 -0
- package/src/runtime/variables/EvalFunctions.ts +132 -0
- package/src/runtime/variables/ProjectVariables.ts +6 -0
- package/src/runtime/variables/VariablesProcessor.ts +543 -0
- package/src/runtime/variables/VariablesTokenizer.ts +55 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Action } from '../../models/actions/Action.js';
|
|
2
|
+
import { Runnable as ModelRunnable } from '../../models/actions/runnable/Runnable.js';
|
|
3
|
+
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
4
|
+
import { IRequestLog } from '../../models/RequestLog.js';
|
|
5
|
+
import { Kind as DeleteCookieKind } from '../../models/actions/runnable/DeleteCookieAction.js';
|
|
6
|
+
import { Kind as SetCookieKind } from '../../models/actions/runnable/SetCookieAction.js';
|
|
7
|
+
import { Kind as SetVariableKind } from '../../models/actions/runnable/SetVariableAction.js';
|
|
8
|
+
import { ActionRunnable } from './runnable/ActionRunnable.js';
|
|
9
|
+
import { DeleteCookieRunnable } from './runnable/DeleteCookieRunnable.js';
|
|
10
|
+
import { SetCookieRunnable } from './runnable/SetCookieRunnable.js';
|
|
11
|
+
import { SetVariableRunnable } from './runnable/SetVariableRunnable.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A class that is responsible for running a single action.
|
|
15
|
+
*/
|
|
16
|
+
export class ActionRunner {
|
|
17
|
+
action: Action;
|
|
18
|
+
eventTarget: EventTarget;
|
|
19
|
+
|
|
20
|
+
constructor(action: Action, eventTarget: EventTarget) {
|
|
21
|
+
this.action = action;
|
|
22
|
+
this.eventTarget = eventTarget;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async request(request: IHttpRequest): Promise<void> {
|
|
26
|
+
const runnable = this.getActionRunnable();
|
|
27
|
+
if (!runnable) {
|
|
28
|
+
throw new Error(`Invalid action configuration. The runnable configuration is not defined.`);
|
|
29
|
+
}
|
|
30
|
+
const { action } = this;
|
|
31
|
+
if (action.sync === false) {
|
|
32
|
+
this.requestAsync(runnable, request);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await runnable.request(request);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async requestAsync(runnable: ActionRunnable, request: IHttpRequest): Promise<void> {
|
|
39
|
+
const { action } = this;
|
|
40
|
+
try {
|
|
41
|
+
await runnable.request(request);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
const err = e as Error;
|
|
44
|
+
console.error(`Unable to run a request action: ${action.name || 'unknown name'}: ${err.message}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getActionRunnable(): ActionRunnable | undefined {
|
|
49
|
+
const { action, eventTarget } = this;
|
|
50
|
+
const config = action.config as ModelRunnable;
|
|
51
|
+
if (!config) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
switch (config.kind) {
|
|
55
|
+
case DeleteCookieKind: return new DeleteCookieRunnable(config.toJSON(), eventTarget);
|
|
56
|
+
case SetCookieKind: return new SetCookieRunnable(config.toJSON(), eventTarget);
|
|
57
|
+
case SetVariableKind: return new SetVariableRunnable(config.toJSON(), eventTarget);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async response(log: IRequestLog): Promise<void> {
|
|
62
|
+
const runnable = this.getActionRunnable();
|
|
63
|
+
if (!runnable) {
|
|
64
|
+
throw new Error(`Invalid action configuration. The runnable configuration is not defined.`);
|
|
65
|
+
}
|
|
66
|
+
const { action } = this;
|
|
67
|
+
if (action.sync === false) {
|
|
68
|
+
this.responseAsync(runnable, log);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
await runnable.response(log);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async responseAsync(runnable: ActionRunnable, log: IRequestLog): Promise<void> {
|
|
75
|
+
const { action } = this;
|
|
76
|
+
try {
|
|
77
|
+
await runnable.response(log);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
const err = e as Error;
|
|
80
|
+
console.error(`Unable to run a response action: ${action.name || 'unknown name'}: ${err.message}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { OperatorEnum } from '../../models/actions/Enums.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if values equal.
|
|
6
|
+
* @param value Value to compare
|
|
7
|
+
* @param condition Comparator value
|
|
8
|
+
* @returns True if objects matches.
|
|
9
|
+
*/
|
|
10
|
+
export function isEqual(value: any, condition: any): boolean {
|
|
11
|
+
if (value === condition) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
let valueTyped = value;
|
|
15
|
+
let conditionTyped = condition;
|
|
16
|
+
if (typeof value !== 'undefined') {
|
|
17
|
+
valueTyped = String(value);
|
|
18
|
+
}
|
|
19
|
+
if (typeof condition !== 'undefined') {
|
|
20
|
+
conditionTyped = String(condition);
|
|
21
|
+
}
|
|
22
|
+
const typedConditionNumber = Number(conditionTyped);
|
|
23
|
+
if (!Number.isNaN(typedConditionNumber)) {
|
|
24
|
+
conditionTyped = typedConditionNumber;
|
|
25
|
+
valueTyped = Number(valueTyped);
|
|
26
|
+
}
|
|
27
|
+
return conditionTyped === valueTyped;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Opposite of `isEqual()`.
|
|
32
|
+
*
|
|
33
|
+
* @param value Value to compare
|
|
34
|
+
* @param condition Comparator value
|
|
35
|
+
* @return False if objects matches.
|
|
36
|
+
*/
|
|
37
|
+
export function isNotEqual(value: any, condition: any): boolean {
|
|
38
|
+
return !isEqual(value, condition);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Checks if value is less than comparator.
|
|
43
|
+
*
|
|
44
|
+
* @param value Value to compare
|
|
45
|
+
* @param condition Comparator value
|
|
46
|
+
* @returns True if value is less than condition.
|
|
47
|
+
*/
|
|
48
|
+
export function isLessThan(value: any, condition: any): boolean {
|
|
49
|
+
const valueNumber = Number(value);
|
|
50
|
+
if (Number.isNaN(valueNumber)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const conditionNumber = Number(condition);
|
|
54
|
+
if (Number.isNaN(conditionNumber)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return valueNumber < conditionNumber;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Checks if value is less than or equal to comparator.
|
|
62
|
+
*
|
|
63
|
+
* @param value Value to compare
|
|
64
|
+
* @param condition Comparator value
|
|
65
|
+
* @returns True if value is less than or equal to `condition`.
|
|
66
|
+
*/
|
|
67
|
+
export function isLessThanEqual(value: any, condition: any): boolean {
|
|
68
|
+
const valueNumber = Number(value);
|
|
69
|
+
if (Number.isNaN(valueNumber)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const conditionNumber = Number(condition);
|
|
73
|
+
if (Number.isNaN(conditionNumber)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return valueNumber <= conditionNumber;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Checks if value is greater than comparator.
|
|
81
|
+
*
|
|
82
|
+
* @param value Value to compare
|
|
83
|
+
* @param condition Comparator value
|
|
84
|
+
* @returns True if value is greater than `condition`.
|
|
85
|
+
*/
|
|
86
|
+
export function isGreaterThan(value: any, condition: any): boolean {
|
|
87
|
+
const valueNumber = Number(value);
|
|
88
|
+
if (Number.isNaN(valueNumber)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const conditionNumber = Number(condition);
|
|
92
|
+
if (Number.isNaN(conditionNumber)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return valueNumber > conditionNumber;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Checks if value is greater than or equal to comparator.
|
|
100
|
+
*
|
|
101
|
+
* @param value Value to compare
|
|
102
|
+
* @param condition Comparator value
|
|
103
|
+
* @returns True if value is greater than or equal to `condition`.
|
|
104
|
+
*/
|
|
105
|
+
export function isGreaterThanEqual(value: any, condition: any): boolean {
|
|
106
|
+
const valueNumber = Number(value);
|
|
107
|
+
if (Number.isNaN(valueNumber)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const conditionNumber = Number(condition);
|
|
111
|
+
if (Number.isNaN(conditionNumber)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return valueNumber >= conditionNumber;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Checks if value contains the `condition`.
|
|
119
|
+
* It works on strings, arrays and objects.
|
|
120
|
+
*
|
|
121
|
+
* @param value Value to compare
|
|
122
|
+
* @param condition Comparator value
|
|
123
|
+
* @returns True if value contains the `condition`.
|
|
124
|
+
*/
|
|
125
|
+
export function contains(value: any, condition: any): boolean {
|
|
126
|
+
if (!value) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (typeof value === 'string') {
|
|
130
|
+
return value.indexOf(condition) !== -1;
|
|
131
|
+
}
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
if (!Number.isNaN(condition) && typeof condition !== 'number') {
|
|
134
|
+
const result = value.indexOf(Number(condition));
|
|
135
|
+
if (result !== -1) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return value.indexOf(condition) !== -1;
|
|
140
|
+
}
|
|
141
|
+
if (typeof value !== 'object') {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return condition in value;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Checks if `value` can be tested against regular expression.
|
|
149
|
+
*
|
|
150
|
+
* @param value Value to compare
|
|
151
|
+
* @param condition Comparator value - regex string.
|
|
152
|
+
* @returns Value of calling `test()` function on string.
|
|
153
|
+
*/
|
|
154
|
+
export function isRegex(value: any, condition: any): boolean {
|
|
155
|
+
let re;
|
|
156
|
+
try {
|
|
157
|
+
re = new RegExp(condition, 'm');
|
|
158
|
+
} catch (e) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
const result = String(value);
|
|
162
|
+
return re.test(result);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Checks if given condition is satisfied by both value and operator.
|
|
167
|
+
*
|
|
168
|
+
* @param value Value read from the response / request object
|
|
169
|
+
* @param operator Comparison term.
|
|
170
|
+
* @param condition Value to compare.
|
|
171
|
+
* @returns True if the condition is satisfied and false otherwise.
|
|
172
|
+
*/
|
|
173
|
+
export function checkCondition(value: any, operator: OperatorEnum, condition: string | number): boolean {
|
|
174
|
+
switch (operator) {
|
|
175
|
+
case 'equal':
|
|
176
|
+
return isEqual(value, condition);
|
|
177
|
+
case 'not-equal':
|
|
178
|
+
return isNotEqual(value, condition);
|
|
179
|
+
case 'greater-than':
|
|
180
|
+
return isGreaterThan(value, condition);
|
|
181
|
+
case 'greater-than-equal':
|
|
182
|
+
return isGreaterThanEqual(value, condition);
|
|
183
|
+
case 'less-than':
|
|
184
|
+
return isLessThan(value, condition);
|
|
185
|
+
case 'less-than-equal':
|
|
186
|
+
return isLessThanEqual(value, condition);
|
|
187
|
+
case 'contains':
|
|
188
|
+
return contains(value, condition);
|
|
189
|
+
case 'regex':
|
|
190
|
+
return isRegex(value, condition);
|
|
191
|
+
default:
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IRunnableAction, RunnableAction } from '../../models/actions/RunnableAction.js';
|
|
2
|
+
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
3
|
+
import { IArcResponse } from '../../models/ArcResponse.js';
|
|
4
|
+
import { ISentRequest } from '../../models/SentRequest.js';
|
|
5
|
+
import { IErrorResponse } from '../../models/ErrorResponse.js';
|
|
6
|
+
import { RequestDataExtractor } from '../../data/RequestDataExtractor.js';
|
|
7
|
+
import { checkCondition } from './ConditionRunner.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A class that represents ARC condition that runs actions when the condition is met.
|
|
11
|
+
*/
|
|
12
|
+
export class RunnableCondition extends RunnableAction {
|
|
13
|
+
/**
|
|
14
|
+
* Tests whether the condition is satisfied for request and/or response.
|
|
15
|
+
*
|
|
16
|
+
* @param request The ARC request object.
|
|
17
|
+
* @param executed The request object representing the actual request that has been executed by the transport library.
|
|
18
|
+
* @param response The ARC response object, if available.
|
|
19
|
+
* @return True when the condition is satisfied.
|
|
20
|
+
*/
|
|
21
|
+
async satisfied(request: IHttpRequest | ISentRequest, response?: IArcResponse | IErrorResponse): Promise<boolean> {
|
|
22
|
+
if (this.enabled === false) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (this.condition.alwaysPass === true) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const extractor = new RequestDataExtractor(request, response);
|
|
29
|
+
const value = await extractor.extract(this.condition);
|
|
30
|
+
|
|
31
|
+
const op = this.condition.operator;
|
|
32
|
+
if (!op || !this.condition.value) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return checkCondition(value, op, this.condition.value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Maps runnables interface to
|
|
41
|
+
* If an item is not an instance of `ArcAction` then it creates an instance of it
|
|
42
|
+
* by passing the map as an argument.
|
|
43
|
+
*
|
|
44
|
+
* @param value Passed list of actions.
|
|
45
|
+
* @returns Mapped actions.
|
|
46
|
+
*/
|
|
47
|
+
export const mapRunnables = (value: (IRunnableAction | RunnableCondition)[]): RunnableCondition[] => {
|
|
48
|
+
if (!Array.isArray(value)) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
return value.map((item) => {
|
|
52
|
+
if (!(item instanceof RunnableCondition)) {
|
|
53
|
+
return new RunnableCondition(item as IRunnableAction);
|
|
54
|
+
}
|
|
55
|
+
return item;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IHttpRequest } from '../../../models/HttpRequest.js';
|
|
2
|
+
import { IRequestLog } from '../../../models/RequestLog.js';
|
|
3
|
+
|
|
4
|
+
export abstract class ActionRunnable {
|
|
5
|
+
/**
|
|
6
|
+
* The specific action configuration.
|
|
7
|
+
* This depends on the action.
|
|
8
|
+
*/
|
|
9
|
+
config: unknown;
|
|
10
|
+
eventTarget: EventTarget;
|
|
11
|
+
|
|
12
|
+
constructor(config: unknown, eventTarget: EventTarget) {
|
|
13
|
+
this.config = Object.freeze(config);
|
|
14
|
+
this.eventTarget = eventTarget;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
abstract request(request: IHttpRequest): Promise<void>;
|
|
18
|
+
abstract response(log: IRequestLog): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IHttpRequest } from 'src/models/HttpRequest.js';
|
|
2
|
+
import { ActionRunnable } from './ActionRunnable.js';
|
|
3
|
+
import { IDeleteCookieAction } from '../../../models/actions/runnable/DeleteCookieAction.js';
|
|
4
|
+
import { Events } from '../../../events/Events.js';
|
|
5
|
+
import { IRequestLog } from 'src/models/RequestLog.js';
|
|
6
|
+
|
|
7
|
+
export class DeleteCookieRunnable extends ActionRunnable {
|
|
8
|
+
async response(log: IRequestLog): Promise<void> {
|
|
9
|
+
if (!log.request) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const config = this.config as IDeleteCookieAction;
|
|
13
|
+
let url;
|
|
14
|
+
if (config.useRequestUrl) {
|
|
15
|
+
url = log.request.url;
|
|
16
|
+
} else {
|
|
17
|
+
url = config.url;
|
|
18
|
+
}
|
|
19
|
+
if (!url) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
Events.Cookie.deleteUrl(this.eventTarget, url, config.name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async request(request: IHttpRequest): Promise<void> {
|
|
26
|
+
const config = this.config as IDeleteCookieAction;
|
|
27
|
+
|
|
28
|
+
let url;
|
|
29
|
+
if (config.useRequestUrl) {
|
|
30
|
+
url = request.url;
|
|
31
|
+
} else {
|
|
32
|
+
url = config.url;
|
|
33
|
+
}
|
|
34
|
+
if (!url) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
Events.Cookie.deleteUrl(this.eventTarget, url, config.name);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { IHttpRequest } from 'src/models/HttpRequest.js';
|
|
2
|
+
import { IHttpCookie } from 'src/models/HttpCookie.js';
|
|
3
|
+
import { ActionRunnable } from './ActionRunnable.js';
|
|
4
|
+
import { ISetCookieAction } from '../../../models/actions/runnable/SetCookieAction.js';
|
|
5
|
+
import { Events } from '../../../events/Events.js';
|
|
6
|
+
import { RequestDataExtractor } from '../../../data/RequestDataExtractor.js';
|
|
7
|
+
import { IRequestLog } from 'src/models/RequestLog.js';
|
|
8
|
+
|
|
9
|
+
export class SetCookieRunnable extends ActionRunnable {
|
|
10
|
+
async request(request: IHttpRequest): Promise<void> {
|
|
11
|
+
const config = this.config as ISetCookieAction;
|
|
12
|
+
const value = await this.readRequestValue(request, config);
|
|
13
|
+
if (typeof value === 'undefined') {
|
|
14
|
+
throw new Error(`Cannot read value for the action`);
|
|
15
|
+
}
|
|
16
|
+
await this.setCookie(request, config, String(value));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async readRequestValue(request: IHttpRequest, config: ISetCookieAction): Promise<string | number | undefined> {
|
|
20
|
+
const { source } = config;
|
|
21
|
+
let value: string | number | undefined;
|
|
22
|
+
if (source.source === 'value') {
|
|
23
|
+
value = source.value;
|
|
24
|
+
} else {
|
|
25
|
+
const extractor = new RequestDataExtractor(request);
|
|
26
|
+
value = await extractor.extract(source);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async setCookie(request: IHttpRequest, config: ISetCookieAction, value: string): Promise<void> {
|
|
32
|
+
let url;
|
|
33
|
+
if (config.useRequestUrl) {
|
|
34
|
+
url = request.url;
|
|
35
|
+
} else {
|
|
36
|
+
url = config.url;
|
|
37
|
+
}
|
|
38
|
+
if (!url) {
|
|
39
|
+
throw new Error('The set cookie action has no URL defined.');
|
|
40
|
+
}
|
|
41
|
+
const parser = new URL(url);
|
|
42
|
+
const cookie: IHttpCookie = {
|
|
43
|
+
name: config.name,
|
|
44
|
+
value,
|
|
45
|
+
sameSite: 'unspecified',
|
|
46
|
+
domain: parser.host, // parser.hostname,
|
|
47
|
+
path: parser.pathname,
|
|
48
|
+
};
|
|
49
|
+
if (config.expires) {
|
|
50
|
+
const typedNumber = Number(config.expires);
|
|
51
|
+
if (Number.isNaN(typedNumber)) {
|
|
52
|
+
const exp = new Date(config.expires);
|
|
53
|
+
cookie.expirationDate = exp.getTime();
|
|
54
|
+
} else {
|
|
55
|
+
const exp = new Date(typedNumber);
|
|
56
|
+
cookie.expirationDate = exp.getTime();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (typeof config.hostOnly === 'boolean') {
|
|
60
|
+
cookie.hostOnly = config.hostOnly;
|
|
61
|
+
}
|
|
62
|
+
if (typeof config.httpOnly === 'boolean') {
|
|
63
|
+
cookie.httpOnly = config.httpOnly;
|
|
64
|
+
}
|
|
65
|
+
if (typeof config.session === 'boolean') {
|
|
66
|
+
cookie.session = config.session;
|
|
67
|
+
}
|
|
68
|
+
if (typeof config.secure === 'boolean') {
|
|
69
|
+
cookie.secure = config.secure;
|
|
70
|
+
}
|
|
71
|
+
Events.Cookie.update(this.eventTarget, cookie);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async response(log: IRequestLog): Promise<void> {
|
|
75
|
+
if (!log.request || !log.response) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const config = this.config as ISetCookieAction;
|
|
79
|
+
const { source } = config;
|
|
80
|
+
let value: string | number | undefined;
|
|
81
|
+
if (source.source === 'value') {
|
|
82
|
+
value = source.value;
|
|
83
|
+
} else {
|
|
84
|
+
const extractor = new RequestDataExtractor(log.request, log.response);
|
|
85
|
+
value = await extractor.extract(source);
|
|
86
|
+
}
|
|
87
|
+
if (typeof value === 'undefined') {
|
|
88
|
+
throw new Error(`Cannot read value for the action`);
|
|
89
|
+
}
|
|
90
|
+
await this.setCookie(log.request, config, String(value));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { IHttpRequest } from 'src/models/HttpRequest.js';
|
|
2
|
+
import { ActionRunnable } from './ActionRunnable.js';
|
|
3
|
+
import { ISetVariableAction } from '../../../models/actions/runnable/SetVariableAction.js';
|
|
4
|
+
import { Events } from '../../../events/Events.js';
|
|
5
|
+
import { RequestDataExtractor } from '../../../data/RequestDataExtractor.js';
|
|
6
|
+
import { IRequestLog } from 'src/models/RequestLog.js';
|
|
7
|
+
|
|
8
|
+
export class SetVariableRunnable extends ActionRunnable {
|
|
9
|
+
async request(request: IHttpRequest): Promise<void> {
|
|
10
|
+
const config = this.config as ISetVariableAction;
|
|
11
|
+
const value = await this.readRequestValue(request, config);
|
|
12
|
+
if (typeof value === 'undefined') {
|
|
13
|
+
throw new Error(`Cannot read value for the action`);
|
|
14
|
+
}
|
|
15
|
+
await this.setVariable(config, String(value));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async readRequestValue(request: IHttpRequest, config: ISetVariableAction): Promise<string | number | undefined> {
|
|
19
|
+
const { source } = config;
|
|
20
|
+
let value: string | number | undefined;
|
|
21
|
+
if (source.source === 'value') {
|
|
22
|
+
value = source.value;
|
|
23
|
+
} else {
|
|
24
|
+
const extractor = new RequestDataExtractor(request);
|
|
25
|
+
value = await extractor.extract(source);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async setVariable(config: ISetVariableAction, value: string): Promise<void> {
|
|
31
|
+
const { name } = config;
|
|
32
|
+
Events.Environment.set(this.eventTarget, name, value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async response(log: IRequestLog): Promise<void> {
|
|
36
|
+
if (!log.request || !log.response) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const config = this.config as ISetVariableAction;
|
|
40
|
+
let value: string | number | undefined;
|
|
41
|
+
const { source } = config;
|
|
42
|
+
if (source.source === 'value') {
|
|
43
|
+
value = source.value;
|
|
44
|
+
} else {
|
|
45
|
+
const extractor = new RequestDataExtractor(log.request, log.response);
|
|
46
|
+
value = await extractor.extract(source);
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'undefined') {
|
|
49
|
+
throw new Error(`Cannot read value for the action`);
|
|
50
|
+
}
|
|
51
|
+
await this.setVariable(config, String(value));
|
|
52
|
+
}
|
|
53
|
+
}
|