@api-client/core 0.3.11 → 0.4.1
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 +7 -1
- package/build/src/mocking/ProjectMock.js +6 -0
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/History.d.ts +70 -0
- package/build/src/mocking/lib/History.js +120 -0
- package/build/src/mocking/lib/History.js.map +1 -0
- 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.d.ts +20 -0
- package/build/src/mocking/lib/User.js +54 -0
- package/build/src/mocking/lib/User.js.map +1 -0
- package/build/src/models/AuthorizationData.d.ts +2 -2
- package/build/src/models/AuthorizationData.js +2 -2
- package/build/src/models/Backend.d.ts +85 -0
- 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 +64 -18
- package/build/src/models/HttpHistory.js +43 -19
- package/build/src/models/HttpHistory.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +4 -5
- package/build/src/models/HttpProject.js +3 -3
- 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 +9 -1
- package/src/mocking/lib/History.ts +179 -0
- package/src/mocking/lib/Request.ts +5 -5
- package/src/mocking/lib/Response.ts +10 -10
- package/src/mocking/lib/User.ts +68 -0
- package/src/models/AuthorizationData.ts +2 -2
- package/src/models/Backend.ts +93 -0
- 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 +89 -27
- package/src/models/HttpProject.ts +5 -6
- 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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
|
|
2
|
+
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
+
import { IListResponse, HistoryListOptions } from '../../models/Backend.js';
|
|
4
|
+
import { IHttpHistory, IHttpHistoryBulkAdd, Kind as HttpHistoryKind } from '../../models/HttpHistory.js';
|
|
5
|
+
|
|
6
|
+
export class HistorySdk extends SdkBase {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a history object.
|
|
9
|
+
* A history object can be created per app (type = app) or a store's space/[project/[request]].
|
|
10
|
+
*
|
|
11
|
+
* The user can always read their own history. If the history is created for a space/project then
|
|
12
|
+
* history records are shared as any other object in the space.
|
|
13
|
+
*
|
|
14
|
+
* Note, history objects cannot be updated. They can only be created or deleted.
|
|
15
|
+
*
|
|
16
|
+
* @param history The history to create
|
|
17
|
+
* @returns The key of the created history.
|
|
18
|
+
*/
|
|
19
|
+
async create(history: IHttpHistory): Promise<string> {
|
|
20
|
+
const { token } = this.sdk;
|
|
21
|
+
const url = this.sdk.getUrl(RouteBuilder.history());
|
|
22
|
+
const body = JSON.stringify(history);
|
|
23
|
+
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
24
|
+
this.inspectCommonStatusCodes(result.status);
|
|
25
|
+
const E_PREFIX = 'Unable to create a history. ';
|
|
26
|
+
if (result.status !== 200) {
|
|
27
|
+
this.logInvalidResponse(result);
|
|
28
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
29
|
+
}
|
|
30
|
+
const location = result.headers.get('location');
|
|
31
|
+
if (!location) {
|
|
32
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
|
|
33
|
+
}
|
|
34
|
+
const id = location.split('/').pop();
|
|
35
|
+
return id as string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates a multiple history objects in a batch operation.
|
|
40
|
+
*
|
|
41
|
+
* @param info The bulk create info object.
|
|
42
|
+
*/
|
|
43
|
+
async createBulk(info: IHttpHistoryBulkAdd): Promise<string[]> {
|
|
44
|
+
const { token } = this.sdk;
|
|
45
|
+
const url = this.sdk.getUrl(RouteBuilder.historyBatchCreate());
|
|
46
|
+
const body = JSON.stringify(info);
|
|
47
|
+
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
48
|
+
this.inspectCommonStatusCodes(result.status);
|
|
49
|
+
const E_PREFIX = 'Unable to create a bulk history. ';
|
|
50
|
+
if (result.status !== 200) {
|
|
51
|
+
this.logInvalidResponse(result);
|
|
52
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
53
|
+
}
|
|
54
|
+
if (!result.body) {
|
|
55
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
56
|
+
}
|
|
57
|
+
let data: string[];
|
|
58
|
+
try {
|
|
59
|
+
data = JSON.parse(result.body);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
62
|
+
}
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Lists the history.
|
|
68
|
+
*
|
|
69
|
+
* @param options Optional query options.
|
|
70
|
+
*/
|
|
71
|
+
async list(options: HistoryListOptions): Promise<IListResponse> {
|
|
72
|
+
const { token } = this.sdk;
|
|
73
|
+
const url = this.sdk.getUrl(RouteBuilder.history());
|
|
74
|
+
this.sdk.appendListOptions(url, options);
|
|
75
|
+
const result = await this.sdk.http.get(url.toString(), { token });
|
|
76
|
+
this.inspectCommonStatusCodes(result.status);
|
|
77
|
+
const E_PREFIX = 'Unable to list history. ';
|
|
78
|
+
if (result.status !== 200) {
|
|
79
|
+
this.logInvalidResponse(result);
|
|
80
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
81
|
+
}
|
|
82
|
+
if (!result.body) {
|
|
83
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
84
|
+
}
|
|
85
|
+
let data: IListResponse;
|
|
86
|
+
try {
|
|
87
|
+
data = JSON.parse(result.body);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
90
|
+
}
|
|
91
|
+
if (!Array.isArray(data.data)) {
|
|
92
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Deletes a history object form the store.
|
|
99
|
+
*
|
|
100
|
+
* @param key The key returned by the store when created the history. Also available via the `key` property on the history object.
|
|
101
|
+
*/
|
|
102
|
+
delete(key: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Deletes a list of history objects in a batch operation.
|
|
105
|
+
*
|
|
106
|
+
* @param keys The keys returned by the store when created the history. Also available via the `key` property on the history object.
|
|
107
|
+
*/
|
|
108
|
+
delete(keys: string[]): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Deletes a history or a list of history objects from the store.
|
|
111
|
+
* @param key A key or a list of keys.
|
|
112
|
+
*/
|
|
113
|
+
async delete(key: string | string[]): Promise<void> {
|
|
114
|
+
const { token } = this.sdk;
|
|
115
|
+
const isArray = Array.isArray(key);
|
|
116
|
+
const path = isArray ? RouteBuilder.historyBatchDelete() : RouteBuilder.historyItem(key);
|
|
117
|
+
const url = this.sdk.getUrl(path);
|
|
118
|
+
|
|
119
|
+
const result = isArray ? await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(key) }) : await this.sdk.http.delete(url.toString(), { token });
|
|
120
|
+
this.inspectCommonStatusCodes(result.status);
|
|
121
|
+
const E_PREFIX = 'Unable to delete history. ';
|
|
122
|
+
if (result.status !== 204) {
|
|
123
|
+
this.logInvalidResponse(result);
|
|
124
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Reads a history definition from the store.
|
|
130
|
+
* @param key The history key
|
|
131
|
+
* @returns The history object
|
|
132
|
+
*/
|
|
133
|
+
async read(key: string): Promise<IHttpHistory> {
|
|
134
|
+
const { token } = this.sdk;
|
|
135
|
+
const url = this.sdk.getUrl(RouteBuilder.historyItem(key));
|
|
136
|
+
const result = await this.sdk.http.get(url.toString(), { token });
|
|
137
|
+
this.inspectCommonStatusCodes(result.status);
|
|
138
|
+
const E_PREFIX = 'Unable to read a history. ';
|
|
139
|
+
if (result.status !== 200) {
|
|
140
|
+
this.logInvalidResponse(result);
|
|
141
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
142
|
+
}
|
|
143
|
+
if (!result.body) {
|
|
144
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
145
|
+
}
|
|
146
|
+
let data: IHttpHistory;
|
|
147
|
+
try {
|
|
148
|
+
data = JSON.parse(result.body);
|
|
149
|
+
} catch (e) {
|
|
150
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
151
|
+
}
|
|
152
|
+
if (data.kind !== HttpHistoryKind) {
|
|
153
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
154
|
+
}
|
|
155
|
+
return data;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SdkBase, IStoreRequestOptions, IStoreResponse } from './SdkBase.js';
|
|
2
|
+
|
|
3
|
+
export abstract class Http extends SdkBase {
|
|
4
|
+
/**
|
|
5
|
+
* Performs the GET request.
|
|
6
|
+
*
|
|
7
|
+
* @param url The request URL
|
|
8
|
+
* @param opts The request options
|
|
9
|
+
* @returns The response info.
|
|
10
|
+
*/
|
|
11
|
+
abstract get(url: string, opts?: IStoreRequestOptions): Promise<IStoreResponse>;
|
|
12
|
+
|
|
13
|
+
abstract post(url: string, opts?: IStoreRequestOptions): Promise<IStoreResponse>;
|
|
14
|
+
|
|
15
|
+
abstract patch(url: string, opts?: IStoreRequestOptions): Promise<IStoreResponse>;
|
|
16
|
+
|
|
17
|
+
abstract delete(url: string, opts?: IStoreRequestOptions): Promise<IStoreResponse>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import https from 'https';
|
|
3
|
+
import { Headers } from '../../lib/headers/Headers.js';
|
|
4
|
+
import { Http } from './Http.js';
|
|
5
|
+
import { IStoreRequestOptions, IStoreResponse } from './SdkBase.js';
|
|
6
|
+
|
|
7
|
+
export class HttpNode extends Http {
|
|
8
|
+
/**
|
|
9
|
+
* Performs the GET request.
|
|
10
|
+
*
|
|
11
|
+
* @param url The request URL
|
|
12
|
+
* @param opts The request options
|
|
13
|
+
* @returns The response info.
|
|
14
|
+
*/
|
|
15
|
+
async get(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
16
|
+
const result = await this._get(url, opts);
|
|
17
|
+
if ([301, 302, 308, 307].includes(result.status)) {
|
|
18
|
+
const loc = result.headers.get('location');
|
|
19
|
+
if (!loc) {
|
|
20
|
+
throw new Error('Expected redirection but no "location" header.')
|
|
21
|
+
}
|
|
22
|
+
const newUrl = new URL(loc, url);
|
|
23
|
+
return this.get(newUrl.toString(), opts);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private _get(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const { method='GET', headers={}, token = this.sdk.token } = opts;
|
|
31
|
+
if (token) {
|
|
32
|
+
headers.authorization = `Bearer ${token}`;
|
|
33
|
+
}
|
|
34
|
+
const isSsl = url.startsWith('https:');
|
|
35
|
+
const lib = isSsl ? https : http;
|
|
36
|
+
// console.log(`${method} ${url}`);
|
|
37
|
+
const request = lib.request(url, {
|
|
38
|
+
method,
|
|
39
|
+
headers,
|
|
40
|
+
rejectUnauthorized: false,
|
|
41
|
+
});
|
|
42
|
+
request.on('response', (response) => {
|
|
43
|
+
const ro: IStoreResponse = {
|
|
44
|
+
status: response.statusCode as number,
|
|
45
|
+
headers: new Headers(response.headers),
|
|
46
|
+
body: '',
|
|
47
|
+
};
|
|
48
|
+
response.on('data', (chunk) => {
|
|
49
|
+
ro.body += chunk;
|
|
50
|
+
});
|
|
51
|
+
response.on('end', () => resolve(ro));
|
|
52
|
+
});
|
|
53
|
+
request.on('error', (error) => reject(error));
|
|
54
|
+
request.end();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
post(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const { method='POST', headers={}, token = this.sdk.token } = opts;
|
|
61
|
+
if (token) {
|
|
62
|
+
headers.authorization = `Bearer ${token}`;
|
|
63
|
+
}
|
|
64
|
+
const isSsl = url.startsWith('https:');
|
|
65
|
+
const lib = isSsl ? https : http;
|
|
66
|
+
const request = lib.request(url, {
|
|
67
|
+
method,
|
|
68
|
+
headers,
|
|
69
|
+
});
|
|
70
|
+
request.on('response', (response) => {
|
|
71
|
+
const ro: IStoreResponse = {
|
|
72
|
+
status: response.statusCode as number,
|
|
73
|
+
headers: new Headers(response.headers),
|
|
74
|
+
body: '',
|
|
75
|
+
};
|
|
76
|
+
response.on('data', (chunk) => {
|
|
77
|
+
ro.body += chunk;
|
|
78
|
+
});
|
|
79
|
+
response.on('end', () => resolve(ro));
|
|
80
|
+
});
|
|
81
|
+
request.on('error', (error) => reject(error));
|
|
82
|
+
if (opts.body) {
|
|
83
|
+
request.write(opts.body);
|
|
84
|
+
}
|
|
85
|
+
request.end();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
patch(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
90
|
+
const options = { ...opts };
|
|
91
|
+
options.method = 'PATCH';
|
|
92
|
+
return this.post(url, options);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
delete(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
96
|
+
const options = { ...opts };
|
|
97
|
+
options.method = 'DELETE';
|
|
98
|
+
return this.post(url, options);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Http } from './Http.js';
|
|
2
|
+
import { IStoreRequestOptions, IStoreResponse } from './SdkBase.js';
|
|
3
|
+
import { Headers } from '../../lib/headers/Headers.js';
|
|
4
|
+
|
|
5
|
+
export class HttpWeb extends Http {
|
|
6
|
+
/**
|
|
7
|
+
* Performs the GET request.
|
|
8
|
+
*
|
|
9
|
+
* @param url The request URL
|
|
10
|
+
* @param opts The request options
|
|
11
|
+
* @returns The response info.
|
|
12
|
+
*/
|
|
13
|
+
async get(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
14
|
+
const { method='GET', headers={}, token = this.sdk.token } = opts;
|
|
15
|
+
if (token) {
|
|
16
|
+
headers.authorization = `Bearer ${token}`;
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line no-undef
|
|
19
|
+
const init: RequestInit = {
|
|
20
|
+
method,
|
|
21
|
+
headers,
|
|
22
|
+
redirect: 'follow',
|
|
23
|
+
};
|
|
24
|
+
const response = await fetch(url, init);
|
|
25
|
+
let body: string | undefined;
|
|
26
|
+
try {
|
|
27
|
+
body = await response.text();
|
|
28
|
+
} catch (e) {
|
|
29
|
+
// ...
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const responseHeaders = new Headers();
|
|
33
|
+
response.headers.forEach((value: string, key: string) => {
|
|
34
|
+
responseHeaders.append(key, value);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const result: IStoreResponse = {
|
|
38
|
+
status: response.status,
|
|
39
|
+
headers: responseHeaders,
|
|
40
|
+
body,
|
|
41
|
+
};
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async post(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
46
|
+
const { method='POST', headers={}, token = this.sdk.token } = opts;
|
|
47
|
+
if (token) {
|
|
48
|
+
headers.authorization = `Bearer ${token}`;
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line no-undef
|
|
51
|
+
const init: RequestInit = {
|
|
52
|
+
method,
|
|
53
|
+
headers,
|
|
54
|
+
redirect: 'follow',
|
|
55
|
+
};
|
|
56
|
+
if (opts.body) {
|
|
57
|
+
init.body = opts.body.toString();
|
|
58
|
+
}
|
|
59
|
+
const response = await fetch(url, init);
|
|
60
|
+
let body: string | undefined;
|
|
61
|
+
try {
|
|
62
|
+
body = await response.text();
|
|
63
|
+
} catch (e) {
|
|
64
|
+
// ...
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const responseHeaders = new Headers();
|
|
68
|
+
response.headers.forEach((value: string, key: string) => {
|
|
69
|
+
responseHeaders.append(key, value);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const result: IStoreResponse = {
|
|
73
|
+
status: response.status,
|
|
74
|
+
headers: responseHeaders,
|
|
75
|
+
body,
|
|
76
|
+
};
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
patch(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
81
|
+
const options: IStoreRequestOptions = { ...opts, method: 'PATCH' };
|
|
82
|
+
return this.post(url, options);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
delete(url: string, opts: IStoreRequestOptions = {}): Promise<IStoreResponse> {
|
|
86
|
+
const options: IStoreRequestOptions = { ...opts, method: 'DELETE' };
|
|
87
|
+
return this.post(url, options);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { JsonPatch } from 'json8-patch';
|
|
2
|
+
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
|
|
3
|
+
import { RouteBuilder } from './RouteBuilder.js';
|
|
4
|
+
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
5
|
+
import { HttpProject, IHttpProject, Kind as HttpProjectKind } from '../../models/HttpProject.js';
|
|
6
|
+
|
|
7
|
+
export class ProjectsSdk extends SdkBase {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a project in a user space.
|
|
10
|
+
*
|
|
11
|
+
* @param space The user space key
|
|
12
|
+
* @param project THe project to create
|
|
13
|
+
* @returns The key of the created project.
|
|
14
|
+
*/
|
|
15
|
+
async create(space: string, project: IHttpProject | HttpProject): Promise<string> {
|
|
16
|
+
const { token } = this.sdk;
|
|
17
|
+
const url = this.sdk.getUrl(RouteBuilder.spaceProjects(space));
|
|
18
|
+
const body = JSON.stringify(project);
|
|
19
|
+
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
20
|
+
this.inspectCommonStatusCodes(result.status);
|
|
21
|
+
const E_PREFIX = 'Unable to create a project. ';
|
|
22
|
+
if (result.status !== 204) {
|
|
23
|
+
this.logInvalidResponse(result);
|
|
24
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
25
|
+
}
|
|
26
|
+
const location = result.headers.get('location');
|
|
27
|
+
if (!location) {
|
|
28
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
|
|
29
|
+
}
|
|
30
|
+
const id = location.split('/').pop();
|
|
31
|
+
return id as string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Reads a project definition from the store.
|
|
36
|
+
* @param space The user space key
|
|
37
|
+
* @param project The project key
|
|
38
|
+
* @returns The definition of the project.
|
|
39
|
+
*/
|
|
40
|
+
async read(space: string, project: string): Promise<IHttpProject> {
|
|
41
|
+
const { token } = this.sdk;
|
|
42
|
+
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
43
|
+
const result = await this.sdk.http.get(url.toString(), { token });
|
|
44
|
+
this.inspectCommonStatusCodes(result.status);
|
|
45
|
+
const E_PREFIX = 'Unable to read a project. ';
|
|
46
|
+
if (result.status !== 200) {
|
|
47
|
+
this.logInvalidResponse(result);
|
|
48
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
49
|
+
}
|
|
50
|
+
if (!result.body) {
|
|
51
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
52
|
+
}
|
|
53
|
+
let data: IHttpProject;
|
|
54
|
+
try {
|
|
55
|
+
data = JSON.parse(result.body);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
58
|
+
}
|
|
59
|
+
if (data.kind !== HttpProjectKind) {
|
|
60
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
61
|
+
}
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Lists projects in the space
|
|
67
|
+
*
|
|
68
|
+
* @param space The user space key
|
|
69
|
+
* @param options Optional query options.
|
|
70
|
+
*/
|
|
71
|
+
async list(space: string, options?: IListOptions): Promise<IListResponse> {
|
|
72
|
+
const { token } = this.sdk;
|
|
73
|
+
const url = this.sdk.getUrl(RouteBuilder.spaceProjects(space));
|
|
74
|
+
this.sdk.appendListOptions(url, options);
|
|
75
|
+
const result = await this.sdk.http.get(url.toString(), { token });
|
|
76
|
+
this.inspectCommonStatusCodes(result.status);
|
|
77
|
+
const E_PREFIX = 'Unable to list projects. ';
|
|
78
|
+
if (result.status !== 200) {
|
|
79
|
+
this.logInvalidResponse(result);
|
|
80
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
81
|
+
}
|
|
82
|
+
if (!result.body) {
|
|
83
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
84
|
+
}
|
|
85
|
+
let data: IListResponse;
|
|
86
|
+
try {
|
|
87
|
+
data = JSON.parse(result.body);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
90
|
+
}
|
|
91
|
+
if (!Array.isArray(data.data)) {
|
|
92
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Deletes a project form the store.
|
|
99
|
+
*
|
|
100
|
+
* @param space The key of the parent space.
|
|
101
|
+
* @param project The key of the project to delete.
|
|
102
|
+
*/
|
|
103
|
+
async delete(space: string, project: string): Promise<void> {
|
|
104
|
+
const { token } = this.sdk;
|
|
105
|
+
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
106
|
+
const result = await this.sdk.http.delete(url.toString(), { token });
|
|
107
|
+
this.inspectCommonStatusCodes(result.status);
|
|
108
|
+
const E_PREFIX = 'Unable to delete a project. ';
|
|
109
|
+
if (result.status !== 204) {
|
|
110
|
+
this.logInvalidResponse(result);
|
|
111
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Patches a project in the store.
|
|
117
|
+
* @param space The key of the parent user space
|
|
118
|
+
* @param project The key of project to patch.
|
|
119
|
+
* @param value The JSON patch to be processed.
|
|
120
|
+
* @returns The JSON patch to revert the change using the `json8-patch` library
|
|
121
|
+
*/
|
|
122
|
+
async patch(space: string, project: string, value: JsonPatch): Promise<JsonPatch> {
|
|
123
|
+
const { token } = this.sdk;
|
|
124
|
+
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
125
|
+
const body = JSON.stringify(value);
|
|
126
|
+
const result = await this.sdk.http.patch(url.toString(), { token, body });
|
|
127
|
+
this.inspectCommonStatusCodes(result.status);
|
|
128
|
+
const E_PREFIX = 'Unable to patch a project. ';
|
|
129
|
+
if (result.status !== 200) {
|
|
130
|
+
this.logInvalidResponse(result);
|
|
131
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
132
|
+
}
|
|
133
|
+
if (!result.body) {
|
|
134
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
135
|
+
}
|
|
136
|
+
let data: any;
|
|
137
|
+
try {
|
|
138
|
+
data = JSON.parse(result.body);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
141
|
+
}
|
|
142
|
+
if (!data.revert) {
|
|
143
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
144
|
+
}
|
|
145
|
+
return data.revert as JsonPatch;
|
|
146
|
+
}
|
|
147
|
+
}
|