@api-client/core 0.6.31 → 0.7.2
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 +6 -14
- package/build/browser.js +11 -16
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +8 -20
- package/build/index.js +13 -25
- package/build/index.js.map +1 -1
- package/build/src/amf/ApiSchemaValues.d.ts +2 -0
- package/build/src/amf/ApiSchemaValues.js +29 -23
- package/build/src/amf/ApiSchemaValues.js.map +1 -1
- package/build/src/authorization/lib/Utils.d.ts +1 -1
- package/build/src/cookies/CookieJar.d.ts +23 -0
- package/build/src/cookies/CookieJar.js +3 -0
- package/build/src/cookies/CookieJar.js.map +1 -0
- package/build/src/cookies/CookieParser.d.ts +67 -0
- package/build/src/cookies/CookieParser.js +316 -0
- package/build/src/cookies/CookieParser.js.map +1 -0
- package/build/src/cookies/InMemoryCookieJar.d.ts +12 -0
- package/build/src/cookies/InMemoryCookieJar.js +68 -0
- package/build/src/cookies/InMemoryCookieJar.js.map +1 -0
- package/build/src/cookies/Punycode.d.ts +12 -0
- package/build/src/cookies/Punycode.js +124 -0
- package/build/src/cookies/Punycode.js.map +1 -0
- package/build/src/data/RequestDataExtractor.d.ts +8 -7
- package/build/src/data/RequestDataExtractor.js +8 -10
- package/build/src/data/RequestDataExtractor.js.map +1 -1
- package/build/src/events/CustomEvent.js +5 -0
- package/build/src/events/CustomEvent.js.map +1 -1
- package/build/src/events/EventTypes.d.ts +43 -43
- package/build/src/events/amf/AmfEventTypes.d.ts +4 -4
- package/build/src/events/authorization/AuthorizationEventTypes.d.ts +4 -4
- package/build/src/events/cookies/CookieEventTypes.d.ts +9 -9
- package/build/src/events/encryption/EncryptionEventTypes.d.ts +2 -2
- package/build/src/events/environment/EnvironmentEventTypes.d.ts +1 -1
- package/build/src/events/models/ModelEventTypes.d.ts +7 -7
- package/build/src/events/process/ProcessEventTypes.d.ts +3 -3
- package/build/src/events/reporting/ReportingEventTypes.d.ts +1 -1
- package/build/src/events/telemetry/TelemetryEventTypes.d.ts +6 -6
- package/build/src/events/transport/TransportEventTypes.d.ts +6 -6
- package/build/src/events/transport/TransportEvents.d.ts +2 -2
- package/build/src/mocking/ProjectMock.d.ts +3 -2
- package/build/src/mocking/ProjectMock.js +3 -3
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/App.d.ts +36 -0
- package/build/src/mocking/lib/App.js +70 -0
- package/build/src/mocking/lib/App.js.map +1 -0
- package/build/src/models/{arc/ArcProject.d.ts → AppProject.d.ts} +296 -134
- package/build/src/models/{arc/ArcProject.js → AppProject.js} +436 -79
- package/build/src/models/AppProject.js.map +1 -0
- package/build/src/models/AppRequest.d.ts +69 -0
- package/build/src/models/{arc/ArcHttpRequest.js → AppRequest.js} +53 -17
- package/build/src/models/AppRequest.js.map +1 -0
- package/build/src/models/ClientCertificate.d.ts +2 -2
- package/build/src/models/Environment.d.ts +8 -1
- package/build/src/models/Environment.js +21 -0
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/HostRule.d.ts +2 -2
- package/build/src/models/HttpCookie.d.ts +63 -12
- package/build/src/models/HttpCookie.js +178 -44
- package/build/src/models/HttpCookie.js.map +1 -1
- package/build/src/models/HttpHistory.d.ts +8 -3
- package/build/src/models/HttpHistory.js +3 -3
- package/build/src/models/HttpHistory.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +34 -1
- package/build/src/models/HttpProject.js +104 -8
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts +2 -0
- package/build/src/models/ProjectFolder.js +14 -0
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectItem.d.ts +2 -0
- package/build/src/models/ProjectItem.js +20 -0
- package/build/src/models/ProjectItem.js.map +1 -1
- package/build/src/models/ProjectParent.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts +3 -2
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/Property.d.ts +2 -2
- package/build/src/models/Property.js +2 -2
- package/build/src/models/Property.js.map +1 -1
- package/build/src/models/Request.d.ts +16 -8
- package/build/src/models/Request.js +20 -15
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestAuthorization.js.map +1 -1
- package/build/src/models/RequestUiMeta.d.ts +0 -14
- package/build/src/models/RequestUiMeta.js +1 -10
- package/build/src/models/RequestUiMeta.js.map +1 -1
- package/build/src/models/Server.d.ts +1 -2
- package/build/src/models/Server.js.map +1 -1
- package/build/src/models/http-actions/HttpActions.d.ts +256 -0
- package/build/src/models/http-actions/HttpActions.js +46 -0
- package/build/src/models/http-actions/HttpActions.js.map +1 -0
- package/build/src/models/http-actions/LegacyTranslator.d.ts +17 -0
- package/build/src/models/http-actions/LegacyTranslator.js +222 -0
- package/build/src/models/http-actions/LegacyTranslator.js.map +1 -0
- package/build/src/models/store/Backend.d.ts +136 -1
- package/build/src/models/store/File.d.ts +1 -1
- package/build/src/models/store/File.js +2 -0
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/User.d.ts +3 -3
- package/build/src/runtime/http-engine/CoreEngine.d.ts +2 -0
- package/build/src/runtime/http-engine/CoreEngine.js +1 -0
- package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
- package/build/src/runtime/http-engine/HttpEngine.d.ts +13 -0
- package/build/src/runtime/http-engine/HttpEngine.js +39 -31
- package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
- package/build/src/runtime/{actions/ConditionRunner.d.ts → http-runner/ConditionCheck.d.ts} +2 -2
- package/build/src/runtime/{actions/ConditionRunner.js → http-runner/ConditionCheck.js} +2 -2
- package/build/src/runtime/http-runner/ConditionCheck.js.map +1 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +62 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.js +217 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -0
- package/build/src/runtime/{node/RequestFactory.d.ts → http-runner/HttpRequestRunner.d.ts} +40 -54
- package/build/src/runtime/http-runner/HttpRequestRunner.js +316 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.d.ts +25 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.js +2 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.js.map +1 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.d.ts +56 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.js +143 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.js.map +1 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.d.ts +24 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.js +65 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.js.map +1 -0
- package/build/src/runtime/node/InteropInterfaces.d.ts +21 -6
- package/build/src/runtime/node/ProjectParallelRunner.js +3 -1
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +24 -10
- package/build/src/runtime/node/ProjectRequestRunner.js +116 -45
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts +5 -7
- package/build/src/runtime/node/ProjectRunner.js +30 -14
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunnerWorker.js +3 -0
- package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
- package/build/src/runtime/reporters/Reporter.d.ts +5 -0
- package/build/src/runtime/reporters/Reporter.js.map +1 -1
- package/build/src/runtime/store/AppSdk.d.ts +185 -0
- package/build/src/runtime/store/AppSdk.js +704 -0
- package/build/src/runtime/store/AppSdk.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.js +4 -4
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/HistorySdk.js +2 -2
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +17 -2
- package/build/src/runtime/store/RouteBuilder.js +60 -3
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/Sdk.d.ts +5 -0
- package/build/src/runtime/store/Sdk.js +5 -0
- package/build/src/runtime/store/Sdk.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.js +1 -1
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/UsersSdk.js +1 -1
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/package.json +2 -2
- package/src/amf/ApiSchemaValues.ts +41 -33
- package/src/cookies/CookieJar.ts +26 -0
- package/src/cookies/CookieParser.ts +327 -0
- package/src/cookies/InMemoryCookieJar.ts +70 -0
- package/src/cookies/Punycode.ts +133 -0
- package/src/data/RequestDataExtractor.ts +14 -15
- package/src/events/CustomEvent.ts +4 -0
- package/src/mocking/ProjectMock.ts +4 -3
- package/src/mocking/lib/App.ts +101 -0
- package/src/models/{arc/ArcProject.ts → AppProject.ts} +671 -225
- package/src/models/AppRequest.ts +176 -0
- package/src/models/ClientCertificate.ts +2 -2
- package/src/models/Environment.ts +24 -2
- package/src/models/HostRule.ts +2 -2
- package/src/models/HttpCookie.ts +210 -48
- package/src/models/HttpHistory.ts +12 -5
- package/src/models/HttpProject.ts +113 -10
- package/src/models/ProjectFolder.ts +16 -0
- package/src/models/ProjectItem.ts +18 -0
- package/src/models/ProjectParent.ts +4 -1
- package/src/models/ProjectRequest.ts +4 -3
- package/src/models/Property.ts +4 -4
- package/src/models/Request.ts +29 -19
- package/src/models/RequestAuthorization.ts +4 -4
- package/src/models/RequestUiMeta.ts +1 -21
- package/src/models/Server.ts +1 -2
- package/src/models/http-actions/HttpActions.ts +270 -0
- package/src/models/http-actions/LegacyTranslator.ts +223 -0
- package/src/models/store/Backend.ts +148 -2
- package/src/models/store/File.ts +3 -1
- package/src/models/store/User.ts +3 -3
- package/src/runtime/http-engine/CoreEngine.ts +3 -2
- package/src/runtime/http-engine/HttpEngine.ts +48 -30
- package/src/runtime/{actions/ConditionRunner.ts → http-runner/ConditionCheck.ts} +3 -3
- package/src/runtime/http-runner/HttpFlowRunner.ts +232 -0
- package/src/runtime/http-runner/HttpRequestRunner.ts +353 -0
- package/src/runtime/http-runner/HttpRuntimeEnvironment.ts +27 -0
- package/src/runtime/http-runner/RequestAuthorizationProcessor.ts +144 -0
- package/src/runtime/http-runner/RequestCookiesProcessor.ts +74 -0
- package/src/runtime/node/InteropInterfaces.ts +24 -6
- package/src/runtime/node/ProjectParallelRunner.ts +4 -2
- package/src/runtime/node/ProjectRequestRunner.ts +130 -60
- package/src/runtime/node/ProjectRunner.ts +37 -22
- package/src/runtime/node/ProjectRunnerWorker.ts +3 -0
- package/src/runtime/reporters/Reporter.ts +5 -0
- package/src/runtime/store/AppSdk.ts +709 -0
- package/src/runtime/store/FilesSdk.ts +4 -4
- package/src/runtime/store/HistorySdk.ts +2 -2
- package/src/runtime/store/RouteBuilder.ts +75 -3
- package/src/runtime/store/Sdk.ts +6 -0
- package/src/runtime/store/SharedSdk.ts +1 -1
- package/src/runtime/store/UsersSdk.ts +1 -1
- package/build/src/lib/cookies/Cookie.d.ts +0 -123
- package/build/src/lib/cookies/Cookie.js +0 -257
- package/build/src/lib/cookies/Cookie.js.map +0 -1
- package/build/src/lib/cookies/Cookies.d.ts +0 -90
- package/build/src/lib/cookies/Cookies.js +0 -310
- package/build/src/lib/cookies/Cookies.js.map +0 -1
- package/build/src/lib/cookies/Utils.d.ts +0 -47
- package/build/src/lib/cookies/Utils.js +0 -163
- package/build/src/lib/cookies/Utils.js.map +0 -1
- package/build/src/mocking/lib/Arc.d.ts +0 -9
- package/build/src/mocking/lib/Arc.js +0 -24
- package/build/src/mocking/lib/Arc.js.map +0 -1
- package/build/src/models/RequestActions.d.ts +0 -65
- package/build/src/models/RequestActions.js +0 -114
- package/build/src/models/RequestActions.js.map +0 -1
- package/build/src/models/actions/Action.d.ts +0 -75
- package/build/src/models/actions/Action.js +0 -188
- package/build/src/models/actions/Action.js.map +0 -1
- package/build/src/models/actions/ActionView.d.ts +0 -15
- package/build/src/models/actions/ActionView.js +0 -33
- package/build/src/models/actions/ActionView.js.map +0 -1
- package/build/src/models/actions/Condition.d.ts +0 -81
- package/build/src/models/actions/Condition.js +0 -185
- package/build/src/models/actions/Condition.js.map +0 -1
- package/build/src/models/actions/ConditionView.d.ts +0 -17
- package/build/src/models/actions/ConditionView.js +0 -34
- package/build/src/models/actions/ConditionView.js.map +0 -1
- package/build/src/models/actions/Enums.d.ts +0 -26
- package/build/src/models/actions/Enums.js +0 -31
- package/build/src/models/actions/Enums.js.map +0 -1
- package/build/src/models/actions/RunnableAction.d.ts +0 -59
- package/build/src/models/actions/RunnableAction.js +0 -106
- package/build/src/models/actions/RunnableAction.js.map +0 -1
- package/build/src/models/actions/runnable/DeleteCookieAction.d.ts +0 -44
- package/build/src/models/actions/runnable/DeleteCookieAction.js +0 -92
- package/build/src/models/actions/runnable/DeleteCookieAction.js.map +0 -1
- package/build/src/models/actions/runnable/Runnable.d.ts +0 -8
- package/build/src/models/actions/runnable/Runnable.js +0 -4
- package/build/src/models/actions/runnable/Runnable.js.map +0 -1
- package/build/src/models/actions/runnable/SetCookieAction.d.ts +0 -87
- package/build/src/models/actions/runnable/SetCookieAction.js +0 -176
- package/build/src/models/actions/runnable/SetCookieAction.js.map +0 -1
- package/build/src/models/actions/runnable/SetVariableAction.d.ts +0 -31
- package/build/src/models/actions/runnable/SetVariableAction.js +0 -63
- package/build/src/models/actions/runnable/SetVariableAction.js.map +0 -1
- package/build/src/models/actions/runnable/index.d.ts +0 -7
- package/build/src/models/actions/runnable/index.js +0 -2
- package/build/src/models/actions/runnable/index.js.map +0 -1
- package/build/src/models/arc/ArcHttpRequest.d.ts +0 -40
- package/build/src/models/arc/ArcHttpRequest.js.map +0 -1
- package/build/src/models/arc/ArcProject.js.map +0 -1
- package/build/src/runtime/actions/ActionRunner.d.ts +0 -17
- package/build/src/runtime/actions/ActionRunner.js +0 -74
- package/build/src/runtime/actions/ActionRunner.js.map +0 -1
- package/build/src/runtime/actions/ConditionRunner.js.map +0 -1
- package/build/src/runtime/actions/RunnableCondition.d.ts +0 -27
- package/build/src/runtime/actions/RunnableCondition.js +0 -50
- package/build/src/runtime/actions/RunnableCondition.js.map +0 -1
- package/build/src/runtime/actions/runnable/ActionRunnable.d.ts +0 -13
- package/build/src/runtime/actions/runnable/ActionRunnable.js +0 -13
- package/build/src/runtime/actions/runnable/ActionRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.d.ts +0 -7
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.js +0 -36
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/SetCookieRunnable.d.ts +0 -10
- package/build/src/runtime/actions/runnable/SetCookieRunnable.js +0 -89
- package/build/src/runtime/actions/runnable/SetCookieRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/SetVariableRunnable.d.ts +0 -10
- package/build/src/runtime/actions/runnable/SetVariableRunnable.js +0 -49
- package/build/src/runtime/actions/runnable/SetVariableRunnable.js.map +0 -1
- package/build/src/runtime/modules/BasicAuthCache.d.ts +0 -39
- package/build/src/runtime/modules/BasicAuthCache.js +0 -122
- package/build/src/runtime/modules/BasicAuthCache.js.map +0 -1
- package/build/src/runtime/modules/ExecutionResponse.d.ts +0 -4
- package/build/src/runtime/modules/ExecutionResponse.js +0 -6
- package/build/src/runtime/modules/ExecutionResponse.js.map +0 -1
- package/build/src/runtime/modules/ModulesRegistry.d.ts +0 -93
- package/build/src/runtime/modules/ModulesRegistry.js +0 -69
- package/build/src/runtime/modules/ModulesRegistry.js.map +0 -1
- package/build/src/runtime/modules/RequestAuthorization.d.ts +0 -6
- package/build/src/runtime/modules/RequestAuthorization.js +0 -110
- package/build/src/runtime/modules/RequestAuthorization.js.map +0 -1
- package/build/src/runtime/modules/RequestCookies.d.ts +0 -17
- package/build/src/runtime/modules/RequestCookies.js +0 -134
- package/build/src/runtime/modules/RequestCookies.js.map +0 -1
- package/build/src/runtime/node/RequestFactory.js +0 -406
- package/build/src/runtime/node/RequestFactory.js.map +0 -1
- package/build/src/runtime/node/VariablesStore.d.ts +0 -9
- package/build/src/runtime/node/VariablesStore.js +0 -19
- package/build/src/runtime/node/VariablesStore.js.map +0 -1
- package/src/lib/cookies/Cookie.ts +0 -312
- package/src/lib/cookies/Cookies.ts +0 -326
- package/src/lib/cookies/Utils.ts +0 -168
- package/src/mocking/lib/Arc.ts +0 -28
- package/src/models/RequestActions.ts +0 -161
- package/src/models/actions/Action.ts +0 -213
- package/src/models/actions/ActionView.ts +0 -40
- package/src/models/actions/Condition.ts +0 -207
- package/src/models/actions/ConditionView.ts +0 -42
- package/src/models/actions/Enums.ts +0 -29
- package/src/models/actions/RunnableAction.ts +0 -144
- package/src/models/actions/runnable/DeleteCookieAction.ts +0 -113
- package/src/models/actions/runnable/Runnable.ts +0 -9
- package/src/models/actions/runnable/SetCookieAction.ts +0 -216
- package/src/models/actions/runnable/SetVariableAction.ts +0 -81
- package/src/models/arc/ArcHttpRequest.ts +0 -129
- package/src/models/arc/readme.md +0 -3
- package/src/runtime/actions/ActionRunner.ts +0 -83
- package/src/runtime/actions/RunnableCondition.ts +0 -56
- package/src/runtime/actions/runnable/ActionRunnable.ts +0 -19
- package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +0 -39
- package/src/runtime/actions/runnable/SetCookieRunnable.ts +0 -92
- package/src/runtime/actions/runnable/SetVariableRunnable.ts +0 -53
- package/src/runtime/modules/BasicAuthCache.ts +0 -129
- package/src/runtime/modules/ExecutionResponse.ts +0 -4
- package/src/runtime/modules/ModulesRegistry.ts +0 -136
- package/src/runtime/modules/RequestAuthorization.ts +0 -106
- package/src/runtime/modules/RequestCookies.ts +0 -146
- package/src/runtime/node/RequestFactory.ts +0 -432
- package/src/runtime/node/VariablesStore.ts +0 -25
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { IHttpRequest } from '../../../models/HttpRequest.js';
|
|
2
|
-
import { IHttpCookie } from '../../../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 '../../../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(cookie, this.eventTarget);
|
|
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
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { IHttpRequest } from '../../../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 '../../../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(name, value, this.eventTarget);
|
|
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
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { Headers } from '../../lib/headers/Headers.js';
|
|
2
|
-
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
3
|
-
import { INtlmAuthorization, IBasicAuthorization } from '../../models/Authorization.js';
|
|
4
|
-
import { ExecutionContext } from './ModulesRegistry.js';
|
|
5
|
-
import { IRequestAuthorization, Kind as RequestAuthorizationKind } from '../../models/RequestAuthorization.js';
|
|
6
|
-
|
|
7
|
-
const cache: any = {};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Removes query parameters and the fragment part from the URL
|
|
11
|
-
* @param url The URL to process.
|
|
12
|
-
* @returns The canonical URL.
|
|
13
|
-
*/
|
|
14
|
-
export function computeUrlPath(url: string): string {
|
|
15
|
-
if (!url) {
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const u = new URL(url);
|
|
20
|
-
u.hash = '';
|
|
21
|
-
u.search = '';
|
|
22
|
-
let result = u.toString();
|
|
23
|
-
// polyfill library has some error and leaves '?#' if was set
|
|
24
|
-
result = result.replace('?', '');
|
|
25
|
-
result = result.replace('#', '');
|
|
26
|
-
return result;
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return url;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Finds an auth data for given `url`.
|
|
34
|
-
*
|
|
35
|
-
* @param type Authorization type.
|
|
36
|
-
* @param url The URL of the request.
|
|
37
|
-
* @return Auth data if exists in the cache.
|
|
38
|
-
*/
|
|
39
|
-
export function findCachedAuthData(type: string, url: string): IBasicAuthorization|INtlmAuthorization|undefined {
|
|
40
|
-
const key = computeUrlPath(url);
|
|
41
|
-
if (!cache || !type || !key || !cache[type]) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
return cache[type][key];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Updates cached authorization data
|
|
49
|
-
*
|
|
50
|
-
* @param type Authorization type.
|
|
51
|
-
* @param url The URL of the request.
|
|
52
|
-
* @param value Auth data to set
|
|
53
|
-
*/
|
|
54
|
-
export function updateCache(type: string, url: string, value: IBasicAuthorization|INtlmAuthorization): void {
|
|
55
|
-
const key = computeUrlPath(url);
|
|
56
|
-
if (!cache[type]) {
|
|
57
|
-
cache[type] = {};
|
|
58
|
-
}
|
|
59
|
-
cache[type][key] = value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Applies the basic authorization data to the request.
|
|
64
|
-
*
|
|
65
|
-
* If the header value have changed then it fires `request-headers-changed` custom event.
|
|
66
|
-
* It sets computed value of the readers to the event's detail object.
|
|
67
|
-
*
|
|
68
|
-
* @param request The event's detail object. Changes made here will be propagated to the event.
|
|
69
|
-
* @param data The authorization data to apply.
|
|
70
|
-
*/
|
|
71
|
-
export function applyRequestBasicAuthData(request: IHttpRequest, data: IBasicAuthorization): void {
|
|
72
|
-
const { username='', password='' } = data;
|
|
73
|
-
const headers = new Headers(request.headers || '');
|
|
74
|
-
let hash: string;
|
|
75
|
-
let decoded = `${username}:${password}`;
|
|
76
|
-
if (typeof Buffer === 'function' && typeof Buffer.from === 'function') {
|
|
77
|
-
hash = Buffer.from(decoded).toString('base64');
|
|
78
|
-
} else {
|
|
79
|
-
hash = btoa(decoded);
|
|
80
|
-
}
|
|
81
|
-
headers.set('authorization', `Basic ${hash}`);
|
|
82
|
-
request.headers = headers.toString();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Applies the NTLM authorization data to the request.
|
|
87
|
-
*
|
|
88
|
-
* Because NTLM requires certain operations on a socket it's bot just about setting a headers
|
|
89
|
-
* but whole NTLM configuration object.
|
|
90
|
-
*
|
|
91
|
-
* Applied the `auth` object to the event's `detail.auth` object.
|
|
92
|
-
*/
|
|
93
|
-
function applyRequestNtlmAuthData(authorization: IRequestAuthorization[], values: INtlmAuthorization): void {
|
|
94
|
-
let ntlm: IRequestAuthorization | undefined = authorization.find(((method) => method.type === 'ntlm'));
|
|
95
|
-
if (!ntlm) {
|
|
96
|
-
ntlm = {
|
|
97
|
-
kind: RequestAuthorizationKind,
|
|
98
|
-
enabled: true,
|
|
99
|
-
type: 'ntlm',
|
|
100
|
-
config: {},
|
|
101
|
-
valid: true,
|
|
102
|
-
};
|
|
103
|
-
authorization.push(ntlm);
|
|
104
|
-
}
|
|
105
|
-
const cnf = ntlm.config as INtlmAuthorization;
|
|
106
|
-
if (cnf.username) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
cnf.username = values.username;
|
|
110
|
-
cnf.password = values.password;
|
|
111
|
-
cnf.domain = values.domain;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Adds basic authorization data to the request, when during this session basic auth was used
|
|
116
|
-
*/
|
|
117
|
-
export default function applyCachedBasicAuthData(request: IHttpRequest, context: ExecutionContext): void {
|
|
118
|
-
// Try to find an auth data for the URL. If has a match, apply it to the request
|
|
119
|
-
let authData = findCachedAuthData('basic', request.url);
|
|
120
|
-
if (authData) {
|
|
121
|
-
applyRequestBasicAuthData(request, authData);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
// Try NTLM
|
|
125
|
-
authData = findCachedAuthData('ntlm', request.url);
|
|
126
|
-
if (authData && Array.isArray(context.authorization)) {
|
|
127
|
-
applyRequestNtlmAuthData(context.authorization, authData as INtlmAuthorization);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
2
|
-
import { EnvironmentEvents } from '../../events/environment/EnvironmentEvents.js';
|
|
3
|
-
import { CookieEvents } from '../../events/cookies/CookieEvents.js';
|
|
4
|
-
import { EncryptionEvents } from '../../events/encryption/EncryptionEvents.js';
|
|
5
|
-
import { ProcessEvents } from '../../events/process/ProcessEvents.js';
|
|
6
|
-
import { AuthorizationEvents } from '../../events/authorization/AuthorizationEvents.js';
|
|
7
|
-
import { ClientCertificateEvents } from '../../events/models/ClientCertificateEvents.js';
|
|
8
|
-
import { IRequestAuthorization } from '../../models/RequestAuthorization.js';
|
|
9
|
-
import { IRequestConfig } from '../../models/RequestConfig.js';
|
|
10
|
-
import { IRequestLog } from '../../models/RequestLog.js';
|
|
11
|
-
import { HttpCertificate } from '../../models/ClientCertificate.js';
|
|
12
|
-
|
|
13
|
-
export interface RegisteredRequestModule {
|
|
14
|
-
fn: (request: IHttpRequest, context: ExecutionContext) => Promise<number>;
|
|
15
|
-
permissions: RegistryPermission[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface RegisteredResponseModule {
|
|
19
|
-
fn: (log: IRequestLog, context: ExecutionContext) => Promise<number>;
|
|
20
|
-
permissions: RegistryPermission[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export enum RegistryPermission {
|
|
24
|
-
environment = 'environment',
|
|
25
|
-
events = 'events',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface ExecutionContext {
|
|
29
|
-
/**
|
|
30
|
-
* The event target for events
|
|
31
|
-
*/
|
|
32
|
-
eventsTarget: EventTarget;
|
|
33
|
-
/**
|
|
34
|
-
* The events to use to communicate with the context store(s)
|
|
35
|
-
*/
|
|
36
|
-
Events?: ExecutionEvents;
|
|
37
|
-
/**
|
|
38
|
-
* The environment variables to use when executing the module.
|
|
39
|
-
*/
|
|
40
|
-
variables?: Record<string, string>;
|
|
41
|
-
/**
|
|
42
|
-
* Request authorization configuration
|
|
43
|
-
*/
|
|
44
|
-
authorization?: IRequestAuthorization[];
|
|
45
|
-
/**
|
|
46
|
-
* Optional request configuration.
|
|
47
|
-
*/
|
|
48
|
-
config?: IRequestConfig;
|
|
49
|
-
/**
|
|
50
|
-
* Can be altered by the actions.
|
|
51
|
-
*/
|
|
52
|
-
certificates?: HttpCertificate[];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface ExecutionEvents {
|
|
56
|
-
Authorization: typeof AuthorizationEvents;
|
|
57
|
-
Environment: typeof EnvironmentEvents;
|
|
58
|
-
Cookie: typeof CookieEvents;
|
|
59
|
-
Encryption: typeof EncryptionEvents;
|
|
60
|
-
Process: typeof ProcessEvents;
|
|
61
|
-
ClientCertificate: typeof ClientCertificateEvents;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The list of registered request processing modules.
|
|
66
|
-
*/
|
|
67
|
-
const requestModules = new Map<string, RegisteredRequestModule>();
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The list of registered response processing modules.
|
|
71
|
-
*/
|
|
72
|
-
const responseModules = new Map<string, RegisteredResponseModule>();
|
|
73
|
-
|
|
74
|
-
export type RequestModule = 'request';
|
|
75
|
-
export type ResponseModule = 'response';
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* A registry for modules.
|
|
79
|
-
*/
|
|
80
|
-
export class ModulesRegistry {
|
|
81
|
-
static get request(): RequestModule { return 'request' }
|
|
82
|
-
|
|
83
|
-
static get response(): ResponseModule { return 'response' }
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Registers a new request or response module in the registry.
|
|
87
|
-
* @param context The name of the execution context
|
|
88
|
-
* @param id The identifier of the module
|
|
89
|
-
* @param fn The function to execute
|
|
90
|
-
* @param permissions The list of permissions for the module
|
|
91
|
-
* @throws {Error} When the module is already registered
|
|
92
|
-
*/
|
|
93
|
-
static register(context: ResponseModule|RequestModule, id: string, fn: Function, permissions?: string[]): void {
|
|
94
|
-
const data = {
|
|
95
|
-
fn,
|
|
96
|
-
permissions: Array.isArray(permissions) ? permissions : [],
|
|
97
|
-
};
|
|
98
|
-
const map = context === ModulesRegistry.request ? requestModules : responseModules;
|
|
99
|
-
if (map.has(id)) {
|
|
100
|
-
throw new Error(`Module ${id} already exists`);
|
|
101
|
-
}
|
|
102
|
-
// @ts-ignore
|
|
103
|
-
map.set(id, data);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Checks whether a module is already registered for the given context.
|
|
108
|
-
* @param {ModulesRegistry.request|ModulesRegistry.response} context The name of the execution context
|
|
109
|
-
* @param id The identifier of the module
|
|
110
|
-
*/
|
|
111
|
-
static has(context: ResponseModule|RequestModule, id: string): boolean {
|
|
112
|
-
const map = context === ModulesRegistry.request ? requestModules : responseModules;
|
|
113
|
-
return map.has(id);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Removes a registered module
|
|
118
|
-
* @param {ModulesRegistry.request|ModulesRegistry.response} context The name of the execution context
|
|
119
|
-
* @param {string} id The identifier of the module
|
|
120
|
-
*/
|
|
121
|
-
static unregister(context: ResponseModule|RequestModule, id: string): void {
|
|
122
|
-
const map = context === ModulesRegistry.request ? requestModules : responseModules;
|
|
123
|
-
map.delete(id);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Reads the list of registered modules
|
|
128
|
-
* @param context The name of the execution context
|
|
129
|
-
* @returns The copy of the map of actions.
|
|
130
|
-
*/
|
|
131
|
-
static get(context: ResponseModule|RequestModule): Map<string, RegisteredRequestModule|RegisteredResponseModule> {
|
|
132
|
-
const map = context === ModulesRegistry.request ? requestModules : responseModules;
|
|
133
|
-
// @ts-ignore
|
|
134
|
-
return new Map(map);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Headers } from '../../lib/headers/Headers.js';
|
|
2
|
-
import { ExecutionResponse } from './ExecutionResponse.js';
|
|
3
|
-
import applyCachedBasicAuthData, { applyRequestBasicAuthData } from './BasicAuthCache.js';
|
|
4
|
-
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
5
|
-
import { IBearerAuthorization, IBasicAuthorization, IOidcAuthorization, IOAuth2Authorization, ICCAuthorization } from '../../models/Authorization.js';
|
|
6
|
-
import { ExecutionContext } from './ModulesRegistry.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Injects client certificate object into the request object
|
|
10
|
-
*/
|
|
11
|
-
async function processClientCertificate(config: ICCAuthorization, context: ExecutionContext): Promise<void> {
|
|
12
|
-
const { certificate } = config;
|
|
13
|
-
if (!certificate) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (!Array.isArray(context.certificates)) {
|
|
17
|
-
context.certificates = [];
|
|
18
|
-
}
|
|
19
|
-
context.certificates.push(certificate);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Injects basic auth header into the request headers.
|
|
24
|
-
*/
|
|
25
|
-
function processBasicAuth(request: IHttpRequest, config: IBasicAuthorization): void {
|
|
26
|
-
const { username } = config;
|
|
27
|
-
if (!username) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
applyRequestBasicAuthData(request, config);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Injects oauth 2 auth header into the request headers.
|
|
35
|
-
*/
|
|
36
|
-
function processOAuth2(request: IHttpRequest, config: IOAuth2Authorization): void {
|
|
37
|
-
const { accessToken, tokenType='Bearer', deliveryMethod='header', deliveryName='authorization' } = config;
|
|
38
|
-
if (!accessToken) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const value = `${tokenType} ${accessToken}`;
|
|
42
|
-
if (deliveryMethod === 'header') {
|
|
43
|
-
const headers = new Headers(request.headers || '');
|
|
44
|
-
headers.append(deliveryName, value);
|
|
45
|
-
request.headers = headers.toString();
|
|
46
|
-
} else if (deliveryMethod === 'query') {
|
|
47
|
-
const { url } = request;
|
|
48
|
-
try {
|
|
49
|
-
const parsed = new URL(url);
|
|
50
|
-
parsed.searchParams.append(deliveryName, value);
|
|
51
|
-
request.url = parsed.toString();
|
|
52
|
-
} catch (e) {
|
|
53
|
-
// ...
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Injects OpenID Connect auth header into the request headers.
|
|
60
|
-
*/
|
|
61
|
-
function processOpenId(request: IHttpRequest, config: IOidcAuthorization): void {
|
|
62
|
-
const { accessToken } = config;
|
|
63
|
-
if (accessToken) {
|
|
64
|
-
processOAuth2(request, config);
|
|
65
|
-
}
|
|
66
|
-
// todo - if AT is missing find the current token from the tokens list in the passed configuration.
|
|
67
|
-
// Currently the authorization method UI sets the token when the requests is generated so it's not as much important.
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Injects bearer auth header into the request headers.
|
|
72
|
-
*/
|
|
73
|
-
function processBearer(request: IHttpRequest, config: IBearerAuthorization): void {
|
|
74
|
-
const { token } = config;
|
|
75
|
-
const value = `Bearer ${token}`;
|
|
76
|
-
const headers = new Headers(request.headers || '');
|
|
77
|
-
headers.append('authorization', value);
|
|
78
|
-
request.headers = headers.toString();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Processes authorization data from the authorization configuration and injects data into the request object when necessary.
|
|
83
|
-
*/
|
|
84
|
-
export default async function processAuth(request: IHttpRequest, context: ExecutionContext): Promise<number> {
|
|
85
|
-
if (!Array.isArray(context.authorization) || !context.authorization.length) {
|
|
86
|
-
return ExecutionResponse.OK;
|
|
87
|
-
}
|
|
88
|
-
for (const auth of context.authorization) {
|
|
89
|
-
if (!auth.enabled || !auth.config) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
switch (auth.type) {
|
|
93
|
-
case 'client certificate': await processClientCertificate(auth.config as ICCAuthorization, context); break;
|
|
94
|
-
case 'basic': processBasicAuth(request, auth.config as IBasicAuthorization); break;
|
|
95
|
-
case 'oauth 2': processOAuth2(request, auth.config as IOAuth2Authorization); break;
|
|
96
|
-
case 'open id': processOpenId(request, auth.config as IOidcAuthorization); break;
|
|
97
|
-
case 'bearer': processBearer(request, auth.config as IBearerAuthorization); break;
|
|
98
|
-
default:
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (request.url && !/^authorization:\s?.+$/gim.test(request.headers || '')) {
|
|
102
|
-
// Try to apply basic auth from the cached during this session values.
|
|
103
|
-
applyCachedBasicAuthData(request, context);
|
|
104
|
-
}
|
|
105
|
-
return ExecutionResponse.OK;
|
|
106
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { CookieEvents } from '../../events/cookies/CookieEvents.js';
|
|
2
|
-
import { Cookies } from '../../lib/cookies/Cookies.js';
|
|
3
|
-
import { Headers } from '../../lib/headers/Headers.js';
|
|
4
|
-
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
5
|
-
import { ExecutionContext } from './ModulesRegistry.js';
|
|
6
|
-
import { IResponseRedirect } from '../../models/ResponseRedirect.js';
|
|
7
|
-
import { IResponse } from '../../models/Response.js';
|
|
8
|
-
import { IErrorResponse } from '../../models/ErrorResponse.js';
|
|
9
|
-
import { IRequestLog } from '../../models/RequestLog.js';
|
|
10
|
-
import { HttpCookie } from '../../models/HttpCookie.js';
|
|
11
|
-
import { Kind as RequestConfigKind } from '../../models/RequestConfig.js';
|
|
12
|
-
import { Cookie } from '../../lib/cookies/Cookie.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get cookies header value for given URL.
|
|
16
|
-
*
|
|
17
|
-
* @param eventsTarget
|
|
18
|
-
* @param url An URL for cookies.
|
|
19
|
-
* @returns A promise that resolves to header value string.
|
|
20
|
-
*/
|
|
21
|
-
async function getCookiesHeaderValue(eventsTarget: EventTarget, url: string): Promise<string> {
|
|
22
|
-
const cookies = await CookieEvents.listUrl(url, eventsTarget);
|
|
23
|
-
if (!cookies || !cookies.length) {
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
return cookies.map((c) => `${c.name}=${c.value}`).join('; ');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Applies cookie header value to current request headers.
|
|
31
|
-
* If header to be applied is computed then it will alter headers string.
|
|
32
|
-
*
|
|
33
|
-
* Note, this element do not sends `request-headers-changed` event.
|
|
34
|
-
*
|
|
35
|
-
* @param header Computed headers string
|
|
36
|
-
* @param request The request object from the event.
|
|
37
|
-
*/
|
|
38
|
-
function applyCookieHeader(header: string, request: IHttpRequest): void {
|
|
39
|
-
const trimmed = header.trim();
|
|
40
|
-
if (!trimmed) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const headers = new Headers(request.headers);
|
|
44
|
-
headers.append('cookie', trimmed);
|
|
45
|
-
request.headers = headers.toString();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Extracts cookies from the `response` object and returns an object with `cookies` and `expired` properties containing array of cookies, each.
|
|
50
|
-
*
|
|
51
|
-
* @param url The request URL.
|
|
52
|
-
* @param redirects List of redirect responses
|
|
53
|
-
* @returns An object with `cookies` and `expired` arrays of cookies.
|
|
54
|
-
*/
|
|
55
|
-
function extract(response: IResponse, url: string, redirects?: IResponseRedirect[]): Record<'expired'|'cookies', Cookie[]> {
|
|
56
|
-
let expired: Cookie[] = [];
|
|
57
|
-
let parser;
|
|
58
|
-
let exp;
|
|
59
|
-
const parsers = [];
|
|
60
|
-
if (redirects && redirects.length) {
|
|
61
|
-
redirects.forEach((r) => {
|
|
62
|
-
const headers = new Headers(r.response.headers);
|
|
63
|
-
if (headers.has('set-cookie')) {
|
|
64
|
-
parser = new Cookies(headers.get('set-cookie'), r.url);
|
|
65
|
-
parser.filter();
|
|
66
|
-
exp = parser.clearExpired();
|
|
67
|
-
if (exp && exp.length) {
|
|
68
|
-
expired = expired.concat(exp);
|
|
69
|
-
}
|
|
70
|
-
parsers.push(parser);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const headers = new Headers(response.headers);
|
|
75
|
-
if (headers.has('set-cookie')) {
|
|
76
|
-
parser = new Cookies(headers.get('set-cookie'), url);
|
|
77
|
-
parser.filter();
|
|
78
|
-
exp = parser.clearExpired();
|
|
79
|
-
if (exp && exp.length) {
|
|
80
|
-
expired = expired.concat(exp);
|
|
81
|
-
}
|
|
82
|
-
parsers.push(parser);
|
|
83
|
-
}
|
|
84
|
-
let mainParser: Cookies|undefined;
|
|
85
|
-
parsers.forEach((item) => {
|
|
86
|
-
if (!mainParser) {
|
|
87
|
-
mainParser = item;
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
mainParser.merge(item);
|
|
91
|
-
});
|
|
92
|
-
return {
|
|
93
|
-
cookies: mainParser ? mainParser.cookies : [],
|
|
94
|
-
expired
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* A request engine request module to apply session cookies to a request.
|
|
100
|
-
* It adds stored session cookies when application configuration applies for it (or request configuration, when apply)
|
|
101
|
-
*
|
|
102
|
-
* Unregister this module when the application settings change to not to use session storage.
|
|
103
|
-
*
|
|
104
|
-
* In electron the session storage is a chrome persistent partition with a session shared with the "log in to a web service".
|
|
105
|
-
* This way cookies can be acquired in through the browser login and store in the application to use them with the request.
|
|
106
|
-
*/
|
|
107
|
-
export async function processRequestCookies(request: IHttpRequest, context: ExecutionContext): Promise<void> {
|
|
108
|
-
const editorRequest = request;
|
|
109
|
-
const { config } = context;
|
|
110
|
-
const ignore = config && config.enabled === true && config.ignoreSessionCookies === true;
|
|
111
|
-
if (ignore) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const cookie = await getCookiesHeaderValue(context.eventsTarget, editorRequest.url);
|
|
115
|
-
applyCookieHeader(cookie, editorRequest);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Processes cookies data from the response and inserts them into the session storage
|
|
120
|
-
*/
|
|
121
|
-
export async function processResponseCookies(log: IRequestLog, context: ExecutionContext): Promise<void> {
|
|
122
|
-
if (!log.response || !log.request) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const typedError = log.response as IErrorResponse;
|
|
126
|
-
if (typedError.error) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const config = context.config || {
|
|
130
|
-
kind: RequestConfigKind,
|
|
131
|
-
enabled: false,
|
|
132
|
-
};
|
|
133
|
-
let ignore = false;
|
|
134
|
-
if (config.enabled !== false && config.ignoreSessionCookies) {
|
|
135
|
-
ignore = true;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (ignore) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const typedResponse = log.response as IResponse;
|
|
142
|
-
const result = extract(typedResponse, log.request.url, log.redirects);
|
|
143
|
-
if (result.cookies.length) {
|
|
144
|
-
await CookieEvents.updateBulk(result.cookies.map(c => HttpCookie.fromCookieParser(c).toJSON()), context.eventsTarget);
|
|
145
|
-
}
|
|
146
|
-
}
|