@api-client/core 0.6.29 → 0.7.0
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/AppRequest.js +150 -0
- 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/FilesSdk.js +4 -4
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/HistorySdk.js +1 -1
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/HttpClientSdk.d.ts +167 -0
- package/build/src/runtime/store/HttpClientSdk.js +624 -0
- package/build/src/runtime/store/HttpClientSdk.js.map +1 -0
- 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/FilesSdk.ts +4 -4
- package/src/runtime/store/HistorySdk.ts +1 -1
- package/src/runtime/store/HttpClientSdk.ts +629 -0
- 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 -10
- package/build/src/mocking/lib/Arc.js +0 -31
- 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 -39
- package/build/src/models/arc/ArcHttpRequest.js +0 -106
- 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 -34
- 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 -121
- 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,312 +0,0 @@
|
|
|
1
|
-
import { CookieSameSiteType } from '../../models/HttpCookie.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Cookie creation options.
|
|
5
|
-
*/
|
|
6
|
-
export interface CookieOptions {
|
|
7
|
-
'max-age'?: number;
|
|
8
|
-
/**
|
|
9
|
-
* When the cookie expires.
|
|
10
|
-
* Note that this value is parsed to a timestamp in the Cookie class.
|
|
11
|
-
*/
|
|
12
|
-
expires?: Date | number | string;
|
|
13
|
-
/**
|
|
14
|
-
* A string representing the domain the cookie belongs to
|
|
15
|
-
* (e.g. "www.google.com", "example.com")
|
|
16
|
-
*/
|
|
17
|
-
domain?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Cookie path
|
|
20
|
-
*/
|
|
21
|
-
path?: string;
|
|
22
|
-
/**
|
|
23
|
-
* A boolean, `true` if the cookie is marked as secure
|
|
24
|
-
* (i.e. its scope is limited to secure channels, typically HTTPS),
|
|
25
|
-
* or `false` otherwise.
|
|
26
|
-
*/
|
|
27
|
-
secure?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* A boolean, `true` if the cookie is marked as HttpOnly
|
|
30
|
-
* (i.e. the cookie is inaccessible to client-side scripts),
|
|
31
|
-
* or `false` otherwise.
|
|
32
|
-
*/
|
|
33
|
-
httpOnly?: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* A boolean, `true` if the cookie is a `host-only` cookie
|
|
36
|
-
* (i.e. the request's host must exactly match the domain of the cookie),
|
|
37
|
-
* or `false` otherwise.
|
|
38
|
-
*/
|
|
39
|
-
hostOnly?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* The SameSite attribute of the Set-Cookie HTTP response header allows you to declare if your cookie should be restricted to a first-party or same-site context.
|
|
42
|
-
*/
|
|
43
|
-
sameSite?: CookieSameSiteType;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/* eslint-disable no-control-regex */
|
|
47
|
-
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* A Cookie object.
|
|
51
|
-
* It is based on https://github.com/pillarjs/cookies/blob/master/lib/cookies.js
|
|
52
|
-
*/
|
|
53
|
-
export class Cookie {
|
|
54
|
-
protected _maxAge?: number;
|
|
55
|
-
protected _expires: number;
|
|
56
|
-
protected _domain?: string;
|
|
57
|
-
name: string;
|
|
58
|
-
value: string;
|
|
59
|
-
created: number;
|
|
60
|
-
lastAccess: number;
|
|
61
|
-
persistent?: boolean;
|
|
62
|
-
hostOnly?: boolean;
|
|
63
|
-
path?: string;
|
|
64
|
-
secure?: boolean;
|
|
65
|
-
httpOnly?: boolean;
|
|
66
|
-
sameSite?: CookieSameSiteType;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Constructs a new cookie.
|
|
70
|
-
*
|
|
71
|
-
* @param name Cookie name
|
|
72
|
-
* @param value Cookie value
|
|
73
|
-
* @param opts Additional cookie attributes.
|
|
74
|
-
*/
|
|
75
|
-
constructor(name: string, value = '', opts: CookieOptions = {}) {
|
|
76
|
-
if (!fieldContentRegExp.test(name)) {
|
|
77
|
-
throw new TypeError('Argument `name` is invalid');
|
|
78
|
-
}
|
|
79
|
-
if (value && !fieldContentRegExp.test(value)) {
|
|
80
|
-
throw new TypeError('Argument `value` is invalid');
|
|
81
|
-
}
|
|
82
|
-
if (opts.path && !fieldContentRegExp.test(opts.path)) {
|
|
83
|
-
throw new TypeError('Option `path` is invalid');
|
|
84
|
-
}
|
|
85
|
-
if (opts.domain && !fieldContentRegExp.test(opts.domain)) {
|
|
86
|
-
throw new TypeError('Option `domain` is invalid');
|
|
87
|
-
}
|
|
88
|
-
this._expires = 0;
|
|
89
|
-
this._domain = undefined;
|
|
90
|
-
this._maxAge = undefined;
|
|
91
|
-
this.name = name;
|
|
92
|
-
this.value = value;
|
|
93
|
-
this.created = Date.now();
|
|
94
|
-
this.lastAccess = this.created;
|
|
95
|
-
|
|
96
|
-
if ('max-age' in opts) {
|
|
97
|
-
this.maxAge = opts['max-age'];
|
|
98
|
-
} else if (typeof opts.expires !== 'undefined') {
|
|
99
|
-
this.setExpires(opts.expires);
|
|
100
|
-
} else {
|
|
101
|
-
this.persistent = false;
|
|
102
|
-
// see http://stackoverflow.com/a/11526569/1127848
|
|
103
|
-
this._expires = new Date(8640000000000000).getTime();
|
|
104
|
-
}
|
|
105
|
-
if ('hostOnly' in opts) {
|
|
106
|
-
this.hostOnly = opts.hostOnly;
|
|
107
|
-
}
|
|
108
|
-
if ('domain' in opts) {
|
|
109
|
-
this.domain = opts.domain;
|
|
110
|
-
} else {
|
|
111
|
-
this.hostOnly = false;
|
|
112
|
-
}
|
|
113
|
-
if ('path' in opts) {
|
|
114
|
-
this.path = opts.path;
|
|
115
|
-
}
|
|
116
|
-
if ('secure' in opts) {
|
|
117
|
-
this.secure = opts.secure;
|
|
118
|
-
}
|
|
119
|
-
if ('httpOnly' in opts) {
|
|
120
|
-
this.httpOnly = opts.httpOnly;
|
|
121
|
-
}
|
|
122
|
-
if ('sameSite' in opts) {
|
|
123
|
-
this.sameSite = opts.sameSite;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @param max The max age value
|
|
129
|
-
*/
|
|
130
|
-
set maxAge(max: number | undefined) {
|
|
131
|
-
const typedMax = Number(max);
|
|
132
|
-
if (Number.isNaN(typedMax)) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
this._maxAge = typedMax;
|
|
136
|
-
if (typedMax <= 0) {
|
|
137
|
-
// see http://stackoverflow.com/a/11526569/1127848
|
|
138
|
-
// and https://tools.ietf.org/html/rfc6265#section-5.2.2
|
|
139
|
-
this._expires = new Date(-8640000000000000).getTime();
|
|
140
|
-
} else {
|
|
141
|
-
let now = Date.now();
|
|
142
|
-
now += typedMax * 1000;
|
|
143
|
-
this._expires = now;
|
|
144
|
-
}
|
|
145
|
-
this.persistent = true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* @return Returns a value of maxAge property
|
|
150
|
-
*/
|
|
151
|
-
get maxAge(): number | undefined {
|
|
152
|
-
return this._maxAge;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
get ['max-age'](): number | undefined {
|
|
156
|
-
return this.maxAge;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
set ['max-age'](value: number | undefined) {
|
|
160
|
-
this.maxAge = value;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* @param expires The value for expires
|
|
165
|
-
*/
|
|
166
|
-
set expires(expires: number | Date | string) {
|
|
167
|
-
const any = expires as unknown;
|
|
168
|
-
if ((expires && typeof any === 'string') || any instanceof Date) {
|
|
169
|
-
this.setExpires(any);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
this._expires = expires as number;
|
|
173
|
-
this.persistent = true;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* @return the current expires value
|
|
178
|
-
*/
|
|
179
|
-
get expires(): number {
|
|
180
|
-
return this._expires;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @param domain The cookie domain
|
|
185
|
-
*/
|
|
186
|
-
set domain(domain: string | undefined) {
|
|
187
|
-
this._domain = domain;
|
|
188
|
-
if (!domain) {
|
|
189
|
-
this.hostOnly = false;
|
|
190
|
-
} else {
|
|
191
|
-
this.hostOnly = true;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @return The cookie domain
|
|
197
|
-
*/
|
|
198
|
-
get domain(): string | undefined {
|
|
199
|
-
return this._domain;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
get samesite(): CookieSameSiteType | undefined {
|
|
203
|
-
return this.sameSite;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
set samesite(value: CookieSameSiteType | undefined) {
|
|
207
|
-
this.sameSite = value;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
get httponly(): boolean | undefined {
|
|
211
|
-
return this.httpOnly;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
set httponly(value: boolean | undefined) {
|
|
215
|
-
this.httpOnly = value;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
get hostonly(): boolean | undefined {
|
|
219
|
-
return this.hostOnly;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
set hostonly(value: boolean | undefined) {
|
|
223
|
-
this.hostOnly = value;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* @return Cookie's `name=value` string.
|
|
228
|
-
*/
|
|
229
|
-
toString(): string {
|
|
230
|
-
const { name, value } = this;
|
|
231
|
-
return `${name}=${value}`;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Returns a Cookie as a HTTP header string.
|
|
236
|
-
* @return Cookie string as a HTTP header value
|
|
237
|
-
*/
|
|
238
|
-
toHeader(): string {
|
|
239
|
-
let header = this.toString();
|
|
240
|
-
let expires;
|
|
241
|
-
if (this._expires) {
|
|
242
|
-
expires = new Date(this._expires);
|
|
243
|
-
if (expires.toString() === 'Invalid Date') {
|
|
244
|
-
expires = new Date(0);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (expires) {
|
|
248
|
-
header += `; expires=${expires.toUTCString()}`;
|
|
249
|
-
}
|
|
250
|
-
const { path, domain, httpOnly, sameSite, secure } = this;
|
|
251
|
-
if (path) {
|
|
252
|
-
header += `; path=${path}`;
|
|
253
|
-
}
|
|
254
|
-
if (domain) {
|
|
255
|
-
header += `; domain=${domain}`;
|
|
256
|
-
}
|
|
257
|
-
if (httpOnly) {
|
|
258
|
-
header += `; httpOnly=${httpOnly}`;
|
|
259
|
-
}
|
|
260
|
-
if (sameSite) {
|
|
261
|
-
header += `; SameSite=${sameSite}`;
|
|
262
|
-
}
|
|
263
|
-
if (secure) {
|
|
264
|
-
header += `; Secure`;
|
|
265
|
-
}
|
|
266
|
-
return header;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Override toJSON behaviour so it will eliminate
|
|
271
|
-
* all _* properties and replace it with a proper ones.
|
|
272
|
-
*
|
|
273
|
-
* @return {object}
|
|
274
|
-
*/
|
|
275
|
-
toJSON(): Record<string, string> {
|
|
276
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
277
|
-
const copy: any = {};
|
|
278
|
-
const keys: (keyof Cookie)[] = Object.keys(this) as (keyof Cookie)[];
|
|
279
|
-
keys.forEach((key) => {
|
|
280
|
-
if (key.indexOf('_') === 0) {
|
|
281
|
-
const realKey = key.substring(1);
|
|
282
|
-
copy[realKey] = this[key];
|
|
283
|
-
} else {
|
|
284
|
-
copy[key] = this[key];
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
return copy;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Sets value for `expirers` propr from other types.
|
|
292
|
-
* @param expires The value for `expires`
|
|
293
|
-
*/
|
|
294
|
-
setExpires(expires: Date | string | number): void {
|
|
295
|
-
let value: number;
|
|
296
|
-
if (expires instanceof Date) {
|
|
297
|
-
value = expires.getTime();
|
|
298
|
-
} else if (typeof expires === 'string') {
|
|
299
|
-
const tmp = new Date(expires);
|
|
300
|
-
if (tmp.toString() === 'Invalid Date') {
|
|
301
|
-
value = 0;
|
|
302
|
-
} else {
|
|
303
|
-
value = tmp.getTime();
|
|
304
|
-
}
|
|
305
|
-
} else if (typeof expires === 'number') {
|
|
306
|
-
value = expires;
|
|
307
|
-
} else {
|
|
308
|
-
value = 0;
|
|
309
|
-
}
|
|
310
|
-
this.expires = value;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
import { Cookie, CookieOptions } from './Cookie.js';
|
|
2
|
-
import {
|
|
3
|
-
getPath,
|
|
4
|
-
matchesDomain,
|
|
5
|
-
matchesPath,
|
|
6
|
-
fillCookieAttributes,
|
|
7
|
-
} from './Utils.js';
|
|
8
|
-
|
|
9
|
-
export const urlSymbol = Symbol('url');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A library to handle Cookie parsing.
|
|
13
|
-
*/
|
|
14
|
-
export class Cookies {
|
|
15
|
-
cookies: Cookie[];
|
|
16
|
-
uri: URL | undefined;
|
|
17
|
-
|
|
18
|
-
[urlSymbol]: string | undefined;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Constructs an object.
|
|
22
|
-
*
|
|
23
|
-
* @param header A HTTP cookie string to parse.
|
|
24
|
-
* @param url A request url for this cookie. If empty some cookie computations (like checking if cookies matches) will be omitted.
|
|
25
|
-
*/
|
|
26
|
-
constructor(header = '', url?: string) {
|
|
27
|
-
/**
|
|
28
|
-
* A base URL for this object.
|
|
29
|
-
*/
|
|
30
|
-
this.url = url;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A list of parsed cookies.
|
|
34
|
-
*/
|
|
35
|
-
this.cookies = Cookies.parse(header);
|
|
36
|
-
if (this.uri && url) {
|
|
37
|
-
fillCookieAttributes(this.uri, url, this.cookies);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Set's the URL and parses it setting `uri` property.
|
|
43
|
-
* @param url Cookie URL
|
|
44
|
-
*/
|
|
45
|
-
set url(url: string | undefined) {
|
|
46
|
-
if (url) {
|
|
47
|
-
this[urlSymbol] = url;
|
|
48
|
-
this.uri = new URL(url);
|
|
49
|
-
} else {
|
|
50
|
-
this[urlSymbol] = undefined;
|
|
51
|
-
this.uri = undefined;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @returns {string} Cookie URL
|
|
57
|
-
*/
|
|
58
|
-
get url(): string | undefined {
|
|
59
|
-
return this[urlSymbol];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Parses a cookie string to a list of Cookie objects.
|
|
64
|
-
*
|
|
65
|
-
* @param cookies A HTTP cookie string
|
|
66
|
-
* @returns List of parsed cookies.
|
|
67
|
-
*/
|
|
68
|
-
static parse(cookies: string): Cookie[] {
|
|
69
|
-
const cookieParts: (keyof Cookie)[] = [
|
|
70
|
-
'path',
|
|
71
|
-
'domain',
|
|
72
|
-
'max-age',
|
|
73
|
-
'expires',
|
|
74
|
-
'secure',
|
|
75
|
-
'httponly',
|
|
76
|
-
'samesite',
|
|
77
|
-
'hostonly',
|
|
78
|
-
];
|
|
79
|
-
const booleanParts: (keyof Cookie)[] = [
|
|
80
|
-
'secure', 'httponly', 'hostonly'
|
|
81
|
-
];
|
|
82
|
-
const list: Cookie[] = [];
|
|
83
|
-
if (!cookies || !cookies.trim()) {
|
|
84
|
-
return list;
|
|
85
|
-
}
|
|
86
|
-
const blocks = cookies.split(';').map(i => i.trim());
|
|
87
|
-
blocks.forEach((part, index) => {
|
|
88
|
-
// Consider the following set-cookie string:
|
|
89
|
-
// c1=v1; Path=/; Expires=Wed, 09 Feb 2022 01:30:04 GMT; HttpOnly,c2=v2; Path=/,c3=v3; Path=/; Secure; SameSite=Strict
|
|
90
|
-
// It is a valid set-cookie header event though it mixes different formatting making it harder to parse cookies.
|
|
91
|
-
// This loop looks for invalid parts and creates a canonical cookie parts array.
|
|
92
|
-
const periodIndex = part.indexOf(',');
|
|
93
|
-
if (periodIndex === -1) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (part.toLowerCase().startsWith('expires=')) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const tmp = part.split(',');
|
|
100
|
-
// remove current
|
|
101
|
-
blocks.splice(index, 1);
|
|
102
|
-
// add the new two
|
|
103
|
-
blocks.splice(index, 0, ...tmp);
|
|
104
|
-
});
|
|
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 Cookie;
|
|
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 (list.length - 1 >= 0) {
|
|
130
|
-
const attr = lowerName as keyof Cookie;
|
|
131
|
-
const previousCookie = list[list.length - 1];
|
|
132
|
-
previousCookie[attr] = value as never;
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
try {
|
|
136
|
-
list.push(new Cookie(name, value as string));
|
|
137
|
-
} catch (e) {
|
|
138
|
-
// ..
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
return list;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get a cookie by name.
|
|
147
|
-
*
|
|
148
|
-
* @param name Cookie name
|
|
149
|
-
* @returns A Cookie object or null.
|
|
150
|
-
*/
|
|
151
|
-
get(name: string): Cookie | null {
|
|
152
|
-
const { cookies } = this;
|
|
153
|
-
// eslint-disable-next-line no-plusplus
|
|
154
|
-
for (let i = 0, len = cookies.length; i < len; i++) {
|
|
155
|
-
if (cookies[i].name === name) {
|
|
156
|
-
return cookies[i];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Adds a cookie to the list of cookies.
|
|
164
|
-
*
|
|
165
|
-
* @param name Name of the cookie.
|
|
166
|
-
* @param value Value of the cookie.
|
|
167
|
-
* @param opts Other cookie options to set.
|
|
168
|
-
*/
|
|
169
|
-
set(name: string, value?: string, opts?: CookieOptions): void {
|
|
170
|
-
const cookie = new Cookie(name, value, opts);
|
|
171
|
-
const cookies = this.cookies.filter((c) => c.name !== name);
|
|
172
|
-
cookies.push(cookie);
|
|
173
|
-
this.cookies = cookies;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Returns a string that can be used in a HTTP header value for Cookie.
|
|
178
|
-
* The structure of the cookie string depends on if you want to send a
|
|
179
|
-
* cookie from the server to client or other way around.
|
|
180
|
-
* When you want to send the `Cookie` header to server set
|
|
181
|
-
* `toServer` argument to true. Then it will produce only `name=value;`
|
|
182
|
-
* string. Otherwise it will be the `Set-Cookie` header value
|
|
183
|
-
* containing all other cookies properties.
|
|
184
|
-
*
|
|
185
|
-
* @param toServer True if produced string is to be used with the `Cookie` header
|
|
186
|
-
* @returns HTTP header string value for all cookies.
|
|
187
|
-
*/
|
|
188
|
-
toString(toServer = false): string {
|
|
189
|
-
const parts: string[] = [];
|
|
190
|
-
this.cookies.forEach((cookie) => {
|
|
191
|
-
parts.push(toServer ? cookie.toString() : cookie.toHeader());
|
|
192
|
-
});
|
|
193
|
-
return parts.join('; ');
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Removes cookies from `this.cookies` that has been set for different
|
|
198
|
-
* domain and path.
|
|
199
|
-
* This function has no effect if the URL is not set.
|
|
200
|
-
*
|
|
201
|
-
* This function follows an algorithm defined in https://tools.ietf.org/html/rfc6265 for
|
|
202
|
-
* domain match.
|
|
203
|
-
*
|
|
204
|
-
* @returns A list of removed cookies.
|
|
205
|
-
*/
|
|
206
|
-
filter(): Cookie[] {
|
|
207
|
-
const { uri, url } = this;
|
|
208
|
-
if (!uri || !url) {
|
|
209
|
-
return [];
|
|
210
|
-
}
|
|
211
|
-
const domain = uri.hostname.toLowerCase();
|
|
212
|
-
const path = getPath(url);
|
|
213
|
-
const removed: Cookie[] = [];
|
|
214
|
-
this.cookies = this.cookies.filter((cookie) => {
|
|
215
|
-
if (!cookie.path) {
|
|
216
|
-
cookie.path = path;
|
|
217
|
-
}
|
|
218
|
-
const cDomain = cookie.domain;
|
|
219
|
-
if (!cDomain) {
|
|
220
|
-
cookie.domain = domain;
|
|
221
|
-
// point 6. of https://tools.ietf.org/html/rfc6265#section-5.3
|
|
222
|
-
cookie.hostOnly = true;
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
const res =
|
|
226
|
-
matchesDomain(cDomain, uri) && matchesPath(cookie.path, uri, url);
|
|
227
|
-
if (!res) {
|
|
228
|
-
removed.push(cookie);
|
|
229
|
-
}
|
|
230
|
-
return res;
|
|
231
|
-
});
|
|
232
|
-
return removed;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Merges this cookies with another Cookies object.
|
|
237
|
-
* This cookies will be overwritten by passed cookies according to
|
|
238
|
-
* the HTTP spec.
|
|
239
|
-
* This function is useful when you need to override cookies with
|
|
240
|
-
* the response from the server
|
|
241
|
-
* as defined in the https://tools.ietf.org/html/rfc6265.
|
|
242
|
-
*
|
|
243
|
-
* @param cookies An Cookies object with newest cookies.
|
|
244
|
-
* @param copyKeys When set, it copies values for given keys from old object to the new one.
|
|
245
|
-
*/
|
|
246
|
-
merge(cookies: Cookies, copyKeys: (keyof Cookie)[] = []): void {
|
|
247
|
-
if (!cookies || !cookies.cookies || cookies.cookies.length === 0) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
if (!this.cookies || this.cookies.length === 0) {
|
|
251
|
-
this.cookies = cookies.cookies;
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
const foreignDomain = cookies.uri ? cookies.uri.hostname : null;
|
|
255
|
-
const foreignPath = cookies.url ? getPath(cookies.url) : null;
|
|
256
|
-
// delete cookies from this.cookies that has the same name as new ones,
|
|
257
|
-
// but are domain/path match
|
|
258
|
-
const newCookies: Cookie[] = cookies.cookies;
|
|
259
|
-
const nLength: number = newCookies.length;
|
|
260
|
-
|
|
261
|
-
const { uri, url } = this;
|
|
262
|
-
if (!uri || !url) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
const copyKeysLength = copyKeys.length;
|
|
266
|
-
for (let i = this.cookies.length - 1; i >= 0; i--) {
|
|
267
|
-
const tName = this.cookies[i].name;
|
|
268
|
-
for (let j = 0; j < nLength; j++) {
|
|
269
|
-
const targetCookie = newCookies[j];
|
|
270
|
-
const nName = targetCookie.name;
|
|
271
|
-
if (nName !== tName) {
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
if (!foreignDomain || !matchesDomain(foreignDomain, uri)) {
|
|
275
|
-
// This is cookie for a different domain. Don't override.
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
if (!foreignPath || !matchesPath(foreignPath, uri, url)) {
|
|
279
|
-
// This is cookie for a different path. Don't override.
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
const removed = this.cookies.splice(i, 1);
|
|
283
|
-
targetCookie.created = removed[0].created;
|
|
284
|
-
if (copyKeysLength) {
|
|
285
|
-
for (let k = 0; k < copyKeysLength; k++) {
|
|
286
|
-
const key = copyKeys[k];
|
|
287
|
-
if (key in removed[0]) {
|
|
288
|
-
targetCookie[key] = removed[0][key] as never;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
// Do not re-set cookies that values are not set.
|
|
296
|
-
for (let i = nLength - 1; i >= 0; i--) {
|
|
297
|
-
const nValue = newCookies[i].value;
|
|
298
|
-
if (!nValue || !nValue.trim || !nValue.trim()) {
|
|
299
|
-
newCookies.splice(i, 1);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
this.cookies = this.cookies.concat(newCookies);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Clears cookies from `this.cookies` that already expired.
|
|
307
|
-
*
|
|
308
|
-
* @returns List of removed (expired) cookies.
|
|
309
|
-
*/
|
|
310
|
-
clearExpired(): Cookie[] {
|
|
311
|
-
const now = Date.now();
|
|
312
|
-
const expired: Cookie[] = [];
|
|
313
|
-
const cookies = this.cookies.filter((cookie) => {
|
|
314
|
-
if (!cookie.expires) {
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
if (now >= cookie.expires) {
|
|
318
|
-
expired.push(cookie);
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
return true;
|
|
322
|
-
});
|
|
323
|
-
this.cookies = cookies;
|
|
324
|
-
return expired;
|
|
325
|
-
}
|
|
326
|
-
}
|