@api-client/core 0.3.3 → 0.3.6
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 +3 -0
- package/build/browser.js +9 -0
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +11 -2
- package/build/index.js +20 -2
- package/build/index.js.map +1 -1
- package/build/src/lib/fs/Fs.d.ts +52 -0
- package/build/src/lib/fs/Fs.js +245 -0
- package/build/src/lib/fs/Fs.js.map +1 -0
- package/build/src/lib/timers/Timers.d.ts +5 -0
- package/build/src/lib/timers/Timers.js +10 -0
- package/build/src/lib/timers/Timers.js.map +1 -0
- package/build/src/mocking/ProjectMock.d.ts +13 -0
- package/build/src/mocking/ProjectMock.js +16 -0
- package/build/src/mocking/ProjectMock.js.map +1 -0
- package/build/src/mocking/lib/Request.d.ts +32 -0
- package/build/src/mocking/lib/Request.js +63 -0
- package/build/src/mocking/lib/Request.js.map +1 -0
- package/build/src/mocking/lib/Response.d.ts +33 -0
- package/build/src/mocking/lib/Response.js +79 -0
- package/build/src/mocking/lib/Response.js.map +1 -0
- package/build/src/models/ErrorResponse.d.ts +5 -4
- package/build/src/models/ErrorResponse.js +18 -5
- package/build/src/models/ErrorResponse.js.map +1 -1
- package/build/src/models/SerializableError.d.ts +30 -0
- package/build/src/models/SerializableError.js +63 -0
- package/build/src/models/SerializableError.js.map +1 -0
- package/build/src/runtime/http-engine/ArcEngine.js +8 -4
- package/build/src/runtime/http-engine/ArcEngine.js.map +1 -1
- package/build/src/runtime/http-engine/HttpEngine.d.ts +3 -3
- package/build/src/runtime/http-engine/HttpEngine.js +3 -3
- package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
- package/build/src/runtime/http-engine/NodeEngine.js +9 -4
- package/build/src/runtime/http-engine/NodeEngine.js.map +1 -1
- package/build/src/runtime/http-engine/NodeEngineDirect.js +8 -2
- package/build/src/runtime/http-engine/NodeEngineDirect.js.map +1 -1
- package/build/src/runtime/node/BaseRunner.d.ts +21 -0
- package/build/src/runtime/node/BaseRunner.js +27 -0
- package/build/src/runtime/node/BaseRunner.js.map +1 -0
- package/build/src/runtime/node/ProjectParallelRunner.d.ts +81 -0
- package/build/src/runtime/node/ProjectParallelRunner.js +173 -0
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -0
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +125 -0
- package/build/src/runtime/node/ProjectRequestRunner.js +185 -0
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -0
- package/build/src/runtime/node/ProjectRunner.d.ts +166 -64
- package/build/src/runtime/node/ProjectRunner.js +191 -139
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunnerWorker.d.ts +1 -0
- package/build/src/runtime/node/ProjectRunnerWorker.js +58 -0
- package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -0
- package/build/src/runtime/node/ProjectSerialRunner.d.ts +11 -0
- package/build/src/runtime/node/ProjectSerialRunner.js +34 -0
- package/build/src/runtime/node/ProjectSerialRunner.js.map +1 -0
- package/build/src/runtime/reporters/ProjectRunCliReporter.d.ts +7 -0
- package/build/src/runtime/reporters/ProjectRunCliReporter.js +73 -0
- package/build/src/runtime/reporters/ProjectRunCliReporter.js.map +1 -0
- package/build/src/runtime/reporters/Reporter.d.ts +62 -0
- package/build/src/runtime/reporters/Reporter.js +98 -0
- package/build/src/runtime/reporters/Reporter.js.map +1 -0
- package/build/src/testing/TestCliHelper.d.ts +23 -0
- package/build/src/testing/TestCliHelper.js +71 -0
- package/build/src/testing/TestCliHelper.js.map +1 -0
- package/build/src/testing/getPort.d.ts +52 -0
- package/build/src/testing/getPort.js +169 -0
- package/build/src/testing/getPort.js.map +1 -0
- package/package.json +2 -1
- package/src/data/DataReader.ts +11 -0
- package/src/data/DataUtils.ts +108 -0
- package/src/data/JmesparthReader.ts +26 -0
- package/src/data/Json2Xml.ts +190 -0
- package/src/data/JsonReader.ts +41 -0
- package/src/data/PayloadPointer.ts +48 -0
- package/src/data/RequestDataExtractor.ts +133 -0
- package/src/data/UrlEncodedReader.ts +20 -0
- package/src/data/XmlReader.ts +103 -0
- package/src/events/BaseEvents.ts +259 -0
- package/src/events/CustomEvent.ts +27 -0
- package/src/events/EventTypes.ts +19 -0
- package/src/events/Events.ts +19 -0
- package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
- package/src/events/authorization/AuthorizationEvents.ts +61 -0
- package/src/events/cookies/CookieEventTypes.ts +13 -0
- package/src/events/cookies/CookieEvents.ts +157 -0
- package/src/events/encryption/EncryptionEventTypes.ts +4 -0
- package/src/events/encryption/EncryptionEvents.ts +51 -0
- package/src/events/environment/EnvironmentEventTypes.ts +3 -0
- package/src/events/environment/EnvironmentEvents.ts +24 -0
- package/src/events/models/ClientCertificateEvents.ts +87 -0
- package/src/events/models/ModelEventTypes.ts +47 -0
- package/src/events/models/ModelEvents.ts +7 -0
- package/src/events/models/ProjectEvents.ts +331 -0
- package/src/events/process/ProcessEventTypes.ts +5 -0
- package/src/events/process/ProcessEvents.ts +76 -0
- package/src/events/readme.md +22 -0
- package/src/events/reporting/ReportingEventTypes.ts +3 -0
- package/src/events/reporting/ReportingEvents.ts +28 -0
- package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
- package/src/events/telemetry/TelemetryEvents.ts +156 -0
- package/src/lib/cookies/Cookie.ts +312 -0
- package/src/lib/cookies/Cookies.ts +326 -0
- package/src/lib/cookies/Utils.ts +168 -0
- package/src/lib/fs/Fs.ts +258 -0
- package/src/lib/headers/Headers.ts +219 -0
- package/src/lib/logging/DefaultLogger.ts +19 -0
- package/src/lib/logging/DummyLogger.ts +21 -0
- package/src/lib/logging/Logger.ts +16 -0
- package/src/lib/timers/Timers.ts +9 -0
- package/src/lib/transformers/PayloadSerializer.ts +332 -0
- package/src/lib/transformers/Utils.ts +18 -0
- package/src/lib/uuid.ts +40 -0
- package/src/mocking/LegacyInterfaces.ts +52 -0
- package/src/mocking/LegacyMock.ts +37 -0
- package/src/mocking/ProjectMock.ts +20 -0
- package/src/mocking/legacy/Authorization.ts +39 -0
- package/src/mocking/legacy/Certificates.ts +145 -0
- package/src/mocking/legacy/Cookies.ts +51 -0
- package/src/mocking/legacy/HostRules.ts +43 -0
- package/src/mocking/legacy/Http.ts +236 -0
- package/src/mocking/legacy/HttpResponse.ts +106 -0
- package/src/mocking/legacy/RestApi.ts +68 -0
- package/src/mocking/legacy/Urls.ts +44 -0
- package/src/mocking/legacy/Variables.ts +53 -0
- package/src/mocking/lib/Request.ts +85 -0
- package/src/mocking/lib/Response.ts +101 -0
- package/src/models/ArcResponse.ts +166 -0
- package/src/models/Authorization.ts +481 -0
- package/src/models/AuthorizationData.ts +60 -0
- package/src/models/Backend.ts +107 -0
- package/src/models/ClientCertificate.ts +68 -0
- package/src/models/Environment.ts +279 -0
- package/src/models/ErrorResponse.ts +113 -0
- package/src/models/HistoryIndex.ts +76 -0
- package/src/models/HistoryRequest.ts +28 -0
- package/src/models/HostRule.ts +163 -0
- package/src/models/HttpCookie.ts +285 -0
- package/src/models/HttpProject.ts +1294 -0
- package/src/models/HttpProjectListItem.ts +23 -0
- package/src/models/HttpRequest.ts +124 -0
- package/src/models/HttpResponse.ts +143 -0
- package/src/models/License.ts +113 -0
- package/src/models/ProjectDefinitionProperty.ts +40 -0
- package/src/models/ProjectFolder.ts +439 -0
- package/src/models/ProjectItem.ts +135 -0
- package/src/models/ProjectParent.ts +113 -0
- package/src/models/ProjectRequest.ts +277 -0
- package/src/models/ProjectSchema.ts +202 -0
- package/src/models/Property.ts +423 -0
- package/src/models/Provider.ts +98 -0
- package/src/models/README.md +20 -0
- package/src/models/Request.ts +452 -0
- package/src/models/RequestActions.ts +163 -0
- package/src/models/RequestAuthorization.ts +115 -0
- package/src/models/RequestConfig.ts +317 -0
- package/src/models/RequestLog.ts +159 -0
- package/src/models/RequestTime.ts +108 -0
- package/src/models/RequestUiMeta.ts +258 -0
- package/src/models/RequestsSize.ts +65 -0
- package/src/models/ResponseAuthorization.ts +104 -0
- package/src/models/ResponseRedirect.ts +158 -0
- package/src/models/RevisionInfo.ts +37 -0
- package/src/models/SentRequest.ts +125 -0
- package/src/models/SerializableError.ts +80 -0
- package/src/models/SerializablePayload.ts +68 -0
- package/src/models/Server.ts +153 -0
- package/src/models/Thing.ts +110 -0
- package/src/models/Url.ts +90 -0
- package/src/models/User.ts +120 -0
- package/src/models/WebApi.ts +234 -0
- package/src/models/WebApiIndex.ts +122 -0
- package/src/models/Workspace.ts +182 -0
- package/src/models/actions/Action.ts +213 -0
- package/src/models/actions/ActionView.ts +40 -0
- package/src/models/actions/Condition.ts +207 -0
- package/src/models/actions/ConditionView.ts +42 -0
- package/src/models/actions/Enums.ts +29 -0
- package/src/models/actions/RunnableAction.ts +144 -0
- package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
- package/src/models/actions/runnable/Runnable.ts +9 -0
- package/src/models/actions/runnable/SetCookieAction.ts +216 -0
- package/src/models/actions/runnable/SetVariableAction.ts +81 -0
- package/src/models/legacy/DataExport.ts +172 -0
- package/src/models/legacy/Normalizer.ts +110 -0
- package/src/models/legacy/actions/Actions.ts +269 -0
- package/src/models/legacy/authorization/Authorization.ts +572 -0
- package/src/models/legacy/models/ApiTypes.ts +202 -0
- package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
- package/src/models/legacy/models/AuthData.ts +17 -0
- package/src/models/legacy/models/ClientCertificate.ts +95 -0
- package/src/models/legacy/models/Cookies.ts +52 -0
- package/src/models/legacy/models/HostRule.ts +35 -0
- package/src/models/legacy/models/RestApi.ts +49 -0
- package/src/models/legacy/models/UrlHistory.ts +37 -0
- package/src/models/legacy/models/Variable.ts +43 -0
- package/src/models/legacy/models/base.d.ts +95 -0
- package/src/models/legacy/request/ArcRequest.ts +405 -0
- package/src/models/legacy/request/ArcResponse.ts +177 -0
- package/src/models/legacy/request/HistoryData.ts +47 -0
- package/src/models/legacy/request/Legacy.ts +45 -0
- package/src/models/legacy/request/RequestBody.ts +87 -0
- package/src/models/transformers/ArcDexieTransformer.ts +323 -0
- package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
- package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
- package/src/models/transformers/ArcPouchTransformer.ts +184 -0
- package/src/models/transformers/BaseTransformer.ts +116 -0
- package/src/models/transformers/ImportUtils.ts +141 -0
- package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
- package/src/models/transformers/LegacyExportProcessor.ts +252 -0
- package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
- package/src/models/transformers/PostmanDataTransformer.ts +50 -0
- package/src/models/transformers/PostmanTransformer.ts +106 -0
- package/src/models/transformers/PostmanV21Transformer.ts +311 -0
- package/src/models/transformers/PostmanV2Transformer.ts +308 -0
- package/src/models/transformers/har.ts +865 -0
- package/src/runtime/actions/ActionRunner.ts +83 -0
- package/src/runtime/actions/ConditionRunner.ts +194 -0
- package/src/runtime/actions/RunnableCondition.ts +57 -0
- package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
- package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
- package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
- package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
- package/src/runtime/http-engine/ArcEngine.ts +1068 -0
- package/src/runtime/http-engine/FormData.ts +85 -0
- package/src/runtime/http-engine/HttpEngine.ts +874 -0
- package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
- package/src/runtime/http-engine/NodeEngine.ts +792 -0
- package/src/runtime/http-engine/NodeEngineDirect.ts +482 -0
- package/src/runtime/http-engine/PayloadSupport.ts +84 -0
- package/src/runtime/http-engine/RequestUtils.ts +164 -0
- package/src/runtime/http-engine/ntlm/Des.ts +345 -0
- package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
- package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
- package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
- package/src/runtime/modules/BasicAuthCache.ts +133 -0
- package/src/runtime/modules/ExecutionResponse.ts +4 -0
- package/src/runtime/modules/ModulesRegistry.ts +136 -0
- package/src/runtime/modules/RequestAuthorization.ts +110 -0
- package/src/runtime/modules/RequestCookies.ts +145 -0
- package/src/runtime/node/BaseRunner.ts +29 -0
- package/src/runtime/node/ProjectParallelRunner.ts +234 -0
- package/src/runtime/node/ProjectRequestRunner.ts +281 -0
- package/src/runtime/node/ProjectRunner.ts +374 -0
- package/src/runtime/node/ProjectRunnerWorker.ts +62 -0
- package/src/runtime/node/ProjectSerialRunner.ts +36 -0
- package/src/runtime/node/RequestFactory.ts +422 -0
- package/src/runtime/node/VariablesStore.ts +25 -0
- package/src/runtime/reporters/ProjectRunCliReporter.ts +79 -0
- package/src/runtime/reporters/Reporter.ts +142 -0
- package/src/runtime/store/StoreSdk.ts +838 -0
- package/src/runtime/variables/Cache.ts +53 -0
- package/src/runtime/variables/EvalFunctions.ts +132 -0
- package/src/runtime/variables/ProjectVariables.ts +6 -0
- package/src/runtime/variables/VariablesProcessor.ts +543 -0
- package/src/runtime/variables/VariablesTokenizer.ts +55 -0
- package/src/testing/TestCliHelper.ts +76 -0
- package/src/testing/getPort.ts +212 -0
- package/build/src/runtime/http-engine/Errors.d.ts +0 -10
- package/build/src/runtime/http-engine/Errors.js +0 -14
- package/build/src/runtime/http-engine/Errors.js.map +0 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { Environment } from '../../models/Environment.js';
|
|
4
|
+
import { Logger } from '../../lib/logging/Logger.js';
|
|
5
|
+
import { IRequestLog } from '../../models/RequestLog.js';
|
|
6
|
+
import { ProjectFolder } from '../../models/ProjectFolder.js';
|
|
7
|
+
import { ProjectRequest } from '../../models/ProjectRequest.js';
|
|
8
|
+
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
9
|
+
import { HttpProject, IProjectRequestIterator } from '../../models/HttpProject.js';
|
|
10
|
+
import { VariablesProcessor } from '../variables/VariablesProcessor.js';
|
|
11
|
+
export interface ProjectRunnerOptions {
|
|
12
|
+
/**
|
|
13
|
+
* When provided it overrides any project / folder defined environment.
|
|
14
|
+
*/
|
|
15
|
+
environment?: Environment;
|
|
16
|
+
/**
|
|
17
|
+
* Additional variables to pass to the selected environment.
|
|
18
|
+
* This can be use to pass system variables, when needed.
|
|
19
|
+
*
|
|
20
|
+
* To use system variables tou can use `init.variables = process.env`;
|
|
21
|
+
*/
|
|
22
|
+
variables?: Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Overrides the default logger (console).
|
|
25
|
+
*/
|
|
26
|
+
logger?: Logger;
|
|
27
|
+
/**
|
|
28
|
+
* The event target to use.
|
|
29
|
+
* By default it creates its own target.
|
|
30
|
+
*/
|
|
31
|
+
eventTarget?: EventTarget;
|
|
32
|
+
}
|
|
33
|
+
export interface ProjectRunnerRunOptions extends IProjectRequestIterator {
|
|
34
|
+
}
|
|
35
|
+
export interface RunResult {
|
|
36
|
+
/**
|
|
37
|
+
* The key of the request from the HttpProject that was executed.
|
|
38
|
+
*/
|
|
39
|
+
key: string;
|
|
40
|
+
/**
|
|
41
|
+
* The key of parent folder of the executed request.
|
|
42
|
+
*/
|
|
43
|
+
parent?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Set when a fatal error occurred so the request couldn't be executed.
|
|
46
|
+
* This is not the same as error reported during a request. The log's response can still be IResponseError.
|
|
47
|
+
*/
|
|
48
|
+
error?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The error message. Always set when the `error` is `true`.
|
|
51
|
+
*/
|
|
52
|
+
errorMessage?: string;
|
|
53
|
+
/**
|
|
54
|
+
* The request log.
|
|
55
|
+
* Always set when the `error` is `false`.
|
|
56
|
+
*/
|
|
57
|
+
log?: IRequestLog;
|
|
58
|
+
}
|
|
59
|
+
export interface ProjectRequestRunner {
|
|
60
|
+
/**
|
|
61
|
+
* The request object is prepared and about to be sent to the HTTP engine
|
|
62
|
+
*/
|
|
63
|
+
on(event: 'request', listener: (key: string, request: IHttpRequest) => void): this;
|
|
64
|
+
/**
|
|
65
|
+
* The response is ready.
|
|
66
|
+
*/
|
|
67
|
+
on(event: 'response', listener: (key: string, log: IRequestLog) => void): this;
|
|
68
|
+
/**
|
|
69
|
+
* There was a general error during the request
|
|
70
|
+
*/
|
|
71
|
+
on(event: 'error', listener: (key: string, log: IRequestLog, message: string) => void): this;
|
|
72
|
+
/**
|
|
73
|
+
* The request object is prepared and about to be sent to the HTTP engine
|
|
74
|
+
*/
|
|
75
|
+
once(event: 'request', listener: (key: string, request: IHttpRequest) => void): this;
|
|
76
|
+
/**
|
|
77
|
+
* The response is ready.
|
|
78
|
+
*/
|
|
79
|
+
once(event: 'response', listener: (key: string, log: IRequestLog) => void): this;
|
|
80
|
+
/**
|
|
81
|
+
* There was a general error during the request
|
|
82
|
+
*/
|
|
83
|
+
once(event: 'error', listener: (key: string, log: IRequestLog, message: string) => void): this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Runs requests in a project.
|
|
87
|
+
* Developers can run the entire project with the `recursive` flag set. They can also
|
|
88
|
+
* set the starting point with the `parent` options.
|
|
89
|
+
*
|
|
90
|
+
* Requests are executed in order defined in the folder.
|
|
91
|
+
*/
|
|
92
|
+
export declare class ProjectRequestRunner extends EventEmitter {
|
|
93
|
+
eventTarget: EventTarget;
|
|
94
|
+
logger?: Logger;
|
|
95
|
+
project: HttpProject;
|
|
96
|
+
protected masterEnvironment?: Environment;
|
|
97
|
+
protected extraVariables?: Record<string, string>;
|
|
98
|
+
/**
|
|
99
|
+
* The variables processor instance.
|
|
100
|
+
*/
|
|
101
|
+
protected variablesProcessor: VariablesProcessor;
|
|
102
|
+
constructor(project: HttpProject, opts?: ProjectRunnerOptions);
|
|
103
|
+
/**
|
|
104
|
+
* Runs the request from the project root or a specified folder.
|
|
105
|
+
* @param options Run options.
|
|
106
|
+
* @returns A promise with the run result.
|
|
107
|
+
*/
|
|
108
|
+
run(options?: ProjectRunnerRunOptions): Promise<RunResult[]>;
|
|
109
|
+
protected execute(request: ProjectRequest, variables: Record<string, string>): Promise<RunResult>;
|
|
110
|
+
protected getVariables(parent: HttpProject | ProjectFolder): Promise<Record<string, string>>;
|
|
111
|
+
protected createEnvironment(parent: HttpProject | ProjectFolder): Promise<Record<string, string>>;
|
|
112
|
+
/**
|
|
113
|
+
* Reads the list of the environments to apply to this runtime.
|
|
114
|
+
*/
|
|
115
|
+
protected readEnvironments(parent: HttpProject | ProjectFolder): Promise<Environment[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Reads the variables and the base URI from the passed environments.
|
|
118
|
+
*/
|
|
119
|
+
protected applyVariables(environments: Environment[]): Promise<Record<string, string>>;
|
|
120
|
+
/**
|
|
121
|
+
* When defined it applies the serve's base URI to relative URLs.
|
|
122
|
+
* @param currentUrl The URL to process.
|
|
123
|
+
*/
|
|
124
|
+
protected prepareRequestUrl(currentUrl: string, variables: Record<string, string>): string;
|
|
125
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { RequestLog } from '../../models/RequestLog.js';
|
|
3
|
+
import { Kind as ProjectFolderKind } from '../../models/ProjectFolder.js';
|
|
4
|
+
import { SentRequest } from '../../models/SentRequest.js';
|
|
5
|
+
import { ErrorResponse } from '../../models/ErrorResponse.js';
|
|
6
|
+
import { VariablesStore } from './VariablesStore.js';
|
|
7
|
+
import { VariablesProcessor } from '../variables/VariablesProcessor.js';
|
|
8
|
+
import { RequestFactory } from './RequestFactory.js';
|
|
9
|
+
import { EventTypes } from '../../events/EventTypes.js';
|
|
10
|
+
/**
|
|
11
|
+
* Runs requests in a project.
|
|
12
|
+
* Developers can run the entire project with the `recursive` flag set. They can also
|
|
13
|
+
* set the starting point with the `parent` options.
|
|
14
|
+
*
|
|
15
|
+
* Requests are executed in order defined in the folder.
|
|
16
|
+
*/
|
|
17
|
+
export class ProjectRequestRunner extends EventEmitter {
|
|
18
|
+
eventTarget;
|
|
19
|
+
logger;
|
|
20
|
+
project;
|
|
21
|
+
masterEnvironment;
|
|
22
|
+
extraVariables;
|
|
23
|
+
/**
|
|
24
|
+
* The variables processor instance.
|
|
25
|
+
*/
|
|
26
|
+
variablesProcessor = new VariablesProcessor();
|
|
27
|
+
constructor(project, opts = {}) {
|
|
28
|
+
super();
|
|
29
|
+
this.project = project;
|
|
30
|
+
this.logger = opts.logger;
|
|
31
|
+
this.eventTarget = opts.eventTarget || new EventTarget();
|
|
32
|
+
this.masterEnvironment = opts.environment;
|
|
33
|
+
this.extraVariables = opts.variables;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Runs the request from the project root or a specified folder.
|
|
37
|
+
* @param options Run options.
|
|
38
|
+
* @returns A promise with the run result.
|
|
39
|
+
*/
|
|
40
|
+
async run(options) {
|
|
41
|
+
const { project } = this;
|
|
42
|
+
const executed = [];
|
|
43
|
+
for (const request of project.requestIterator(options)) {
|
|
44
|
+
const parent = request.getParent() || project;
|
|
45
|
+
let variables;
|
|
46
|
+
if (VariablesStore.has(parent)) {
|
|
47
|
+
variables = VariablesStore.get(parent);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
variables = await this.getVariables(parent);
|
|
51
|
+
VariablesStore.set(parent, variables);
|
|
52
|
+
}
|
|
53
|
+
const info = await this.execute(request, variables);
|
|
54
|
+
executed.push(info);
|
|
55
|
+
}
|
|
56
|
+
return executed;
|
|
57
|
+
}
|
|
58
|
+
async execute(request, variables) {
|
|
59
|
+
const config = request.getConfig();
|
|
60
|
+
const factory = new RequestFactory(this.eventTarget);
|
|
61
|
+
factory.variables = variables;
|
|
62
|
+
if (request.authorization) {
|
|
63
|
+
factory.authorization = request.authorization.map(i => i.toJSON());
|
|
64
|
+
}
|
|
65
|
+
if (request.actions) {
|
|
66
|
+
factory.actions = request.actions.toJSON();
|
|
67
|
+
}
|
|
68
|
+
if (request.clientCertificate) {
|
|
69
|
+
factory.certificates = [request.clientCertificate];
|
|
70
|
+
}
|
|
71
|
+
if (config.enabled !== false) {
|
|
72
|
+
factory.config = config.toJSON();
|
|
73
|
+
}
|
|
74
|
+
if (this.logger) {
|
|
75
|
+
factory.logger = this.logger;
|
|
76
|
+
}
|
|
77
|
+
const info = {
|
|
78
|
+
key: request.key,
|
|
79
|
+
};
|
|
80
|
+
const requestData = request.expects.toJSON();
|
|
81
|
+
requestData.url = this.prepareRequestUrl(requestData.url, variables);
|
|
82
|
+
function variableHandler(e) {
|
|
83
|
+
if (e.defaultPrevented) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const { name, value } = e.detail;
|
|
87
|
+
variables[name] = value;
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
e.detail.result = Promise.resolve();
|
|
90
|
+
}
|
|
91
|
+
this.eventTarget.addEventListener(EventTypes.Environment.set, variableHandler);
|
|
92
|
+
try {
|
|
93
|
+
// Below replaces the single call to the `run()` function of the factory to
|
|
94
|
+
// report via the events a request object that has evaluated with the Jexl library.
|
|
95
|
+
const requestCopy = await factory.processRequestVariables(requestData);
|
|
96
|
+
this.emit('request', request.key, { ...requestCopy });
|
|
97
|
+
await factory.processRequestLogic(requestCopy);
|
|
98
|
+
const result = await factory.executeRequest(requestCopy);
|
|
99
|
+
await factory.processResponse(result);
|
|
100
|
+
request.setLog(result);
|
|
101
|
+
info.log = result;
|
|
102
|
+
this.emit('response', request.key, { ...result });
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
const cause = e;
|
|
106
|
+
info.error = true;
|
|
107
|
+
info.errorMessage = cause.message;
|
|
108
|
+
const sent = new SentRequest({ ...requestData, startTime: 0, endTime: 0, });
|
|
109
|
+
const response = ErrorResponse.fromError(info.errorMessage);
|
|
110
|
+
const log = RequestLog.fromRequestResponse(sent.toJSON(), response.toJSON()).toJSON();
|
|
111
|
+
this.emit('error', request.key, log, info.errorMessage);
|
|
112
|
+
}
|
|
113
|
+
this.eventTarget.removeEventListener(EventTypes.Environment.set, variableHandler);
|
|
114
|
+
return info;
|
|
115
|
+
}
|
|
116
|
+
async getVariables(parent) {
|
|
117
|
+
if (this.masterEnvironment) {
|
|
118
|
+
return this.applyVariables([this.masterEnvironment]);
|
|
119
|
+
}
|
|
120
|
+
return this.createEnvironment(parent);
|
|
121
|
+
}
|
|
122
|
+
async createEnvironment(parent) {
|
|
123
|
+
const envs = await this.readEnvironments(parent);
|
|
124
|
+
return this.applyVariables(envs);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Reads the list of the environments to apply to this runtime.
|
|
128
|
+
*/
|
|
129
|
+
async readEnvironments(parent) {
|
|
130
|
+
const folderKey = parent.kind === ProjectFolderKind ? parent.key : undefined;
|
|
131
|
+
return this.project.readEnvironments({ folderKey });
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Reads the variables and the base URI from the passed environments.
|
|
135
|
+
*/
|
|
136
|
+
async applyVariables(environments) {
|
|
137
|
+
let baseUri = '';
|
|
138
|
+
const variables = [];
|
|
139
|
+
environments.forEach((environment) => {
|
|
140
|
+
const { server, variables: envVariables } = environment;
|
|
141
|
+
if (server) {
|
|
142
|
+
baseUri = server.readUri();
|
|
143
|
+
}
|
|
144
|
+
if (envVariables.length) {
|
|
145
|
+
envVariables.forEach((item) => {
|
|
146
|
+
const defined = variables.findIndex(i => i.name === item.name);
|
|
147
|
+
if (defined >= 0) {
|
|
148
|
+
variables[defined] = item;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
variables.push(item);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const { extraVariables } = this;
|
|
157
|
+
const ctx = VariablesProcessor.createContextFromProperties(variables);
|
|
158
|
+
if (extraVariables) {
|
|
159
|
+
Object.keys(extraVariables).forEach((key) => {
|
|
160
|
+
ctx[key] = extraVariables[key];
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// the `baseUri` is reserved and always set to the environment's `baseUri`.
|
|
164
|
+
ctx.baseUri = baseUri || '';
|
|
165
|
+
return this.variablesProcessor.buildContext(ctx);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* When defined it applies the serve's base URI to relative URLs.
|
|
169
|
+
* @param currentUrl The URL to process.
|
|
170
|
+
*/
|
|
171
|
+
prepareRequestUrl(currentUrl, variables) {
|
|
172
|
+
const { baseUri } = variables;
|
|
173
|
+
if (!baseUri) {
|
|
174
|
+
return currentUrl;
|
|
175
|
+
}
|
|
176
|
+
if (currentUrl.startsWith('http:') || currentUrl.startsWith('https:')) {
|
|
177
|
+
return currentUrl;
|
|
178
|
+
}
|
|
179
|
+
if (currentUrl.startsWith('/')) {
|
|
180
|
+
return `${baseUri}${currentUrl}`;
|
|
181
|
+
}
|
|
182
|
+
return `${baseUri}/${currentUrl}`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=ProjectRequestRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProjectRequestRunner.js","sourceRoot":"","sources":["../../../../src/runtime/node/ProjectRequestRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAe,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAErE,OAAO,EAAiB,IAAI,IAAI,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAIzF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAgFxD;;;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I,CAAC,OAAO,EAAE;YACZ,OAAO,UAAU,CAAC;SACnB;QACD,IAAI,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YACrE,OAAO,UAAU,CAAC;SACnB;QACD,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC9B,OAAO,GAAG,OAAO,GAAG,UAAU,EAAE,CAAC;SAClC;QACD,OAAO,GAAG,OAAO,IAAI,UAAU,EAAE,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -1,62 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { HttpProject } from '../../models/HttpProject.js';
|
|
2
|
+
import { ProjectFolder } from '../../models/ProjectFolder.js';
|
|
3
3
|
import { Environment } from '../../models/Environment.js';
|
|
4
4
|
import { Logger } from '../../lib/logging/Logger.js';
|
|
5
5
|
import { IRequestLog } from '../../models/RequestLog.js';
|
|
6
|
-
import { ProjectFolder } from '../../models/ProjectFolder.js';
|
|
7
|
-
import { ProjectRequest } from '../../models/ProjectRequest.js';
|
|
8
6
|
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
7
|
+
import { IProjectExecutionIteration, IProjectExecutionLog } from '../reporters/Reporter.js';
|
|
8
|
+
import { BaseRunner } from './BaseRunner.js';
|
|
9
|
+
declare type ProjectParent = HttpProject | ProjectFolder;
|
|
10
|
+
export interface IProjectRunnerOptions {
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* The environment to use.
|
|
13
|
+
* This can be a name or the key of the environment located under the parent or root.
|
|
14
|
+
* It can also be a path to the environment definition. If the file exists it is used. Otherwise it tried to
|
|
15
|
+
* find the environment in the project.
|
|
14
16
|
*/
|
|
15
|
-
environment?:
|
|
17
|
+
environment?: string;
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
18
|
-
* This can be use to pass system variables, when needed.
|
|
19
|
-
*
|
|
20
|
-
* To use system variables tou can use `init.variables = process.env`;
|
|
19
|
+
* The parent folder to execute.
|
|
21
20
|
*/
|
|
22
|
-
|
|
21
|
+
parent?: string;
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
23
|
+
* The names or the keys of requests to execute.
|
|
24
|
+
* This can be used to limit the number of requests.
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
request?: string[];
|
|
27
27
|
/**
|
|
28
|
-
* The
|
|
29
|
-
*
|
|
28
|
+
* The number of times the execution should be repeated.
|
|
29
|
+
* Default to 1.
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
export interface ProjectRunnerRunOptions extends IProjectRequestIterator {
|
|
34
|
-
}
|
|
35
|
-
export interface RunResult {
|
|
31
|
+
iterations?: number;
|
|
36
32
|
/**
|
|
37
|
-
* The
|
|
33
|
+
* The number of milliseconds to wait between each iteration.
|
|
34
|
+
* Default to the next frame (vary from 1 to tens of milliseconds).
|
|
38
35
|
*/
|
|
39
|
-
|
|
36
|
+
iterationDelay?: number;
|
|
40
37
|
/**
|
|
41
|
-
*
|
|
38
|
+
* When set it performs parallel execution for each iteration.
|
|
39
|
+
* The number of executions at the same time depends on the number of processor cores
|
|
40
|
+
* available on the current machine. The maximum of the parallel execution
|
|
41
|
+
* is the number of available cores. When the `iterations` number is higher
|
|
42
|
+
* then the "rest" is added to the iterations per each core.
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
+
parallel?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* When set it includes requests in the current folder and sub-folder according to the order
|
|
47
|
+
* defined in the folder.
|
|
48
|
+
*/
|
|
49
|
+
recursive?: boolean;
|
|
44
50
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
51
|
+
* The opposite of the `requests`. The list of names or keys of requests or folders to ignore.
|
|
52
|
+
* Note, ignore is tested before the `requests`.
|
|
47
53
|
*/
|
|
48
|
-
|
|
54
|
+
ignore?: string[];
|
|
49
55
|
/**
|
|
50
|
-
* The
|
|
56
|
+
* The logger to use with the request factory.
|
|
57
|
+
* When not set it uses the dummy logger (no output).
|
|
51
58
|
*/
|
|
52
|
-
|
|
59
|
+
logger?: Logger;
|
|
53
60
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
61
|
+
* When true it copies all system variables to the execution environment.
|
|
62
|
+
* When an array of strings, only takes system variables that are listed in the array.
|
|
63
|
+
* When a map, it uses this map as a list of variables.
|
|
64
|
+
* When not set it does not read system variables.
|
|
56
65
|
*/
|
|
57
|
-
|
|
66
|
+
variables?: boolean | string[] | Record<string, string>;
|
|
58
67
|
}
|
|
59
68
|
export interface ProjectRunner {
|
|
69
|
+
/**
|
|
70
|
+
* Event dispatched when an iteration is about to start.
|
|
71
|
+
*/
|
|
72
|
+
on(event: 'before-iteration', listener: (index: number, iterated: boolean) => void): this;
|
|
73
|
+
/**
|
|
74
|
+
* Event dispatched when an iteration finished.
|
|
75
|
+
*/
|
|
76
|
+
on(event: 'after-iteration', listener: (index: number, iterated: boolean) => void): this;
|
|
77
|
+
/**
|
|
78
|
+
* Event dispatched before the iteration is going to sleep for the set period of time.
|
|
79
|
+
*/
|
|
80
|
+
on(event: 'before-sleep', listener: () => void): this;
|
|
81
|
+
/**
|
|
82
|
+
* Event dispatched after the iteration is woke up.
|
|
83
|
+
*/
|
|
84
|
+
on(event: 'after-sleep', listener: () => void): this;
|
|
60
85
|
/**
|
|
61
86
|
* The request object is prepared and about to be sent to the HTTP engine
|
|
62
87
|
*/
|
|
@@ -68,7 +93,23 @@ export interface ProjectRunner {
|
|
|
68
93
|
/**
|
|
69
94
|
* There was a general error during the request
|
|
70
95
|
*/
|
|
71
|
-
on(event: 'error', listener: (key: string,
|
|
96
|
+
on(event: 'error', listener: (key: string, log: IRequestLog, message: string) => void): this;
|
|
97
|
+
/**
|
|
98
|
+
* Event dispatched when an iteration is about to start.
|
|
99
|
+
*/
|
|
100
|
+
once(event: 'before-iteration', listener: (index: number, iterated: boolean) => void): this;
|
|
101
|
+
/**
|
|
102
|
+
* Event dispatched when an iteration finished.
|
|
103
|
+
*/
|
|
104
|
+
once(event: 'after-iteration', listener: (index: number, iterated: boolean) => void): this;
|
|
105
|
+
/**
|
|
106
|
+
* Event dispatched before the iteration is going to sleep for the set period of time.
|
|
107
|
+
*/
|
|
108
|
+
once(event: 'before-sleep', listener: () => void): this;
|
|
109
|
+
/**
|
|
110
|
+
* Event dispatched after the iteration is woke up.
|
|
111
|
+
*/
|
|
112
|
+
once(event: 'after-sleep', listener: () => void): this;
|
|
72
113
|
/**
|
|
73
114
|
* The request object is prepared and about to be sent to the HTTP engine
|
|
74
115
|
*/
|
|
@@ -80,46 +121,107 @@ export interface ProjectRunner {
|
|
|
80
121
|
/**
|
|
81
122
|
* There was a general error during the request
|
|
82
123
|
*/
|
|
83
|
-
once(event: 'error', listener: (key: string,
|
|
124
|
+
once(event: 'error', listener: (key: string, log: IRequestLog, message: string) => void): this;
|
|
84
125
|
}
|
|
85
126
|
/**
|
|
86
|
-
*
|
|
87
|
-
* Developers can run the entire project with the `recursive` flag set. They can also
|
|
88
|
-
* set the starting point with the `parent` options.
|
|
127
|
+
* A class to be extended to run an entire API Project for the given configuration options.
|
|
89
128
|
*
|
|
90
|
-
*
|
|
129
|
+
* The main purpose of this class (and its children) is to iterate over requests
|
|
130
|
+
* in the project and execute them one-by-one.
|
|
131
|
+
*
|
|
132
|
+
* Implementations allow to execute the requests in a serial model or in parallel mode, where
|
|
133
|
+
* a separate workers are created to run the same HTTP requests in each worker.
|
|
134
|
+
*
|
|
135
|
+
* This class generates a run report which other programs can use to build all kinds of UIs
|
|
136
|
+
* around the data collected during the run.
|
|
91
137
|
*/
|
|
92
|
-
export declare class ProjectRunner extends
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
138
|
+
export declare abstract class ProjectRunner extends BaseRunner {
|
|
139
|
+
/**
|
|
140
|
+
* The HTTP project to run requests from.
|
|
141
|
+
*/
|
|
142
|
+
project?: HttpProject;
|
|
143
|
+
/**
|
|
144
|
+
* The execution options for the project.
|
|
145
|
+
*/
|
|
146
|
+
options?: IProjectRunnerOptions;
|
|
147
|
+
/**
|
|
148
|
+
* The root object (project or a folder) where the program starts iterating over the requests.
|
|
149
|
+
*/
|
|
150
|
+
root?: ProjectParent;
|
|
151
|
+
/**
|
|
152
|
+
* The selected environment to apply to the requests.
|
|
153
|
+
*/
|
|
154
|
+
environment?: Environment;
|
|
155
|
+
/**
|
|
156
|
+
* The events target instance for events dispatched by the request factory.
|
|
157
|
+
*/
|
|
158
|
+
target: EventTarget;
|
|
159
|
+
/**
|
|
160
|
+
* This is used with `--iterations`. The index of the current iteration.
|
|
161
|
+
*/
|
|
162
|
+
protected index: number;
|
|
163
|
+
/**
|
|
164
|
+
* The currently executed iteration loop.
|
|
165
|
+
*/
|
|
166
|
+
protected currentIteration?: IProjectExecutionIteration;
|
|
167
|
+
/**
|
|
168
|
+
* The number of remaining iterations to run.
|
|
169
|
+
*/
|
|
170
|
+
protected remaining: number;
|
|
171
|
+
/**
|
|
172
|
+
* Whether the configuration allows iterations (the parallel mode).
|
|
173
|
+
*/
|
|
174
|
+
protected hasIterations: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* When set it won't amit any event.
|
|
177
|
+
* This can be used in a background worker when events are never handled.
|
|
178
|
+
*/
|
|
179
|
+
noEmit: boolean;
|
|
180
|
+
constructor();
|
|
181
|
+
/**
|
|
182
|
+
* A required step before running the project.
|
|
183
|
+
* It configures the execution context. It may throw an error when configuration is not valid.
|
|
184
|
+
*/
|
|
185
|
+
configure(project: HttpProject, opts?: IProjectRunnerOptions): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* Executes the requests in the project.
|
|
188
|
+
* @returns The execution log created by calling the `createReport()` function.
|
|
189
|
+
*/
|
|
190
|
+
abstract execute(): Promise<IProjectExecutionLog>;
|
|
191
|
+
/**
|
|
192
|
+
* Creates the report of the execution.
|
|
193
|
+
*/
|
|
194
|
+
protected createReport(): Promise<IProjectExecutionLog>;
|
|
195
|
+
/**
|
|
196
|
+
* Reads the environment data to use with the execution.
|
|
197
|
+
* If the configured environment is a location of a file
|
|
198
|
+
* it is read as API Client's environment and used in the execution.
|
|
199
|
+
* Otherwise it searches for the environment in the list of the defined
|
|
200
|
+
* environments by the name of the key.
|
|
201
|
+
*
|
|
202
|
+
* It throws when the environment cannot be found or when the file contents is invalid.
|
|
203
|
+
*/
|
|
204
|
+
protected getEnvironment(): Promise<Environment | undefined>;
|
|
98
205
|
/**
|
|
99
|
-
*
|
|
206
|
+
* Runs the requests from the project as configured.
|
|
100
207
|
*/
|
|
101
|
-
protected
|
|
102
|
-
constructor(project: HttpProject, opts?: ProjectRunnerOptions);
|
|
208
|
+
protected executeIteration(): Promise<void>;
|
|
103
209
|
/**
|
|
104
|
-
*
|
|
105
|
-
* @param options Run options.
|
|
106
|
-
* @returns A promise with the run result.
|
|
210
|
+
* Retargets the "request" event from the factory.
|
|
107
211
|
*/
|
|
108
|
-
|
|
109
|
-
protected execute(request: ProjectRequest, variables: Record<string, string>): Promise<RunResult>;
|
|
110
|
-
protected getVariables(parent: HttpProject | ProjectFolder): Promise<Record<string, string>>;
|
|
111
|
-
protected createEnvironment(parent: HttpProject | ProjectFolder): Promise<Record<string, string>>;
|
|
212
|
+
protected _requestHandler(key: string, request: IHttpRequest): void;
|
|
112
213
|
/**
|
|
113
|
-
*
|
|
214
|
+
* Retargets the "response" event from the factory.
|
|
114
215
|
*/
|
|
115
|
-
protected
|
|
216
|
+
protected _responseHandler(key: string, log: IRequestLog): void;
|
|
116
217
|
/**
|
|
117
|
-
*
|
|
218
|
+
* Retargets the "error" event from the factory.
|
|
118
219
|
*/
|
|
119
|
-
protected
|
|
220
|
+
protected _errorHandler(key: string, log: IRequestLog, message: string): void;
|
|
120
221
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @param currentUrl The URL to process.
|
|
222
|
+
* @returns Reads the system variables based on the library configuration.
|
|
123
223
|
*/
|
|
124
|
-
protected
|
|
224
|
+
protected getSystemVariables(): Record<string, string>;
|
|
225
|
+
private _readSystemVariables;
|
|
125
226
|
}
|
|
227
|
+
export {};
|