@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,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes given name to a value that can be accepted by `createElement`
|
|
3
|
+
* function on a document object.
|
|
4
|
+
* @param name A name to process
|
|
5
|
+
* @returns Normalized name
|
|
6
|
+
*/
|
|
7
|
+
export const normalizeXmlTagName = (name: string): string => name.replace(/[^a-zA-Z0-9-_.]/g, '');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Converts a JSON value to an XML.
|
|
11
|
+
*
|
|
12
|
+
* To convert a JSON to XML call the `convert()` function. This creates the `doc` property with the XML document.
|
|
13
|
+
* To transform the document into an XML string, use the `serialize()` function.
|
|
14
|
+
*
|
|
15
|
+
* This library work in both browser and NodeJS (via the `@xmldom/xmldom` library.)
|
|
16
|
+
*/
|
|
17
|
+
export class Json2Xml {
|
|
18
|
+
/**
|
|
19
|
+
* Whether it uses native or synthetic API.
|
|
20
|
+
*/
|
|
21
|
+
syntheticApi: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Created document
|
|
24
|
+
*/
|
|
25
|
+
doc?: XMLDocument;
|
|
26
|
+
/**
|
|
27
|
+
* The current node that is being processed.
|
|
28
|
+
*/
|
|
29
|
+
currentNode?: Element;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
this.syntheticApi = typeof DOMParser === 'undefined';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Converts a JavaScript object to an XML document.
|
|
37
|
+
* This creates the `doc` property with the JSON translated to the XML document.
|
|
38
|
+
* Use the `serialize()` to convert it to string.
|
|
39
|
+
*
|
|
40
|
+
* @param data A JavaScript object to convert
|
|
41
|
+
* @param root The name of the root node. Defaults to "root"
|
|
42
|
+
*/
|
|
43
|
+
async convert(data: any, root='root'): Promise<void> {
|
|
44
|
+
const doc = await this.getDocument();
|
|
45
|
+
this.doc = doc;
|
|
46
|
+
const rootNode = doc.createElement(root);
|
|
47
|
+
doc.appendChild(rootNode);
|
|
48
|
+
this.currentNode = rootNode;
|
|
49
|
+
|
|
50
|
+
if (Array.isArray(data)) {
|
|
51
|
+
this.processArray(data);
|
|
52
|
+
} else if (typeof data === 'object') {
|
|
53
|
+
this.processObject(data);
|
|
54
|
+
} else {
|
|
55
|
+
throw new Error('Invalid object. Unable to process non-object property.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Converts the current document to a string.
|
|
61
|
+
* @returns The converted document.
|
|
62
|
+
*/
|
|
63
|
+
async serialize(): Promise<string> {
|
|
64
|
+
const { doc } = this;
|
|
65
|
+
if (!doc) {
|
|
66
|
+
throw new Error(`No document created.`);
|
|
67
|
+
}
|
|
68
|
+
const serializer = await this.getSerializer();
|
|
69
|
+
return serializer.serializeToString(doc);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A helper function to convert and serialize a JSON to XML.
|
|
74
|
+
*
|
|
75
|
+
* @param data The JSON data to serialize
|
|
76
|
+
* @param root The name of the root node. Defaults to "root"
|
|
77
|
+
* @returns The serialized to XML value.
|
|
78
|
+
*/
|
|
79
|
+
async serializeJson(data: any, root='root'): Promise<string> {
|
|
80
|
+
await this.convert(data, root);
|
|
81
|
+
return this.serialize();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Depending on the environment it creates the XML document implementation.
|
|
86
|
+
*
|
|
87
|
+
* @returns The XML document to use
|
|
88
|
+
*/
|
|
89
|
+
async getDocument(): Promise<XMLDocument> {
|
|
90
|
+
let doc: XMLDocument;
|
|
91
|
+
if (this.syntheticApi) {
|
|
92
|
+
const { DOMImplementation } = await import('@xmldom/xmldom');
|
|
93
|
+
doc = new DOMImplementation().createDocument(null, null, null);
|
|
94
|
+
} else {
|
|
95
|
+
doc = document.implementation.createDocument(null, null, null);
|
|
96
|
+
}
|
|
97
|
+
return doc;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Depending on the environment it creates the XML serializer implementation.
|
|
102
|
+
*
|
|
103
|
+
* @returns The XML serializer to use
|
|
104
|
+
*/
|
|
105
|
+
async getSerializer(): Promise<XMLSerializer> {
|
|
106
|
+
if (this.syntheticApi) {
|
|
107
|
+
const { XMLSerializer } = await import('@xmldom/xmldom');
|
|
108
|
+
return new XMLSerializer;
|
|
109
|
+
}
|
|
110
|
+
return new XMLSerializer();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Processes a property which type is not yet detected
|
|
115
|
+
* @param input The input to process.
|
|
116
|
+
*/
|
|
117
|
+
processAny(input: any): void {
|
|
118
|
+
const type = typeof input;
|
|
119
|
+
if (Array.isArray(input)) {
|
|
120
|
+
this.processArray(input);
|
|
121
|
+
} else if (type === 'object' && input !== null) {
|
|
122
|
+
this.processObject(input);
|
|
123
|
+
} else {
|
|
124
|
+
this.processScalar(input);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Processes an array.
|
|
130
|
+
* @param input The array to process.
|
|
131
|
+
*/
|
|
132
|
+
processArray(input: any[]): void {
|
|
133
|
+
if (!Array.isArray(input)) {
|
|
134
|
+
throw new Error(`Expected array. ${typeof input} given.`);
|
|
135
|
+
}
|
|
136
|
+
input.forEach((item) => this.processAny(item));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Appends object properties to the current node.
|
|
141
|
+
* @param input The object to process.
|
|
142
|
+
*/
|
|
143
|
+
processObject(input: any): void {
|
|
144
|
+
const { currentNode, doc } = this;
|
|
145
|
+
if (!currentNode || !doc) {
|
|
146
|
+
throw new Error(`Library not initialized. Call the convert() function.`);
|
|
147
|
+
}
|
|
148
|
+
Object.keys(input).forEach((key) => {
|
|
149
|
+
const val = input[key];
|
|
150
|
+
const elementName = normalizeXmlTagName(key);
|
|
151
|
+
const element = doc.createElement(elementName);
|
|
152
|
+
currentNode.appendChild(element);
|
|
153
|
+
this.currentNode = element;
|
|
154
|
+
this.processAny(val);
|
|
155
|
+
});
|
|
156
|
+
this.currentNode = currentNode;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Adds the value to the current node.
|
|
161
|
+
* @param input the scalar to add
|
|
162
|
+
*/
|
|
163
|
+
processScalar(input: any): void {
|
|
164
|
+
const { currentNode, doc } = this;
|
|
165
|
+
if (!currentNode || !doc) {
|
|
166
|
+
throw new Error(`Library not initialized. Call the convert() function.`);
|
|
167
|
+
}
|
|
168
|
+
if (input === undefined || input === null) {
|
|
169
|
+
// nothing to add. silently quit.
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
let value: any = '';
|
|
173
|
+
let valid = false;
|
|
174
|
+
if (!valid && ['boolean', 'string', 'number', 'bigint'].includes(typeof input)) {
|
|
175
|
+
valid = true;
|
|
176
|
+
value = input;
|
|
177
|
+
}
|
|
178
|
+
if (!valid) {
|
|
179
|
+
throw new Error(`Invalid scalar type: ${typeof input}.`);
|
|
180
|
+
}
|
|
181
|
+
const typedValue = String(value);
|
|
182
|
+
if (typedValue.includes('<') || typedValue.includes('>')) {
|
|
183
|
+
const cdata = doc.createCDATASection(typedValue);
|
|
184
|
+
currentNode.appendChild(cdata);
|
|
185
|
+
} else {
|
|
186
|
+
const node = doc.createTextNode(typedValue);
|
|
187
|
+
currentNode.appendChild(node);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Json2Xml } from './Json2Xml.js';
|
|
2
|
+
import { XmlReader } from './XmlReader.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A class that converts the passed JSON value to XML and then it performs
|
|
6
|
+
* search through the XPath implementation.
|
|
7
|
+
*/
|
|
8
|
+
export class JsonReader extends XmlReader {
|
|
9
|
+
async getValue(path: string): Promise<unknown> {
|
|
10
|
+
const body = await this.readPayloadAsString();
|
|
11
|
+
if (!body) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
let obj: any;
|
|
15
|
+
try {
|
|
16
|
+
obj = JSON.parse(body);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const factory = new Json2Xml();
|
|
21
|
+
const str = await factory.serializeJson(obj);
|
|
22
|
+
const doc = await this.getDocumentWithBody(str);
|
|
23
|
+
if (!doc) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// the below works well in a browser but in Node it won't process the document created from
|
|
28
|
+
// a synthetic API.
|
|
29
|
+
// await factory.convert(obj);
|
|
30
|
+
// const doc = factory.doc as XMLDocument;
|
|
31
|
+
|
|
32
|
+
let finalPath = path;
|
|
33
|
+
if (finalPath.startsWith('/') && !finalPath.startsWith('//')) {
|
|
34
|
+
finalPath = `/root${finalPath}`;
|
|
35
|
+
} else if (!finalPath.startsWith('/')) {
|
|
36
|
+
finalPath = `/root/${finalPath}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return this.queryDocument(finalPath, doc);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Payload } from '../lib/transformers/PayloadSerializer.js';
|
|
2
|
+
import { JsonReader } from './JsonReader.js'
|
|
3
|
+
import { XmlReader } from './XmlReader.js'
|
|
4
|
+
import { UrlEncodedReader } from './UrlEncodedReader.js'
|
|
5
|
+
import { DataReader } from './DataReader.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A class that creates a pointer to a value in a Payload.
|
|
9
|
+
*/
|
|
10
|
+
export class PayloadPointer {
|
|
11
|
+
payload?: Payload;
|
|
12
|
+
mime?: string;
|
|
13
|
+
path: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param path The path to the data.
|
|
17
|
+
* @param payload The Payload value. Note, without the payload the `getValue()` always returns `undefined`. This is optional for convenience.
|
|
18
|
+
* @param mime The content type of the body message. Note, without the payload's mime the `getValue()` always returns `undefined`. This is optional for convenience.
|
|
19
|
+
*/
|
|
20
|
+
constructor(path: string, payload?: Payload, mime?: string) {
|
|
21
|
+
this.path = path;
|
|
22
|
+
this.payload = payload;
|
|
23
|
+
this.mime = mime;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @returns the value for the `path`.
|
|
28
|
+
*/
|
|
29
|
+
async getValue(): Promise<unknown> {
|
|
30
|
+
const { path, payload, mime } = this;
|
|
31
|
+
if (!mime || !path || !payload) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
let reader: DataReader | undefined;
|
|
35
|
+
if (mime.includes('json')) {
|
|
36
|
+
reader = new JsonReader();
|
|
37
|
+
} else if (mime.includes('xml')) {
|
|
38
|
+
reader = new XmlReader();
|
|
39
|
+
} else if (mime.includes('x-www-form-urlencoded')) {
|
|
40
|
+
reader = new UrlEncodedReader();
|
|
41
|
+
}
|
|
42
|
+
if (!reader) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
reader.payload = payload;
|
|
46
|
+
return reader.getValue(path);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as DataUtils from './DataUtils.js';
|
|
2
|
+
import { IHttpRequest, HttpRequest } from '../models/HttpRequest.js';
|
|
3
|
+
import { ISentRequest, SentRequest } from '../models/SentRequest.js';
|
|
4
|
+
import { IHttpResponse, HttpResponse } from '../models/HttpResponse.js';
|
|
5
|
+
import { IErrorResponse, ErrorResponse } from '../models/ErrorResponse.js';
|
|
6
|
+
import { IDataSource } from '../models/actions/Condition.js';
|
|
7
|
+
import { ActionTypeEnum } from '../models/actions/Enums.js';
|
|
8
|
+
import { Headers } from '../lib/headers/Headers.js';
|
|
9
|
+
import { JsonReader } from './JsonReader.js';
|
|
10
|
+
import { XmlReader } from './XmlReader.js';
|
|
11
|
+
import { UrlEncodedReader } from './UrlEncodedReader.js';
|
|
12
|
+
import { DataReader } from './DataReader.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A class to extract data from the request or the response.
|
|
16
|
+
*/
|
|
17
|
+
export class RequestDataExtractor {
|
|
18
|
+
/**
|
|
19
|
+
* The request that has been sent to the server.
|
|
20
|
+
*/
|
|
21
|
+
request: HttpRequest | SentRequest;
|
|
22
|
+
/**
|
|
23
|
+
* The response object
|
|
24
|
+
*/
|
|
25
|
+
response?: HttpResponse | ErrorResponse;
|
|
26
|
+
constructor(request: IHttpRequest | ISentRequest, response?: IHttpResponse | IErrorResponse) {
|
|
27
|
+
this.request = new HttpRequest(request);
|
|
28
|
+
if (response) {
|
|
29
|
+
if (ErrorResponse.isErrorResponse(response)) {
|
|
30
|
+
this.response = new ErrorResponse(response as IErrorResponse);
|
|
31
|
+
} else {
|
|
32
|
+
this.response = new HttpResponse(response);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Reads the data from the selected path.
|
|
39
|
+
*
|
|
40
|
+
* @param config The configuration of the data source
|
|
41
|
+
* @return Data to be processed
|
|
42
|
+
*/
|
|
43
|
+
async extract(config: IDataSource): Promise<string | number | undefined> {
|
|
44
|
+
const { type, source, path, value } = config;
|
|
45
|
+
if (source === 'value') {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
const args = path ? path.split('.') : [];
|
|
49
|
+
switch (source) {
|
|
50
|
+
case 'url':
|
|
51
|
+
return DataUtils.getDataUrl(this.getUrl(), args);
|
|
52
|
+
case 'headers':
|
|
53
|
+
return DataUtils.getDataHeaders(this.getHeaders(type), args);
|
|
54
|
+
case 'status':
|
|
55
|
+
return this.response && this.response.status;
|
|
56
|
+
case 'method':
|
|
57
|
+
return this.request.method;
|
|
58
|
+
case 'body':
|
|
59
|
+
return this.processBody(path, type);
|
|
60
|
+
default:
|
|
61
|
+
throw new Error(`Unknown source ${source} for ${type} data`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param source The source name
|
|
67
|
+
* @returns The URL of the request
|
|
68
|
+
*/
|
|
69
|
+
getUrl(): string {
|
|
70
|
+
return this.request.url;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param source The source name
|
|
75
|
+
* @returns The headers from the request / response
|
|
76
|
+
*/
|
|
77
|
+
getHeaders(source?: ActionTypeEnum): string {
|
|
78
|
+
if (source === 'request') {
|
|
79
|
+
return this.request.headers || '';
|
|
80
|
+
}
|
|
81
|
+
return this.response && this.response.headers || '';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async processBody(path?: string, source?: ActionTypeEnum): Promise<string | undefined> {
|
|
85
|
+
const value = await this.getBody(source);
|
|
86
|
+
if (!value) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
if (!path) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
const headersValue = this.getHeaders(source);
|
|
93
|
+
if (!headersValue) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const headers = new Headers(headersValue);
|
|
97
|
+
const mime = headers.get('content-type');
|
|
98
|
+
if (!mime) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return this.extractBody(value, mime, path);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param source The source name
|
|
106
|
+
* @returns The headers from the request / response
|
|
107
|
+
*/
|
|
108
|
+
async getBody(source?: ActionTypeEnum): Promise<string | undefined> {
|
|
109
|
+
if (source === 'request') {
|
|
110
|
+
return this.request.readPayloadAsString();
|
|
111
|
+
}
|
|
112
|
+
if (this.response) {
|
|
113
|
+
return this.response.readPayloadAsString();
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async extractBody(value: string, mime: string, path: string): Promise<string | undefined> {
|
|
119
|
+
let reader: DataReader | undefined;
|
|
120
|
+
if (mime.includes('json')) {
|
|
121
|
+
reader = new JsonReader();
|
|
122
|
+
} else if (mime.includes('xml')) {
|
|
123
|
+
reader = new XmlReader();
|
|
124
|
+
} else if (mime.includes('x-www-form-urlencoded')) {
|
|
125
|
+
reader = new UrlEncodedReader();
|
|
126
|
+
}
|
|
127
|
+
if (!reader) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
await reader.writePayload(value);
|
|
131
|
+
return reader.getValue(path) as Promise<string>;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DataReader } from './DataReader.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads a value for a property in an `application/x-www-form-urlencoded` body.
|
|
5
|
+
*/
|
|
6
|
+
export class UrlEncodedReader extends DataReader {
|
|
7
|
+
/**
|
|
8
|
+
* @param path Since the `application/x-www-form-urlencoded` is a key-value pair this can be just a simple name of the property to read.
|
|
9
|
+
* @returns The value of the property or undefined.
|
|
10
|
+
*/
|
|
11
|
+
async getValue(path: string): Promise<unknown> {
|
|
12
|
+
const body = await this.readPayloadAsString();
|
|
13
|
+
const parsed = new URLSearchParams(body);
|
|
14
|
+
const result = parsed.get(path);
|
|
15
|
+
if (result === null) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { DataReader } from './DataReader.js';
|
|
2
|
+
|
|
3
|
+
let xResult: typeof XPathResult | undefined = typeof XPathResult !== 'undefined' ? XPathResult : undefined;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Reads the data from an XML using the xpath.
|
|
7
|
+
* See https://www.w3schools.com/xml/xpath_syntax.asp.
|
|
8
|
+
*/
|
|
9
|
+
export class XmlReader extends DataReader {
|
|
10
|
+
async getValue(path: string): Promise<unknown> {
|
|
11
|
+
const doc = await this.getDocument();
|
|
12
|
+
if (!doc) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return this.queryDocument(path, doc);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
queryDocument(path: string, doc: Document): unknown {
|
|
19
|
+
try {
|
|
20
|
+
const result = doc.evaluate(path, doc);
|
|
21
|
+
switch (result.resultType) {
|
|
22
|
+
case xResult!.NUMBER_TYPE: return result.numberValue;
|
|
23
|
+
case xResult!.STRING_TYPE: return result.stringValue;
|
|
24
|
+
case xResult!.BOOLEAN_TYPE: return result.booleanValue;
|
|
25
|
+
case xResult!.UNORDERED_NODE_ITERATOR_TYPE:
|
|
26
|
+
case xResult!.ORDERED_NODE_ITERATOR_TYPE:
|
|
27
|
+
return this.processNodeResult(result);
|
|
28
|
+
default:
|
|
29
|
+
console.error(`Unsupported xpath result type: [${result.resultType}]`);
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(e);
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
processNodeResult(result: XPathResult): unknown {
|
|
39
|
+
const results: any[] = [];
|
|
40
|
+
let next = result.iterateNext();
|
|
41
|
+
while (next) {
|
|
42
|
+
const value = next.textContent;
|
|
43
|
+
if (value) {
|
|
44
|
+
results.push(value.trim());
|
|
45
|
+
}
|
|
46
|
+
next = result.iterateNext();
|
|
47
|
+
}
|
|
48
|
+
if (!results.length) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return results.length === 1 ? results[0] : results;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getDocument(): Promise<Document|undefined> {
|
|
55
|
+
const body = await this.readPayloadAsString();
|
|
56
|
+
if (!body) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
return this.getDocumentWithBody(body);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getDocumentWithBody(body: string): Promise<Document|undefined> {
|
|
63
|
+
if (typeof DOMParser === 'undefined') {
|
|
64
|
+
return this.getNodeDocument(body);
|
|
65
|
+
}
|
|
66
|
+
return this.getWebDocument(body);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getWebDocument(data: string): Promise<Document|undefined> {
|
|
70
|
+
const parser = new DOMParser();
|
|
71
|
+
const dom = parser.parseFromString(data, 'text/xml');
|
|
72
|
+
if (dom.querySelector('parsererror')) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return dom;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async getNodeDocument(data: string): Promise<Document|undefined> {
|
|
79
|
+
const { DOMParser } = await import('@xmldom/xmldom');
|
|
80
|
+
const xpath = await import('xpath');
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
xResult = xpath.default.XPathResult;
|
|
83
|
+
let errored = false;
|
|
84
|
+
const parser = new DOMParser({
|
|
85
|
+
errorHandler: {
|
|
86
|
+
error: (): void => {
|
|
87
|
+
errored = true;
|
|
88
|
+
},
|
|
89
|
+
fatalError: (): void => {
|
|
90
|
+
errored = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const dom = parser.parseFromString(data, 'text/xml');
|
|
95
|
+
if (errored) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
dom.evaluate = (expression: string, contextNode: Node): XPathResult => {
|
|
99
|
+
return xpath.default.evaluate(expression, contextNode, null, 0, null);
|
|
100
|
+
}
|
|
101
|
+
return dom;
|
|
102
|
+
}
|
|
103
|
+
}
|