@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
|
+
import { IHttpRequest, HttpRequest, Kind, IBaseHttpRequest } from './HttpRequest.js';
|
|
2
|
+
import { TransportRequest as LegacyTransportRequest } from './legacy/request/ArcRequest.js';
|
|
3
|
+
import { PayloadSerializer } from '../lib/transformers/PayloadSerializer.js';
|
|
4
|
+
|
|
5
|
+
export interface IBaseSentRequest extends IBaseHttpRequest {
|
|
6
|
+
/**
|
|
7
|
+
* The HTTP message sent to the server (full message).
|
|
8
|
+
* Some HTTP clients may not give this information.
|
|
9
|
+
*/
|
|
10
|
+
httpMessage?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The timestamp when the request was started (before the connection is made)
|
|
13
|
+
*/
|
|
14
|
+
startTime: number;
|
|
15
|
+
/**
|
|
16
|
+
* The timestamp of when the response ended.
|
|
17
|
+
* This is always set when the response is ready. May not be set when the request is ongoing.
|
|
18
|
+
*/
|
|
19
|
+
endTime?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* An interface describing a request made by the HTTP transport.
|
|
24
|
+
* Each transport used by ARC must return this structure in the response event.
|
|
25
|
+
* This is not a replacement for the editor request that also has to be returned.
|
|
26
|
+
*
|
|
27
|
+
* Another difference is that this headers contains a final list of headers sent to the
|
|
28
|
+
* server, including default headers, content-length, authorization, and so on.
|
|
29
|
+
*/
|
|
30
|
+
export interface ISentRequest extends IHttpRequest, IBaseSentRequest {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A class that describes a request that has been sent by the transport library
|
|
35
|
+
* to the remote machine. It contains the base HTTP request properties plus
|
|
36
|
+
* the sent message and start and end time.
|
|
37
|
+
*/
|
|
38
|
+
export class SentRequest extends HttpRequest {
|
|
39
|
+
/**
|
|
40
|
+
* The HTTP message sent to the server (full message).
|
|
41
|
+
* Some HTTP clients may not give this information.
|
|
42
|
+
*/
|
|
43
|
+
httpMessage?: string;
|
|
44
|
+
/**
|
|
45
|
+
* The timestamp when the request was started (before the connection is made)
|
|
46
|
+
*/
|
|
47
|
+
startTime = 0;
|
|
48
|
+
/**
|
|
49
|
+
* The timestamp of when the response ended.
|
|
50
|
+
* When `0` then the requests is still being transported.
|
|
51
|
+
*/
|
|
52
|
+
endTime = 0;
|
|
53
|
+
|
|
54
|
+
static fromBaseValues(values: IBaseSentRequest): SentRequest {
|
|
55
|
+
return new SentRequest({
|
|
56
|
+
...values,
|
|
57
|
+
kind: Kind,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static async fromLegacy(input: LegacyTransportRequest): Promise<SentRequest> {
|
|
62
|
+
const init: ISentRequest = {
|
|
63
|
+
kind: Kind,
|
|
64
|
+
url: input.url || '',
|
|
65
|
+
startTime: input.startTime || 0,
|
|
66
|
+
};
|
|
67
|
+
if (typeof input.endTime === 'number') {
|
|
68
|
+
init.endTime = input.endTime;
|
|
69
|
+
}
|
|
70
|
+
if (input.headers) {
|
|
71
|
+
init.headers = input.headers;
|
|
72
|
+
}
|
|
73
|
+
if (input.httpMessage) {
|
|
74
|
+
init.httpMessage = input.httpMessage;
|
|
75
|
+
}
|
|
76
|
+
if (input.method) {
|
|
77
|
+
init.method = input.method;
|
|
78
|
+
}
|
|
79
|
+
if (input.payload) {
|
|
80
|
+
init.payload = await PayloadSerializer.serialize(input.payload);
|
|
81
|
+
}
|
|
82
|
+
return new SentRequest(init);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param input The request definition used to restore the state.
|
|
87
|
+
*/
|
|
88
|
+
constructor(input?: string|ISentRequest) {
|
|
89
|
+
super(input);
|
|
90
|
+
let init: ISentRequest;
|
|
91
|
+
if (typeof input === 'string') {
|
|
92
|
+
init = JSON.parse(input);
|
|
93
|
+
} else if (typeof input === 'object') {
|
|
94
|
+
init = input;
|
|
95
|
+
} else {
|
|
96
|
+
init = {
|
|
97
|
+
kind: Kind,
|
|
98
|
+
url: '',
|
|
99
|
+
startTime: 0,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
this.new(init);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new request clearing anything that is so far defined.
|
|
107
|
+
*
|
|
108
|
+
* Note, this throws an error when the object is not an ARC request.
|
|
109
|
+
*/
|
|
110
|
+
new(init: ISentRequest): void {
|
|
111
|
+
super.new(init);
|
|
112
|
+
const { httpMessage, startTime=0, endTime=0 } = init;
|
|
113
|
+
this.httpMessage = httpMessage;
|
|
114
|
+
this.startTime = startTime;
|
|
115
|
+
this.endTime = endTime;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
toJSON(): ISentRequest {
|
|
119
|
+
const request = super.toJSON() as ISentRequest;
|
|
120
|
+
request.httpMessage = this.httpMessage;
|
|
121
|
+
request.startTime = this.startTime;
|
|
122
|
+
request.endTime = this.endTime;
|
|
123
|
+
return request;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
interface IErrorOptions {
|
|
2
|
+
cause?: Error;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface ISerializedError {
|
|
6
|
+
message: string;
|
|
7
|
+
stack?: string;
|
|
8
|
+
code?: string | number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An error that serializes!
|
|
13
|
+
* It is a copy of the normal definition of an error but allows
|
|
14
|
+
* to serialize the value via the toJSON() function and restore previous values
|
|
15
|
+
* with the `new()` function.
|
|
16
|
+
*/
|
|
17
|
+
export class SerializableError {
|
|
18
|
+
message: string;
|
|
19
|
+
code?: number | string;
|
|
20
|
+
private stackValue?: string;
|
|
21
|
+
get stack(): string | undefined {
|
|
22
|
+
return this.stackValue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get name(): string {
|
|
26
|
+
return 'SerializableError';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor();
|
|
30
|
+
constructor(error: Error);
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
constructor(message: string, options: IErrorOptions);
|
|
33
|
+
constructor(message: string, code?: number | string);
|
|
34
|
+
|
|
35
|
+
constructor(message?: string | Error, options: IErrorOptions | number | string = {}) {
|
|
36
|
+
if (typeof message === 'string') {
|
|
37
|
+
this.message = message;
|
|
38
|
+
} else if (message) {
|
|
39
|
+
this.message = message.message;
|
|
40
|
+
this.stackValue = message.stack;
|
|
41
|
+
} else {
|
|
42
|
+
this.message = '';
|
|
43
|
+
}
|
|
44
|
+
if (typeof options === 'string' || typeof options === 'number') {
|
|
45
|
+
this.code = options;
|
|
46
|
+
} else if (options.cause && options.cause.stack) {
|
|
47
|
+
this.stackValue = options.cause.stack;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
new(values: ISerializedError): void {
|
|
52
|
+
if (values.message) {
|
|
53
|
+
this.message = values.message;
|
|
54
|
+
}
|
|
55
|
+
if (values.stack) {
|
|
56
|
+
this.stackValue = values.stack;
|
|
57
|
+
}
|
|
58
|
+
if (values.code || values.code === 0) {
|
|
59
|
+
this.code = values.code;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
toJSON(): ISerializedError {
|
|
64
|
+
const { message, stackValue: stack, code } = this;
|
|
65
|
+
const result: ISerializedError = {
|
|
66
|
+
message,
|
|
67
|
+
};
|
|
68
|
+
if (stack) {
|
|
69
|
+
result.stack = stack;
|
|
70
|
+
}
|
|
71
|
+
if (code || code === 0) {
|
|
72
|
+
result.code = code;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
toString(): string {
|
|
78
|
+
return this.message;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PayloadSerializer, Payload, DeserializedPayload, hasBuffer } from '../lib/transformers/PayloadSerializer.js';
|
|
2
|
+
|
|
3
|
+
export class SerializablePayload {
|
|
4
|
+
/**
|
|
5
|
+
* The serialized payload message.
|
|
6
|
+
*/
|
|
7
|
+
payload?: Payload;
|
|
8
|
+
/**
|
|
9
|
+
* The payload in its original format.
|
|
10
|
+
* May not be populated when the `getPayload()` was not yet read.
|
|
11
|
+
*/
|
|
12
|
+
protected _sourcePayload: unknown;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sets the payload on the request.
|
|
16
|
+
* This transforms the source `message` to its serialized form using the `PayloadSerializer`.
|
|
17
|
+
*/
|
|
18
|
+
async writePayload(message: unknown): Promise<void> {
|
|
19
|
+
this._sourcePayload = message;
|
|
20
|
+
if (typeof message === 'string') {
|
|
21
|
+
this.payload = message;
|
|
22
|
+
} else {
|
|
23
|
+
this.payload = await PayloadSerializer.serialize(message as DeserializedPayload);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Reads the payload as its original format.
|
|
29
|
+
* It uses the `PayloadSerializer` to process the data.
|
|
30
|
+
*/
|
|
31
|
+
async readPayload(): Promise<DeserializedPayload> {
|
|
32
|
+
if (!this._sourcePayload) {
|
|
33
|
+
this._sourcePayload = await PayloadSerializer.deserialize(this.payload);
|
|
34
|
+
}
|
|
35
|
+
return this._sourcePayload as DeserializedPayload;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reads the payload as string, when it is possible.
|
|
40
|
+
* This method assumes that the payload is a string regardless on the format of the data
|
|
41
|
+
* (Buffer, ArrayBuffer, ...) and returns a string representation of the payload.
|
|
42
|
+
*
|
|
43
|
+
* @returns The string value of the payload of undefined if unable to process.
|
|
44
|
+
*/
|
|
45
|
+
async readPayloadAsString(): Promise<string | undefined> {
|
|
46
|
+
const { payload } = this;
|
|
47
|
+
if (!payload) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
if (typeof payload === 'string') {
|
|
51
|
+
return payload;
|
|
52
|
+
}
|
|
53
|
+
if (payload.type === 'string') {
|
|
54
|
+
return payload.data as string;
|
|
55
|
+
}
|
|
56
|
+
if (['blob', 'file', 'formdata'].includes(payload.type)) {
|
|
57
|
+
// should this return a string from the blob?
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const body = await this.readPayload();
|
|
61
|
+
if (hasBuffer && body instanceof Buffer) {
|
|
62
|
+
return body.toString();
|
|
63
|
+
}
|
|
64
|
+
const dataView = new DataView(body as ArrayBuffer);
|
|
65
|
+
const decoder = new TextDecoder();
|
|
66
|
+
return decoder.decode(dataView);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export const Kind = 'ARC#Server';
|
|
2
|
+
|
|
3
|
+
export interface IServer {
|
|
4
|
+
kind: 'ARC#Server';
|
|
5
|
+
/**
|
|
6
|
+
* The base URI of the server.
|
|
7
|
+
*
|
|
8
|
+
* Note, the URL can contain URI templates (e.g. `http://{host}.api.com/v1`)
|
|
9
|
+
* In this case the variable is replaced with the system or project variables.
|
|
10
|
+
*
|
|
11
|
+
* For simplicity, the `uri` can be the full base URI with protocol, host, and the `basePath`
|
|
12
|
+
*/
|
|
13
|
+
uri: string;
|
|
14
|
+
/**
|
|
15
|
+
* Usually included in the `uri`. When the `uri` is missing a protocol
|
|
16
|
+
* this is then used.
|
|
17
|
+
*/
|
|
18
|
+
protocol?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The base path for the server. It starts with the `/`.
|
|
21
|
+
* When set, it is appended to the `uri` value.
|
|
22
|
+
*/
|
|
23
|
+
basePath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Optional description of the server.
|
|
26
|
+
*/
|
|
27
|
+
description?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class Server {
|
|
31
|
+
kind = Kind;
|
|
32
|
+
/**
|
|
33
|
+
* The base URI of the server.
|
|
34
|
+
*
|
|
35
|
+
* Note, the URL can contain URI templates (e.g. `http://{host}.api.com/v1`)
|
|
36
|
+
* In this case the variable is replaced with the system or project variables.
|
|
37
|
+
*
|
|
38
|
+
* For simplicity, the `uri` can be the full base URI with protocol, host, and the `basePath`
|
|
39
|
+
*/
|
|
40
|
+
uri = '';
|
|
41
|
+
/**
|
|
42
|
+
* Usually included in the `uri`. When the `uri` is missing a protocol
|
|
43
|
+
* this is then used.
|
|
44
|
+
*/
|
|
45
|
+
protocol?: string;
|
|
46
|
+
/**
|
|
47
|
+
* The base path for the server. It starts with the `/`.
|
|
48
|
+
* When set, it is appended to the `uri` value.
|
|
49
|
+
*/
|
|
50
|
+
basePath?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Optional description of the server.
|
|
53
|
+
*/
|
|
54
|
+
description?: string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a server definition from a base URI.
|
|
58
|
+
*/
|
|
59
|
+
static fromUri(uri: string): Server {
|
|
60
|
+
const srv = new Server({
|
|
61
|
+
kind: Kind,
|
|
62
|
+
uri,
|
|
63
|
+
});
|
|
64
|
+
return srv;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param input The server definition used to restore the state.
|
|
69
|
+
*/
|
|
70
|
+
constructor(input?: string|IServer) {
|
|
71
|
+
let init: IServer;
|
|
72
|
+
if (typeof input === 'string') {
|
|
73
|
+
init = JSON.parse(input);
|
|
74
|
+
} else if (typeof input === 'object') {
|
|
75
|
+
init = input;
|
|
76
|
+
} else {
|
|
77
|
+
init = {
|
|
78
|
+
kind: Kind,
|
|
79
|
+
uri: '',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
this.new(init);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Creates a new server clearing anything that is so far defined.
|
|
87
|
+
*
|
|
88
|
+
* Note, this throws an error when the server is not an ARC server.
|
|
89
|
+
*/
|
|
90
|
+
new(init: IServer): void {
|
|
91
|
+
if (!Server.isServer(init)) {
|
|
92
|
+
throw new Error(`Not an ARC server.`);
|
|
93
|
+
}
|
|
94
|
+
const { uri, description, protocol, basePath } = init;
|
|
95
|
+
this.kind = Kind;
|
|
96
|
+
this.uri = uri;
|
|
97
|
+
this.description = description;
|
|
98
|
+
this.protocol = protocol;
|
|
99
|
+
this.basePath = basePath;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Checks whether the input is a definition of a server.
|
|
104
|
+
*/
|
|
105
|
+
static isServer(input: unknown): boolean {
|
|
106
|
+
const typed = input as IServer;
|
|
107
|
+
if (!input || typeof typed.uri === 'undefined' || typed.kind !== Kind) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
toJSON(): IServer {
|
|
114
|
+
const result: IServer = {
|
|
115
|
+
kind: Kind,
|
|
116
|
+
uri: this.uri,
|
|
117
|
+
};
|
|
118
|
+
if (this.description) {
|
|
119
|
+
result.description = this.description;
|
|
120
|
+
}
|
|
121
|
+
if (this.protocol) {
|
|
122
|
+
result.protocol = this.protocol;
|
|
123
|
+
}
|
|
124
|
+
if (this.basePath) {
|
|
125
|
+
result.basePath = this.basePath;
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Constructs the final URI from the server configuration.
|
|
132
|
+
*/
|
|
133
|
+
readUri(): string {
|
|
134
|
+
const { uri, protocol, basePath } = this;
|
|
135
|
+
let result = '';
|
|
136
|
+
if (!uri) {
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let tmp = uri;
|
|
141
|
+
if (protocol && !uri.includes('://')) {
|
|
142
|
+
tmp = `${protocol}//${uri}`;
|
|
143
|
+
}
|
|
144
|
+
result = tmp;
|
|
145
|
+
if (basePath) {
|
|
146
|
+
if (result.endsWith('/')) {
|
|
147
|
+
result = result.substring(0, result.length - 1);
|
|
148
|
+
}
|
|
149
|
+
result += basePath.startsWith('/') ? basePath : `/${basePath}`
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export const Kind = 'ARC#Thing';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An interface describing a base metadata of a thing.
|
|
5
|
+
*/
|
|
6
|
+
export declare interface IThing {
|
|
7
|
+
/**
|
|
8
|
+
* The data kind. The application ignores the input with an unknown `kind`, unless it can be determined from the context.
|
|
9
|
+
*/
|
|
10
|
+
kind?: 'ARC#Thing';
|
|
11
|
+
/**
|
|
12
|
+
* The name of the thing.
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The description of the thing.
|
|
17
|
+
*/
|
|
18
|
+
description?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The version number of the thing.
|
|
21
|
+
*/
|
|
22
|
+
version?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class Thing {
|
|
26
|
+
kind = Kind;
|
|
27
|
+
/**
|
|
28
|
+
* The name of the thing.
|
|
29
|
+
*/
|
|
30
|
+
name?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The description of the thing.
|
|
33
|
+
*/
|
|
34
|
+
description?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The version number of the thing.
|
|
37
|
+
*/
|
|
38
|
+
version?: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a basic description from a name.
|
|
42
|
+
*/
|
|
43
|
+
static fromName(name: string): Thing {
|
|
44
|
+
const thing = new Thing({
|
|
45
|
+
name,
|
|
46
|
+
kind: Kind,
|
|
47
|
+
});
|
|
48
|
+
return thing;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param input The thing definition used to restore the state.
|
|
53
|
+
*/
|
|
54
|
+
constructor(input?: string | IThing) {
|
|
55
|
+
let init: IThing;
|
|
56
|
+
if (typeof input === 'string') {
|
|
57
|
+
init = JSON.parse(input);
|
|
58
|
+
} else if (typeof input === 'object') {
|
|
59
|
+
init = input;
|
|
60
|
+
} else {
|
|
61
|
+
init = {
|
|
62
|
+
kind: Kind,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
this.new(init);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new thing clearing anything that is so far defined.
|
|
70
|
+
*
|
|
71
|
+
* Note, this throws an error when the server is not an ARC thing.
|
|
72
|
+
*/
|
|
73
|
+
new(init: IThing): void {
|
|
74
|
+
if (!Thing.isThing(init)) {
|
|
75
|
+
throw new Error(`Not an ARC thing.`);
|
|
76
|
+
}
|
|
77
|
+
const { description, name, version } = init;
|
|
78
|
+
this.kind = Kind;
|
|
79
|
+
this.name = name;
|
|
80
|
+
this.description = description;
|
|
81
|
+
this.version = version;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Checks whether the input is a definition of a server.
|
|
86
|
+
*/
|
|
87
|
+
static isThing(input: unknown): boolean {
|
|
88
|
+
const typed = input as IThing;
|
|
89
|
+
if (input && typed.kind === Kind) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
toJSON(): IThing {
|
|
96
|
+
const result: IThing = {
|
|
97
|
+
kind: Kind,
|
|
98
|
+
};
|
|
99
|
+
if (this.name) {
|
|
100
|
+
result.name = this.name;
|
|
101
|
+
}
|
|
102
|
+
if (this.description) {
|
|
103
|
+
result.description = this.description;
|
|
104
|
+
}
|
|
105
|
+
if (this.version) {
|
|
106
|
+
result.version = this.version;
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
|
|
2
|
+
export interface IUrl {
|
|
3
|
+
/**
|
|
4
|
+
* A number of times the URL was used
|
|
5
|
+
*/
|
|
6
|
+
cnt: number;
|
|
7
|
+
/**
|
|
8
|
+
* Last use timestamp.
|
|
9
|
+
*/
|
|
10
|
+
time: number;
|
|
11
|
+
/**
|
|
12
|
+
* The request URL stored in the history.
|
|
13
|
+
*/
|
|
14
|
+
url: string;
|
|
15
|
+
/**
|
|
16
|
+
* A timestamp of the midnight that corresponds to the `time` property.
|
|
17
|
+
*/
|
|
18
|
+
midnight?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An object representing an URL stored in the data store.
|
|
23
|
+
* This is an URL used to make a request.
|
|
24
|
+
*/
|
|
25
|
+
export class Url {
|
|
26
|
+
/**
|
|
27
|
+
* A number of times the URL was used
|
|
28
|
+
*/
|
|
29
|
+
cnt = 0;
|
|
30
|
+
/**
|
|
31
|
+
* Last use timestamp.
|
|
32
|
+
*/
|
|
33
|
+
time:number = Date.now();
|
|
34
|
+
/**
|
|
35
|
+
* The request URL stored in the history.
|
|
36
|
+
*/
|
|
37
|
+
url = '';
|
|
38
|
+
/**
|
|
39
|
+
* A timestamp of the midnight that corresponds to the `time` property.
|
|
40
|
+
*/
|
|
41
|
+
midnight?: number;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param input The environment definition used to restore the state.
|
|
45
|
+
*/
|
|
46
|
+
constructor(input: string|IUrl) {
|
|
47
|
+
let init: IUrl;
|
|
48
|
+
if (typeof input === 'string') {
|
|
49
|
+
init = JSON.parse(input);
|
|
50
|
+
} else if (typeof input === 'object') {
|
|
51
|
+
init = input;
|
|
52
|
+
} else {
|
|
53
|
+
init = {
|
|
54
|
+
cnt: 0,
|
|
55
|
+
time: Date.now(),
|
|
56
|
+
url: '',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
this.new(init);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new environment clearing anything that is so far defined.
|
|
64
|
+
*
|
|
65
|
+
* Note, this throws an error when the environment is not an ARC environment.
|
|
66
|
+
*/
|
|
67
|
+
new(init: IUrl): void {
|
|
68
|
+
const { url='', cnt=0, time = Date.now(), midnight } = init;
|
|
69
|
+
this.url = url;
|
|
70
|
+
this.cnt = cnt;
|
|
71
|
+
this.time = time;
|
|
72
|
+
if (midnight) {
|
|
73
|
+
this.midnight = midnight;
|
|
74
|
+
} else {
|
|
75
|
+
const d = new Date(this.time);
|
|
76
|
+
d.setHours(0, 0, 0, 0)
|
|
77
|
+
this.midnight = d.getTime();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
toJSON(): IUrl {
|
|
82
|
+
const result: IUrl = {
|
|
83
|
+
url: this.url,
|
|
84
|
+
cnt: this.cnt,
|
|
85
|
+
time: this.time,
|
|
86
|
+
midnight: this.midnight,
|
|
87
|
+
};
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
}
|