@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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IHttpCookie, HttpCookie } from '../models/HttpCookie.js';
|
|
2
|
+
|
|
3
|
+
export abstract class CookieJar {
|
|
4
|
+
/**
|
|
5
|
+
* Requests the store to list all cookies that should be sent with the HTTP request.
|
|
6
|
+
*
|
|
7
|
+
* @param url The request URL to match the cookies for.
|
|
8
|
+
*/
|
|
9
|
+
abstract listCookies(url: string): Promise<HttpCookie[]>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Writes cookies to the store.
|
|
13
|
+
*
|
|
14
|
+
* @param url The request URL the cookies were set for.
|
|
15
|
+
* @param cookies The list of cookies to store.
|
|
16
|
+
*/
|
|
17
|
+
abstract setCookies(url: string, cookies: IHttpCookie[] | HttpCookie[]): Promise<void>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Deletes cookies by the URL and optionally by name.
|
|
21
|
+
*
|
|
22
|
+
* @param url The URL to delete the cookies for.
|
|
23
|
+
* @param name The name of the cookie. When not set it deletes all cookies for the URL.
|
|
24
|
+
*/
|
|
25
|
+
abstract deleteCookies(url: string, name?: string): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/* eslint-disable no-control-regex */
|
|
2
|
+
import { Punycode } from "./Punycode.js";
|
|
3
|
+
import { HttpCookie } from '../models/HttpCookie.js';
|
|
4
|
+
|
|
5
|
+
export type SameSiteValue = 'Lax' | 'Strict' | 'None';
|
|
6
|
+
|
|
7
|
+
const cookieParts: (keyof HttpCookie)[] = [
|
|
8
|
+
'path',
|
|
9
|
+
'domain',
|
|
10
|
+
'max-age',
|
|
11
|
+
'expires',
|
|
12
|
+
'secure',
|
|
13
|
+
'httponly',
|
|
14
|
+
'samesite',
|
|
15
|
+
'hostonly',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const v6reStr = `
|
|
19
|
+
\\[?(?:
|
|
20
|
+
(?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|
|
|
21
|
+
(?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|
|
|
22
|
+
(?:[a-fA-F\\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,2}|:)|
|
|
23
|
+
(?:[a-fA-F\\d]{1,4}:){4}(?:(?::[a-fA-F\\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,3}|:)|
|
|
24
|
+
(?:[a-fA-F\\d]{1,4}:){3}(?:(?::[a-fA-F\\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,4}|:)|
|
|
25
|
+
(?:[a-fA-F\\d]{1,4}:){2}(?:(?::[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,5}|:)|
|
|
26
|
+
(?:[a-fA-F\\d]{1,4}:){1}(?:(?::[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,6}|:)|
|
|
27
|
+
(?::(?:(?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:))
|
|
28
|
+
)(?:%[0-9a-zA-Z]{1,})?\\]?
|
|
29
|
+
`
|
|
30
|
+
.replace(/\s*\/\/.*$/gm, "")
|
|
31
|
+
.replace(/\n/g, "")
|
|
32
|
+
.trim();
|
|
33
|
+
|
|
34
|
+
const ipV6re = new RegExp(`^${v6reStr}$`);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A class that parses the `set-cookie` header string to a list of cookies.
|
|
38
|
+
*/
|
|
39
|
+
export class CookieParser {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a cookie canonical domain from the full request URL.
|
|
42
|
+
*
|
|
43
|
+
* @param url The HTTP request URL.
|
|
44
|
+
* @returns The canonical domain for the URL.
|
|
45
|
+
*/
|
|
46
|
+
static canonicalDomainUrl(url: string): string {
|
|
47
|
+
const parser = new URL(url);
|
|
48
|
+
return this.canonicalDomain(parser.host);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a cookie canonical domain from the host name.
|
|
53
|
+
*
|
|
54
|
+
* @param host The same as `new URL('...').host`.
|
|
55
|
+
* @returns The canonical domain for the URL.
|
|
56
|
+
*/
|
|
57
|
+
static canonicalDomain(host: string): string {
|
|
58
|
+
let str = host;
|
|
59
|
+
str = str.trim();
|
|
60
|
+
if (ipV6re.test(str)) {
|
|
61
|
+
str = str.replace("[", "").replace("]", "");
|
|
62
|
+
}
|
|
63
|
+
if (/[^\u0001-\u007f]/.test(str)) {
|
|
64
|
+
str = Punycode.toASCII(str);
|
|
65
|
+
}
|
|
66
|
+
// if (str[0] !== '.') {
|
|
67
|
+
// str = `.${str}`;
|
|
68
|
+
// }
|
|
69
|
+
return str.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Parses the `set-cookie` header value and creates a list of cookies.
|
|
74
|
+
* The cookie configuration must match the `url`. This means that if the cookie has a `host` property
|
|
75
|
+
* this must match the request URL (browsers do not allow setting cookies from one domain for another).
|
|
76
|
+
*
|
|
77
|
+
* When `host` or `path` part is missing from the cookie, the URL values are used.
|
|
78
|
+
*
|
|
79
|
+
* @param requestUrl The HTTP request URL. Cookies must match this URL or will be ignored.
|
|
80
|
+
* @param setCookie The value of the `set-cookie` string.
|
|
81
|
+
*/
|
|
82
|
+
static parse(requestUrl: string, setCookie?: string): HttpCookie[] {
|
|
83
|
+
const result: HttpCookie[] = [];
|
|
84
|
+
if (!setCookie || typeof setCookie !== 'string') {
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
const blocks = setCookie.split(';').map(i => i.trim());
|
|
88
|
+
blocks.forEach((part, index) => {
|
|
89
|
+
// Consider the following set-cookie string:
|
|
90
|
+
// c1=v1; Path=/; Expires=Wed, 09 Feb 2022 01:30:04 GMT; HttpOnly,c2=v2; Path=/,c3=v3; Path=/; Secure; SameSite=Strict
|
|
91
|
+
// It is a valid set-cookie header event though it mixes different formatting making it harder to parse cookies.
|
|
92
|
+
// This loop looks for invalid parts and creates a canonical cookie parts array.
|
|
93
|
+
const periodIndex = part.indexOf(',');
|
|
94
|
+
if (periodIndex === -1) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (part.toLowerCase().startsWith('expires=')) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const tmp = part.split(',');
|
|
101
|
+
// remove current
|
|
102
|
+
blocks.splice(index, 1);
|
|
103
|
+
// add the new two
|
|
104
|
+
blocks.splice(index, 0, ...tmp);
|
|
105
|
+
});
|
|
106
|
+
blocks.forEach((cookie) => {
|
|
107
|
+
const parts = cookie.split(/=/, 2);
|
|
108
|
+
if (parts.length === 0) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const name = decodeURIComponent(parts[0].trim());
|
|
112
|
+
if (!name) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const lowerName = name.toLowerCase() as keyof HttpCookie;
|
|
116
|
+
let value: string | boolean | undefined;
|
|
117
|
+
if (parts.length > 1) {
|
|
118
|
+
try {
|
|
119
|
+
value = decodeURIComponent(parts[1].trim());
|
|
120
|
+
} catch (e) {
|
|
121
|
+
value = parts[1];
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
value = true;
|
|
125
|
+
}
|
|
126
|
+
// if this is an attribute of previous cookie, set it for last
|
|
127
|
+
// added cookie.
|
|
128
|
+
if (cookieParts.includes(lowerName)) {
|
|
129
|
+
if (result.length - 1 >= 0) {
|
|
130
|
+
const attr = lowerName as keyof HttpCookie;
|
|
131
|
+
const previousCookie = result[result.length - 1];
|
|
132
|
+
if (attr === 'samesite') {
|
|
133
|
+
const typed = value as SameSiteValue;
|
|
134
|
+
switch (typed.toLowerCase()) {
|
|
135
|
+
case 'lax': previousCookie[attr] = 'lax'; break;
|
|
136
|
+
case 'strict': previousCookie[attr] = 'strict'; break;
|
|
137
|
+
case 'none': previousCookie[attr] = 'no_restriction'; break;
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
previousCookie[attr] = value as never;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
try {
|
|
145
|
+
result.push(new HttpCookie({
|
|
146
|
+
name,
|
|
147
|
+
value: value as string,
|
|
148
|
+
sameSite: 'unspecified',
|
|
149
|
+
}));
|
|
150
|
+
} catch (e) {
|
|
151
|
+
// ..
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// At this point we have all cookies set by the server. Now we need to filter out cookies
|
|
157
|
+
// set for a different domains.
|
|
158
|
+
|
|
159
|
+
// first lets set cookie domain and path.
|
|
160
|
+
const url = new URL(requestUrl);
|
|
161
|
+
const domain = this.canonicalDomain(url.host);
|
|
162
|
+
const path = this.getPath(url);
|
|
163
|
+
|
|
164
|
+
result.forEach((cookie) => {
|
|
165
|
+
if (!cookie.path) {
|
|
166
|
+
cookie.path = path;
|
|
167
|
+
}
|
|
168
|
+
if (!cookie.domain) {
|
|
169
|
+
// point 6. of https://tools.ietf.org/html/rfc6265#section-5.3
|
|
170
|
+
cookie.domain = domain;
|
|
171
|
+
cookie.hostOnly = true;
|
|
172
|
+
} else if (cookie.domain[0] !== '.') {
|
|
173
|
+
// https://stackoverflow.com/a/1063760/1127848
|
|
174
|
+
cookie.domain = `.${cookie.domain}`;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return this.filterCookies(result, requestUrl);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Filters a list of cookies to match the given `requestUrl`.
|
|
182
|
+
* This means that both the `domain` and the `path` part of the cookie must match the URL.
|
|
183
|
+
*
|
|
184
|
+
* @param cookies The list of cookies to filter.
|
|
185
|
+
* @param requestUrl The request URL to filter against.
|
|
186
|
+
* @returns The filtered list of cookies that can be used with the URL.
|
|
187
|
+
*/
|
|
188
|
+
static filterCookies(cookies: HttpCookie[], requestUrl: string): HttpCookie[] {
|
|
189
|
+
const url = new URL(requestUrl);
|
|
190
|
+
const domain = this.canonicalDomain(url.host);
|
|
191
|
+
return cookies.filter((cookie) => {
|
|
192
|
+
if (!cookie.path || !cookie.domain) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
return this.matchesDomain(cookie.domain, domain) && this.matchesPath(cookie.path, url);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Gets the path for a domain as defined in
|
|
201
|
+
* https://tools.ietf.org/html/rfc6265#section-5.1.4
|
|
202
|
+
*/
|
|
203
|
+
static getPath(url: URL): string {
|
|
204
|
+
let value = url.pathname;
|
|
205
|
+
// /a/b/c -> /a/b
|
|
206
|
+
// /a/b/c/ -> /a/b/c
|
|
207
|
+
// /a -> /
|
|
208
|
+
// /a/ -> /a
|
|
209
|
+
let index = value.indexOf('/', 1);
|
|
210
|
+
if (index === -1) {
|
|
211
|
+
return '/';
|
|
212
|
+
}
|
|
213
|
+
index = value.lastIndexOf('/');
|
|
214
|
+
if (index !== 0) {
|
|
215
|
+
value = value.substring(0, index);
|
|
216
|
+
}
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* This follows the algorithm defined in https://tools.ietf.org/html/rfc6265#section-5.1.3
|
|
222
|
+
*
|
|
223
|
+
* @param string A string to test whether it matches the domain.
|
|
224
|
+
* @param domain The domain to compare to
|
|
225
|
+
* @return True if domains matches.
|
|
226
|
+
*/
|
|
227
|
+
static matchesDomain(string: string, domain: string): boolean {
|
|
228
|
+
if (!string || !domain) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let canonicalString = this.canonicalDomain(string);
|
|
233
|
+
const canonicalDomain = this.canonicalDomain(domain);
|
|
234
|
+
|
|
235
|
+
if (canonicalString[0] === '.') {
|
|
236
|
+
canonicalString = canonicalString.substring(1);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// section-5.1.3 p.1
|
|
240
|
+
if (canonicalString === canonicalDomain) {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// section-5.1.3 p.2.1
|
|
245
|
+
// The domain string is a suffix of the string.
|
|
246
|
+
if (canonicalDomain.endsWith(canonicalString)) {
|
|
247
|
+
// section-5.1.3 p.2.2
|
|
248
|
+
// The last character of the string that is not included
|
|
249
|
+
// in the domain string is a %x2E (".") character.
|
|
250
|
+
const index = canonicalDomain.indexOf(canonicalString);
|
|
251
|
+
const char = canonicalDomain.substring(index - 1, index);
|
|
252
|
+
if (char === '.') {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Checks if paths mach as defined in
|
|
261
|
+
* https://tools.ietf.org/html/rfc6265#section-5.1.4
|
|
262
|
+
*
|
|
263
|
+
* Note: This function will return false if the `this.url` was not set.
|
|
264
|
+
*
|
|
265
|
+
* @param cookiePath Path from the cookie.
|
|
266
|
+
* @param url
|
|
267
|
+
* @return True when paths matches.
|
|
268
|
+
*/
|
|
269
|
+
static matchesPath(cookiePath: string, url: URL): boolean {
|
|
270
|
+
if (!cookiePath) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
const requestPath = this.getPath(url);
|
|
274
|
+
return this._matchesPath(cookiePath, requestPath);
|
|
275
|
+
|
|
276
|
+
// const index = requestPath.indexOf(cookiePath);
|
|
277
|
+
// if (index === 0 && cookiePath[cookiePath.length - 1] === '/') {
|
|
278
|
+
// return true;
|
|
279
|
+
// }
|
|
280
|
+
// if (index === 0 && cookiePath.indexOf('/', 1) === -1) {
|
|
281
|
+
// return true;
|
|
282
|
+
// }
|
|
283
|
+
|
|
284
|
+
// if (index === 0) {
|
|
285
|
+
// // eslint-disable-next-line no-plusplus
|
|
286
|
+
// for (let i = 0, len = requestPath.length; i < len; i++) {
|
|
287
|
+
// if (cookiePath.indexOf(requestPath[i]) === -1 && requestPath[i] === '/') {
|
|
288
|
+
// return true;
|
|
289
|
+
// }
|
|
290
|
+
// }
|
|
291
|
+
// }
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
protected static _matchesPath(cookiePath: string, requestPath: string): boolean {
|
|
295
|
+
// p1: The cookie-path and the request-path are identical.
|
|
296
|
+
if (requestPath === cookiePath) {
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// p2,p3: The cookie-path is a prefix of the request-path ...
|
|
301
|
+
if (requestPath.startsWith(cookiePath)) {
|
|
302
|
+
// p2: and the last character of the cookie-path is U+002F ("/").
|
|
303
|
+
if (cookiePath.endsWith('/')) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
// p3: and the first character of the request-path that is not included in the cookie-path
|
|
307
|
+
// is a U+002F ("/") character.
|
|
308
|
+
if (requestPath.replace(cookiePath, '')[0] === '/') {
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
static matchesCookie(c1: HttpCookie, c2: HttpCookie): boolean {
|
|
316
|
+
if (c1.name !== c2.name) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
if (!c1.domain || !c2.domain) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
if (!c1.path || !c2.path) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
return this.matchesDomain(c1.domain, c2.domain) && this._matchesPath(c1.path, c2.path);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CookieJar } from "./CookieJar.js";
|
|
2
|
+
import { CookieParser } from "./CookieParser.js";
|
|
3
|
+
import { IHttpCookie, HttpCookie } from '../models/HttpCookie.js';
|
|
4
|
+
|
|
5
|
+
const cache: HttpCookie[] = [];
|
|
6
|
+
|
|
7
|
+
export function clearStore(): void {
|
|
8
|
+
cache.splice(0);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class InMemoryCookieJar extends CookieJar {
|
|
12
|
+
/**
|
|
13
|
+
* Clears the memory store from all values.
|
|
14
|
+
*/
|
|
15
|
+
clear(): void {
|
|
16
|
+
cache.splice(0);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async deleteCookies(requestUrl: string, name?: string): Promise<void> {
|
|
20
|
+
const url = new URL(requestUrl);
|
|
21
|
+
const domain = CookieParser.canonicalDomain(url.host);
|
|
22
|
+
for (let i = cache.length - 1; i >= 0; i--) {
|
|
23
|
+
const cookie = cache[i];
|
|
24
|
+
if (!cookie.path || !cookie.domain) {
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
if (name && name !== cookie.name) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (CookieParser.matchesDomain(cookie.domain, domain) && CookieParser.matchesPath(cookie.path, url)) {
|
|
31
|
+
cache.splice(i, 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async listCookies(url: string): Promise<HttpCookie[]> {
|
|
37
|
+
return CookieParser.filterCookies(cache, url);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async setCookies(url: string, cookies: HttpCookie[] | IHttpCookie[]): Promise<void> {
|
|
41
|
+
const uri = new URL(url);
|
|
42
|
+
const domain = CookieParser.canonicalDomain(uri.host);
|
|
43
|
+
const path = CookieParser.getPath(uri);
|
|
44
|
+
cookies.forEach((cookie) => {
|
|
45
|
+
let typed: HttpCookie;
|
|
46
|
+
if (typeof (cookie as HttpCookie).toJSON !== 'function') {
|
|
47
|
+
typed = new HttpCookie(cookie);
|
|
48
|
+
} else {
|
|
49
|
+
typed = cookie as HttpCookie;
|
|
50
|
+
}
|
|
51
|
+
if (!typed.path) {
|
|
52
|
+
typed.path = path;
|
|
53
|
+
}
|
|
54
|
+
if (!typed.domain) {
|
|
55
|
+
// point 6. of https://tools.ietf.org/html/rfc6265#section-5.3
|
|
56
|
+
typed.domain = domain;
|
|
57
|
+
typed.hostOnly = true;
|
|
58
|
+
} else if (typed.domain[0] !== '.') {
|
|
59
|
+
// https://stackoverflow.com/a/1063760/1127848
|
|
60
|
+
typed.domain = `.${typed.domain}`;
|
|
61
|
+
}
|
|
62
|
+
const index = cache.findIndex(cached => CookieParser.matchesCookie(typed, cached));
|
|
63
|
+
if (index >= 0) {
|
|
64
|
+
cache[index] = typed;
|
|
65
|
+
} else {
|
|
66
|
+
cache.push(typed);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
|
|
2
|
+
const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
|
|
3
|
+
const maxInt = 2147483647;
|
|
4
|
+
const base = 36;
|
|
5
|
+
const tMin = 1;
|
|
6
|
+
const tMax = 26;
|
|
7
|
+
const damp = 700;
|
|
8
|
+
const skew = 38;
|
|
9
|
+
const baseMinusTMin = base - tMin;
|
|
10
|
+
const overflowError = 'Overflow: input needs wider integers to process';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This is a short copy of https://github.com/mathiasbynens/punycode.js/blob/master/punycode.js
|
|
14
|
+
* but written for ESM and browsers.
|
|
15
|
+
* All credits to the original author: Mathias Bynens
|
|
16
|
+
*/
|
|
17
|
+
export class Punycode {
|
|
18
|
+
static toASCII(input: string): string {
|
|
19
|
+
let result = '';
|
|
20
|
+
const parts = input.split('@');
|
|
21
|
+
if (parts.length > 1) {
|
|
22
|
+
result = parts[0] + '@';
|
|
23
|
+
input = parts[1];
|
|
24
|
+
}
|
|
25
|
+
input = input.replace(regexSeparators, '\x2E');
|
|
26
|
+
const labels = input.split('.');
|
|
27
|
+
const encoded = labels.map((part) => {
|
|
28
|
+
return regexNonASCII.test(part) ? 'xn--' + this.encode(part) : part;
|
|
29
|
+
}).join('.');
|
|
30
|
+
return result + encoded;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected static encode(value: string): string {
|
|
34
|
+
const output = [];
|
|
35
|
+
const input = this.ucs2decode(value);
|
|
36
|
+
const inputLength = input.length;
|
|
37
|
+
let n = 128;
|
|
38
|
+
let delta = 0;
|
|
39
|
+
let bias = 72;
|
|
40
|
+
for (const currentValue of input) {
|
|
41
|
+
if (currentValue < 0x80) {
|
|
42
|
+
output.push(String.fromCharCode(currentValue));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const basicLength = output.length;
|
|
46
|
+
let handledCPCount = basicLength;
|
|
47
|
+
if (basicLength) {
|
|
48
|
+
output.push('-');
|
|
49
|
+
}
|
|
50
|
+
while (handledCPCount < inputLength) {
|
|
51
|
+
let m = maxInt;
|
|
52
|
+
for (const currentValue of input) {
|
|
53
|
+
if (currentValue >= n && currentValue < m) {
|
|
54
|
+
m = currentValue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const handledCPCountPlusOne = handledCPCount + 1;
|
|
59
|
+
if (m - n > Math.floor((maxInt - delta) / handledCPCountPlusOne)) {
|
|
60
|
+
throw new RangeError(overflowError);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
delta += (m - n) * handledCPCountPlusOne;
|
|
64
|
+
n = m;
|
|
65
|
+
|
|
66
|
+
for (const currentValue of input) {
|
|
67
|
+
if (currentValue < n && ++delta > maxInt) {
|
|
68
|
+
throw new RangeError(overflowError);
|
|
69
|
+
}
|
|
70
|
+
if (currentValue == n) {
|
|
71
|
+
// Represent delta as a generalized variable-length integer.
|
|
72
|
+
let q = delta;
|
|
73
|
+
for (let k = base; /* no condition */; k += base) {
|
|
74
|
+
const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
|
75
|
+
if (q < t) {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
const qMinusT = q - t;
|
|
79
|
+
const baseMinusT = base - t;
|
|
80
|
+
output.push(
|
|
81
|
+
String.fromCharCode(this.digitToBasic(t + qMinusT % baseMinusT, 0))
|
|
82
|
+
);
|
|
83
|
+
q = Math.floor(qMinusT / baseMinusT);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
output.push(String.fromCharCode(this.digitToBasic(q, 0)));
|
|
87
|
+
bias = this.adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
|
|
88
|
+
delta = 0;
|
|
89
|
+
++handledCPCount;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
++delta;
|
|
93
|
+
++n;
|
|
94
|
+
}
|
|
95
|
+
return output.join('');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected static digitToBasic(digit: number, flag: number): number {
|
|
99
|
+
return digit + 22 + 75 * (digit < 26 ? 1 : 0) - ((flag !== 0 ? 1 : 0) << 5);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
protected static adapt(delta: number, numPoints: number, firstTime: boolean): number {
|
|
103
|
+
let k = 0;
|
|
104
|
+
delta = firstTime ? Math.floor(delta / damp) : delta >> 1;
|
|
105
|
+
delta += Math.floor(delta / numPoints);
|
|
106
|
+
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
|
|
107
|
+
delta = Math.floor(delta / baseMinusTMin);
|
|
108
|
+
}
|
|
109
|
+
return Math.floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
protected static ucs2decode(input: string): number[] {
|
|
113
|
+
const result: number[] = [];
|
|
114
|
+
let i = 0;
|
|
115
|
+
const len = input.length;
|
|
116
|
+
|
|
117
|
+
while (i < len) {
|
|
118
|
+
const value = input.charCodeAt(i++);
|
|
119
|
+
if (value >= 0xD800 && value <= 0xDBFF && i < len) {
|
|
120
|
+
const extra = input.charCodeAt(i++);
|
|
121
|
+
if ((extra & 0xFC00) == 0xDC00) {
|
|
122
|
+
result.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
|
123
|
+
} else {
|
|
124
|
+
result.push(value);
|
|
125
|
+
i--;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
result.push(value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -3,8 +3,7 @@ import { IHttpRequest, HttpRequest } from '../models/HttpRequest.js';
|
|
|
3
3
|
import { ISentRequest, SentRequest } from '../models/SentRequest.js';
|
|
4
4
|
import { IHttpResponse, HttpResponse } from '../models/HttpResponse.js';
|
|
5
5
|
import { IErrorResponse, ErrorResponse } from '../models/ErrorResponse.js';
|
|
6
|
-
import {
|
|
7
|
-
import { ActionTypeEnum } from '../models/actions/Enums.js';
|
|
6
|
+
import { ActionRequestDataEnum, ActionResponseDataEnum, ActionSourceEnum } from '../models/http-actions/HttpActions.js';
|
|
8
7
|
import { Headers } from '../lib/headers/Headers.js';
|
|
9
8
|
import { JsonReader } from './JsonReader.js';
|
|
10
9
|
import { XmlReader } from './XmlReader.js';
|
|
@@ -19,10 +18,12 @@ export class RequestDataExtractor {
|
|
|
19
18
|
* The request that has been sent to the server.
|
|
20
19
|
*/
|
|
21
20
|
request: HttpRequest | SentRequest;
|
|
21
|
+
|
|
22
22
|
/**
|
|
23
23
|
* The response object
|
|
24
24
|
*/
|
|
25
25
|
response?: HttpResponse | ErrorResponse;
|
|
26
|
+
|
|
26
27
|
constructor(request: IHttpRequest | ISentRequest, response?: IHttpResponse | IErrorResponse) {
|
|
27
28
|
this.request = new HttpRequest(request);
|
|
28
29
|
if (response) {
|
|
@@ -37,28 +38,26 @@ export class RequestDataExtractor {
|
|
|
37
38
|
/**
|
|
38
39
|
* Reads the data from the selected path.
|
|
39
40
|
*
|
|
40
|
-
* @param
|
|
41
|
+
* @param source The source of the data to read. Note, variables are not supported here.
|
|
42
|
+
* @param data The kind of data to read the value from
|
|
43
|
+
* @param path The path to the data.
|
|
41
44
|
* @return Data to be processed
|
|
42
45
|
*/
|
|
43
|
-
async extract(
|
|
44
|
-
const { type, source, path, value } = config;
|
|
45
|
-
if (source === 'value') {
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
46
|
+
async extract(source: ActionSourceEnum, data?: ActionRequestDataEnum | ActionResponseDataEnum, path?: string): Promise<string | number | undefined> {
|
|
48
47
|
const args = path ? path.split('.') : [];
|
|
49
|
-
switch (
|
|
48
|
+
switch (data) {
|
|
50
49
|
case 'url':
|
|
51
50
|
return DataUtils.getDataUrl(this.getUrl(), args);
|
|
52
51
|
case 'headers':
|
|
53
|
-
return DataUtils.getDataHeaders(this.getHeaders(
|
|
52
|
+
return DataUtils.getDataHeaders(this.getHeaders(source), args);
|
|
54
53
|
case 'status':
|
|
55
54
|
return this.response && this.response.status;
|
|
56
55
|
case 'method':
|
|
57
56
|
return this.request.method;
|
|
58
57
|
case 'body':
|
|
59
|
-
return this.processBody(path,
|
|
58
|
+
return this.processBody(path, source);
|
|
60
59
|
default:
|
|
61
|
-
throw new Error(`Unknown
|
|
60
|
+
throw new Error(`Unknown data ${data} for ${source} data`);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
|
|
@@ -74,14 +73,14 @@ export class RequestDataExtractor {
|
|
|
74
73
|
* @param source The source name
|
|
75
74
|
* @returns The headers from the request / response
|
|
76
75
|
*/
|
|
77
|
-
getHeaders(source?:
|
|
76
|
+
getHeaders(source?: ActionSourceEnum): string {
|
|
78
77
|
if (source === 'request') {
|
|
79
78
|
return this.request.headers || '';
|
|
80
79
|
}
|
|
81
80
|
return this.response && this.response.headers || '';
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
async processBody(path?: string, source?:
|
|
83
|
+
async processBody(path?: string, source?: ActionSourceEnum): Promise<string | undefined> {
|
|
85
84
|
const value = await this.getBody(source);
|
|
86
85
|
if (!value) {
|
|
87
86
|
return undefined;
|
|
@@ -105,7 +104,7 @@ export class RequestDataExtractor {
|
|
|
105
104
|
* @param source The source name
|
|
106
105
|
* @returns The headers from the request / response
|
|
107
106
|
*/
|
|
108
|
-
async getBody(source?:
|
|
107
|
+
async getBody(source?: ActionSourceEnum): Promise<string | undefined> {
|
|
109
108
|
if (source === 'request') {
|
|
110
109
|
return this.request.readPayloadAsString();
|
|
111
110
|
}
|
|
@@ -15,6 +15,10 @@ if (typeof CustomEvent === 'function') {
|
|
|
15
15
|
super(type, eventInitDict);
|
|
16
16
|
if (eventInitDict && eventInitDict.detail) {
|
|
17
17
|
this[detailSymbol] = eventInitDict.detail;
|
|
18
|
+
} else {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
this[detailSymbol] = null;
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
24
|
|
|
@@ -6,12 +6,13 @@ import { History } from './lib/History.js';
|
|
|
6
6
|
import { Url } from './lib/Url.js';
|
|
7
7
|
import { Certificates } from './lib/Certificates.js';
|
|
8
8
|
import { HostRules } from './lib/HostRules.js';
|
|
9
|
-
import {
|
|
9
|
+
import { App } from './lib/App.js';
|
|
10
10
|
|
|
11
11
|
export { IRequestLogInit } from './lib/Request.js';
|
|
12
12
|
export { IResponseInit } from './lib/Response.js';
|
|
13
13
|
export { IUserInit } from './lib/User.js';
|
|
14
14
|
export { IHttpHistoryInit, IHttpHistoryListInit } from './lib/History.js';
|
|
15
|
+
export { IAppRequestInit } from './lib/App.js';
|
|
15
16
|
|
|
16
17
|
export class ProjectMock extends DataMock {
|
|
17
18
|
projectRequest: Request;
|
|
@@ -21,7 +22,7 @@ export class ProjectMock extends DataMock {
|
|
|
21
22
|
url: Url;
|
|
22
23
|
certificates: Certificates;
|
|
23
24
|
hostRules: HostRules;
|
|
24
|
-
|
|
25
|
+
app: App;
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* @param init The library init options.
|
|
@@ -35,6 +36,6 @@ export class ProjectMock extends DataMock {
|
|
|
35
36
|
this.url = new Url(init);
|
|
36
37
|
this.certificates = new Certificates(init);
|
|
37
38
|
this.hostRules = new HostRules(init);
|
|
38
|
-
this.
|
|
39
|
+
this.app = new App(init);
|
|
39
40
|
}
|
|
40
41
|
}
|