@api-client/core 0.3.12 → 0.4.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 +10 -8
- package/build/browser.js +11 -7
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +12 -11
- package/build/index.js +9 -9
- package/build/index.js.map +1 -1
- package/build/src/data/JmesparthReader.d.ts +1 -1
- package/build/src/data/JmesparthReader.js +1 -1
- package/build/src/events/models/ProjectEvents.d.ts +1 -1
- package/build/src/events/models/ProjectEvents.js +1 -2
- package/build/src/events/models/ProjectEvents.js.map +1 -1
- package/build/src/lib/transformers/PayloadSerializer.d.ts +2 -2
- package/build/src/lib/transformers/PayloadSerializer.js +3 -3
- package/build/src/lib/transformers/PayloadSerializer.js.map +1 -1
- package/build/src/mocking/ProjectMock.d.ts +1 -1
- package/build/src/mocking/lib/Request.d.ts +2 -2
- package/build/src/mocking/lib/Request.js +3 -2
- package/build/src/mocking/lib/Request.js.map +1 -1
- package/build/src/mocking/lib/Response.d.ts +6 -6
- package/build/src/mocking/lib/Response.js +6 -6
- package/build/src/mocking/lib/Response.js.map +1 -1
- package/build/src/mocking/lib/User.js +3 -0
- package/build/src/mocking/lib/User.js.map +1 -1
- package/build/src/models/AuthorizationData.d.ts +2 -2
- package/build/src/models/AuthorizationData.js +2 -2
- package/build/src/models/ClientCertificate.d.ts +1 -1
- package/build/src/models/Environment.d.ts +3 -3
- package/build/src/models/Environment.js +3 -3
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/ErrorResponse.d.ts +1 -1
- package/build/src/models/ErrorResponse.js +1 -1
- package/build/src/models/HostRule.d.ts +4 -4
- package/build/src/models/HostRule.js +4 -4
- package/build/src/models/HostRule.js.map +1 -1
- package/build/src/models/HttpHistory.d.ts +30 -1
- package/build/src/models/HttpHistory.js +1 -1
- package/build/src/models/HttpHistory.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +41 -6
- package/build/src/models/HttpProject.js +52 -4
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/HttpProjectListItem.d.ts +1 -1
- package/build/src/models/HttpProjectListItem.js +1 -1
- package/build/src/models/HttpProjectListItem.js.map +1 -1
- package/build/src/models/HttpRequest.d.ts +2 -2
- package/build/src/models/HttpRequest.js +2 -2
- package/build/src/models/HttpRequest.js.map +1 -1
- package/build/src/models/HttpResponse.d.ts +2 -2
- package/build/src/models/HttpResponse.js +3 -3
- package/build/src/models/HttpResponse.js.map +1 -1
- package/build/src/models/License.d.ts +3 -3
- package/build/src/models/License.js +3 -3
- package/build/src/models/License.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts +2 -2
- package/build/src/models/ProjectFolder.js +3 -3
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectItem.d.ts +1 -1
- package/build/src/models/ProjectItem.js +2 -2
- package/build/src/models/ProjectItem.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts +2 -2
- package/build/src/models/ProjectRequest.js +1 -1
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/ProjectSchema.d.ts +2 -2
- package/build/src/models/ProjectSchema.js +1 -1
- package/build/src/models/ProjectSchema.js.map +1 -1
- package/build/src/models/Property.d.ts +4 -4
- package/build/src/models/Property.js +4 -4
- package/build/src/models/Property.js.map +1 -1
- package/build/src/models/Provider.d.ts +3 -3
- package/build/src/models/Provider.js +3 -3
- package/build/src/models/Provider.js.map +1 -1
- package/build/src/models/Request.d.ts +2 -2
- package/build/src/models/Request.js +3 -3
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestActions.d.ts +2 -4
- package/build/src/models/RequestActions.js +2 -4
- package/build/src/models/RequestActions.js.map +1 -1
- package/build/src/models/RequestAuthorization.d.ts +3 -5
- package/build/src/models/RequestAuthorization.js +2 -4
- package/build/src/models/RequestAuthorization.js.map +1 -1
- package/build/src/models/RequestConfig.d.ts +3 -5
- package/build/src/models/RequestConfig.js +1 -3
- package/build/src/models/RequestConfig.js.map +1 -1
- package/build/src/models/RequestLog.d.ts +14 -8
- package/build/src/models/RequestLog.js +18 -7
- package/build/src/models/RequestLog.js.map +1 -1
- package/build/src/models/RequestTime.d.ts +4 -6
- package/build/src/models/RequestTime.js +2 -4
- package/build/src/models/RequestTime.js.map +1 -1
- package/build/src/models/RequestUiMeta.d.ts +5 -5
- package/build/src/models/RequestUiMeta.js +2 -2
- package/build/src/models/RequestUiMeta.js.map +1 -1
- package/build/src/models/RequestsSize.d.ts +1 -3
- package/build/src/models/RequestsSize.js +1 -3
- package/build/src/models/RequestsSize.js.map +1 -1
- package/build/src/models/{ArcResponse.d.ts → Response.d.ts} +7 -9
- package/build/src/models/{ArcResponse.js → Response.js} +4 -6
- package/build/src/models/Response.js.map +1 -0
- package/build/src/models/ResponseAuthorization.d.ts +3 -3
- package/build/src/models/ResponseAuthorization.js +3 -3
- package/build/src/models/ResponseAuthorization.js.map +1 -1
- package/build/src/models/ResponseRedirect.d.ts +3 -5
- package/build/src/models/ResponseRedirect.js +1 -3
- package/build/src/models/ResponseRedirect.js.map +1 -1
- package/build/src/models/RevisionInfo.d.ts +1 -1
- package/build/src/models/RevisionInfo.js +1 -1
- package/build/src/models/RevisionInfo.js.map +1 -1
- package/build/src/models/SentRequest.d.ts +2 -4
- package/build/src/models/SentRequest.js +1 -3
- package/build/src/models/SentRequest.js.map +1 -1
- package/build/src/models/Server.d.ts +3 -3
- package/build/src/models/Server.js +3 -3
- package/build/src/models/Server.js.map +1 -1
- package/build/src/models/Thing.d.ts +3 -3
- package/build/src/models/Thing.js +3 -3
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/Url.d.ts +2 -4
- package/build/src/models/Url.js +2 -4
- package/build/src/models/Url.js.map +1 -1
- package/build/src/models/User.d.ts +2 -1
- package/build/src/models/User.js +1 -1
- package/build/src/models/User.js.map +1 -1
- package/build/src/models/WebApi.d.ts +1 -1
- package/build/src/models/WebApi.js +1 -1
- package/build/src/models/WebApi.js.map +1 -1
- package/build/src/models/WebApiIndex.d.ts +1 -1
- package/build/src/models/WebApiIndex.js +1 -1
- package/build/src/models/WebApiIndex.js.map +1 -1
- package/build/src/models/Workspace.d.ts +4 -4
- package/build/src/models/Workspace.js +4 -4
- package/build/src/models/Workspace.js.map +1 -1
- package/build/src/models/actions/Action.d.ts +2 -2
- package/build/src/models/actions/Action.js +1 -1
- package/build/src/models/actions/Action.js.map +1 -1
- package/build/src/models/actions/Condition.d.ts +2 -2
- package/build/src/models/actions/Condition.js +1 -1
- package/build/src/models/actions/Condition.js.map +1 -1
- package/build/src/models/actions/RunnableAction.d.ts +1 -1
- package/build/src/models/actions/RunnableAction.js +1 -1
- package/build/src/models/actions/RunnableAction.js.map +1 -1
- package/build/src/models/actions/runnable/DeleteCookieAction.d.ts +2 -2
- package/build/src/models/actions/runnable/DeleteCookieAction.js +1 -1
- package/build/src/models/actions/runnable/DeleteCookieAction.js.map +1 -1
- package/build/src/models/actions/runnable/SetCookieAction.d.ts +2 -2
- package/build/src/models/actions/runnable/SetCookieAction.js +1 -1
- package/build/src/models/actions/runnable/SetCookieAction.js.map +1 -1
- package/build/src/models/actions/runnable/SetVariableAction.d.ts +2 -2
- package/build/src/models/actions/runnable/SetVariableAction.js +1 -1
- package/build/src/models/actions/runnable/SetVariableAction.js.map +1 -1
- package/build/src/models/transformers/ImportUtils.d.ts +1 -1
- package/build/src/models/transformers/ImportUtils.js +1 -1
- package/build/src/models/transformers/PostmanBackupTransformer.js +2 -1
- package/build/src/models/transformers/PostmanBackupTransformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.js +2 -1
- package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js +2 -1
- package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
- package/build/src/runtime/actions/RunnableCondition.d.ts +6 -7
- package/build/src/runtime/actions/RunnableCondition.js +4 -5
- package/build/src/runtime/actions/RunnableCondition.js.map +1 -1
- package/build/src/runtime/http-engine/{ArcEngine.d.ts → CoreEngine.d.ts} +3 -3
- package/build/src/runtime/http-engine/{ArcEngine.js → CoreEngine.js} +8 -8
- package/build/src/runtime/http-engine/CoreEngine.js.map +1 -0
- package/build/src/runtime/http-engine/HttpEngine.d.ts +3 -3
- package/build/src/runtime/http-engine/HttpEngine.js +3 -20
- package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
- package/build/src/runtime/modules/BasicAuthCache.js +2 -5
- package/build/src/runtime/modules/BasicAuthCache.js.map +1 -1
- package/build/src/runtime/modules/RequestCookies.d.ts +1 -1
- package/build/src/runtime/modules/RequestCookies.js +3 -2
- package/build/src/runtime/modules/RequestCookies.js.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.d.ts +115 -0
- package/build/src/runtime/node/InteropInterfaces.js +2 -0
- package/build/src/runtime/node/InteropInterfaces.js.map +1 -0
- package/build/src/runtime/node/ProjectParallelRunner.d.ts +2 -7
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +17 -49
- package/build/src/runtime/node/ProjectRequestRunner.js +39 -10
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts +1 -59
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
- package/build/src/runtime/node/RequestFactory.d.ts +1 -1
- package/build/src/runtime/node/RequestFactory.js +3 -3
- package/build/src/runtime/node/RequestFactory.js.map +1 -1
- package/build/src/runtime/reporters/ProjectRunCliReporter.js.map +1 -1
- package/build/src/runtime/reporters/Reporter.js.map +1 -1
- package/build/src/runtime/store/AuthSdk.d.ts +28 -0
- package/build/src/runtime/store/AuthSdk.js +123 -0
- package/build/src/runtime/store/AuthSdk.js.map +1 -0
- package/build/src/runtime/store/BackendSdk.d.ts +8 -0
- package/build/src/runtime/store/BackendSdk.js +25 -0
- package/build/src/runtime/store/BackendSdk.js.map +1 -0
- package/build/src/runtime/store/HistorySdk.d.ts +48 -0
- package/build/src/runtime/store/HistorySdk.js +142 -0
- package/build/src/runtime/store/HistorySdk.js.map +1 -0
- package/build/src/runtime/store/Http.d.ts +14 -0
- package/build/src/runtime/store/Http.js +4 -0
- package/build/src/runtime/store/Http.js.map +1 -0
- package/build/src/runtime/store/HttpNode.d.ts +16 -0
- package/build/src/runtime/store/HttpNode.js +95 -0
- package/build/src/runtime/store/HttpNode.js.map +1 -0
- package/build/src/runtime/store/HttpWeb.d.ts +15 -0
- package/build/src/runtime/store/HttpWeb.js +83 -0
- package/build/src/runtime/store/HttpWeb.js.map +1 -0
- package/build/src/runtime/store/ProjectsSdk.d.ts +43 -0
- package/build/src/runtime/store/ProjectsSdk.js +144 -0
- package/build/src/runtime/store/ProjectsSdk.js.map +1 -0
- package/build/src/runtime/store/RouteBuilder.d.ts +42 -0
- package/build/src/runtime/store/RouteBuilder.js +75 -0
- package/build/src/runtime/store/RouteBuilder.js.map +1 -0
- package/build/src/runtime/store/Sdk.d.ts +79 -0
- package/build/src/runtime/store/Sdk.js +117 -0
- package/build/src/runtime/store/Sdk.js.map +1 -0
- package/build/src/runtime/store/SdkBase.d.ts +45 -0
- package/build/src/runtime/store/SdkBase.js +40 -0
- package/build/src/runtime/store/SdkBase.js.map +1 -0
- package/build/src/runtime/store/SpacesSdk.d.ts +50 -0
- package/build/src/runtime/store/SpacesSdk.js +185 -0
- package/build/src/runtime/store/SpacesSdk.js.map +1 -0
- package/build/src/runtime/store/StoreSdkNode.d.ts +10 -0
- package/build/src/runtime/store/StoreSdkNode.js +11 -0
- package/build/src/runtime/store/StoreSdkNode.js.map +1 -0
- package/build/src/runtime/store/StoreSdkWeb.d.ts +10 -0
- package/build/src/runtime/store/StoreSdkWeb.js +11 -0
- package/build/src/runtime/store/StoreSdkWeb.js.map +1 -0
- package/build/src/runtime/store/UsersSdk.d.ts +18 -0
- package/build/src/runtime/store/UsersSdk.js +88 -0
- package/build/src/runtime/store/UsersSdk.js.map +1 -0
- package/build/src/runtime/store/WsClient.d.ts +24 -0
- package/build/src/runtime/store/WsClient.js +4 -0
- package/build/src/runtime/store/WsClient.js.map +1 -0
- package/build/src/runtime/store/WsClientNode.d.ts +24 -0
- package/build/src/runtime/store/WsClientNode.js +66 -0
- package/build/src/runtime/store/WsClientNode.js.map +1 -0
- package/build/src/runtime/store/WsClientWeb.d.ts +23 -0
- package/build/src/runtime/store/WsClientWeb.js +73 -0
- package/build/src/runtime/store/WsClientWeb.js.map +1 -0
- package/package.json +6 -8
- package/readme.md +5 -5
- package/src/data/JmesparthReader.ts +1 -1
- package/src/events/models/ProjectEvents.ts +2 -2
- package/src/events/readme.md +1 -1
- package/src/lib/transformers/PayloadSerializer.ts +3 -3
- package/src/mocking/ProjectMock.ts +1 -1
- package/src/mocking/lib/Request.ts +5 -5
- package/src/mocking/lib/Response.ts +10 -10
- package/src/mocking/lib/User.ts +2 -1
- package/src/models/AuthorizationData.ts +2 -2
- package/src/models/ClientCertificate.ts +1 -1
- package/src/models/Environment.ts +4 -4
- package/src/models/ErrorResponse.ts +1 -1
- package/src/models/HostRule.ts +5 -5
- package/src/models/HttpHistory.ts +31 -1
- package/src/models/HttpProject.ts +87 -7
- package/src/models/HttpProjectListItem.ts +1 -1
- package/src/models/HttpRequest.ts +2 -2
- package/src/models/HttpResponse.ts +3 -3
- package/src/models/License.ts +4 -4
- package/src/models/ProjectFolder.ts +3 -3
- package/src/models/ProjectItem.ts +2 -2
- package/src/models/ProjectRequest.ts +2 -2
- package/src/models/ProjectSchema.ts +2 -2
- package/src/models/Property.ts +5 -5
- package/src/models/Provider.ts +4 -4
- package/src/models/README.md +2 -2
- package/src/models/Request.ts +4 -4
- package/src/models/RequestActions.ts +2 -4
- package/src/models/RequestAuthorization.ts +3 -5
- package/src/models/RequestConfig.ts +3 -5
- package/src/models/RequestLog.ts +25 -11
- package/src/models/RequestTime.ts +4 -6
- package/src/models/RequestUiMeta.ts +5 -5
- package/src/models/RequestsSize.ts +1 -3
- package/src/models/{ArcResponse.ts → Response.ts} +12 -14
- package/src/models/ResponseAuthorization.ts +4 -4
- package/src/models/ResponseRedirect.ts +3 -5
- package/src/models/RevisionInfo.ts +1 -1
- package/src/models/SentRequest.ts +2 -4
- package/src/models/Server.ts +4 -4
- package/src/models/Thing.ts +4 -4
- package/src/models/Url.ts +2 -4
- package/src/models/User.ts +2 -1
- package/src/models/WebApi.ts +1 -1
- package/src/models/WebApiIndex.ts +1 -1
- package/src/models/Workspace.ts +5 -5
- package/src/models/actions/Action.ts +2 -2
- package/src/models/actions/Condition.ts +2 -2
- package/src/models/actions/RunnableAction.ts +1 -1
- package/src/models/actions/runnable/DeleteCookieAction.ts +2 -2
- package/src/models/actions/runnable/SetCookieAction.ts +2 -2
- package/src/models/actions/runnable/SetVariableAction.ts +2 -2
- package/src/models/transformers/ImportUtils.ts +1 -1
- package/src/models/transformers/PostmanBackupTransformer.ts +2 -1
- package/src/models/transformers/PostmanV21Transformer.ts +2 -1
- package/src/models/transformers/PostmanV2Transformer.ts +2 -1
- package/src/runtime/actions/RunnableCondition.ts +6 -7
- package/src/runtime/http-engine/{ArcEngine.ts → CoreEngine.ts} +7 -7
- package/src/runtime/http-engine/HttpEngine.ts +5 -24
- package/src/runtime/modules/BasicAuthCache.ts +2 -6
- package/src/runtime/modules/RequestCookies.ts +6 -5
- package/src/runtime/node/InteropInterfaces.ts +121 -0
- package/src/runtime/node/ProjectParallelRunner.ts +2 -9
- package/src/runtime/node/ProjectRequestRunner.ts +42 -61
- package/src/runtime/node/ProjectRunner.ts +1 -60
- package/src/runtime/node/ProjectRunnerWorker.ts +2 -1
- package/src/runtime/node/RequestFactory.ts +3 -3
- package/src/runtime/reporters/ProjectRunCliReporter.ts +2 -2
- package/src/runtime/reporters/Reporter.ts +4 -4
- package/src/runtime/store/AuthSdk.ts +126 -0
- package/src/runtime/store/BackendSdk.ts +25 -0
- package/src/runtime/store/HistorySdk.ts +157 -0
- package/src/runtime/store/Http.ts +18 -0
- package/src/runtime/store/HttpNode.ts +100 -0
- package/src/runtime/store/HttpWeb.ts +89 -0
- package/src/runtime/store/ProjectsSdk.ts +147 -0
- package/src/runtime/store/RouteBuilder.ts +89 -0
- package/src/runtime/store/Sdk.ts +131 -0
- package/src/runtime/store/SdkBase.ts +72 -0
- package/src/runtime/store/SpacesSdk.ts +190 -0
- package/src/runtime/store/StoreSdkNode.ts +13 -0
- package/src/runtime/store/StoreSdkWeb.ts +13 -0
- package/src/runtime/store/UsersSdk.ts +89 -0
- package/src/runtime/store/WsClient.ts +28 -0
- package/src/runtime/store/WsClientNode.ts +68 -0
- package/src/runtime/store/WsClientWeb.ts +75 -0
- package/build/src/models/ArcResponse.js.map +0 -1
- package/build/src/models/HistoryIndex.d.ts +0 -43
- package/build/src/models/HistoryIndex.js +0 -53
- package/build/src/models/HistoryIndex.js.map +0 -1
- package/build/src/models/HistoryRequest.d.ts +0 -13
- package/build/src/models/HistoryRequest.js +0 -25
- package/build/src/models/HistoryRequest.js.map +0 -1
- package/build/src/runtime/http-engine/ArcEngine.js.map +0 -1
- package/build/src/runtime/http-engine/NodeEngine.d.ts +0 -154
- package/build/src/runtime/http-engine/NodeEngine.js +0 -766
- package/build/src/runtime/http-engine/NodeEngine.js.map +0 -1
- package/build/src/runtime/http-engine/NodeEngineDirect.d.ts +0 -113
- package/build/src/runtime/http-engine/NodeEngineDirect.js +0 -449
- package/build/src/runtime/http-engine/NodeEngineDirect.js.map +0 -1
- package/build/src/runtime/store/StoreSdk.d.ts +0 -279
- package/build/src/runtime/store/StoreSdk.js +0 -840
- package/build/src/runtime/store/StoreSdk.js.map +0 -1
- package/src/models/HistoryIndex.ts +0 -76
- package/src/models/HistoryRequest.ts +0 -28
- package/src/runtime/http-engine/NodeEngine.ts +0 -792
- package/src/runtime/http-engine/NodeEngineDirect.ts +0 -482
- package/src/runtime/store/StoreSdk.ts +0 -895
|
@@ -4,10 +4,11 @@ import { Headers } from '../../lib/headers/Headers.js';
|
|
|
4
4
|
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
5
5
|
import { ExecutionContext } from './ModulesRegistry.js';
|
|
6
6
|
import { IResponseRedirect } from '../../models/ResponseRedirect.js';
|
|
7
|
-
import {
|
|
7
|
+
import { IResponse } from '../../models/Response.js';
|
|
8
8
|
import { IErrorResponse } from '../../models/ErrorResponse.js';
|
|
9
9
|
import { IRequestLog } from '../../models/RequestLog.js';
|
|
10
10
|
import { HttpCookie } from '../../models/HttpCookie.js';
|
|
11
|
+
import { Kind as RequestConfigKind } from '../../models/RequestConfig.js';
|
|
11
12
|
import { Cookie } from '../../lib/cookies/Cookie.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -51,7 +52,7 @@ function applyCookieHeader(header: string, request: IHttpRequest): void {
|
|
|
51
52
|
* @param redirects List of redirect responses
|
|
52
53
|
* @returns An object with `cookies` and `expired` arrays of cookies.
|
|
53
54
|
*/
|
|
54
|
-
function extract(response:
|
|
55
|
+
function extract(response: IResponse, url: string, redirects?: IResponseRedirect[]): Record<'expired'|'cookies', Cookie[]> {
|
|
55
56
|
let expired: Cookie[] = [];
|
|
56
57
|
let parser;
|
|
57
58
|
let exp;
|
|
@@ -100,7 +101,7 @@ function extract(response: IArcResponse, url: string, redirects?: IResponseRedir
|
|
|
100
101
|
*
|
|
101
102
|
* Unregister this module when the application settings change to not to use session storage.
|
|
102
103
|
*
|
|
103
|
-
* In
|
|
104
|
+
* In electron the session storage is a chrome persistent partition with a session shared with the "log in to a web service".
|
|
104
105
|
* This way cookies can be acquired in through the browser login and store in the application to use them with the request.
|
|
105
106
|
*/
|
|
106
107
|
export async function processRequestCookies(request: IHttpRequest, context: ExecutionContext): Promise<void> {
|
|
@@ -126,7 +127,7 @@ export async function processResponseCookies(log: IRequestLog, context: Executio
|
|
|
126
127
|
return;
|
|
127
128
|
}
|
|
128
129
|
const config = context.config || {
|
|
129
|
-
kind:
|
|
130
|
+
kind: RequestConfigKind,
|
|
130
131
|
enabled: false,
|
|
131
132
|
};
|
|
132
133
|
let ignore = false;
|
|
@@ -137,7 +138,7 @@ export async function processResponseCookies(log: IRequestLog, context: Executio
|
|
|
137
138
|
if (ignore) {
|
|
138
139
|
return;
|
|
139
140
|
}
|
|
140
|
-
const typedResponse = log.response as
|
|
141
|
+
const typedResponse = log.response as IResponse;
|
|
141
142
|
const result = extract(typedResponse, log.request.url, log.redirects);
|
|
142
143
|
if (result.cookies.length) {
|
|
143
144
|
await CookieEvents.updateBulk(context.eventsTarget, result.cookies.map(c => HttpCookie.fromCookieParser(c).toJSON()));
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { IProjectRequestIterator, IHttpProject } from '../../models/HttpProject.js';
|
|
2
|
+
import { Environment } from '../../models/Environment.js';
|
|
3
|
+
import { Logger } from '../../lib/logging/Logger.js';
|
|
4
|
+
import { IRequestLog } from '../../models/RequestLog.js';
|
|
5
|
+
|
|
6
|
+
export interface ProjectRunnerOptions {
|
|
7
|
+
/**
|
|
8
|
+
* When provided it overrides any project / folder defined environment.
|
|
9
|
+
*/
|
|
10
|
+
environment?: Environment;
|
|
11
|
+
/**
|
|
12
|
+
* Additional variables to pass to the selected environment.
|
|
13
|
+
* This can be use to pass system variables, when needed.
|
|
14
|
+
*
|
|
15
|
+
* To use system variables tou can use `init.variables = process.env`;
|
|
16
|
+
*/
|
|
17
|
+
variables?: Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Overrides the default logger (console).
|
|
20
|
+
*/
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
/**
|
|
23
|
+
* The event target to use.
|
|
24
|
+
* By default it creates its own target.
|
|
25
|
+
*/
|
|
26
|
+
eventTarget?: EventTarget;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ProjectRunnerRunOptions extends IProjectRequestIterator {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RunResult {
|
|
33
|
+
/**
|
|
34
|
+
* The key of the request from the HttpProject that was executed.
|
|
35
|
+
*/
|
|
36
|
+
key: string;
|
|
37
|
+
/**
|
|
38
|
+
* The key of parent folder of the executed request.
|
|
39
|
+
*/
|
|
40
|
+
parent?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Set when a fatal error occurred so the request couldn't be executed.
|
|
43
|
+
* This is not the same as error reported during a request. The log's response can still be IResponseError.
|
|
44
|
+
*/
|
|
45
|
+
error?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The error message. Always set when the `error` is `true`.
|
|
48
|
+
*/
|
|
49
|
+
errorMessage?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The request log.
|
|
52
|
+
* Always set when the `error` is `false`.
|
|
53
|
+
*/
|
|
54
|
+
log?: IRequestLog;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface IProjectParallelRunnerOptions extends IProjectRunnerOptions {
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface IProjectParallelWorkerOptions extends IProjectRunnerOptions {
|
|
61
|
+
project: IHttpProject;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface IProjectRunnerOptions {
|
|
65
|
+
/**
|
|
66
|
+
* The environment to use.
|
|
67
|
+
* This can be a name or the key of the environment located under the parent or root.
|
|
68
|
+
* It can also be a path to the environment definition. If the file exists it is used. Otherwise it tried to
|
|
69
|
+
* find the environment in the project.
|
|
70
|
+
*/
|
|
71
|
+
environment?: string;
|
|
72
|
+
/**
|
|
73
|
+
* The parent folder to execute.
|
|
74
|
+
*/
|
|
75
|
+
parent?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The names or the keys of requests to execute.
|
|
78
|
+
* This can be used to limit the number of requests.
|
|
79
|
+
*/
|
|
80
|
+
request?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* The number of times the execution should be repeated.
|
|
83
|
+
* Default to 1.
|
|
84
|
+
*/
|
|
85
|
+
iterations?: number;
|
|
86
|
+
/**
|
|
87
|
+
* The number of milliseconds to wait between each iteration.
|
|
88
|
+
* Default to the next frame (vary from 1 to tens of milliseconds).
|
|
89
|
+
*/
|
|
90
|
+
iterationDelay?: number;
|
|
91
|
+
/**
|
|
92
|
+
* When set it performs parallel execution for each iteration.
|
|
93
|
+
* The number of executions at the same time depends on the number of processor cores
|
|
94
|
+
* available on the current machine. The maximum of the parallel execution
|
|
95
|
+
* is the number of available cores. When the `iterations` number is higher
|
|
96
|
+
* then the "rest" is added to the iterations per each core.
|
|
97
|
+
*/
|
|
98
|
+
parallel?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* When set it includes requests in the current folder and sub-folder according to the order
|
|
101
|
+
* defined in the folder.
|
|
102
|
+
*/
|
|
103
|
+
recursive?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* The opposite of the `requests`. The list of names or keys of requests or folders to ignore.
|
|
106
|
+
* Note, ignore is tested before the `requests`.
|
|
107
|
+
*/
|
|
108
|
+
ignore?: string[];
|
|
109
|
+
/**
|
|
110
|
+
* The logger to use with the request factory.
|
|
111
|
+
* When not set it uses the dummy logger (no output).
|
|
112
|
+
*/
|
|
113
|
+
logger?: Logger;
|
|
114
|
+
/**
|
|
115
|
+
* When true it copies all system variables to the execution environment.
|
|
116
|
+
* When an array of strings, only takes system variables that are listed in the array.
|
|
117
|
+
* When a map, it uses this map as a list of variables.
|
|
118
|
+
* When not set it does not read system variables.
|
|
119
|
+
*/
|
|
120
|
+
variables?: boolean | string[] | Record<string, string>;
|
|
121
|
+
}
|
|
@@ -2,10 +2,10 @@ import cluster, { Worker } from 'cluster';
|
|
|
2
2
|
import { cpus } from 'os';
|
|
3
3
|
import { dirname, join } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import { HttpProject
|
|
6
|
-
import { IProjectRunnerOptions } from './ProjectRunner.js';
|
|
5
|
+
import { HttpProject } from '../../models/HttpProject.js';
|
|
7
6
|
import { IProjectExecutionLog, IProjectExecutionIteration } from '../reporters/Reporter.js';
|
|
8
7
|
import { BaseRunner } from './BaseRunner.js';
|
|
8
|
+
import { IProjectParallelRunnerOptions, IProjectParallelWorkerOptions } from './InteropInterfaces.js'
|
|
9
9
|
|
|
10
10
|
const numCPUs = cpus().length;
|
|
11
11
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -40,13 +40,6 @@ export interface IWorkerMessage {
|
|
|
40
40
|
data?: unknown;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export interface IProjectParallelRunnerOptions extends IProjectRunnerOptions {
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface IProjectParallelWorkerOptions extends IProjectRunnerOptions {
|
|
47
|
-
project: IHttpProject;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
43
|
export interface ProjectParallelRunner {
|
|
51
44
|
/**
|
|
52
45
|
* Dispatched when a status of a worker change.
|
|
@@ -6,64 +6,14 @@ import { Property } from '../../models/Property.js';
|
|
|
6
6
|
import { ProjectFolder, Kind as ProjectFolderKind } from '../../models/ProjectFolder.js';
|
|
7
7
|
import { ProjectRequest } from '../../models/ProjectRequest.js';
|
|
8
8
|
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
9
|
-
import { HttpProject
|
|
9
|
+
import { HttpProject } from '../../models/HttpProject.js';
|
|
10
10
|
import { SentRequest } from '../../models/SentRequest.js';
|
|
11
11
|
import { ErrorResponse } from '../../models/ErrorResponse.js';
|
|
12
12
|
import { VariablesStore } from './VariablesStore.js';
|
|
13
13
|
import { VariablesProcessor } from '../variables/VariablesProcessor.js';
|
|
14
14
|
import { RequestFactory } from './RequestFactory.js';
|
|
15
15
|
import { EventTypes } from '../../events/EventTypes.js';
|
|
16
|
-
|
|
17
|
-
export interface ProjectRunnerOptions {
|
|
18
|
-
/**
|
|
19
|
-
* When provided it overrides any project / folder defined environment.
|
|
20
|
-
*/
|
|
21
|
-
environment?: Environment;
|
|
22
|
-
/**
|
|
23
|
-
* Additional variables to pass to the selected environment.
|
|
24
|
-
* This can be use to pass system variables, when needed.
|
|
25
|
-
*
|
|
26
|
-
* To use system variables tou can use `init.variables = process.env`;
|
|
27
|
-
*/
|
|
28
|
-
variables?: Record<string, string>;
|
|
29
|
-
/**
|
|
30
|
-
* Overrides the default logger (console).
|
|
31
|
-
*/
|
|
32
|
-
logger?: Logger;
|
|
33
|
-
/**
|
|
34
|
-
* The event target to use.
|
|
35
|
-
* By default it creates its own target.
|
|
36
|
-
*/
|
|
37
|
-
eventTarget?: EventTarget;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface ProjectRunnerRunOptions extends IProjectRequestIterator {
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface RunResult {
|
|
44
|
-
/**
|
|
45
|
-
* The key of the request from the HttpProject that was executed.
|
|
46
|
-
*/
|
|
47
|
-
key: string;
|
|
48
|
-
/**
|
|
49
|
-
* The key of parent folder of the executed request.
|
|
50
|
-
*/
|
|
51
|
-
parent?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Set when a fatal error occurred so the request couldn't be executed.
|
|
54
|
-
* This is not the same as error reported during a request. The log's response can still be IResponseError.
|
|
55
|
-
*/
|
|
56
|
-
error?: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* The error message. Always set when the `error` is `true`.
|
|
59
|
-
*/
|
|
60
|
-
errorMessage?: string;
|
|
61
|
-
/**
|
|
62
|
-
* The request log.
|
|
63
|
-
* Always set when the `error` is `false`.
|
|
64
|
-
*/
|
|
65
|
-
log?: IRequestLog;
|
|
66
|
-
}
|
|
16
|
+
import { ProjectRunnerOptions, ProjectRunnerRunOptions, RunResult } from './InteropInterfaces.js';
|
|
67
17
|
|
|
68
18
|
export interface ProjectRequestRunner {
|
|
69
19
|
/**
|
|
@@ -130,20 +80,50 @@ export class ProjectRequestRunner extends EventEmitter {
|
|
|
130
80
|
const { project } = this;
|
|
131
81
|
const executed: RunResult[] = [];
|
|
132
82
|
for (const request of project.requestIterator(options)) {
|
|
133
|
-
const
|
|
134
|
-
let variables: Record<string, string>;
|
|
135
|
-
if (VariablesStore.has(parent)) {
|
|
136
|
-
variables = VariablesStore.get(parent);
|
|
137
|
-
} else {
|
|
138
|
-
variables = await this.getVariables(parent);
|
|
139
|
-
VariablesStore.set(parent, variables);
|
|
140
|
-
}
|
|
141
|
-
const info = await this.execute(request, variables);
|
|
83
|
+
const info = await this._runItem(request);
|
|
142
84
|
executed.push(info);
|
|
143
85
|
}
|
|
144
86
|
return executed;
|
|
145
87
|
}
|
|
146
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Allows to iterate over project requests recursively and execute each request
|
|
91
|
+
* in order. The generator yields the `RunResult` for the request.
|
|
92
|
+
*
|
|
93
|
+
* Example:
|
|
94
|
+
*
|
|
95
|
+
* ```javascript
|
|
96
|
+
* const runner = new ProjectRequestRunner(...);
|
|
97
|
+
* for await (let runResult of runner) {
|
|
98
|
+
* console.log(runResult);
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
async* [Symbol.asyncIterator](): AsyncGenerator<RunResult> {
|
|
103
|
+
const { project } = this;
|
|
104
|
+
for (const request of project.requestIterator({ recursive: true })) {
|
|
105
|
+
const info = await this._runItem(request);
|
|
106
|
+
yield info;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private async _runItem(request: ProjectRequest): Promise<RunResult> {
|
|
111
|
+
const folder = request.getParent();
|
|
112
|
+
const parent = folder || this.project;
|
|
113
|
+
let variables: Record<string, string>;
|
|
114
|
+
if (VariablesStore.has(parent)) {
|
|
115
|
+
variables = VariablesStore.get(parent);
|
|
116
|
+
} else {
|
|
117
|
+
variables = await this.getVariables(parent);
|
|
118
|
+
VariablesStore.set(parent, variables);
|
|
119
|
+
}
|
|
120
|
+
const info = await this.execute(request, variables);
|
|
121
|
+
if (folder && folder !== this.project) {
|
|
122
|
+
info.parent = folder.key;
|
|
123
|
+
}
|
|
124
|
+
return info;
|
|
125
|
+
}
|
|
126
|
+
|
|
147
127
|
protected async execute(request: ProjectRequest, variables: Record<string, string>): Promise<RunResult> {
|
|
148
128
|
const config = request.getConfig();
|
|
149
129
|
const factory = new RequestFactory(this.eventTarget);
|
|
@@ -189,6 +169,7 @@ export class ProjectRequestRunner extends EventEmitter {
|
|
|
189
169
|
this.emit('request', request.key, { ...requestCopy });
|
|
190
170
|
await factory.processRequestLogic(requestCopy);
|
|
191
171
|
const result = await factory.executeRequest(requestCopy);
|
|
172
|
+
result.requestId = request.key;
|
|
192
173
|
await factory.processResponse(result);
|
|
193
174
|
request.setLog(result);
|
|
194
175
|
info.log = result;
|
|
@@ -3,75 +3,16 @@ import { HttpProject } from '../../models/HttpProject.js';
|
|
|
3
3
|
import { ProjectFolder } from '../../models/ProjectFolder.js';
|
|
4
4
|
import { Environment, IEnvironment } from '../../models/Environment.js';
|
|
5
5
|
import { DummyLogger } from '../../lib/logging/DummyLogger.js';
|
|
6
|
-
import { Logger } from '../../lib/logging/Logger.js';
|
|
7
6
|
import { IRequestLog } from '../../models/RequestLog.js';
|
|
8
7
|
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
9
8
|
import { ProjectRequestRunner } from './ProjectRequestRunner.js';
|
|
10
9
|
import { IProjectExecutionIteration, IProjectExecutionLog } from '../reporters/Reporter.js';
|
|
11
10
|
import { pathExists, readJson } from '../../lib/fs/Fs.js';
|
|
12
11
|
import { BaseRunner } from './BaseRunner.js';
|
|
12
|
+
import { IProjectRunnerOptions } from './InteropInterfaces.js';
|
|
13
13
|
|
|
14
14
|
type ProjectParent = HttpProject | ProjectFolder;
|
|
15
15
|
|
|
16
|
-
export interface IProjectRunnerOptions {
|
|
17
|
-
/**
|
|
18
|
-
* The environment to use.
|
|
19
|
-
* This can be a name or the key of the environment located under the parent or root.
|
|
20
|
-
* It can also be a path to the environment definition. If the file exists it is used. Otherwise it tried to
|
|
21
|
-
* find the environment in the project.
|
|
22
|
-
*/
|
|
23
|
-
environment?: string;
|
|
24
|
-
/**
|
|
25
|
-
* The parent folder to execute.
|
|
26
|
-
*/
|
|
27
|
-
parent?: string;
|
|
28
|
-
/**
|
|
29
|
-
* The names or the keys of requests to execute.
|
|
30
|
-
* This can be used to limit the number of requests.
|
|
31
|
-
*/
|
|
32
|
-
request?: string[];
|
|
33
|
-
/**
|
|
34
|
-
* The number of times the execution should be repeated.
|
|
35
|
-
* Default to 1.
|
|
36
|
-
*/
|
|
37
|
-
iterations?: number;
|
|
38
|
-
/**
|
|
39
|
-
* The number of milliseconds to wait between each iteration.
|
|
40
|
-
* Default to the next frame (vary from 1 to tens of milliseconds).
|
|
41
|
-
*/
|
|
42
|
-
iterationDelay?: number;
|
|
43
|
-
/**
|
|
44
|
-
* When set it performs parallel execution for each iteration.
|
|
45
|
-
* The number of executions at the same time depends on the number of processor cores
|
|
46
|
-
* available on the current machine. The maximum of the parallel execution
|
|
47
|
-
* is the number of available cores. When the `iterations` number is higher
|
|
48
|
-
* then the "rest" is added to the iterations per each core.
|
|
49
|
-
*/
|
|
50
|
-
parallel?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* When set it includes requests in the current folder and sub-folder according to the order
|
|
53
|
-
* defined in the folder.
|
|
54
|
-
*/
|
|
55
|
-
recursive?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* The opposite of the `requests`. The list of names or keys of requests or folders to ignore.
|
|
58
|
-
* Note, ignore is tested before the `requests`.
|
|
59
|
-
*/
|
|
60
|
-
ignore?: string[];
|
|
61
|
-
/**
|
|
62
|
-
* The logger to use with the request factory.
|
|
63
|
-
* When not set it uses the dummy logger (no output).
|
|
64
|
-
*/
|
|
65
|
-
logger?: Logger;
|
|
66
|
-
/**
|
|
67
|
-
* When true it copies all system variables to the execution environment.
|
|
68
|
-
* When an array of strings, only takes system variables that are listed in the array.
|
|
69
|
-
* When a map, it uses this map as a list of variables.
|
|
70
|
-
* When not set it does not read system variables.
|
|
71
|
-
*/
|
|
72
|
-
variables?: boolean | string[] | Record<string, string>;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
16
|
export interface ProjectRunner {
|
|
76
17
|
/**
|
|
77
18
|
* Event dispatched when an iteration is about to start.
|
|
@@ -3,7 +3,8 @@ import process from 'process';
|
|
|
3
3
|
import cluster from 'cluster';
|
|
4
4
|
import { HttpProject } from '../../models/HttpProject.js';
|
|
5
5
|
import { IProjectExecutionLog } from '../reporters/Reporter.js';
|
|
6
|
-
import { IWorkerMessage
|
|
6
|
+
import { IWorkerMessage } from './ProjectParallelRunner.js';
|
|
7
|
+
import { IProjectParallelWorkerOptions } from './InteropInterfaces.js';
|
|
7
8
|
import { sleep } from '../../lib/timers/Timers.js';
|
|
8
9
|
import { ProjectRunner } from './ProjectRunner.js';
|
|
9
10
|
|
|
@@ -11,14 +11,14 @@ import { Action } from '../../models/actions/Action.js';
|
|
|
11
11
|
import { RunnableCondition } from '../actions/RunnableCondition.js';
|
|
12
12
|
import { ActionRunner } from '../actions/ActionRunner.js';
|
|
13
13
|
import { HttpEngineOptions } from '../http-engine/HttpEngine.js';
|
|
14
|
-
import {
|
|
14
|
+
import { CoreEngine } from '../http-engine/CoreEngine.js';
|
|
15
15
|
import { ModulesRegistry, RegisteredRequestModule, RegisteredResponseModule, ExecutionContext, RegistryPermission } from '../modules/ModulesRegistry.js';
|
|
16
16
|
import { ExecutionResponse } from '../modules/ExecutionResponse.js';
|
|
17
17
|
import { Events } from '../../events/Events.js';
|
|
18
18
|
import { Logger } from '../../lib/logging/Logger.js';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* The main class to make HTTP requests in the API Client
|
|
21
|
+
* The main class to make HTTP requests in the API Client.
|
|
22
22
|
* This factory includes all logic components to perform the entire HTTP request lifecycle. This includes:
|
|
23
23
|
*
|
|
24
24
|
* - variables evaluation on the request object
|
|
@@ -294,7 +294,7 @@ export class RequestFactory {
|
|
|
294
294
|
*/
|
|
295
295
|
async executeRequest(request: IHttpRequest): Promise<IRequestLog> {
|
|
296
296
|
const opts = await this.prepareEngineConfig();
|
|
297
|
-
const engine = new
|
|
297
|
+
const engine = new CoreEngine(request, opts);
|
|
298
298
|
return engine.send();
|
|
299
299
|
}
|
|
300
300
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Table } from 'console-table-printer';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { ErrorResponse, IErrorResponse } from '../../models/ErrorResponse.js';
|
|
4
|
-
import {
|
|
4
|
+
import { IResponse } from '../../models/Response.js';
|
|
5
5
|
import { ISerializedError } from '../../models/SerializableError.js';
|
|
6
6
|
import { Reporter } from './Reporter.js';
|
|
7
7
|
|
|
@@ -70,7 +70,7 @@ export class ProjectRunCliReporter extends Reporter {
|
|
|
70
70
|
process.stdout.write('Request not executed.\n');
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
|
-
const response = log.response as
|
|
73
|
+
const response = log.response as IResponse;
|
|
74
74
|
process.stdout.write(`${prefix} Status code is: ${response.status}\n`);
|
|
75
75
|
});
|
|
76
76
|
process.stdout.write('\n\n');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IRequestLog } from '../../models/RequestLog.js';
|
|
2
|
-
import {
|
|
2
|
+
import { IResponse } from '../../models/Response.js';
|
|
3
3
|
import { ErrorResponse } from '../../models/ErrorResponse.js';
|
|
4
4
|
|
|
5
5
|
export interface IProjectExecutionIteration {
|
|
@@ -56,7 +56,7 @@ export abstract class Reporter {
|
|
|
56
56
|
if (!log.response || ErrorResponse.isErrorResponse(log.response)) {
|
|
57
57
|
return true;
|
|
58
58
|
}
|
|
59
|
-
const response = log.response as
|
|
59
|
+
const response = log.response as IResponse;
|
|
60
60
|
if (response.status >= 400) {
|
|
61
61
|
return true;
|
|
62
62
|
}
|
|
@@ -93,7 +93,7 @@ export abstract class Reporter {
|
|
|
93
93
|
if (!log.response || ErrorResponse.isErrorResponse(log.response)) {
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
|
-
const response = log.response as
|
|
96
|
+
const response = log.response as IResponse;
|
|
97
97
|
if (response.status < 400) {
|
|
98
98
|
result++;
|
|
99
99
|
}
|
|
@@ -114,7 +114,7 @@ export abstract class Reporter {
|
|
|
114
114
|
if (!log.response || ErrorResponse.isErrorResponse(log.response)) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
|
-
const response = log.response as
|
|
117
|
+
const response = log.response as IResponse;
|
|
118
118
|
if (response.loadingTime && response.loadingTime > 0) {
|
|
119
119
|
result += response.loadingTime;
|
|
120
120
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { SdkBase, IStoreTokenInfo } from './SdkBase.js';
|
|
2
|
+
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
+
import { Headers } from '../../lib/headers/Headers.js';
|
|
4
|
+
import WebSocketNode from 'ws';
|
|
5
|
+
|
|
6
|
+
export class AuthSdk extends SdkBase {
|
|
7
|
+
protected getExpires(headers: Headers): number | undefined {
|
|
8
|
+
const expires = headers.get('expires');
|
|
9
|
+
if (!expires) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const d = new Date(expires);
|
|
13
|
+
const time = d.getTime();
|
|
14
|
+
if (Number.isNaN(time)) {
|
|
15
|
+
console.warn(`Invalid session response: the expires header cannot be parsed.`);
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return time;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates unauthenticated session in the backend.
|
|
23
|
+
* @returns The JWT for unauthenticated user.
|
|
24
|
+
*/
|
|
25
|
+
async createSession(): Promise<IStoreTokenInfo> {
|
|
26
|
+
const url = this.sdk.getUrl(RouteBuilder.sessions());
|
|
27
|
+
// console.log('Create session: ', url);
|
|
28
|
+
const result = await this.sdk.http.post(url.toString());
|
|
29
|
+
this.inspectCommonStatusCodes(result.status);
|
|
30
|
+
if (result.status !== 200) {
|
|
31
|
+
throw new Error(`Unable to create the session. Invalid response status: ${result.status}`);
|
|
32
|
+
}
|
|
33
|
+
if (!result.body) {
|
|
34
|
+
throw new Error(`Unable to create the session. Response has no token.`);
|
|
35
|
+
}
|
|
36
|
+
const info: IStoreTokenInfo = {
|
|
37
|
+
token: result.body,
|
|
38
|
+
};
|
|
39
|
+
const expires = this.getExpires(result.headers);
|
|
40
|
+
if (expires) {
|
|
41
|
+
info.expires = expires;
|
|
42
|
+
}
|
|
43
|
+
return info;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Initializes the authentication session.
|
|
48
|
+
* @param token The unauthenticated session JWT. Required when not set on the class.
|
|
49
|
+
* @returns The location of the authorization endpoint.
|
|
50
|
+
*/
|
|
51
|
+
async createAuthSession(token?: string, loginPath = '/auth/login'): Promise<string> {
|
|
52
|
+
const url = this.sdk.getUrl(loginPath);
|
|
53
|
+
const result = await this.sdk.http.post(url.toString(), { token });
|
|
54
|
+
this.inspectCommonStatusCodes(result.status);
|
|
55
|
+
const loc = result.headers.get('location');
|
|
56
|
+
if (!loc) {
|
|
57
|
+
throw new Error(`The location header not returned by the server.`);
|
|
58
|
+
}
|
|
59
|
+
return loc;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Listens to the first message coming to the client from the auth endpoint.
|
|
64
|
+
* @param authPath The authorization path returned by the server info or 401 response.
|
|
65
|
+
* @param token Optional token to use.
|
|
66
|
+
*/
|
|
67
|
+
async listenAuth(authPath: string, token?: string): Promise<void> {
|
|
68
|
+
const url = this.sdk.getUrl(authPath);
|
|
69
|
+
const client = await this.sdk.ws.createAndConnect(url.toString(), token);
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const { sdk } = this;
|
|
72
|
+
async function finishData(data: any): Promise<void> {
|
|
73
|
+
let message: any;
|
|
74
|
+
try {
|
|
75
|
+
message = JSON.parse(data.toString());
|
|
76
|
+
await sdk.ws.disconnect(client);
|
|
77
|
+
} catch (cause) {
|
|
78
|
+
reject(cause);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (message.status === 'OK') {
|
|
82
|
+
resolve();
|
|
83
|
+
} else {
|
|
84
|
+
reject(new Error(message.message || 'Unknown error'));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const typedNode = client as WebSocketNode;
|
|
88
|
+
if (typeof typedNode.on === 'function') {
|
|
89
|
+
typedNode.on('message', (data: Buffer) => {
|
|
90
|
+
finishData(data);
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
const typedWeb = client as WebSocket;
|
|
94
|
+
typedWeb.addEventListener('message', (event) => {
|
|
95
|
+
finishData(event.data);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Renews authenticated token to a new one when the token expires.
|
|
103
|
+
* @param token Optional token to use.
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
async renewToken(token = this.sdk.token): Promise<IStoreTokenInfo> {
|
|
107
|
+
const authPath = RouteBuilder.sessionRenew();
|
|
108
|
+
const url = this.sdk.getUrl(authPath);
|
|
109
|
+
const result = await this.sdk.http.post(url.toString(), { token });
|
|
110
|
+
this.inspectCommonStatusCodes(result.status);
|
|
111
|
+
if (result.status !== 200) {
|
|
112
|
+
throw new Error(`Unable to renew the token. Invalid response status: ${result.status}`);
|
|
113
|
+
}
|
|
114
|
+
if (!result.body) {
|
|
115
|
+
throw new Error(`Unable to create the session. Response has no token.`);
|
|
116
|
+
}
|
|
117
|
+
const info: IStoreTokenInfo = {
|
|
118
|
+
token: result.body,
|
|
119
|
+
};
|
|
120
|
+
const expires = this.getExpires(result.headers);
|
|
121
|
+
if (expires) {
|
|
122
|
+
info.expires = expires;
|
|
123
|
+
}
|
|
124
|
+
return info;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SdkBase } from './SdkBase.js';
|
|
2
|
+
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
+
import { IBackendInfo } from '../../models/Backend.js';
|
|
4
|
+
|
|
5
|
+
export class BackendSdk extends SdkBase {
|
|
6
|
+
/**
|
|
7
|
+
* @returns Client information about the store configuration.
|
|
8
|
+
*/
|
|
9
|
+
async getInfo(): Promise<IBackendInfo> {
|
|
10
|
+
const url = this.sdk.getUrl(RouteBuilder.backend());
|
|
11
|
+
const result = await this.sdk.http.get(url.toString());
|
|
12
|
+
this.inspectCommonStatusCodes(result.status);
|
|
13
|
+
if (result.status !== 200) {
|
|
14
|
+
throw new Error(`Invalid store response. Expected 200 status and ${result.status} received.`);
|
|
15
|
+
}
|
|
16
|
+
const body = result.body as string;
|
|
17
|
+
let data;
|
|
18
|
+
try {
|
|
19
|
+
data = JSON.parse(body);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
throw new Error(`The server returned invalid response. Unable to read store status.`);
|
|
22
|
+
}
|
|
23
|
+
return data as IBackendInfo;
|
|
24
|
+
}
|
|
25
|
+
}
|