@api-client/core 0.6.30 → 0.7.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 +6 -14
- package/build/browser.js +11 -16
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +8 -20
- package/build/index.js +13 -25
- package/build/index.js.map +1 -1
- package/build/src/amf/ApiSchemaValues.d.ts +2 -0
- package/build/src/amf/ApiSchemaValues.js +29 -23
- package/build/src/amf/ApiSchemaValues.js.map +1 -1
- package/build/src/authorization/lib/Utils.d.ts +1 -1
- package/build/src/cookies/CookieJar.d.ts +23 -0
- package/build/src/cookies/CookieJar.js +3 -0
- package/build/src/cookies/CookieJar.js.map +1 -0
- package/build/src/cookies/CookieParser.d.ts +67 -0
- package/build/src/cookies/CookieParser.js +316 -0
- package/build/src/cookies/CookieParser.js.map +1 -0
- package/build/src/cookies/InMemoryCookieJar.d.ts +12 -0
- package/build/src/cookies/InMemoryCookieJar.js +68 -0
- package/build/src/cookies/InMemoryCookieJar.js.map +1 -0
- package/build/src/cookies/Punycode.d.ts +12 -0
- package/build/src/cookies/Punycode.js +124 -0
- package/build/src/cookies/Punycode.js.map +1 -0
- package/build/src/data/RequestDataExtractor.d.ts +8 -7
- package/build/src/data/RequestDataExtractor.js +8 -10
- package/build/src/data/RequestDataExtractor.js.map +1 -1
- package/build/src/events/CustomEvent.js +5 -0
- package/build/src/events/CustomEvent.js.map +1 -1
- package/build/src/events/EventTypes.d.ts +43 -43
- package/build/src/events/amf/AmfEventTypes.d.ts +4 -4
- package/build/src/events/authorization/AuthorizationEventTypes.d.ts +4 -4
- package/build/src/events/cookies/CookieEventTypes.d.ts +9 -9
- package/build/src/events/encryption/EncryptionEventTypes.d.ts +2 -2
- package/build/src/events/environment/EnvironmentEventTypes.d.ts +1 -1
- package/build/src/events/models/ModelEventTypes.d.ts +7 -7
- package/build/src/events/process/ProcessEventTypes.d.ts +3 -3
- package/build/src/events/reporting/ReportingEventTypes.d.ts +1 -1
- package/build/src/events/telemetry/TelemetryEventTypes.d.ts +6 -6
- package/build/src/events/transport/TransportEventTypes.d.ts +6 -6
- package/build/src/events/transport/TransportEvents.d.ts +2 -2
- package/build/src/mocking/ProjectMock.d.ts +3 -2
- package/build/src/mocking/ProjectMock.js +3 -3
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/App.d.ts +36 -0
- package/build/src/mocking/lib/App.js +70 -0
- package/build/src/mocking/lib/App.js.map +1 -0
- package/build/src/models/{arc/ArcProject.d.ts → AppProject.d.ts} +296 -134
- package/build/src/models/{arc/ArcProject.js → AppProject.js} +436 -79
- package/build/src/models/AppProject.js.map +1 -0
- package/build/src/models/AppRequest.d.ts +69 -0
- package/build/src/models/{arc/ArcHttpRequest.js → AppRequest.js} +53 -17
- package/build/src/models/AppRequest.js.map +1 -0
- package/build/src/models/ClientCertificate.d.ts +2 -2
- package/build/src/models/Environment.d.ts +8 -1
- package/build/src/models/Environment.js +21 -0
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/HostRule.d.ts +2 -2
- package/build/src/models/HttpCookie.d.ts +63 -12
- package/build/src/models/HttpCookie.js +178 -44
- package/build/src/models/HttpCookie.js.map +1 -1
- package/build/src/models/HttpHistory.d.ts +8 -3
- package/build/src/models/HttpHistory.js +3 -3
- package/build/src/models/HttpHistory.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +34 -1
- package/build/src/models/HttpProject.js +104 -8
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts +2 -0
- package/build/src/models/ProjectFolder.js +14 -0
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectItem.d.ts +2 -0
- package/build/src/models/ProjectItem.js +20 -0
- package/build/src/models/ProjectItem.js.map +1 -1
- package/build/src/models/ProjectParent.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts +3 -2
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/Property.d.ts +2 -2
- package/build/src/models/Property.js +2 -2
- package/build/src/models/Property.js.map +1 -1
- package/build/src/models/Request.d.ts +16 -8
- package/build/src/models/Request.js +20 -15
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestAuthorization.js.map +1 -1
- package/build/src/models/RequestUiMeta.d.ts +0 -14
- package/build/src/models/RequestUiMeta.js +1 -10
- package/build/src/models/RequestUiMeta.js.map +1 -1
- package/build/src/models/Server.d.ts +1 -2
- package/build/src/models/Server.js.map +1 -1
- package/build/src/models/http-actions/HttpActions.d.ts +256 -0
- package/build/src/models/http-actions/HttpActions.js +46 -0
- package/build/src/models/http-actions/HttpActions.js.map +1 -0
- package/build/src/models/http-actions/LegacyTranslator.d.ts +17 -0
- package/build/src/models/http-actions/LegacyTranslator.js +222 -0
- package/build/src/models/http-actions/LegacyTranslator.js.map +1 -0
- package/build/src/models/store/Backend.d.ts +136 -1
- package/build/src/models/store/File.d.ts +1 -1
- package/build/src/models/store/File.js +2 -0
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/User.d.ts +3 -3
- package/build/src/runtime/http-engine/CoreEngine.d.ts +2 -0
- package/build/src/runtime/http-engine/CoreEngine.js +1 -0
- package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
- package/build/src/runtime/http-engine/HttpEngine.d.ts +13 -0
- package/build/src/runtime/http-engine/HttpEngine.js +39 -31
- package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
- package/build/src/runtime/{actions/ConditionRunner.d.ts → http-runner/ConditionCheck.d.ts} +2 -2
- package/build/src/runtime/{actions/ConditionRunner.js → http-runner/ConditionCheck.js} +2 -2
- package/build/src/runtime/http-runner/ConditionCheck.js.map +1 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +62 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.js +217 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -0
- package/build/src/runtime/{node/RequestFactory.d.ts → http-runner/HttpRequestRunner.d.ts} +40 -54
- package/build/src/runtime/http-runner/HttpRequestRunner.js +316 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.d.ts +25 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.js +2 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.js.map +1 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.d.ts +56 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.js +143 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.js.map +1 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.d.ts +24 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.js +65 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.js.map +1 -0
- package/build/src/runtime/node/InteropInterfaces.d.ts +21 -6
- package/build/src/runtime/node/ProjectParallelRunner.js +3 -1
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +24 -10
- package/build/src/runtime/node/ProjectRequestRunner.js +116 -45
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts +5 -7
- package/build/src/runtime/node/ProjectRunner.js +30 -14
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunnerWorker.js +3 -0
- package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
- package/build/src/runtime/reporters/Reporter.d.ts +5 -0
- package/build/src/runtime/reporters/Reporter.js.map +1 -1
- package/build/src/runtime/store/AppSdk.d.ts +185 -0
- package/build/src/runtime/store/AppSdk.js +704 -0
- package/build/src/runtime/store/AppSdk.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.js +4 -4
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/HistorySdk.js +2 -2
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +17 -2
- package/build/src/runtime/store/RouteBuilder.js +60 -3
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/Sdk.d.ts +5 -0
- package/build/src/runtime/store/Sdk.js +5 -0
- package/build/src/runtime/store/Sdk.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.js +1 -1
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/UsersSdk.js +1 -1
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/package.json +2 -2
- package/src/amf/ApiSchemaValues.ts +41 -33
- package/src/cookies/CookieJar.ts +26 -0
- package/src/cookies/CookieParser.ts +327 -0
- package/src/cookies/InMemoryCookieJar.ts +70 -0
- package/src/cookies/Punycode.ts +133 -0
- package/src/data/RequestDataExtractor.ts +14 -15
- package/src/events/CustomEvent.ts +4 -0
- package/src/mocking/ProjectMock.ts +4 -3
- package/src/mocking/lib/App.ts +101 -0
- package/src/models/{arc/ArcProject.ts → AppProject.ts} +671 -225
- package/src/models/AppRequest.ts +176 -0
- package/src/models/ClientCertificate.ts +2 -2
- package/src/models/Environment.ts +24 -2
- package/src/models/HostRule.ts +2 -2
- package/src/models/HttpCookie.ts +210 -48
- package/src/models/HttpHistory.ts +12 -5
- package/src/models/HttpProject.ts +113 -10
- package/src/models/ProjectFolder.ts +16 -0
- package/src/models/ProjectItem.ts +18 -0
- package/src/models/ProjectParent.ts +4 -1
- package/src/models/ProjectRequest.ts +4 -3
- package/src/models/Property.ts +4 -4
- package/src/models/Request.ts +29 -19
- package/src/models/RequestAuthorization.ts +4 -4
- package/src/models/RequestUiMeta.ts +1 -21
- package/src/models/Server.ts +1 -2
- package/src/models/http-actions/HttpActions.ts +270 -0
- package/src/models/http-actions/LegacyTranslator.ts +223 -0
- package/src/models/store/Backend.ts +148 -2
- package/src/models/store/File.ts +3 -1
- package/src/models/store/User.ts +3 -3
- package/src/runtime/http-engine/CoreEngine.ts +3 -2
- package/src/runtime/http-engine/HttpEngine.ts +48 -30
- package/src/runtime/{actions/ConditionRunner.ts → http-runner/ConditionCheck.ts} +3 -3
- package/src/runtime/http-runner/HttpFlowRunner.ts +232 -0
- package/src/runtime/http-runner/HttpRequestRunner.ts +353 -0
- package/src/runtime/http-runner/HttpRuntimeEnvironment.ts +27 -0
- package/src/runtime/http-runner/RequestAuthorizationProcessor.ts +144 -0
- package/src/runtime/http-runner/RequestCookiesProcessor.ts +74 -0
- package/src/runtime/node/InteropInterfaces.ts +24 -6
- package/src/runtime/node/ProjectParallelRunner.ts +4 -2
- package/src/runtime/node/ProjectRequestRunner.ts +130 -60
- package/src/runtime/node/ProjectRunner.ts +37 -22
- package/src/runtime/node/ProjectRunnerWorker.ts +3 -0
- package/src/runtime/reporters/Reporter.ts +5 -0
- package/src/runtime/store/AppSdk.ts +709 -0
- package/src/runtime/store/FilesSdk.ts +4 -4
- package/src/runtime/store/HistorySdk.ts +2 -2
- package/src/runtime/store/RouteBuilder.ts +75 -3
- package/src/runtime/store/Sdk.ts +6 -0
- package/src/runtime/store/SharedSdk.ts +1 -1
- package/src/runtime/store/UsersSdk.ts +1 -1
- package/build/src/lib/cookies/Cookie.d.ts +0 -123
- package/build/src/lib/cookies/Cookie.js +0 -257
- package/build/src/lib/cookies/Cookie.js.map +0 -1
- package/build/src/lib/cookies/Cookies.d.ts +0 -90
- package/build/src/lib/cookies/Cookies.js +0 -310
- package/build/src/lib/cookies/Cookies.js.map +0 -1
- package/build/src/lib/cookies/Utils.d.ts +0 -47
- package/build/src/lib/cookies/Utils.js +0 -163
- package/build/src/lib/cookies/Utils.js.map +0 -1
- package/build/src/mocking/lib/Arc.d.ts +0 -10
- package/build/src/mocking/lib/Arc.js +0 -31
- package/build/src/mocking/lib/Arc.js.map +0 -1
- package/build/src/models/RequestActions.d.ts +0 -65
- package/build/src/models/RequestActions.js +0 -114
- package/build/src/models/RequestActions.js.map +0 -1
- package/build/src/models/actions/Action.d.ts +0 -75
- package/build/src/models/actions/Action.js +0 -188
- package/build/src/models/actions/Action.js.map +0 -1
- package/build/src/models/actions/ActionView.d.ts +0 -15
- package/build/src/models/actions/ActionView.js +0 -33
- package/build/src/models/actions/ActionView.js.map +0 -1
- package/build/src/models/actions/Condition.d.ts +0 -81
- package/build/src/models/actions/Condition.js +0 -185
- package/build/src/models/actions/Condition.js.map +0 -1
- package/build/src/models/actions/ConditionView.d.ts +0 -17
- package/build/src/models/actions/ConditionView.js +0 -34
- package/build/src/models/actions/ConditionView.js.map +0 -1
- package/build/src/models/actions/Enums.d.ts +0 -26
- package/build/src/models/actions/Enums.js +0 -31
- package/build/src/models/actions/Enums.js.map +0 -1
- package/build/src/models/actions/RunnableAction.d.ts +0 -59
- package/build/src/models/actions/RunnableAction.js +0 -106
- package/build/src/models/actions/RunnableAction.js.map +0 -1
- package/build/src/models/actions/runnable/DeleteCookieAction.d.ts +0 -44
- package/build/src/models/actions/runnable/DeleteCookieAction.js +0 -92
- package/build/src/models/actions/runnable/DeleteCookieAction.js.map +0 -1
- package/build/src/models/actions/runnable/Runnable.d.ts +0 -8
- package/build/src/models/actions/runnable/Runnable.js +0 -4
- package/build/src/models/actions/runnable/Runnable.js.map +0 -1
- package/build/src/models/actions/runnable/SetCookieAction.d.ts +0 -87
- package/build/src/models/actions/runnable/SetCookieAction.js +0 -176
- package/build/src/models/actions/runnable/SetCookieAction.js.map +0 -1
- package/build/src/models/actions/runnable/SetVariableAction.d.ts +0 -31
- package/build/src/models/actions/runnable/SetVariableAction.js +0 -63
- package/build/src/models/actions/runnable/SetVariableAction.js.map +0 -1
- package/build/src/models/actions/runnable/index.d.ts +0 -7
- package/build/src/models/actions/runnable/index.js +0 -2
- package/build/src/models/actions/runnable/index.js.map +0 -1
- package/build/src/models/arc/ArcHttpRequest.d.ts +0 -40
- package/build/src/models/arc/ArcHttpRequest.js.map +0 -1
- package/build/src/models/arc/ArcProject.js.map +0 -1
- package/build/src/runtime/actions/ActionRunner.d.ts +0 -17
- package/build/src/runtime/actions/ActionRunner.js +0 -74
- package/build/src/runtime/actions/ActionRunner.js.map +0 -1
- package/build/src/runtime/actions/ConditionRunner.js.map +0 -1
- package/build/src/runtime/actions/RunnableCondition.d.ts +0 -27
- package/build/src/runtime/actions/RunnableCondition.js +0 -50
- package/build/src/runtime/actions/RunnableCondition.js.map +0 -1
- package/build/src/runtime/actions/runnable/ActionRunnable.d.ts +0 -13
- package/build/src/runtime/actions/runnable/ActionRunnable.js +0 -13
- package/build/src/runtime/actions/runnable/ActionRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.d.ts +0 -7
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.js +0 -36
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/SetCookieRunnable.d.ts +0 -10
- package/build/src/runtime/actions/runnable/SetCookieRunnable.js +0 -89
- package/build/src/runtime/actions/runnable/SetCookieRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/SetVariableRunnable.d.ts +0 -10
- package/build/src/runtime/actions/runnable/SetVariableRunnable.js +0 -49
- package/build/src/runtime/actions/runnable/SetVariableRunnable.js.map +0 -1
- package/build/src/runtime/modules/BasicAuthCache.d.ts +0 -39
- package/build/src/runtime/modules/BasicAuthCache.js +0 -122
- package/build/src/runtime/modules/BasicAuthCache.js.map +0 -1
- package/build/src/runtime/modules/ExecutionResponse.d.ts +0 -4
- package/build/src/runtime/modules/ExecutionResponse.js +0 -6
- package/build/src/runtime/modules/ExecutionResponse.js.map +0 -1
- package/build/src/runtime/modules/ModulesRegistry.d.ts +0 -93
- package/build/src/runtime/modules/ModulesRegistry.js +0 -69
- package/build/src/runtime/modules/ModulesRegistry.js.map +0 -1
- package/build/src/runtime/modules/RequestAuthorization.d.ts +0 -6
- package/build/src/runtime/modules/RequestAuthorization.js +0 -110
- package/build/src/runtime/modules/RequestAuthorization.js.map +0 -1
- package/build/src/runtime/modules/RequestCookies.d.ts +0 -17
- package/build/src/runtime/modules/RequestCookies.js +0 -134
- package/build/src/runtime/modules/RequestCookies.js.map +0 -1
- package/build/src/runtime/node/RequestFactory.js +0 -406
- package/build/src/runtime/node/RequestFactory.js.map +0 -1
- package/build/src/runtime/node/VariablesStore.d.ts +0 -9
- package/build/src/runtime/node/VariablesStore.js +0 -19
- package/build/src/runtime/node/VariablesStore.js.map +0 -1
- package/src/lib/cookies/Cookie.ts +0 -312
- package/src/lib/cookies/Cookies.ts +0 -326
- package/src/lib/cookies/Utils.ts +0 -168
- package/src/mocking/lib/Arc.ts +0 -34
- package/src/models/RequestActions.ts +0 -161
- package/src/models/actions/Action.ts +0 -213
- package/src/models/actions/ActionView.ts +0 -40
- package/src/models/actions/Condition.ts +0 -207
- package/src/models/actions/ConditionView.ts +0 -42
- package/src/models/actions/Enums.ts +0 -29
- package/src/models/actions/RunnableAction.ts +0 -144
- package/src/models/actions/runnable/DeleteCookieAction.ts +0 -113
- package/src/models/actions/runnable/Runnable.ts +0 -9
- package/src/models/actions/runnable/SetCookieAction.ts +0 -216
- package/src/models/actions/runnable/SetVariableAction.ts +0 -81
- package/src/models/arc/ArcHttpRequest.ts +0 -129
- package/src/models/arc/readme.md +0 -3
- package/src/runtime/actions/ActionRunner.ts +0 -83
- package/src/runtime/actions/RunnableCondition.ts +0 -56
- package/src/runtime/actions/runnable/ActionRunnable.ts +0 -19
- package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +0 -39
- package/src/runtime/actions/runnable/SetCookieRunnable.ts +0 -92
- package/src/runtime/actions/runnable/SetVariableRunnable.ts +0 -53
- package/src/runtime/modules/BasicAuthCache.ts +0 -129
- package/src/runtime/modules/ExecutionResponse.ts +0 -4
- package/src/runtime/modules/ModulesRegistry.ts +0 -136
- package/src/runtime/modules/RequestAuthorization.ts +0 -106
- package/src/runtime/modules/RequestCookies.ts +0 -146
- package/src/runtime/node/RequestFactory.ts +0 -432
- package/src/runtime/node/VariablesStore.ts +0 -25
|
@@ -4,18 +4,36 @@
|
|
|
4
4
|
/* eslint-disable max-classes-per-file */
|
|
5
5
|
// import { ARCHistoryRequest, ARCSavedRequest } from "@api-client/core/build/legacy.js";
|
|
6
6
|
|
|
7
|
-
import v4 from "
|
|
8
|
-
import { HttpRequest, IHttpRequest } from "
|
|
9
|
-
import { IRequest, Request } from "
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
7
|
+
import v4 from "../lib/uuid.js";
|
|
8
|
+
import { HttpRequest, IHttpRequest } from "./HttpRequest.js";
|
|
9
|
+
import { IRequest, Request } from "./Request.js";
|
|
10
|
+
import { Environment, IEnvironment, Kind as EnvironmentKind } from './Environment.js';
|
|
11
|
+
import { IThing, Thing } from "./Thing.js";
|
|
12
|
+
import { ARCHistoryRequest, ARCSavedRequest } from "./legacy/request/ArcRequest.js";
|
|
13
|
+
import { ARCProject } from "./legacy/models/ArcLegacyProject.js";
|
|
14
|
+
import { Certificate, HttpCertificate } from "./ClientCertificate.js";
|
|
15
|
+
import { ICCAuthorization } from "./Authorization.js";
|
|
16
|
+
import { IProjectRequestIterator } from "./HttpProject.js";
|
|
13
17
|
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
18
|
+
export const AppProjectKind = 'Core#AppProject';
|
|
19
|
+
export const AppProjectFolderKind = 'Core#AppProjectFolder';
|
|
20
|
+
export const AppProjectRequestKind = 'Core#AppProjectRequest';
|
|
17
21
|
|
|
18
|
-
export interface
|
|
22
|
+
export interface IAppProjectItemOptions {
|
|
23
|
+
/**
|
|
24
|
+
* The parent folder to add the item to.
|
|
25
|
+
*/
|
|
26
|
+
parent?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IAppProjectItemCreateOptions extends IAppProjectItemOptions {
|
|
30
|
+
/**
|
|
31
|
+
* The position at which to add the item.
|
|
32
|
+
*/
|
|
33
|
+
index?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IAppProjectRequestCloneOptions {
|
|
19
37
|
/**
|
|
20
38
|
* By default it revalidates (re-creates) keys in the request.
|
|
21
39
|
* Set this to true to not make any changes to the keys.
|
|
@@ -29,14 +47,14 @@ export interface IArcRequestCloneOptions {
|
|
|
29
47
|
withoutAttach?: boolean;
|
|
30
48
|
}
|
|
31
49
|
|
|
32
|
-
export interface
|
|
50
|
+
export interface IAppProjectFolderAddOptions {
|
|
33
51
|
/**
|
|
34
52
|
* Optionally the position at which to add the request into the list of items.
|
|
35
53
|
*/
|
|
36
54
|
index?: number;
|
|
37
55
|
}
|
|
38
56
|
|
|
39
|
-
export interface
|
|
57
|
+
export interface IAppProjectFolderCloneOptions {
|
|
40
58
|
/**
|
|
41
59
|
* By default it clones the folder with all requests in it.
|
|
42
60
|
* Set this to `true` to skip copying the requests along with the folder.
|
|
@@ -53,7 +71,7 @@ export interface IArcFolderCloneOptions {
|
|
|
53
71
|
* is put into the project root rather than the parent folder (as it would when cloning
|
|
54
72
|
* a folder inside the same project).
|
|
55
73
|
*/
|
|
56
|
-
targetProject?:
|
|
74
|
+
targetProject?: AppProject;
|
|
57
75
|
/**
|
|
58
76
|
* The **key** of the target folder.
|
|
59
77
|
*
|
|
@@ -63,23 +81,19 @@ export interface IArcFolderCloneOptions {
|
|
|
63
81
|
targetFolder?: string;
|
|
64
82
|
}
|
|
65
83
|
|
|
66
|
-
export interface
|
|
84
|
+
export interface IAppProjectFolderCreateOptions extends IAppProjectItemOptions {
|
|
67
85
|
/**
|
|
68
86
|
* Ignores the operation when the folder with the same name already exists.
|
|
69
87
|
* This command can be used used to ensure that the folder exists.
|
|
70
88
|
*/
|
|
71
89
|
skipExisting?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* The id of the parent folder. When not set it adds the folder to the project root.
|
|
74
|
-
*/
|
|
75
|
-
parent?: string;
|
|
76
90
|
/**
|
|
77
91
|
* Optionally the position at which to add the folder into the list of items.
|
|
78
92
|
*/
|
|
79
93
|
index?: number;
|
|
80
94
|
}
|
|
81
95
|
|
|
82
|
-
export interface
|
|
96
|
+
export interface IAppProjectFolderSearchOptions {
|
|
83
97
|
/**
|
|
84
98
|
* When set it searches for a folder using keys only.
|
|
85
99
|
* By default it searches for a key and the name.
|
|
@@ -87,25 +101,21 @@ export interface IArcFolderSearchOptions {
|
|
|
87
101
|
keyOnly?: boolean;
|
|
88
102
|
}
|
|
89
103
|
|
|
90
|
-
export interface
|
|
104
|
+
export interface IAppProjectFolderDeleteOptions {
|
|
91
105
|
/**
|
|
92
106
|
* When set it won't throw an error when the folder is not found in the project.
|
|
93
107
|
*/
|
|
94
108
|
safe?: boolean;
|
|
95
109
|
}
|
|
96
110
|
|
|
97
|
-
export interface
|
|
98
|
-
/**
|
|
99
|
-
* The id of the parent folder. When not set it adds the request to the project root.
|
|
100
|
-
*/
|
|
101
|
-
parent?: string;
|
|
111
|
+
export interface IAppProjectRequestAddOptions extends IAppProjectItemOptions {
|
|
102
112
|
/**
|
|
103
113
|
* Optionally the position at which to add the request into the list of items.
|
|
104
114
|
*/
|
|
105
115
|
index?: number;
|
|
106
116
|
}
|
|
107
117
|
|
|
108
|
-
export interface
|
|
118
|
+
export interface IAppProjectRequestSearchOptions {
|
|
109
119
|
/**
|
|
110
120
|
* When set it searches for a request using keys only.
|
|
111
121
|
* By default it searches for a key and the name.
|
|
@@ -113,33 +123,28 @@ export interface IArcRequestSearchOptions {
|
|
|
113
123
|
keyOnly?: boolean;
|
|
114
124
|
}
|
|
115
125
|
|
|
116
|
-
export interface
|
|
126
|
+
export interface IAppProjectRequestDeleteOptions {
|
|
117
127
|
/**
|
|
118
128
|
* When set it won't throw an error when the request is not found in the project.
|
|
119
129
|
*/
|
|
120
130
|
safe?: boolean;
|
|
121
131
|
}
|
|
122
132
|
|
|
123
|
-
export interface
|
|
133
|
+
export interface IAppProjectProjectMoveOptions extends IAppProjectItemOptions {
|
|
124
134
|
/**
|
|
125
135
|
* The position at which to insert the object in the destination. BY default it adds the object at the end.
|
|
126
136
|
*/
|
|
127
137
|
index?: number;
|
|
128
|
-
/**
|
|
129
|
-
* The name or the key of the parent folder to move the item into.
|
|
130
|
-
* When not set it moves the item to the project's root.
|
|
131
|
-
*/
|
|
132
|
-
parent?: string;
|
|
133
138
|
}
|
|
134
139
|
|
|
135
|
-
export interface
|
|
140
|
+
export interface IAppProjectFolderListOptions {
|
|
136
141
|
/**
|
|
137
142
|
* Folder name or key to list folders for.
|
|
138
143
|
*/
|
|
139
144
|
folder?: string;
|
|
140
145
|
}
|
|
141
146
|
|
|
142
|
-
export interface
|
|
147
|
+
export interface IAppProjectProjectCloneOptions {
|
|
143
148
|
/**
|
|
144
149
|
* By default it revalidates (re-creates) keys in the request.
|
|
145
150
|
* Set this to true to not make any changes to the keys.
|
|
@@ -147,49 +152,72 @@ export interface IArcProjectCloneOptions {
|
|
|
147
152
|
withoutRevalidate?: boolean;
|
|
148
153
|
}
|
|
149
154
|
|
|
150
|
-
export interface
|
|
151
|
-
|
|
155
|
+
export interface IAppProjectEnvironmentCreateOptions extends IAppProjectItemOptions {
|
|
156
|
+
/**
|
|
157
|
+
* The position at which to add the item.
|
|
158
|
+
*/
|
|
159
|
+
index?: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface IAppProjectReadEnvironmentOptions extends IAppProjectItemOptions {
|
|
163
|
+
/**
|
|
164
|
+
* The name or the key of the environment to select.
|
|
165
|
+
*
|
|
166
|
+
* When the name is not specified it selects:
|
|
167
|
+
* - the first environment from the project, if any
|
|
168
|
+
* - any parent folder's first environment to the requested folder, if any (if parent is set)
|
|
169
|
+
* - the requested folder's first environment, if any (if parent is set)
|
|
170
|
+
*/
|
|
171
|
+
nameOrKey?: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface IAppProjectRequest extends IRequest {
|
|
175
|
+
kind: typeof AppProjectRequestKind;
|
|
152
176
|
key: string;
|
|
153
177
|
}
|
|
154
178
|
|
|
155
|
-
export interface
|
|
156
|
-
kind: typeof
|
|
179
|
+
export interface IAppProjectItem {
|
|
180
|
+
kind: typeof AppProjectFolderKind | typeof AppProjectRequestKind | typeof EnvironmentKind;
|
|
157
181
|
key: string;
|
|
158
182
|
}
|
|
159
183
|
|
|
160
|
-
export interface
|
|
184
|
+
export interface IAppProjectDefinitions {
|
|
161
185
|
/**
|
|
162
186
|
* The list of all folders defined in the project.
|
|
163
187
|
*/
|
|
164
|
-
folders?:
|
|
188
|
+
folders?: IAppProjectParent[];
|
|
165
189
|
/**
|
|
166
190
|
* The list of all requests defined in the project.
|
|
167
191
|
*/
|
|
168
|
-
requests?:
|
|
192
|
+
requests?: IAppProjectRequest[];
|
|
193
|
+
environments?: IEnvironment[];
|
|
194
|
+
certificates?: HttpCertificate[];
|
|
169
195
|
}
|
|
170
196
|
|
|
171
|
-
export interface
|
|
197
|
+
export interface AppProjectDefinitions {
|
|
172
198
|
/**
|
|
173
199
|
* The list of all folders defined in the project.
|
|
174
200
|
*/
|
|
175
|
-
folders:
|
|
201
|
+
folders: AppProjectFolder[];
|
|
176
202
|
/**
|
|
177
203
|
* The list of all requests defined in the project.
|
|
178
204
|
*/
|
|
179
|
-
requests:
|
|
205
|
+
requests: AppProjectRequest[];
|
|
206
|
+
environments: Environment[];
|
|
207
|
+
certificates: Certificate[];
|
|
180
208
|
}
|
|
181
209
|
|
|
182
|
-
|
|
183
|
-
|
|
210
|
+
/**
|
|
211
|
+
* An app project is similar to the HttpProject but stored for a single application
|
|
212
|
+
* and has no sharing options. The AppProject can be upgraded to an HttpProject.
|
|
213
|
+
*/
|
|
214
|
+
export interface IAppProject extends IAppProjectParent {
|
|
215
|
+
definitions: IAppProjectDefinitions;
|
|
184
216
|
}
|
|
185
217
|
|
|
186
|
-
export interface
|
|
218
|
+
export interface IAppProjectParent {
|
|
187
219
|
key: string;
|
|
188
|
-
|
|
189
|
-
* The auto-generated key for the folder object.
|
|
190
|
-
* For the project root this is the same as the `_id`.
|
|
191
|
-
*/
|
|
192
|
-
kind: typeof ArcProjectKind | typeof ArcProjectFolderKind;
|
|
220
|
+
kind: typeof AppProjectKind | typeof AppProjectFolderKind;
|
|
193
221
|
/**
|
|
194
222
|
* Folder meta
|
|
195
223
|
*/
|
|
@@ -199,7 +227,7 @@ export interface IProjectParent {
|
|
|
199
227
|
* It is an ordered list of requests and folders.
|
|
200
228
|
* The actual definition is kept in the root's `definitions`.
|
|
201
229
|
*/
|
|
202
|
-
items:
|
|
230
|
+
items: IAppProjectItem[];
|
|
203
231
|
/**
|
|
204
232
|
* Timestamp when the project was last updated.
|
|
205
233
|
*/
|
|
@@ -210,8 +238,8 @@ export interface IProjectParent {
|
|
|
210
238
|
created?: number;
|
|
211
239
|
}
|
|
212
240
|
|
|
213
|
-
export class
|
|
214
|
-
kind =
|
|
241
|
+
export class AppProjectRequest extends Request {
|
|
242
|
+
kind = AppProjectRequestKind;
|
|
215
243
|
|
|
216
244
|
/**
|
|
217
245
|
* The identifier of the request.
|
|
@@ -221,7 +249,7 @@ export class ArcProjectRequest extends Request {
|
|
|
221
249
|
/**
|
|
222
250
|
* A reference to the top level project object.
|
|
223
251
|
*/
|
|
224
|
-
project:
|
|
252
|
+
project: AppProject;
|
|
225
253
|
|
|
226
254
|
/**
|
|
227
255
|
* Creates a project request from an URL.
|
|
@@ -230,14 +258,14 @@ export class ArcProjectRequest extends Request {
|
|
|
230
258
|
* @param url The Request URL. This is required.
|
|
231
259
|
* @param project The parent project.
|
|
232
260
|
*/
|
|
233
|
-
static fromUrl(url: string, project?:
|
|
261
|
+
static fromUrl(url: string, project?: AppProject): AppProjectRequest {
|
|
234
262
|
if (!project) {
|
|
235
263
|
throw new Error(`The project is required.`);
|
|
236
264
|
}
|
|
237
265
|
const now: number = Date.now();
|
|
238
|
-
const request = new
|
|
266
|
+
const request = new AppProjectRequest(project, {
|
|
239
267
|
key: v4(),
|
|
240
|
-
kind:
|
|
268
|
+
kind: AppProjectRequestKind,
|
|
241
269
|
created: now,
|
|
242
270
|
updated: now,
|
|
243
271
|
expects: HttpRequest.fromBaseValues({ url, method: 'GET' }).toJSON(),
|
|
@@ -253,14 +281,14 @@ export class ArcProjectRequest extends Request {
|
|
|
253
281
|
* @param name The Request name.
|
|
254
282
|
* @param project The parent project.This is required.
|
|
255
283
|
*/
|
|
256
|
-
static fromName(name: string, project?:
|
|
284
|
+
static fromName(name: string, project?: AppProject): AppProjectRequest {
|
|
257
285
|
if (!project) {
|
|
258
286
|
throw new Error(`The project is required.`);
|
|
259
287
|
}
|
|
260
288
|
const now: number = Date.now();
|
|
261
|
-
const request = new
|
|
289
|
+
const request = new AppProjectRequest(project, {
|
|
262
290
|
key: v4(),
|
|
263
|
-
kind:
|
|
291
|
+
kind: AppProjectRequestKind,
|
|
264
292
|
created: now,
|
|
265
293
|
updated: now,
|
|
266
294
|
expects: new HttpRequest().toJSON(),
|
|
@@ -276,14 +304,14 @@ export class ArcProjectRequest extends Request {
|
|
|
276
304
|
* @param project The parent project This is required.
|
|
277
305
|
* @param info The request data.
|
|
278
306
|
*/
|
|
279
|
-
static fromHttpRequest(info: IHttpRequest, project?:
|
|
307
|
+
static fromHttpRequest(info: IHttpRequest, project?: AppProject): AppProjectRequest {
|
|
280
308
|
if (!project) {
|
|
281
309
|
throw new Error(`The project is required.`);
|
|
282
310
|
}
|
|
283
311
|
const now: number = Date.now();
|
|
284
|
-
const request = new
|
|
312
|
+
const request = new AppProjectRequest(project, {
|
|
285
313
|
key: v4(),
|
|
286
|
-
kind:
|
|
314
|
+
kind: AppProjectRequestKind,
|
|
287
315
|
created: now,
|
|
288
316
|
updated: now,
|
|
289
317
|
expects: HttpRequest.fromBaseValues({ method: info.method, url: info.url, headers: info.headers, payload: info.payload }).toJSON(),
|
|
@@ -295,18 +323,18 @@ export class ArcProjectRequest extends Request {
|
|
|
295
323
|
/**
|
|
296
324
|
* Creates a project request for a schema of a Request.
|
|
297
325
|
*/
|
|
298
|
-
static fromRequest(request: IRequest, project:
|
|
326
|
+
static fromRequest(request: IRequest, project: AppProject): AppProjectRequest {
|
|
299
327
|
const key = v4();
|
|
300
|
-
const init:
|
|
301
|
-
const result = new
|
|
328
|
+
const init: IAppProjectRequest = { ...request, key, kind: AppProjectRequestKind };
|
|
329
|
+
const result = new AppProjectRequest(project, init);
|
|
302
330
|
return result;
|
|
303
331
|
}
|
|
304
332
|
|
|
305
|
-
constructor(project:
|
|
333
|
+
constructor(project: AppProject, input?: string | IAppProjectRequest) {
|
|
306
334
|
super(input);
|
|
307
335
|
this.project = project;
|
|
308
336
|
|
|
309
|
-
let init:
|
|
337
|
+
let init: IAppProjectRequest | undefined;
|
|
310
338
|
if (typeof input === 'string') {
|
|
311
339
|
init = JSON.parse(input);
|
|
312
340
|
} else if (typeof input === 'object') {
|
|
@@ -315,27 +343,27 @@ export class ArcProjectRequest extends Request {
|
|
|
315
343
|
if (init) {
|
|
316
344
|
this.key = init.key || v4();
|
|
317
345
|
}
|
|
318
|
-
this.kind =
|
|
346
|
+
this.kind = AppProjectRequestKind;
|
|
319
347
|
}
|
|
320
348
|
|
|
321
|
-
new(init:
|
|
349
|
+
new(init: IAppProjectRequest): void {
|
|
322
350
|
super.new(init);
|
|
323
351
|
|
|
324
352
|
const { key = v4() } = init;
|
|
325
353
|
this.key = key;
|
|
326
|
-
this.kind =
|
|
354
|
+
this.kind = AppProjectRequestKind;
|
|
327
355
|
}
|
|
328
356
|
|
|
329
|
-
toJSON():
|
|
357
|
+
toJSON(): IAppProjectRequest {
|
|
330
358
|
const request = super.toJSON();
|
|
331
|
-
const result:
|
|
359
|
+
const result: IAppProjectRequest = { ...request, key: this.key, kind: AppProjectRequestKind };
|
|
332
360
|
return result;
|
|
333
361
|
}
|
|
334
362
|
|
|
335
363
|
/**
|
|
336
364
|
* @returns The instance of the ArcProject or a ArcProjectFolder that is a closes parent of this instance.
|
|
337
365
|
*/
|
|
338
|
-
getParent():
|
|
366
|
+
getParent(): AppProjectFolder | AppProject | undefined {
|
|
339
367
|
const { project, key } = this;
|
|
340
368
|
return project.findParent(key);
|
|
341
369
|
}
|
|
@@ -343,7 +371,7 @@ export class ArcProjectRequest extends Request {
|
|
|
343
371
|
/**
|
|
344
372
|
* @returns A reference to the parent folder or the top-level HTTP project.
|
|
345
373
|
*/
|
|
346
|
-
getProject():
|
|
374
|
+
getProject(): AppProject {
|
|
347
375
|
return this.project;
|
|
348
376
|
}
|
|
349
377
|
|
|
@@ -359,8 +387,8 @@ export class ArcProjectRequest extends Request {
|
|
|
359
387
|
* By default it attaches the copied request to the same parent.
|
|
360
388
|
* Use the options dictionary to control this behavior.
|
|
361
389
|
*/
|
|
362
|
-
clone(opts:
|
|
363
|
-
const copy = new
|
|
390
|
+
clone(opts: IAppProjectRequestCloneOptions = {}): AppProjectRequest {
|
|
391
|
+
const copy = new AppProjectRequest(this.project, this.toJSON());
|
|
364
392
|
if (!opts.withoutRevalidate) {
|
|
365
393
|
copy.key = v4();
|
|
366
394
|
}
|
|
@@ -382,17 +410,17 @@ export class ArcProjectRequest extends Request {
|
|
|
382
410
|
* @param opts Optional options.
|
|
383
411
|
* @returns The copied request.
|
|
384
412
|
*/
|
|
385
|
-
static clone(request:
|
|
386
|
-
const obj = new
|
|
413
|
+
static clone(request: IAppProjectRequest, project: AppProject, opts: IAppProjectRequestCloneOptions = {}): AppProjectRequest {
|
|
414
|
+
const obj = new AppProjectRequest(project, request);
|
|
387
415
|
return obj.clone(opts);
|
|
388
416
|
}
|
|
389
417
|
}
|
|
390
418
|
|
|
391
|
-
export class
|
|
419
|
+
export class AppProjectItem {
|
|
392
420
|
/**
|
|
393
421
|
* The kind of the item.
|
|
394
422
|
*/
|
|
395
|
-
kind: typeof
|
|
423
|
+
kind: typeof AppProjectFolderKind | typeof AppProjectRequestKind | typeof EnvironmentKind = AppProjectRequestKind;
|
|
396
424
|
|
|
397
425
|
/**
|
|
398
426
|
* The identifier of the object in the `definitions` array of the project.
|
|
@@ -402,14 +430,14 @@ export class ArcProjectItem {
|
|
|
402
430
|
/**
|
|
403
431
|
* A reference to the top level project object.
|
|
404
432
|
*/
|
|
405
|
-
project:
|
|
433
|
+
project: AppProject;
|
|
406
434
|
|
|
407
435
|
/**
|
|
408
436
|
* Checks whether the input is a definition of a project item.
|
|
409
437
|
*/
|
|
410
438
|
static isProjectItem(input: unknown): boolean {
|
|
411
|
-
const typed = input as
|
|
412
|
-
if (!input || ![
|
|
439
|
+
const typed = input as IAppProjectItem;
|
|
440
|
+
if (!input || ![AppProjectFolderKind, AppProjectRequestKind, EnvironmentKind].includes(typed.kind)) {
|
|
413
441
|
return false;
|
|
414
442
|
}
|
|
415
443
|
return true;
|
|
@@ -418,9 +446,9 @@ export class ArcProjectItem {
|
|
|
418
446
|
/**
|
|
419
447
|
* @return An instance that represents a request item
|
|
420
448
|
*/
|
|
421
|
-
static projectRequest(project:
|
|
422
|
-
const item = new
|
|
423
|
-
kind:
|
|
449
|
+
static projectRequest(project: AppProject, key: string): AppProjectItem {
|
|
450
|
+
const item = new AppProjectItem(project, {
|
|
451
|
+
kind: AppProjectRequestKind,
|
|
424
452
|
key,
|
|
425
453
|
});
|
|
426
454
|
return item;
|
|
@@ -429,9 +457,20 @@ export class ArcProjectItem {
|
|
|
429
457
|
/**
|
|
430
458
|
* @return An instance that represents a folder item
|
|
431
459
|
*/
|
|
432
|
-
static projectFolder(project:
|
|
433
|
-
const item = new
|
|
434
|
-
kind:
|
|
460
|
+
static projectFolder(project: AppProject, key: string): AppProjectItem {
|
|
461
|
+
const item = new AppProjectItem(project, {
|
|
462
|
+
kind: AppProjectFolderKind,
|
|
463
|
+
key,
|
|
464
|
+
});
|
|
465
|
+
return item;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @return An instance that represents an environment item
|
|
470
|
+
*/
|
|
471
|
+
static projectEnvironment(project: AppProject, key: string): AppProjectItem {
|
|
472
|
+
const item = new AppProjectItem(project, {
|
|
473
|
+
kind: EnvironmentKind,
|
|
435
474
|
key,
|
|
436
475
|
});
|
|
437
476
|
return item;
|
|
@@ -441,18 +480,23 @@ export class ArcProjectItem {
|
|
|
441
480
|
* @param project The top-most project.
|
|
442
481
|
* @param input The project item definition used to restore the state.
|
|
443
482
|
*/
|
|
444
|
-
constructor(project:
|
|
483
|
+
constructor(project: AppProject, input: string | IAppProjectItem) {
|
|
445
484
|
this.project = project;
|
|
446
|
-
let init:
|
|
485
|
+
let init: IAppProjectItem;
|
|
447
486
|
if (typeof input === 'string') {
|
|
448
487
|
if (input === 'http-request') {
|
|
449
488
|
init = {
|
|
450
|
-
kind:
|
|
489
|
+
kind: AppProjectRequestKind,
|
|
451
490
|
key: '',
|
|
452
491
|
};
|
|
453
492
|
} else if (input === 'folder') {
|
|
454
493
|
init = {
|
|
455
|
-
kind:
|
|
494
|
+
kind: AppProjectFolderKind,
|
|
495
|
+
key: '',
|
|
496
|
+
};
|
|
497
|
+
} else if (input === 'environment') {
|
|
498
|
+
init = {
|
|
499
|
+
kind: EnvironmentKind,
|
|
456
500
|
key: '',
|
|
457
501
|
};
|
|
458
502
|
} else {
|
|
@@ -471,8 +515,8 @@ export class ArcProjectItem {
|
|
|
471
515
|
*
|
|
472
516
|
* Note, this throws an error when the project item is not a project item.
|
|
473
517
|
*/
|
|
474
|
-
new(init:
|
|
475
|
-
if (!
|
|
518
|
+
new(init: IAppProjectItem): void {
|
|
519
|
+
if (!AppProjectItem.isProjectItem(init)) {
|
|
476
520
|
throw new Error(`Not a project item.`);
|
|
477
521
|
}
|
|
478
522
|
const { kind, key } = init;
|
|
@@ -480,8 +524,8 @@ export class ArcProjectItem {
|
|
|
480
524
|
this.key = key;
|
|
481
525
|
}
|
|
482
526
|
|
|
483
|
-
toJSON():
|
|
484
|
-
const result:
|
|
527
|
+
toJSON(): IAppProjectItem {
|
|
528
|
+
const result: IAppProjectItem = {
|
|
485
529
|
kind: this.kind,
|
|
486
530
|
key: this.key,
|
|
487
531
|
};
|
|
@@ -491,33 +535,36 @@ export class ArcProjectItem {
|
|
|
491
535
|
/**
|
|
492
536
|
* @returns The instance of the definition associated with this item.
|
|
493
537
|
*/
|
|
494
|
-
getItem():
|
|
538
|
+
getItem(): AppProjectFolder | AppProjectRequest | Environment | undefined {
|
|
495
539
|
const { project, key, kind } = this;
|
|
496
540
|
const { definitions } = project;
|
|
497
|
-
if (kind ===
|
|
541
|
+
if (kind === AppProjectRequestKind) {
|
|
498
542
|
return definitions.requests.find(i => i.key === key);
|
|
499
543
|
}
|
|
500
|
-
if (kind ===
|
|
544
|
+
if (kind === AppProjectFolderKind) {
|
|
501
545
|
return definitions.folders.find(i => i.key === key);
|
|
502
546
|
}
|
|
547
|
+
if (kind === EnvironmentKind) {
|
|
548
|
+
return definitions.environments.find(i => i.key === key);
|
|
549
|
+
}
|
|
503
550
|
return undefined;
|
|
504
551
|
}
|
|
505
552
|
|
|
506
553
|
/**
|
|
507
554
|
* @returns The instance of the ArcProject or a ArcProjectFolder that is a closest parent of this item.
|
|
508
555
|
*/
|
|
509
|
-
getParent():
|
|
556
|
+
getParent(): AppProjectFolder | AppProject | undefined {
|
|
510
557
|
const { project, key } = this;
|
|
511
558
|
return project.findParent(key);
|
|
512
559
|
}
|
|
513
560
|
}
|
|
514
561
|
|
|
515
|
-
export abstract class
|
|
562
|
+
export abstract class AppProjectParent {
|
|
516
563
|
/**
|
|
517
564
|
* The auto-generated key for the folder object.
|
|
518
565
|
* For the project root this is the same as the `_id`.
|
|
519
566
|
*/
|
|
520
|
-
kind: typeof
|
|
567
|
+
kind: typeof AppProjectKind | typeof AppProjectFolderKind;
|
|
521
568
|
|
|
522
569
|
/**
|
|
523
570
|
* The key of the project / folder.
|
|
@@ -534,7 +581,7 @@ export abstract class ArcProjectParent {
|
|
|
534
581
|
* It is an ordered list of requests and folders.
|
|
535
582
|
* The actual definition is kept in the root's `definitions`.
|
|
536
583
|
*/
|
|
537
|
-
items:
|
|
584
|
+
items: AppProjectItem[] = [];
|
|
538
585
|
|
|
539
586
|
/**
|
|
540
587
|
* Timestamp when the project was last updated.
|
|
@@ -546,10 +593,10 @@ export abstract class ArcProjectParent {
|
|
|
546
593
|
*/
|
|
547
594
|
created: number = Date.now();
|
|
548
595
|
|
|
549
|
-
constructor(kind: typeof
|
|
596
|
+
constructor(kind: typeof AppProjectKind | typeof AppProjectFolderKind, input?: string | IAppProjectParent) {
|
|
550
597
|
this.kind = kind;
|
|
551
598
|
|
|
552
|
-
let init:
|
|
599
|
+
let init: IAppProjectParent;
|
|
553
600
|
if (typeof input === 'string') {
|
|
554
601
|
init = JSON.parse(input);
|
|
555
602
|
} else if (typeof input === 'object') {
|
|
@@ -573,7 +620,7 @@ export abstract class ArcProjectParent {
|
|
|
573
620
|
*
|
|
574
621
|
* Note, this throws an error when the project folder is not a project folder.
|
|
575
622
|
*/
|
|
576
|
-
new(init:
|
|
623
|
+
new(init: IAppProjectParent): void {
|
|
577
624
|
const { key = v4(), created = Date.now(), updated = Date.now(), items, info, kind } = init;
|
|
578
625
|
this.kind = kind;
|
|
579
626
|
this.key = key;
|
|
@@ -587,54 +634,54 @@ export abstract class ArcProjectParent {
|
|
|
587
634
|
}
|
|
588
635
|
}
|
|
589
636
|
|
|
590
|
-
abstract setItems(items?:
|
|
637
|
+
abstract setItems(items?: IAppProjectItem[]): void;
|
|
591
638
|
|
|
592
639
|
/**
|
|
593
640
|
* Lists items (not the actual definitions!) that are folders.
|
|
594
641
|
*/
|
|
595
|
-
listFolderItems():
|
|
642
|
+
listFolderItems(): AppProjectItem[] {
|
|
596
643
|
const { items = [] } = this;
|
|
597
|
-
return items.filter(i => i.kind ===
|
|
644
|
+
return items.filter(i => i.kind === AppProjectFolderKind);
|
|
598
645
|
}
|
|
599
646
|
|
|
600
647
|
/**
|
|
601
648
|
* Lists items (not the actual definitions!) that are requests.
|
|
602
649
|
*/
|
|
603
|
-
listRequestItems():
|
|
650
|
+
listRequestItems(): AppProjectItem[] {
|
|
604
651
|
const { items = [] } = this;
|
|
605
|
-
return items.filter(i => i.kind ===
|
|
652
|
+
return items.filter(i => i.kind === AppProjectRequestKind);
|
|
606
653
|
}
|
|
607
654
|
}
|
|
608
655
|
|
|
609
|
-
export class
|
|
656
|
+
export class AppProjectFolder extends AppProjectParent {
|
|
610
657
|
|
|
611
|
-
project:
|
|
658
|
+
project: AppProject;
|
|
612
659
|
|
|
613
660
|
/**
|
|
614
661
|
* Creates a new ArcProjectFolder object from a name.
|
|
615
662
|
* @param project The top-most project.
|
|
616
663
|
* @param name The name to set.
|
|
617
664
|
*/
|
|
618
|
-
static fromName(project:
|
|
665
|
+
static fromName(project: AppProject, name = 'New folder'): AppProjectFolder {
|
|
619
666
|
const now = Date.now();
|
|
620
667
|
const key = v4();
|
|
621
668
|
const info = Thing.fromName(name);
|
|
622
|
-
const definition = new
|
|
669
|
+
const definition = new AppProjectFolder(project, {
|
|
623
670
|
key,
|
|
624
671
|
created: now,
|
|
625
672
|
updated: now,
|
|
626
673
|
items: [],
|
|
627
|
-
kind:
|
|
674
|
+
kind: AppProjectFolderKind,
|
|
628
675
|
info: info.toJSON(),
|
|
629
676
|
});
|
|
630
677
|
return definition;
|
|
631
678
|
}
|
|
632
679
|
|
|
633
|
-
constructor(project:
|
|
634
|
-
super(
|
|
680
|
+
constructor(project: AppProject, input?: string | IAppProjectParent) {
|
|
681
|
+
super(AppProjectFolderKind, input);
|
|
635
682
|
this.project = project;
|
|
636
683
|
|
|
637
|
-
let init:
|
|
684
|
+
let init: IAppProjectParent | undefined;
|
|
638
685
|
if (typeof input === 'string') {
|
|
639
686
|
init = JSON.parse(input);
|
|
640
687
|
} else if (typeof input === 'object') {
|
|
@@ -643,12 +690,12 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
643
690
|
if (init) {
|
|
644
691
|
this.key = init.key || v4();
|
|
645
692
|
}
|
|
646
|
-
this.kind =
|
|
693
|
+
this.kind = AppProjectFolderKind;
|
|
647
694
|
}
|
|
648
695
|
|
|
649
|
-
toJSON():
|
|
650
|
-
const result:
|
|
651
|
-
kind:
|
|
696
|
+
toJSON(): IAppProjectParent {
|
|
697
|
+
const result: IAppProjectParent = {
|
|
698
|
+
kind: AppProjectFolderKind,
|
|
652
699
|
info: this.info.toJSON(),
|
|
653
700
|
key: this.key,
|
|
654
701
|
created: this.created,
|
|
@@ -661,9 +708,9 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
661
708
|
return result;
|
|
662
709
|
}
|
|
663
710
|
|
|
664
|
-
setItems(items?:
|
|
711
|
+
setItems(items?: IAppProjectItem[]): void {
|
|
665
712
|
if (Array.isArray(items)) {
|
|
666
|
-
this.items = items.map(i => new
|
|
713
|
+
this.items = items.map(i => new AppProjectItem(this.project, i));
|
|
667
714
|
} else {
|
|
668
715
|
this.items = [];
|
|
669
716
|
}
|
|
@@ -675,7 +722,7 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
675
722
|
* @param folder The folder to add to this project.
|
|
676
723
|
* @returns The added folder.
|
|
677
724
|
*/
|
|
678
|
-
addFolder(folder:
|
|
725
|
+
addFolder(folder: AppProjectFolder): AppProjectFolder;
|
|
679
726
|
|
|
680
727
|
/**
|
|
681
728
|
* Appends new folder to a project from a full folder schema.
|
|
@@ -685,7 +732,7 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
685
732
|
* @param folder The folder schema to add to this project.
|
|
686
733
|
* @returns The added folder.
|
|
687
734
|
*/
|
|
688
|
-
addFolder(folder:
|
|
735
|
+
addFolder(folder: IAppProjectParent): AppProjectFolder;
|
|
689
736
|
|
|
690
737
|
/**
|
|
691
738
|
* Appends a new folder to the project or a sub-folder.
|
|
@@ -693,15 +740,15 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
693
740
|
* @param name The name to set. Optional.
|
|
694
741
|
* @returns The newly inserted folder. If the folder already existed it returns its instance.
|
|
695
742
|
*/
|
|
696
|
-
addFolder(name?: string):
|
|
743
|
+
addFolder(name?: string): AppProjectFolder;
|
|
697
744
|
|
|
698
745
|
/**
|
|
699
746
|
* Appends a new folder to the folder. It updates the project to add the request definition.
|
|
700
747
|
* @param name The name to set. Optional.
|
|
701
748
|
* @returns The key of newly inserted folder.
|
|
702
749
|
*/
|
|
703
|
-
addFolder(name: string |
|
|
704
|
-
return this.project.addFolder(name as
|
|
750
|
+
addFolder(name: string | IAppProjectParent | AppProjectFolder | undefined): AppProjectFolder {
|
|
751
|
+
return this.project.addFolder(name as AppProjectFolder, { parent: this.key });
|
|
705
752
|
}
|
|
706
753
|
|
|
707
754
|
/**
|
|
@@ -711,7 +758,7 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
711
758
|
* @param opts The request add options.
|
|
712
759
|
* @returns The inserted into the definitions request.
|
|
713
760
|
*/
|
|
714
|
-
addRequest(url: string, opts?:
|
|
761
|
+
addRequest(url: string, opts?: IAppProjectFolderAddOptions): AppProjectRequest;
|
|
715
762
|
|
|
716
763
|
/**
|
|
717
764
|
* Adds a request to the project or a sub-folder.
|
|
@@ -720,14 +767,14 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
720
767
|
* @param opts The request add options.
|
|
721
768
|
* @returns The inserted into the definitions request.
|
|
722
769
|
*/
|
|
723
|
-
addRequest(request:
|
|
770
|
+
addRequest(request: IAppProjectRequest | AppProjectRequest, opts?: IAppProjectFolderAddOptions): AppProjectRequest;
|
|
724
771
|
|
|
725
772
|
/**
|
|
726
773
|
* Appends a new request to the folder. It updates the project to add the request definition.
|
|
727
774
|
* @param request The request to append to the folder.
|
|
728
775
|
* @returns The key of newly inserted request.
|
|
729
776
|
*/
|
|
730
|
-
addRequest(request:
|
|
777
|
+
addRequest(request: IAppProjectRequest | AppProjectRequest | string, opts: IAppProjectFolderAddOptions = {}): AppProjectRequest {
|
|
731
778
|
const addOptions = { parent: this.key, ...opts };
|
|
732
779
|
if (typeof request === 'string') {
|
|
733
780
|
return this.project.addRequest(request, addOptions);
|
|
@@ -738,7 +785,7 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
738
785
|
/**
|
|
739
786
|
* @returns The instance of the ArcProject or a ArcProjectFolder that is a closes parent of this instance.
|
|
740
787
|
*/
|
|
741
|
-
getParent():
|
|
788
|
+
getParent(): AppProjectFolder | AppProject | undefined {
|
|
742
789
|
const { project, key } = this;
|
|
743
790
|
return project.findParent(key);
|
|
744
791
|
}
|
|
@@ -746,7 +793,7 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
746
793
|
/**
|
|
747
794
|
* @returns A reference to the parent folder or the top-level HTTP project.
|
|
748
795
|
*/
|
|
749
|
-
getProject():
|
|
796
|
+
getProject(): AppProject {
|
|
750
797
|
return this.project;
|
|
751
798
|
}
|
|
752
799
|
|
|
@@ -766,9 +813,9 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
766
813
|
*
|
|
767
814
|
* @param opts Cloning options
|
|
768
815
|
*/
|
|
769
|
-
clone(opts:
|
|
816
|
+
clone(opts: IAppProjectFolderCloneOptions = {}): AppProjectFolder {
|
|
770
817
|
const { targetProject = this.project, targetFolder } = opts;
|
|
771
|
-
const copy = new
|
|
818
|
+
const copy = new AppProjectFolder(targetProject, this.toJSON());
|
|
772
819
|
copy.key = v4();
|
|
773
820
|
|
|
774
821
|
const extProject = targetProject !== this.project;
|
|
@@ -808,8 +855,8 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
808
855
|
* @param folder The target folder into which to put the requests. The folder has to have the target project attached to it.
|
|
809
856
|
* @param project The originating project where the definitions are stored
|
|
810
857
|
*/
|
|
811
|
-
protected cloneRequests(folder:
|
|
812
|
-
const requests = this.items.filter(i => i.kind ===
|
|
858
|
+
protected cloneRequests(folder: AppProjectFolder, project: AppProject): void {
|
|
859
|
+
const requests = this.items.filter(i => i.kind === AppProjectRequestKind);
|
|
813
860
|
requests.forEach(r => {
|
|
814
861
|
const request = project.findRequest(r.key, { keyOnly: true });
|
|
815
862
|
if (!request) {
|
|
@@ -835,14 +882,14 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
835
882
|
* @param project The originating project where the definitions are stored
|
|
836
883
|
* @param withRequests Whether to clone requests with the folder.
|
|
837
884
|
*/
|
|
838
|
-
protected cloneSubFolders(folder:
|
|
839
|
-
const folders = this.items.filter(i => i.kind ===
|
|
885
|
+
protected cloneSubFolders(folder: AppProjectFolder, project: AppProject, withRequests = true): void {
|
|
886
|
+
const folders = this.items.filter(i => i.kind === AppProjectFolderKind);
|
|
840
887
|
folders.forEach(f => {
|
|
841
888
|
const definition = project.findFolder(f.key, { keyOnly: true });
|
|
842
889
|
if (!definition) {
|
|
843
890
|
return;
|
|
844
891
|
}
|
|
845
|
-
const copy = new
|
|
892
|
+
const copy = new AppProjectFolder(folder.getProject(), definition.toJSON());
|
|
846
893
|
copy.key = v4();
|
|
847
894
|
copy.items = [];
|
|
848
895
|
folder.addFolder(copy);
|
|
@@ -856,14 +903,14 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
856
903
|
/**
|
|
857
904
|
* Lists folders in this folder.
|
|
858
905
|
*/
|
|
859
|
-
listFolders():
|
|
906
|
+
listFolders(): AppProjectFolder[] {
|
|
860
907
|
return this.project.listFolders({ folder: this.key });
|
|
861
908
|
}
|
|
862
909
|
|
|
863
910
|
/**
|
|
864
911
|
* Lists requests in this folder.
|
|
865
912
|
*/
|
|
866
|
-
listRequests():
|
|
913
|
+
listRequests(): AppProjectRequest[] {
|
|
867
914
|
return this.project.listRequests(this.key);
|
|
868
915
|
}
|
|
869
916
|
|
|
@@ -873,14 +920,76 @@ export class ArcProjectFolder extends ArcProjectParent {
|
|
|
873
920
|
* @param legacy The legacy request definition.
|
|
874
921
|
* @returns The created project request.
|
|
875
922
|
*/
|
|
876
|
-
async addLegacyRequest(legacy: ARCSavedRequest | ARCHistoryRequest): Promise<
|
|
923
|
+
async addLegacyRequest(legacy: ARCSavedRequest | ARCHistoryRequest): Promise<AppProjectRequest> {
|
|
877
924
|
const request = await Request.fromLegacy(legacy);
|
|
878
|
-
const projectRequest =
|
|
925
|
+
const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), this.project);
|
|
879
926
|
return this.addRequest(projectRequest);
|
|
880
927
|
}
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Adds an environment to the project.
|
|
931
|
+
*
|
|
932
|
+
* @param env The definition of the environment to use to create the environment
|
|
933
|
+
* @returns The same or created environment.
|
|
934
|
+
*/
|
|
935
|
+
addEnvironment(env: IEnvironment, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Adds an environment to the project.
|
|
939
|
+
*
|
|
940
|
+
* @param env The instance of the environment to add
|
|
941
|
+
* @returns The same or created environment.
|
|
942
|
+
*/
|
|
943
|
+
addEnvironment(env: Environment, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Adds an environment to the project.
|
|
947
|
+
*
|
|
948
|
+
* @param env The name of the environment to create
|
|
949
|
+
* @returns The same or created environment.
|
|
950
|
+
*/
|
|
951
|
+
addEnvironment(env: string, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* Adds an environment to the project.
|
|
955
|
+
* @returns The same or created environment.
|
|
956
|
+
*/
|
|
957
|
+
addEnvironment(env: IEnvironment | Environment | string, opts: IAppProjectEnvironmentCreateOptions = {}): Environment {
|
|
958
|
+
const newOptions: IAppProjectEnvironmentCreateOptions = { ...opts, parent: this.key };
|
|
959
|
+
return this.project.addEnvironment(env as Environment, newOptions);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* @param key The environment key to read.
|
|
964
|
+
*/
|
|
965
|
+
getEnvironment(key: string): Environment | undefined {
|
|
966
|
+
return this.project.getEnvironment(key, { parent: this.key });
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Removes an environment from the folder or a sub-folder.
|
|
971
|
+
*
|
|
972
|
+
* @param key the key of the environment to remove
|
|
973
|
+
* @returns The removed environment, if any.
|
|
974
|
+
*/
|
|
975
|
+
removeEnvironment(key: string): Environment | undefined {
|
|
976
|
+
return this.project.removeEnvironment(key, { parent: this.key });
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* This is a link to the `getEnvironments()`. The difference is that on the
|
|
981
|
+
* project level it won't return environments defined with the class initialization.
|
|
982
|
+
*/
|
|
983
|
+
listEnvironments(): Environment[] {
|
|
984
|
+
return this.project.listEnvironments({ parent: this.key });
|
|
985
|
+
}
|
|
881
986
|
}
|
|
882
987
|
|
|
883
|
-
|
|
988
|
+
/**
|
|
989
|
+
* An app project is similar to the HttpProject but stored for a single application
|
|
990
|
+
* and has no sharing options. The AppProject can be upgraded to an HttpProject.
|
|
991
|
+
*/
|
|
992
|
+
export class AppProject extends AppProjectParent {
|
|
884
993
|
/**
|
|
885
994
|
* Timestamp when the project was last updated.
|
|
886
995
|
*/
|
|
@@ -891,14 +1000,14 @@ export class ArcProject extends ArcProjectParent {
|
|
|
891
1000
|
*/
|
|
892
1001
|
created: number = Date.now();
|
|
893
1002
|
|
|
894
|
-
definitions:
|
|
1003
|
+
definitions: AppProjectDefinitions;
|
|
895
1004
|
|
|
896
1005
|
/**
|
|
897
1006
|
* Creates a new ARC project from a name.
|
|
898
1007
|
* @param name The name to set.
|
|
899
1008
|
*/
|
|
900
|
-
static fromName(name: string):
|
|
901
|
-
const project = new
|
|
1009
|
+
static fromName(name: string): AppProject {
|
|
1010
|
+
const project = new AppProject();
|
|
902
1011
|
const info = Thing.fromName(name);
|
|
903
1012
|
project.info = info;
|
|
904
1013
|
return project;
|
|
@@ -909,9 +1018,9 @@ export class ArcProject extends ArcProjectParent {
|
|
|
909
1018
|
*
|
|
910
1019
|
* Note, the `requests` should be processed and the payload restored to it's original value.
|
|
911
1020
|
*/
|
|
912
|
-
static async fromLegacyProject(project: ARCProject, requests: ARCSavedRequest[]): Promise<
|
|
1021
|
+
static async fromLegacyProject(project: ARCProject, requests: ARCSavedRequest[]): Promise<AppProject> {
|
|
913
1022
|
const { name = 'Unnamed project', description, requests: ids } = project;
|
|
914
|
-
const result =
|
|
1023
|
+
const result = AppProject.fromName(name);
|
|
915
1024
|
if (project._id) {
|
|
916
1025
|
result.key = project._id;
|
|
917
1026
|
}
|
|
@@ -925,7 +1034,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
925
1034
|
return;
|
|
926
1035
|
}
|
|
927
1036
|
const request = await Request.fromLegacy(old);
|
|
928
|
-
const projectRequest =
|
|
1037
|
+
const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), result);
|
|
929
1038
|
if (old._id) {
|
|
930
1039
|
projectRequest.key = old._id;
|
|
931
1040
|
}
|
|
@@ -936,24 +1045,26 @@ export class ArcProject extends ArcProjectParent {
|
|
|
936
1045
|
return result;
|
|
937
1046
|
}
|
|
938
1047
|
|
|
939
|
-
constructor(input?: string |
|
|
940
|
-
super(
|
|
1048
|
+
constructor(input?: string | IAppProject) {
|
|
1049
|
+
super(AppProjectKind);
|
|
941
1050
|
this.definitions = {
|
|
942
1051
|
folders: [],
|
|
943
1052
|
requests: [],
|
|
1053
|
+
environments: [],
|
|
1054
|
+
certificates: [],
|
|
944
1055
|
};
|
|
945
|
-
let init:
|
|
1056
|
+
let init: IAppProject;
|
|
946
1057
|
if (typeof input === 'string') {
|
|
947
1058
|
init = JSON.parse(input);
|
|
948
1059
|
} else if (typeof input === 'object') {
|
|
949
1060
|
init = input;
|
|
950
1061
|
if (!init.kind) {
|
|
951
|
-
init.kind =
|
|
1062
|
+
init.kind = AppProjectKind;
|
|
952
1063
|
}
|
|
953
1064
|
} else {
|
|
954
1065
|
const now = Date.now();
|
|
955
1066
|
init = {
|
|
956
|
-
kind:
|
|
1067
|
+
kind: AppProjectKind,
|
|
957
1068
|
key: v4(),
|
|
958
1069
|
definitions: {},
|
|
959
1070
|
items: [],
|
|
@@ -965,7 +1076,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
965
1076
|
this.new(init);
|
|
966
1077
|
}
|
|
967
1078
|
|
|
968
|
-
new(init:
|
|
1079
|
+
new(init: IAppProject): void {
|
|
969
1080
|
if (!init || !init.items) {
|
|
970
1081
|
throw new Error(`Not a project.`);
|
|
971
1082
|
}
|
|
@@ -982,24 +1093,32 @@ export class ArcProject extends ArcProjectParent {
|
|
|
982
1093
|
this.definitions = {
|
|
983
1094
|
folders: [],
|
|
984
1095
|
requests: [],
|
|
1096
|
+
environments: [],
|
|
1097
|
+
certificates: [],
|
|
985
1098
|
};
|
|
986
1099
|
if (Array.isArray(definitions.requests)) {
|
|
987
1100
|
this.definitions.requests = definitions.requests.map(i => {
|
|
988
|
-
const instance = new
|
|
1101
|
+
const instance = new AppProjectRequest(this, i);
|
|
989
1102
|
return instance;
|
|
990
1103
|
});
|
|
991
1104
|
}
|
|
992
1105
|
if (Array.isArray(definitions.folders)) {
|
|
993
1106
|
this.definitions.folders = definitions.folders.map(i => {
|
|
994
|
-
const instance = new
|
|
1107
|
+
const instance = new AppProjectFolder(this, i);
|
|
995
1108
|
return instance;
|
|
996
1109
|
});
|
|
997
1110
|
}
|
|
1111
|
+
if (Array.isArray(definitions.environments)) {
|
|
1112
|
+
this.definitions.environments = definitions.environments.map(i => new Environment(i));
|
|
1113
|
+
}
|
|
1114
|
+
if (Array.isArray(definitions.certificates)) {
|
|
1115
|
+
this.definitions.certificates = definitions.certificates.map(i => new Certificate(i));
|
|
1116
|
+
}
|
|
998
1117
|
}
|
|
999
1118
|
|
|
1000
|
-
toJSON():
|
|
1001
|
-
const result:
|
|
1002
|
-
kind:
|
|
1119
|
+
toJSON(): IAppProject {
|
|
1120
|
+
const result: IAppProject = {
|
|
1121
|
+
kind: AppProjectKind,
|
|
1003
1122
|
key: this.key,
|
|
1004
1123
|
definitions: {},
|
|
1005
1124
|
items: [],
|
|
@@ -1013,15 +1132,21 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1013
1132
|
if (Array.isArray(this.definitions.folders) && this.definitions.folders.length) {
|
|
1014
1133
|
result.definitions.folders = this.definitions.folders.map(i => i.toJSON());
|
|
1015
1134
|
}
|
|
1135
|
+
if (Array.isArray(this.definitions.environments) && this.definitions.environments.length) {
|
|
1136
|
+
result.definitions.environments = this.definitions.environments.map(i => i.toJSON());
|
|
1137
|
+
}
|
|
1138
|
+
if (Array.isArray(this.definitions.certificates) && this.definitions.certificates.length) {
|
|
1139
|
+
result.definitions.certificates = this.definitions.certificates.map(i => i.toJSON());
|
|
1140
|
+
}
|
|
1016
1141
|
if (Array.isArray(this.items) && this.items.length) {
|
|
1017
1142
|
result.items = this.items.map(i => i.toJSON());
|
|
1018
1143
|
}
|
|
1019
1144
|
return result;
|
|
1020
1145
|
}
|
|
1021
1146
|
|
|
1022
|
-
setItems(items?:
|
|
1147
|
+
setItems(items?: IAppProjectItem[]): void {
|
|
1023
1148
|
if (Array.isArray(items)) {
|
|
1024
|
-
this.items = items.map(i => new
|
|
1149
|
+
this.items = items.map(i => new AppProjectItem(this, i));
|
|
1025
1150
|
} else {
|
|
1026
1151
|
this.items = [];
|
|
1027
1152
|
}
|
|
@@ -1033,7 +1158,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1033
1158
|
* @param key The key of the definition.
|
|
1034
1159
|
* @returns The parent or undefine when not found.
|
|
1035
1160
|
*/
|
|
1036
|
-
findParent(key: string):
|
|
1161
|
+
findParent(key: string): AppProjectFolder | AppProject | undefined {
|
|
1037
1162
|
const { definitions, items = [] } = this;
|
|
1038
1163
|
const projectItemsIndex = items.findIndex(i => i.key === key);
|
|
1039
1164
|
if (projectItemsIndex > -1) {
|
|
@@ -1053,7 +1178,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1053
1178
|
* @param opts Optional folder add options.
|
|
1054
1179
|
* @returns The added folder.
|
|
1055
1180
|
*/
|
|
1056
|
-
addFolder(folder:
|
|
1181
|
+
addFolder(folder: AppProjectFolder, opts?: IAppProjectFolderCreateOptions): AppProjectFolder;
|
|
1057
1182
|
|
|
1058
1183
|
/**
|
|
1059
1184
|
* Appends new folder to a project from a full folder schema.
|
|
@@ -1064,7 +1189,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1064
1189
|
* @param opts Optional folder add options.
|
|
1065
1190
|
* @returns The added folder.
|
|
1066
1191
|
*/
|
|
1067
|
-
addFolder(folder:
|
|
1192
|
+
addFolder(folder: IAppProjectParent, opts?: IAppProjectFolderCreateOptions): AppProjectFolder;
|
|
1068
1193
|
|
|
1069
1194
|
/**
|
|
1070
1195
|
* Appends a new folder to the project or a sub-folder.
|
|
@@ -1073,7 +1198,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1073
1198
|
* @param opts Folder create options.
|
|
1074
1199
|
* @returns The newly inserted folder. If the folder already existed it returns its instance.
|
|
1075
1200
|
*/
|
|
1076
|
-
addFolder(name?: string, opts?:
|
|
1201
|
+
addFolder(name?: string, opts?: IAppProjectFolderCreateOptions): AppProjectFolder;
|
|
1077
1202
|
|
|
1078
1203
|
/**
|
|
1079
1204
|
* Appends a new folder to the project or a sub-folder.
|
|
@@ -1085,7 +1210,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1085
1210
|
* @param opts Folder create options.
|
|
1086
1211
|
* @returns The newly inserted folder. If the folder already existed it returns its instance.
|
|
1087
1212
|
*/
|
|
1088
|
-
addFolder(init: string |
|
|
1213
|
+
addFolder(init: string | IAppProjectParent | AppProjectFolder = 'New Folder', opts: IAppProjectFolderCreateOptions = {}): AppProjectFolder {
|
|
1089
1214
|
if (!Array.isArray(this.items)) {
|
|
1090
1215
|
this.items = [];
|
|
1091
1216
|
}
|
|
@@ -1093,7 +1218,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1093
1218
|
this.definitions.folders = [];
|
|
1094
1219
|
}
|
|
1095
1220
|
const { skipExisting, parent } = opts;
|
|
1096
|
-
let root:
|
|
1221
|
+
let root: AppProjectFolder | AppProject;
|
|
1097
1222
|
if (parent) {
|
|
1098
1223
|
const rootCandidate = this.findFolder(parent);
|
|
1099
1224
|
if (!rootCandidate) {
|
|
@@ -1103,13 +1228,13 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1103
1228
|
} else {
|
|
1104
1229
|
root = this;
|
|
1105
1230
|
}
|
|
1106
|
-
let definition:
|
|
1231
|
+
let definition: AppProjectFolder;
|
|
1107
1232
|
if (typeof init === 'string') {
|
|
1108
|
-
definition =
|
|
1109
|
-
} else if (init instanceof
|
|
1233
|
+
definition = AppProjectFolder.fromName(this, init);
|
|
1234
|
+
} else if (init instanceof AppProjectFolder) {
|
|
1110
1235
|
definition = init;
|
|
1111
1236
|
} else {
|
|
1112
|
-
definition = new
|
|
1237
|
+
definition = new AppProjectFolder(this, init);
|
|
1113
1238
|
}
|
|
1114
1239
|
if (skipExisting) {
|
|
1115
1240
|
const folders = root.listFolderItems();
|
|
@@ -1122,7 +1247,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1122
1247
|
}
|
|
1123
1248
|
|
|
1124
1249
|
this.definitions.folders.push(definition);
|
|
1125
|
-
const item =
|
|
1250
|
+
const item = AppProjectItem.projectFolder(this, definition.key);
|
|
1126
1251
|
if (!Array.isArray(root.items)) {
|
|
1127
1252
|
root.items = [];
|
|
1128
1253
|
}
|
|
@@ -1141,13 +1266,13 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1141
1266
|
* @param opts Optional search options.
|
|
1142
1267
|
* @returns Found project folder or undefined.
|
|
1143
1268
|
*/
|
|
1144
|
-
findFolder(nameOrKey: string, opts:
|
|
1269
|
+
findFolder(nameOrKey: string, opts: IAppProjectFolderSearchOptions = {}): AppProjectFolder | undefined {
|
|
1145
1270
|
const { definitions } = this;
|
|
1146
1271
|
const item = definitions.folders.find((i) => {
|
|
1147
|
-
if (i.kind !==
|
|
1272
|
+
if (i.kind !== AppProjectFolderKind) {
|
|
1148
1273
|
return false;
|
|
1149
1274
|
}
|
|
1150
|
-
const folder = (i as
|
|
1275
|
+
const folder = (i as AppProjectFolder);
|
|
1151
1276
|
if (folder.key === nameOrKey) {
|
|
1152
1277
|
return true;
|
|
1153
1278
|
}
|
|
@@ -1157,7 +1282,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1157
1282
|
return !!folder.info && folder.info.name === nameOrKey;
|
|
1158
1283
|
});
|
|
1159
1284
|
if (item) {
|
|
1160
|
-
return item as
|
|
1285
|
+
return item as AppProjectFolder;
|
|
1161
1286
|
}
|
|
1162
1287
|
return undefined;
|
|
1163
1288
|
}
|
|
@@ -1168,7 +1293,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1168
1293
|
* @param opts Folder remove options.
|
|
1169
1294
|
* @returns The removed folder definition or undefined when not removed.
|
|
1170
1295
|
*/
|
|
1171
|
-
removeFolder(key: string, opts:
|
|
1296
|
+
removeFolder(key: string, opts: IAppProjectFolderDeleteOptions = {}): AppProjectFolder | undefined {
|
|
1172
1297
|
const { definitions } = this;
|
|
1173
1298
|
const folder = this.findFolder(key, { keyOnly: true });
|
|
1174
1299
|
if (!folder) {
|
|
@@ -1207,7 +1332,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1207
1332
|
* @param key The key of the request to move.
|
|
1208
1333
|
* @param opts The moving options.
|
|
1209
1334
|
*/
|
|
1210
|
-
moveFolder(key: string, opts:
|
|
1335
|
+
moveFolder(key: string, opts: IAppProjectProjectMoveOptions = {}): void {
|
|
1211
1336
|
const { index, parent } = opts;
|
|
1212
1337
|
const movedFolder = this.findFolder(key);
|
|
1213
1338
|
if (!movedFolder) {
|
|
@@ -1263,7 +1388,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1263
1388
|
if (item.key === child) {
|
|
1264
1389
|
return true;
|
|
1265
1390
|
}
|
|
1266
|
-
if (item.kind ===
|
|
1391
|
+
if (item.kind === AppProjectFolderKind) {
|
|
1267
1392
|
const hasChild = this.hasChild(child, item.key);
|
|
1268
1393
|
if (hasChild) {
|
|
1269
1394
|
return true;
|
|
@@ -1280,7 +1405,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1280
1405
|
* @param opts The request add options.
|
|
1281
1406
|
* @returns The inserted into the definitions request.
|
|
1282
1407
|
*/
|
|
1283
|
-
addRequest(url: string, opts?:
|
|
1408
|
+
addRequest(url: string, opts?: IAppProjectRequestAddOptions): AppProjectRequest;
|
|
1284
1409
|
|
|
1285
1410
|
/**
|
|
1286
1411
|
* Adds a request to the project or a sub-folder.
|
|
@@ -1289,7 +1414,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1289
1414
|
* @param opts The request add options.
|
|
1290
1415
|
* @returns The inserted into the definitions request.
|
|
1291
1416
|
*/
|
|
1292
|
-
addRequest(request:
|
|
1417
|
+
addRequest(request: IAppProjectRequest | AppProjectRequest, opts?: IAppProjectRequestAddOptions): AppProjectRequest;
|
|
1293
1418
|
|
|
1294
1419
|
/**
|
|
1295
1420
|
* Adds a request to the project or a sub-folder.
|
|
@@ -1297,7 +1422,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1297
1422
|
* @param opts Thew request add options.
|
|
1298
1423
|
* @returns The inserted into the definitions request.
|
|
1299
1424
|
*/
|
|
1300
|
-
addRequest(request:
|
|
1425
|
+
addRequest(request: IAppProjectRequest | AppProjectRequest | string, opts: IAppProjectRequestAddOptions = {}): AppProjectRequest {
|
|
1301
1426
|
if (!Array.isArray(this.definitions.requests)) {
|
|
1302
1427
|
this.definitions.requests = [];
|
|
1303
1428
|
}
|
|
@@ -1308,7 +1433,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1308
1433
|
if (typeof request === 'object' && request.key) {
|
|
1309
1434
|
const existing = this.definitions.requests.find(i => i.key === request.key);
|
|
1310
1435
|
if (existing) {
|
|
1311
|
-
existing.new(request as
|
|
1436
|
+
existing.new(request as IAppProjectRequest);
|
|
1312
1437
|
return existing;
|
|
1313
1438
|
}
|
|
1314
1439
|
}
|
|
@@ -1317,18 +1442,18 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1317
1442
|
|
|
1318
1443
|
let finalRequest;
|
|
1319
1444
|
if (typeof request === 'string') {
|
|
1320
|
-
finalRequest =
|
|
1321
|
-
} else if (request instanceof
|
|
1445
|
+
finalRequest = AppProjectRequest.fromUrl(request, this);
|
|
1446
|
+
} else if (request instanceof AppProjectRequest) {
|
|
1322
1447
|
finalRequest = request;
|
|
1323
1448
|
finalRequest.project = this;
|
|
1324
1449
|
} else {
|
|
1325
|
-
finalRequest = new
|
|
1450
|
+
finalRequest = new AppProjectRequest(this, request);
|
|
1326
1451
|
}
|
|
1327
1452
|
if (!finalRequest.key) {
|
|
1328
1453
|
finalRequest.key = v4();
|
|
1329
1454
|
}
|
|
1330
1455
|
|
|
1331
|
-
let root:
|
|
1456
|
+
let root: AppProjectFolder | AppProject;
|
|
1332
1457
|
if (opts.parent) {
|
|
1333
1458
|
const rootCandidate = this.findFolder(opts.parent);
|
|
1334
1459
|
if (!rootCandidate) {
|
|
@@ -1351,7 +1476,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1351
1476
|
}
|
|
1352
1477
|
|
|
1353
1478
|
this.definitions.requests.push(finalRequest);
|
|
1354
|
-
const item =
|
|
1479
|
+
const item = AppProjectItem.projectRequest(this, finalRequest.key);
|
|
1355
1480
|
|
|
1356
1481
|
if (typeof opts.index === 'number') {
|
|
1357
1482
|
root.items.splice(opts.index, 0, item);
|
|
@@ -1367,9 +1492,9 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1367
1492
|
* @param legacy The legacy request definition.
|
|
1368
1493
|
* @returns The created project request.
|
|
1369
1494
|
*/
|
|
1370
|
-
async addLegacyRequest(legacy: ARCSavedRequest | ARCHistoryRequest): Promise<
|
|
1495
|
+
async addLegacyRequest(legacy: ARCSavedRequest | ARCHistoryRequest): Promise<AppProjectRequest> {
|
|
1371
1496
|
const request = await Request.fromLegacy(legacy);
|
|
1372
|
-
const projectRequest =
|
|
1497
|
+
const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), this);
|
|
1373
1498
|
return this.addRequest(projectRequest);
|
|
1374
1499
|
}
|
|
1375
1500
|
|
|
@@ -1380,7 +1505,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1380
1505
|
* @param opts Optional search options.
|
|
1381
1506
|
* @returns Found project request or undefined.
|
|
1382
1507
|
*/
|
|
1383
|
-
findRequest(nameOrKey: string, opts:
|
|
1508
|
+
findRequest(nameOrKey: string, opts: IAppProjectRequestSearchOptions = {}): AppProjectRequest | undefined {
|
|
1384
1509
|
const { definitions } = this;
|
|
1385
1510
|
const item = definitions.requests.find((request) => {
|
|
1386
1511
|
if (request.key === nameOrKey) {
|
|
@@ -1392,7 +1517,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1392
1517
|
return !!request.info && request.info.name === nameOrKey;
|
|
1393
1518
|
});
|
|
1394
1519
|
if (item) {
|
|
1395
|
-
return item as
|
|
1520
|
+
return item as AppProjectRequest;
|
|
1396
1521
|
}
|
|
1397
1522
|
return undefined;
|
|
1398
1523
|
}
|
|
@@ -1404,7 +1529,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1404
1529
|
* @param opts Request remove options.
|
|
1405
1530
|
* @returns The removed request definition or undefined when not removed.
|
|
1406
1531
|
*/
|
|
1407
|
-
removeRequest(key: string, opts:
|
|
1532
|
+
removeRequest(key: string, opts: IAppProjectRequestDeleteOptions = {}): AppProjectRequest | undefined {
|
|
1408
1533
|
const { definitions } = this;
|
|
1409
1534
|
const request = this.findRequest(key, { keyOnly: true });
|
|
1410
1535
|
if (!request) {
|
|
@@ -1437,7 +1562,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1437
1562
|
* @param key The key of the request to move.
|
|
1438
1563
|
* @param opts The moving options.
|
|
1439
1564
|
*/
|
|
1440
|
-
moveRequest(key: string, opts:
|
|
1565
|
+
moveRequest(key: string, opts: IAppProjectProjectMoveOptions = {}): void {
|
|
1441
1566
|
const { index, parent } = opts;
|
|
1442
1567
|
const request = this.findRequest(key);
|
|
1443
1568
|
if (!request) {
|
|
@@ -1473,24 +1598,24 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1473
1598
|
/**
|
|
1474
1599
|
* Lists items (not the actual definitions!) that are folders.
|
|
1475
1600
|
*/
|
|
1476
|
-
listFolderItems():
|
|
1601
|
+
listFolderItems(): AppProjectItem[] {
|
|
1477
1602
|
const { items = [] } = this;
|
|
1478
|
-
return items.filter(i => i.kind ===
|
|
1603
|
+
return items.filter(i => i.kind === AppProjectFolderKind);
|
|
1479
1604
|
}
|
|
1480
1605
|
|
|
1481
1606
|
/**
|
|
1482
1607
|
* Lists items (not the actual definitions!) that are requests.
|
|
1483
1608
|
*/
|
|
1484
|
-
listRequestItems():
|
|
1609
|
+
listRequestItems(): AppProjectItem[] {
|
|
1485
1610
|
const { items = [] } = this;
|
|
1486
|
-
return items.filter(i => i.kind ===
|
|
1611
|
+
return items.filter(i => i.kind === AppProjectRequestKind);
|
|
1487
1612
|
}
|
|
1488
1613
|
|
|
1489
1614
|
/**
|
|
1490
1615
|
* Lists folders from the project or a sub-folder.
|
|
1491
1616
|
* @param opts Folder listing options.
|
|
1492
1617
|
*/
|
|
1493
|
-
listFolders(opts:
|
|
1618
|
+
listFolders(opts: IAppProjectFolderListOptions = {}): AppProjectFolder[] {
|
|
1494
1619
|
let root;
|
|
1495
1620
|
if (opts.folder) {
|
|
1496
1621
|
const parent = this.findFolder(opts.folder);
|
|
@@ -1502,7 +1627,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1502
1627
|
root = this;
|
|
1503
1628
|
}
|
|
1504
1629
|
const items = root.listFolderItems();
|
|
1505
|
-
const result:
|
|
1630
|
+
const result: AppProjectFolder[] = [];
|
|
1506
1631
|
const { definitions } = this;
|
|
1507
1632
|
items.forEach((i) => {
|
|
1508
1633
|
const definition = definitions.folders.find(d => i.key === d.key);
|
|
@@ -1517,7 +1642,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1517
1642
|
* Lists requests in this project or a sub-folder.
|
|
1518
1643
|
* @param folder The optional folder name or the key to list requests for.
|
|
1519
1644
|
*/
|
|
1520
|
-
listRequests(folder?: string):
|
|
1645
|
+
listRequests(folder?: string): AppProjectRequest[] {
|
|
1521
1646
|
let root;
|
|
1522
1647
|
if (folder) {
|
|
1523
1648
|
const parent = this.findFolder(folder);
|
|
@@ -1529,7 +1654,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1529
1654
|
root = this;
|
|
1530
1655
|
}
|
|
1531
1656
|
const items = root.listRequestItems();
|
|
1532
|
-
const result:
|
|
1657
|
+
const result: AppProjectRequest[] = [];
|
|
1533
1658
|
const { definitions } = this;
|
|
1534
1659
|
items.forEach((i) => {
|
|
1535
1660
|
const definition = definitions.requests.find(d => i.key === d.key);
|
|
@@ -1544,7 +1669,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1544
1669
|
* Lists definitions for the `items` of the project or a folder.
|
|
1545
1670
|
* @param folder Optionally the folder name to list the definitions for.
|
|
1546
1671
|
*/
|
|
1547
|
-
listDefinitions(folder?: string): (
|
|
1672
|
+
listDefinitions(folder?: string): (AppProjectFolder | AppProjectRequest | Environment)[] {
|
|
1548
1673
|
let root;
|
|
1549
1674
|
if (folder) {
|
|
1550
1675
|
const parent = this.findFolder(folder);
|
|
@@ -1555,15 +1680,17 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1555
1680
|
} else {
|
|
1556
1681
|
root = this;
|
|
1557
1682
|
}
|
|
1558
|
-
const result: (
|
|
1683
|
+
const result: (AppProjectFolder | AppProjectRequest | Environment)[] = [];
|
|
1559
1684
|
const { items = [] } = root;
|
|
1560
1685
|
const { definitions } = this;
|
|
1561
1686
|
items.forEach((item) => {
|
|
1562
|
-
let definition:
|
|
1563
|
-
if (item.kind ===
|
|
1687
|
+
let definition: AppProjectFolder | AppProjectRequest | Environment | undefined;
|
|
1688
|
+
if (item.kind === AppProjectFolderKind) {
|
|
1564
1689
|
definition = definitions.folders.find(d => item.key === d.key);
|
|
1565
|
-
} else if (item.kind ===
|
|
1690
|
+
} else if (item.kind === AppProjectRequestKind) {
|
|
1566
1691
|
definition = definitions.requests.find(d => item.key === d.key);
|
|
1692
|
+
} else if (item.kind === EnvironmentKind) {
|
|
1693
|
+
definition = definitions.environments.find(d => item.key === d.key);
|
|
1567
1694
|
}
|
|
1568
1695
|
if (definition) {
|
|
1569
1696
|
result.push(definition);
|
|
@@ -1575,28 +1702,28 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1575
1702
|
/**
|
|
1576
1703
|
* @returns On the project level this always returns undefined.
|
|
1577
1704
|
*/
|
|
1578
|
-
getParent():
|
|
1705
|
+
getParent(): AppProjectFolder | AppProject | undefined {
|
|
1579
1706
|
return undefined;
|
|
1580
1707
|
}
|
|
1581
1708
|
|
|
1582
|
-
getProject():
|
|
1709
|
+
getProject(): AppProject {
|
|
1583
1710
|
return this;
|
|
1584
1711
|
}
|
|
1585
1712
|
|
|
1586
1713
|
/**
|
|
1587
1714
|
* Makes a copy of this project.
|
|
1588
1715
|
*/
|
|
1589
|
-
clone(opts:
|
|
1590
|
-
const copy = new
|
|
1716
|
+
clone(opts: IAppProjectProjectCloneOptions = {}): AppProject {
|
|
1717
|
+
const copy = new AppProject(this.toJSON());
|
|
1591
1718
|
if (!opts.withoutRevalidate) {
|
|
1592
1719
|
copy.key = v4();
|
|
1593
|
-
|
|
1720
|
+
AppProject.regenerateKeys(copy);
|
|
1594
1721
|
}
|
|
1595
1722
|
return copy;
|
|
1596
1723
|
}
|
|
1597
1724
|
|
|
1598
|
-
static clone(project:
|
|
1599
|
-
const obj = new
|
|
1725
|
+
static clone(project: IAppProject, opts: IAppProjectProjectCloneOptions = {}): AppProject {
|
|
1726
|
+
const obj = new AppProject(project);
|
|
1600
1727
|
return obj.clone(opts);
|
|
1601
1728
|
}
|
|
1602
1729
|
|
|
@@ -1607,7 +1734,7 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1607
1734
|
*
|
|
1608
1735
|
* @param src The project instance to re-generate keys for.
|
|
1609
1736
|
*/
|
|
1610
|
-
static regenerateKeys(src:
|
|
1737
|
+
static regenerateKeys(src: AppProject): void {
|
|
1611
1738
|
const { items = [], definitions } = src;
|
|
1612
1739
|
// create a flat list of all "items" in the project and all folders.
|
|
1613
1740
|
let flatItems = [...items];
|
|
@@ -1639,5 +1766,324 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1639
1766
|
indexObject.key = newKey;
|
|
1640
1767
|
request.key = newKey;
|
|
1641
1768
|
});
|
|
1769
|
+
(definitions.environments || []).forEach((environment) => {
|
|
1770
|
+
const oldKey = environment.key;
|
|
1771
|
+
const indexObject = flatItems.find(i => i.key === oldKey);
|
|
1772
|
+
if (!indexObject) {
|
|
1773
|
+
return;
|
|
1774
|
+
}
|
|
1775
|
+
const newKey = v4();
|
|
1776
|
+
indexObject.key = newKey;
|
|
1777
|
+
environment.key = newKey;
|
|
1778
|
+
});
|
|
1779
|
+
(definitions.certificates || []).forEach((cert) => {
|
|
1780
|
+
cert.key = v4();
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
/**
|
|
1785
|
+
* Adds an environment to the project.
|
|
1786
|
+
*
|
|
1787
|
+
* @param env The definition of the environment to use to create the environment
|
|
1788
|
+
* @returns The same or created environment.
|
|
1789
|
+
*/
|
|
1790
|
+
addEnvironment(env: IEnvironment, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
* Adds an environment to the project.
|
|
1794
|
+
*
|
|
1795
|
+
* @param env The instance of the environment to add
|
|
1796
|
+
* @returns The same or created environment.
|
|
1797
|
+
*/
|
|
1798
|
+
addEnvironment(env: Environment, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* Adds an environment to the project.
|
|
1802
|
+
*
|
|
1803
|
+
* @param env The name of the environment to create
|
|
1804
|
+
* @returns The same or created environment.
|
|
1805
|
+
*/
|
|
1806
|
+
addEnvironment(env: string, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
1807
|
+
|
|
1808
|
+
/**
|
|
1809
|
+
* Adds an environment to the project.
|
|
1810
|
+
* @returns The same or created environment.
|
|
1811
|
+
*/
|
|
1812
|
+
addEnvironment(env: IEnvironment | Environment | string, opts: IAppProjectEnvironmentCreateOptions = {}): Environment {
|
|
1813
|
+
const environment = this._createEnv(env);
|
|
1814
|
+
const root = this._getRoot(opts);
|
|
1815
|
+
const project = this.getProject();
|
|
1816
|
+
if (!project.definitions.environments) {
|
|
1817
|
+
project.definitions.environments = [];
|
|
1818
|
+
}
|
|
1819
|
+
project.definitions.environments.push(environment);
|
|
1820
|
+
const item = AppProjectItem.projectEnvironment(project, environment.key);
|
|
1821
|
+
this._insertItem(item, root, opts);
|
|
1822
|
+
return environment;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
protected _createEnv(env: IEnvironment | Environment | string): Environment {
|
|
1826
|
+
let finalEnv: Environment;
|
|
1827
|
+
if (env instanceof Environment) {
|
|
1828
|
+
finalEnv = env;
|
|
1829
|
+
} else if (typeof env === 'string') {
|
|
1830
|
+
finalEnv = Environment.fromName(env);
|
|
1831
|
+
} else {
|
|
1832
|
+
finalEnv = new Environment(env);
|
|
1833
|
+
}
|
|
1834
|
+
if (!finalEnv.key) {
|
|
1835
|
+
finalEnv.key = v4();
|
|
1836
|
+
}
|
|
1837
|
+
return finalEnv;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* @param key The environment key to read.
|
|
1842
|
+
*/
|
|
1843
|
+
getEnvironment(key: string, opts: IAppProjectItemOptions = {}): Environment | undefined {
|
|
1844
|
+
const root = this._getRoot(opts);
|
|
1845
|
+
const item = root.items.find(i => i.key === key);
|
|
1846
|
+
if (!item) {
|
|
1847
|
+
return undefined;
|
|
1848
|
+
}
|
|
1849
|
+
const project = this.getProject();
|
|
1850
|
+
if (!Array.isArray(project.definitions.environments)) {
|
|
1851
|
+
project.definitions.environments = [];
|
|
1852
|
+
}
|
|
1853
|
+
return project.definitions.environments.find(e => e.key === key);
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
/**
|
|
1857
|
+
* Removes an environment from the folder or a sub-folder.
|
|
1858
|
+
*
|
|
1859
|
+
* @param key the key of the environment to remove
|
|
1860
|
+
* @returns The removed environment, if any.
|
|
1861
|
+
*/
|
|
1862
|
+
removeEnvironment(key: string, opts: IAppProjectItemOptions = {}): Environment | undefined {
|
|
1863
|
+
const root = this._getRoot(opts);
|
|
1864
|
+
const itemIndex = root.items.findIndex(i => i.key === key);
|
|
1865
|
+
if (itemIndex < 0) {
|
|
1866
|
+
return undefined;
|
|
1867
|
+
}
|
|
1868
|
+
root.items.splice(itemIndex, 1);
|
|
1869
|
+
const project = this.getProject();
|
|
1870
|
+
if (!Array.isArray(project.definitions.environments)) {
|
|
1871
|
+
project.definitions.environments = [];
|
|
1872
|
+
}
|
|
1873
|
+
const defIndex = project.definitions.environments.findIndex(i => i.key === key);
|
|
1874
|
+
if (defIndex < 0) {
|
|
1875
|
+
return undefined;
|
|
1876
|
+
}
|
|
1877
|
+
const env = project.definitions.environments[defIndex];
|
|
1878
|
+
project.definitions.environments.splice(defIndex, 1);
|
|
1879
|
+
return env;
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* This is a link to the `getEnvironments()`. The difference is that on the
|
|
1884
|
+
* project level it won't return environments defined with the class initialization.
|
|
1885
|
+
*/
|
|
1886
|
+
listEnvironments(opts: IAppProjectItemOptions = {}): Environment[] {
|
|
1887
|
+
const root = this._getRoot(opts);
|
|
1888
|
+
const items = root.items.filter(i => i.kind === EnvironmentKind).map(i => i.key);
|
|
1889
|
+
const project = this.getProject();
|
|
1890
|
+
if (!Array.isArray(project.definitions.environments)) {
|
|
1891
|
+
project.definitions.environments = [];
|
|
1892
|
+
}
|
|
1893
|
+
return project.definitions.environments.filter(e => items.includes(e.key));
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* Reads the list of environments from then selected folder up to the project root.
|
|
1898
|
+
* It stops going up in the project structure when selected environment has the `encapsulated`
|
|
1899
|
+
* property set to true.
|
|
1900
|
+
* The environments are ordered from the top-most level to the selected folder.
|
|
1901
|
+
*
|
|
1902
|
+
* @param opts The environment read options
|
|
1903
|
+
*/
|
|
1904
|
+
readEnvironments(opts: IAppProjectReadEnvironmentOptions = {}): Environment[] {
|
|
1905
|
+
const result: Environment[] = [];
|
|
1906
|
+
const { parent, nameOrKey } = opts;
|
|
1907
|
+
|
|
1908
|
+
const root = parent ? this.findFolder(parent, { keyOnly: true }) : this;
|
|
1909
|
+
if (!root) {
|
|
1910
|
+
return result;
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
let current: AppProject | AppProjectFolder | undefined = root;
|
|
1914
|
+
while (current) {
|
|
1915
|
+
const environments = current.listEnvironments();
|
|
1916
|
+
if (environments.length) {
|
|
1917
|
+
const selected = nameOrKey ? environments.find(i => i.key === nameOrKey || i.info.name === nameOrKey) : environments[0];
|
|
1918
|
+
if (selected) {
|
|
1919
|
+
result.push(selected);
|
|
1920
|
+
if (selected.encapsulated) {
|
|
1921
|
+
break;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
current = current.getParent();
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
return result.reverse();
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
/**
|
|
1932
|
+
* Finds a definition for an environment regardless of its parent.
|
|
1933
|
+
*
|
|
1934
|
+
* @param key The Key of the environment to find.
|
|
1935
|
+
* @returns The environment definition or undefined if not found.
|
|
1936
|
+
*/
|
|
1937
|
+
findEnvironment(key: string): Environment | undefined {
|
|
1938
|
+
return this.definitions.environments.find(i => i.key === key);
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
/**
|
|
1942
|
+
* Depending on the options returns a project or a folder.
|
|
1943
|
+
* It throws when parent folder cannot ber found.
|
|
1944
|
+
*/
|
|
1945
|
+
protected _getRoot(opts: { parent?: string }): AppProjectFolder | AppProject {
|
|
1946
|
+
const project = this.getProject();
|
|
1947
|
+
if (opts.parent) {
|
|
1948
|
+
const parent = project.findFolder(opts.parent);
|
|
1949
|
+
if (!parent) {
|
|
1950
|
+
throw new Error(`Unable to find the parent folder ${opts.parent}.`);
|
|
1951
|
+
}
|
|
1952
|
+
return parent;
|
|
1953
|
+
}
|
|
1954
|
+
return project;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
protected _insertItem(item: AppProjectItem, root: AppProjectFolder | AppProject, opts: IAppProjectItemCreateOptions): void {
|
|
1958
|
+
if (!Array.isArray(root.items)) {
|
|
1959
|
+
root.items = [];
|
|
1960
|
+
}
|
|
1961
|
+
if (typeof opts.index === 'number') {
|
|
1962
|
+
root.items.splice(opts.index, 0, item);
|
|
1963
|
+
} else {
|
|
1964
|
+
root.items.push(item);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
/**
|
|
1969
|
+
* Finds a definition for a certificate.
|
|
1970
|
+
*
|
|
1971
|
+
* @param key The key of the certificate to find.
|
|
1972
|
+
* @returns The certificate definition or undefined if not found.
|
|
1973
|
+
*/
|
|
1974
|
+
findCertificate(key: string): Certificate | undefined {
|
|
1975
|
+
return this.definitions.certificates.find(i => i.key === key);
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
/**
|
|
1979
|
+
* Adds a certificate to the project.
|
|
1980
|
+
*
|
|
1981
|
+
* @param init Either an instance of a certificate or its definition.
|
|
1982
|
+
* @returns The inserted certificate.
|
|
1983
|
+
*/
|
|
1984
|
+
addCertificate(init: Certificate | HttpCertificate): Certificate {
|
|
1985
|
+
let finalCert: Certificate;
|
|
1986
|
+
if (init instanceof Certificate) {
|
|
1987
|
+
finalCert = init;
|
|
1988
|
+
} else {
|
|
1989
|
+
finalCert = new Certificate(init);
|
|
1990
|
+
}
|
|
1991
|
+
if (!this.definitions.certificates) {
|
|
1992
|
+
this.definitions.certificates = [];
|
|
1993
|
+
}
|
|
1994
|
+
this.definitions.certificates.push(finalCert);
|
|
1995
|
+
return finalCert;
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* Removes a certificate from the project.
|
|
2000
|
+
*
|
|
2001
|
+
* @param key the key of the certificate to remove
|
|
2002
|
+
* @returns The removed certificate, if any.
|
|
2003
|
+
*/
|
|
2004
|
+
removeCertificate(key: string): Certificate | undefined {
|
|
2005
|
+
if (!Array.isArray(this.definitions.certificates)) {
|
|
2006
|
+
return undefined
|
|
2007
|
+
}
|
|
2008
|
+
const defIndex = this.definitions.certificates.findIndex(i => i.key === key);
|
|
2009
|
+
if (defIndex < 0) {
|
|
2010
|
+
return undefined;
|
|
2011
|
+
}
|
|
2012
|
+
const cert = this.definitions.certificates[defIndex];
|
|
2013
|
+
this.definitions.certificates.splice(defIndex, 1);
|
|
2014
|
+
return cert;
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
/**
|
|
2018
|
+
* Finds the requests that are using the certificate identified by the key.
|
|
2019
|
+
*
|
|
2020
|
+
* @param key The key of the certificate to find the usage for.
|
|
2021
|
+
* @returns The list of requests that use this certificate.
|
|
2022
|
+
*/
|
|
2023
|
+
findCertificateRequests(key: string): AppProjectRequest[] {
|
|
2024
|
+
return this.definitions.requests.filter((request) => {
|
|
2025
|
+
if (!Array.isArray(request.authorization)) {
|
|
2026
|
+
return false;
|
|
2027
|
+
}
|
|
2028
|
+
const ccAuth = request.authorization.find(auth => auth.type === 'client certificate');
|
|
2029
|
+
if (!ccAuth) {
|
|
2030
|
+
return false;
|
|
2031
|
+
}
|
|
2032
|
+
const cnf = ccAuth.config as ICCAuthorization;
|
|
2033
|
+
return !!cnf && !!cnf.certificate && cnf.certificate.key === key;
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
/**
|
|
2038
|
+
* Iterates over requests in the project.
|
|
2039
|
+
*/
|
|
2040
|
+
* requestIterator(opts: IProjectRequestIterator = {}): Generator<AppProjectRequest> {
|
|
2041
|
+
const { definitions } = this;
|
|
2042
|
+
const { ignore=[], parent, recursive, requests=[] } = opts;
|
|
2043
|
+
const root = parent ? this.findFolder(parent) : this;
|
|
2044
|
+
if (!root) {
|
|
2045
|
+
throw new Error(`The parent folder not found: ${parent}.`);
|
|
2046
|
+
}
|
|
2047
|
+
const items = root.items;
|
|
2048
|
+
if (!items || !items.length) {
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
for (const item of items) {
|
|
2052
|
+
if (ignore.includes(item.key)) {
|
|
2053
|
+
continue;
|
|
2054
|
+
}
|
|
2055
|
+
if (item.kind === AppProjectRequestKind) {
|
|
2056
|
+
const request = definitions.requests.find(i => i.key === item.key);
|
|
2057
|
+
if (!request) {
|
|
2058
|
+
continue;
|
|
2059
|
+
}
|
|
2060
|
+
const name = request.info.name || '';
|
|
2061
|
+
if (ignore.includes(name)) {
|
|
2062
|
+
continue;
|
|
2063
|
+
}
|
|
2064
|
+
if (requests.length && !requests.includes(item.key) && !requests.includes(name)) {
|
|
2065
|
+
continue;
|
|
2066
|
+
}
|
|
2067
|
+
yield request;
|
|
2068
|
+
} else if (recursive && item.kind === AppProjectFolderKind) {
|
|
2069
|
+
const folder = definitions.folders.find(i => i.key === item.key);
|
|
2070
|
+
if (!folder) {
|
|
2071
|
+
continue;
|
|
2072
|
+
}
|
|
2073
|
+
const name = folder.info.name || '';
|
|
2074
|
+
if (ignore.includes(name)) {
|
|
2075
|
+
continue;
|
|
2076
|
+
}
|
|
2077
|
+
const it = this.requestIterator({
|
|
2078
|
+
parent: item.key,
|
|
2079
|
+
recursive,
|
|
2080
|
+
ignore,
|
|
2081
|
+
requests,
|
|
2082
|
+
});
|
|
2083
|
+
for (const request of it) {
|
|
2084
|
+
yield request;
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
1642
2088
|
}
|
|
1643
2089
|
}
|