@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,311 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
import { PostmanTransformer, dataValue, paramValue } from './PostmanTransformer.js';
|
|
3
|
+
import { HttpProject, IHttpProject, Kind as ProjectKind } from '../HttpProject.js';
|
|
4
|
+
import { ProjectFolder } from '../ProjectFolder.js';
|
|
5
|
+
import { ProjectRequest } from '../ProjectRequest.js';
|
|
6
|
+
import { IMultipartBody } from '../../lib/transformers/PayloadSerializer.js';
|
|
7
|
+
import v4 from '../../lib/uuid.js';
|
|
8
|
+
import { Environment } from '../Environment.js';
|
|
9
|
+
|
|
10
|
+
export const currentItemValue = Symbol('currentItemValue');
|
|
11
|
+
|
|
12
|
+
interface PostmanInfo {
|
|
13
|
+
/**
|
|
14
|
+
* Name of the collection
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* This should ideally hold a link to the Postman schema that is used to validate this collection. E.g: https://schema.getpostman.com/collection/v1
|
|
19
|
+
*/
|
|
20
|
+
schema: string;
|
|
21
|
+
/**
|
|
22
|
+
* Every collection is identified by the unique value of this field. The value of this field is usually easiest to generate using a UID generator function. If you already have a collection, it is recommended that you maintain the same id since changing the id usually implies that is a different collection than it was originally.\n *Note: This field exists for compatibility reasons with Collection Format V1.
|
|
23
|
+
*/
|
|
24
|
+
_postman_id?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface PostmanRequestUrl {
|
|
29
|
+
raw?: string;
|
|
30
|
+
protocol?: string;
|
|
31
|
+
host?: string | string[];
|
|
32
|
+
path?: string | string[];
|
|
33
|
+
port?: string;
|
|
34
|
+
}
|
|
35
|
+
interface PostmanParameter {
|
|
36
|
+
key?: string|null;
|
|
37
|
+
value?: string|null;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
description?: string;
|
|
40
|
+
}
|
|
41
|
+
interface PostmanHeader extends PostmanParameter {
|
|
42
|
+
}
|
|
43
|
+
interface PostmanUrlEncoded extends PostmanParameter {
|
|
44
|
+
type?: string;
|
|
45
|
+
}
|
|
46
|
+
interface PostmanFormData extends PostmanParameter {
|
|
47
|
+
type?: string;
|
|
48
|
+
src?: string;
|
|
49
|
+
contentType?: string;
|
|
50
|
+
}
|
|
51
|
+
interface PostmanFile {
|
|
52
|
+
src: string|null;
|
|
53
|
+
contentType?: string;
|
|
54
|
+
}
|
|
55
|
+
interface PostmanBody {
|
|
56
|
+
mode: string | null;
|
|
57
|
+
raw?: string;
|
|
58
|
+
urlencoded?: PostmanUrlEncoded[];
|
|
59
|
+
formdata?: PostmanFormData[];
|
|
60
|
+
file?: PostmanFile;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface PostmanRequest {
|
|
64
|
+
url?: string | PostmanRequestUrl;
|
|
65
|
+
method?: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
header?: string|PostmanHeader[];
|
|
68
|
+
body?: PostmanBody;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface PostmanResponse {
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface PostmanItem {
|
|
75
|
+
/**
|
|
76
|
+
* A unique ID that is used to identify collections internally
|
|
77
|
+
*/
|
|
78
|
+
id?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Name of the collection
|
|
81
|
+
*/
|
|
82
|
+
name?: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
request: PostmanRequest;
|
|
85
|
+
response?: PostmanResponse[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface PostmanItemGroup {
|
|
89
|
+
/**
|
|
90
|
+
* A folder's friendly name is defined by this field. You would want to set this field to a value that would allow you to easily identify this folder.
|
|
91
|
+
*/
|
|
92
|
+
name?: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
item: PostmanItem[] | PostmanItemGroup[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface PostmanVariable {
|
|
98
|
+
disabled?: boolean;
|
|
99
|
+
key: string;
|
|
100
|
+
value: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface PostmanV2 {
|
|
104
|
+
variable?: PostmanVariable[];
|
|
105
|
+
info: PostmanInfo;
|
|
106
|
+
item: PostmanItem[] | PostmanItemGroup[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Transforms Postman v2.1 collections to ARC import object.
|
|
112
|
+
*/
|
|
113
|
+
export class PostmanV21Transformer extends PostmanTransformer {
|
|
114
|
+
/**
|
|
115
|
+
* Transforms `_data` into ARC data model.
|
|
116
|
+
* @returns Promise resolved when data are transformed.
|
|
117
|
+
*/
|
|
118
|
+
async transform(): Promise<HttpProject> {
|
|
119
|
+
const raw = this[dataValue] as PostmanV2;
|
|
120
|
+
const project = this.createProject(raw);
|
|
121
|
+
this.setProjectVariables(project, raw);
|
|
122
|
+
if (Array.isArray(raw.item)) {
|
|
123
|
+
for (const item of raw.item) {
|
|
124
|
+
await this.addProjectItem(project, item);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return project;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
createProject(data: PostmanV2): HttpProject {
|
|
131
|
+
const { info } = data;
|
|
132
|
+
const init: IHttpProject = {
|
|
133
|
+
kind: ProjectKind,
|
|
134
|
+
definitions: {},
|
|
135
|
+
environments: [],
|
|
136
|
+
info: {
|
|
137
|
+
kind: 'ARC#Thing',
|
|
138
|
+
name: info.name || 'Unnamed Postman project',
|
|
139
|
+
},
|
|
140
|
+
items: [],
|
|
141
|
+
key: info._postman_id || v4(),
|
|
142
|
+
};
|
|
143
|
+
if (info.description) {
|
|
144
|
+
init.info.description = info.description;
|
|
145
|
+
}
|
|
146
|
+
const project = new HttpProject(init);
|
|
147
|
+
return project;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
setProjectVariables(project: HttpProject, collection: PostmanV2): void {
|
|
151
|
+
const { variable } = collection;
|
|
152
|
+
if (!Array.isArray(variable)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const env = Environment.fromName('Default');
|
|
156
|
+
project.addEnvironment(env);
|
|
157
|
+
variable.forEach((param) => {
|
|
158
|
+
const { disabled=false, key, value } = param;
|
|
159
|
+
|
|
160
|
+
const parsed = this.ensureVariablesSyntax(value) as string;
|
|
161
|
+
const created = env.addVariable(key, parsed);
|
|
162
|
+
created.enabled = !disabled;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async addProjectItem(current: HttpProject | ProjectFolder, item: PostmanItem | PostmanItemGroup): Promise<void> {
|
|
167
|
+
const typedGroup = item as PostmanItemGroup;
|
|
168
|
+
if (typedGroup.item) {
|
|
169
|
+
return this.addProjectFolder(current, typedGroup);
|
|
170
|
+
}
|
|
171
|
+
const typedItem = item as PostmanItem;
|
|
172
|
+
if (typedItem.request) {
|
|
173
|
+
return this.addProjectRequest(current, item as PostmanItem);
|
|
174
|
+
}
|
|
175
|
+
this.addLog('error', 'Error when adding an item to the project. Unable to determine item type. Tested for a folder and a request.');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async addProjectFolder(current: HttpProject | ProjectFolder, group: PostmanItemGroup): Promise<void> {
|
|
179
|
+
const { description, name='Unnamed folder', item } = group;
|
|
180
|
+
const created = current.addFolder(name);
|
|
181
|
+
if (description) {
|
|
182
|
+
created.info.description = description;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (Array.isArray(item)) {
|
|
186
|
+
for (const tmp of item) {
|
|
187
|
+
await this.addProjectItem(created, tmp);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async addProjectRequest(current: HttpProject | ProjectFolder, item: PostmanItem): Promise<void> {
|
|
193
|
+
const { request, description } = item;
|
|
194
|
+
const name = item.name || 'Unnamed request';
|
|
195
|
+
let url: string;
|
|
196
|
+
if (typeof request.url === 'string') {
|
|
197
|
+
url = request.url;
|
|
198
|
+
} else if (request.url && request.url.raw) {
|
|
199
|
+
url = request.url.raw;
|
|
200
|
+
} else {
|
|
201
|
+
url = 'http://';
|
|
202
|
+
}
|
|
203
|
+
url = this.ensureVariablesSyntax(url) as string;
|
|
204
|
+
let method = request.method || 'GET';
|
|
205
|
+
method = this.ensureVariablesSyntax(method) as string;
|
|
206
|
+
|
|
207
|
+
const header = this.ensureVarsRecursively(request.header);
|
|
208
|
+
const headers = this.computeHeaders(header);
|
|
209
|
+
|
|
210
|
+
const created = current.addRequest(url);
|
|
211
|
+
created.info.name = name;
|
|
212
|
+
if (request.description) {
|
|
213
|
+
created.info.description = request.description;
|
|
214
|
+
} else if (description) {
|
|
215
|
+
created.info.description = description;
|
|
216
|
+
}
|
|
217
|
+
created.expects.method = method;
|
|
218
|
+
if (headers) {
|
|
219
|
+
created.expects.headers = headers;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
await this.addRequestBody(created, request.body);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Computes headers string from item's headers.
|
|
227
|
+
*
|
|
228
|
+
* @param headers Postman Request.header model.
|
|
229
|
+
* @returns Computed value of headers.
|
|
230
|
+
*/
|
|
231
|
+
computeHeaders(headers: string|PostmanHeader[]): string {
|
|
232
|
+
if (typeof headers === 'string') {
|
|
233
|
+
return headers;
|
|
234
|
+
}
|
|
235
|
+
if (!Array.isArray(headers)) {
|
|
236
|
+
return '';
|
|
237
|
+
}
|
|
238
|
+
const tmp = headers.filter((h) => !h.disabled);
|
|
239
|
+
return tmp.map((item) => `${item.key}: ${item.value}`).join('\n');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async addRequestBody(created: ProjectRequest, body?: PostmanBody): Promise<void> {
|
|
243
|
+
if (!body) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
switch (body.mode) {
|
|
247
|
+
case 'file': return this.addBinaryBody(created, body);
|
|
248
|
+
case 'urlencoded': return this.addUrlencodedBody(created, body);
|
|
249
|
+
case 'formdata': return this.addParamsBody(created, body);
|
|
250
|
+
case 'raw': return this.addRawBody(created, body);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async addBinaryBody(created: ProjectRequest, body: PostmanBody): Promise<void> {
|
|
255
|
+
// Postman sets the `body.file.src` property with the path to the file
|
|
256
|
+
// but not data itself. Because of that this method is a stub that can be extended
|
|
257
|
+
// by particular implementation (like node, CLI).
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async addUrlencodedBody(created: ProjectRequest, body: PostmanBody): Promise<void> {
|
|
261
|
+
const items = body[body.mode as keyof PostmanBody] as PostmanUrlEncoded[];
|
|
262
|
+
if (!Array.isArray(items)) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const data = this.ensureVarsRecursively(items) as PostmanUrlEncoded[];
|
|
266
|
+
const str = data.map(i => `${paramValue(i.key || 'missing name')}=${paramValue(i.value || '')}`).join('&');
|
|
267
|
+
await created.expects.writePayload(str);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async addParamsBody(created: ProjectRequest, body: PostmanBody): Promise<void> {
|
|
271
|
+
const items = body[body.mode as keyof PostmanBody] as PostmanFormData[];
|
|
272
|
+
if (!Array.isArray(items)) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const data = this.ensureVarsRecursively(items) as PostmanFormData[];
|
|
276
|
+
const multipartBody: IMultipartBody[] = [];
|
|
277
|
+
for (const part of data) {
|
|
278
|
+
if (part.type === 'text') {
|
|
279
|
+
await this.addParamsTextPart(multipartBody, part);
|
|
280
|
+
} else if (part.type === 'file') {
|
|
281
|
+
await this.addParamsFilePart(multipartBody, part);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
created.expects.payload = {
|
|
285
|
+
type: 'formdata',
|
|
286
|
+
data: multipartBody,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async addParamsTextPart(body: IMultipartBody[], param: PostmanFormData): Promise<void> {
|
|
291
|
+
const { key, value, disabled=false, } = param;
|
|
292
|
+
body.push({
|
|
293
|
+
isFile: false,
|
|
294
|
+
name: key || 'unnamed part',
|
|
295
|
+
value: value || '',
|
|
296
|
+
enabled: !disabled,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async addParamsFilePart(body: IMultipartBody[], param: PostmanFormData): Promise<void> {
|
|
301
|
+
// Postman sets the `value` property with the path to the file
|
|
302
|
+
// but not data itself. Because of that this method is a stub that can be extended
|
|
303
|
+
// by particular implementation (like node, CLI).
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async addRawBody(created: ProjectRequest, body: PostmanBody): Promise<void> {
|
|
307
|
+
if (body.raw) {
|
|
308
|
+
await created.expects.writePayload(body.raw);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
import { PostmanTransformer, dataValue, paramValue } from './PostmanTransformer.js';
|
|
3
|
+
import { HttpProject, IHttpProject, Kind as ProjectKind } from '../HttpProject.js';
|
|
4
|
+
import { ProjectFolder } from '../ProjectFolder.js';
|
|
5
|
+
import { ProjectRequest } from '../ProjectRequest.js';
|
|
6
|
+
import { IMultipartBody } from '../../lib/transformers/PayloadSerializer.js';
|
|
7
|
+
import v4 from '../../lib/uuid.js';
|
|
8
|
+
import { Environment } from '../Environment.js';
|
|
9
|
+
|
|
10
|
+
export const currentItemValue = Symbol('currentItemValue');
|
|
11
|
+
|
|
12
|
+
interface PostmanInfo {
|
|
13
|
+
/**
|
|
14
|
+
* Name of the collection
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* This should ideally hold a link to the Postman schema that is used to validate this collection. E.g: https://schema.getpostman.com/collection/v1
|
|
19
|
+
*/
|
|
20
|
+
schema: string;
|
|
21
|
+
/**
|
|
22
|
+
* Every collection is identified by the unique value of this field. The value of this field is usually easiest to generate using a UID generator function. If you already have a collection, it is recommended that you maintain the same id since changing the id usually implies that is a different collection than it was originally.\n *Note: This field exists for compatibility reasons with Collection Format V1.
|
|
23
|
+
*/
|
|
24
|
+
_postman_id?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface PostmanRequestUrl {
|
|
29
|
+
raw?: string;
|
|
30
|
+
protocol?: string;
|
|
31
|
+
host?: string | string[];
|
|
32
|
+
path?: string | string[];
|
|
33
|
+
port?: string;
|
|
34
|
+
}
|
|
35
|
+
interface PostmanParameter {
|
|
36
|
+
key?: string|null;
|
|
37
|
+
value?: string|null;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
description?: string;
|
|
40
|
+
}
|
|
41
|
+
interface PostmanUrlEncoded extends PostmanParameter {
|
|
42
|
+
type?: string;
|
|
43
|
+
}
|
|
44
|
+
interface PostmanFormData extends PostmanParameter {
|
|
45
|
+
type?: string;
|
|
46
|
+
src?: string;
|
|
47
|
+
contentType?: string;
|
|
48
|
+
}
|
|
49
|
+
interface PostmanFile {
|
|
50
|
+
src: string|null;
|
|
51
|
+
contentType?: string;
|
|
52
|
+
}
|
|
53
|
+
interface PostmanBody {
|
|
54
|
+
mode: string | null;
|
|
55
|
+
raw?: string;
|
|
56
|
+
urlencoded?: PostmanUrlEncoded[];
|
|
57
|
+
formdata?: PostmanFormData[];
|
|
58
|
+
file?: PostmanFile;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface PostmanRequest {
|
|
62
|
+
url?: string | PostmanRequestUrl;
|
|
63
|
+
method?: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
header?: string|PostmanParameter[];
|
|
66
|
+
body?: PostmanBody;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface PostmanResponse {
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface PostmanItem {
|
|
73
|
+
/**
|
|
74
|
+
* A unique ID that is used to identify collections internally
|
|
75
|
+
*/
|
|
76
|
+
id?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Name of the collection
|
|
79
|
+
*/
|
|
80
|
+
name?: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
request: PostmanRequest;
|
|
83
|
+
response?: PostmanResponse[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface PostmanItemGroup {
|
|
87
|
+
/**
|
|
88
|
+
* A folder's friendly name is defined by this field. You would want to set this field to a value that would allow you to easily identify this folder.
|
|
89
|
+
*/
|
|
90
|
+
name?: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
item: PostmanItem[] | PostmanItemGroup[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface PostmanVariable {
|
|
96
|
+
disabled?: boolean;
|
|
97
|
+
key: string;
|
|
98
|
+
value: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface PostmanV2 {
|
|
102
|
+
variable?: PostmanVariable[];
|
|
103
|
+
info: PostmanInfo;
|
|
104
|
+
item: PostmanItem[] | PostmanItemGroup[];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Transforms Postman v2 collections to ARC import object.
|
|
109
|
+
*/
|
|
110
|
+
export class PostmanV2Transformer extends PostmanTransformer {
|
|
111
|
+
/**
|
|
112
|
+
* Transforms `_data` into ARC data model.
|
|
113
|
+
* @returns Promise resolved when data are transformed.
|
|
114
|
+
*/
|
|
115
|
+
async transform(): Promise<HttpProject> {
|
|
116
|
+
const raw = this[dataValue] as PostmanV2;
|
|
117
|
+
const project = this.createProject(raw);
|
|
118
|
+
this.setProjectVariables(project, raw);
|
|
119
|
+
if (Array.isArray(raw.item)) {
|
|
120
|
+
for (const item of raw.item) {
|
|
121
|
+
await this.addProjectItem(project, item);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return project;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
createProject(data: PostmanV2): HttpProject {
|
|
128
|
+
const { info } = data;
|
|
129
|
+
const init: IHttpProject = {
|
|
130
|
+
kind: ProjectKind,
|
|
131
|
+
definitions: {},
|
|
132
|
+
environments: [],
|
|
133
|
+
info: {
|
|
134
|
+
kind: 'ARC#Thing',
|
|
135
|
+
name: info.name || 'Unnamed Postman project',
|
|
136
|
+
},
|
|
137
|
+
items: [],
|
|
138
|
+
key: info._postman_id || v4(),
|
|
139
|
+
};
|
|
140
|
+
if (info.description) {
|
|
141
|
+
init.info.description = info.description;
|
|
142
|
+
}
|
|
143
|
+
const project = new HttpProject(init);
|
|
144
|
+
return project;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
setProjectVariables(project: HttpProject, collection: PostmanV2): void {
|
|
148
|
+
const { variable } = collection;
|
|
149
|
+
if (!Array.isArray(variable)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const env = Environment.fromName('Default');
|
|
153
|
+
project.addEnvironment(env);
|
|
154
|
+
variable.forEach((param) => {
|
|
155
|
+
const { disabled=false, key, value } = param;
|
|
156
|
+
|
|
157
|
+
const parsed = this.ensureVariablesSyntax(value) as string;
|
|
158
|
+
const created = env.addVariable(key, parsed);
|
|
159
|
+
created.enabled = !disabled;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async addProjectItem(current: HttpProject | ProjectFolder, item: PostmanItem | PostmanItemGroup): Promise<void> {
|
|
164
|
+
const typedGroup = item as PostmanItemGroup;
|
|
165
|
+
if (typedGroup.item) {
|
|
166
|
+
return this.addProjectFolder(current, typedGroup);
|
|
167
|
+
}
|
|
168
|
+
const typedItem = item as PostmanItem;
|
|
169
|
+
if (typedItem.request) {
|
|
170
|
+
return this.addProjectRequest(current, item as PostmanItem);
|
|
171
|
+
}
|
|
172
|
+
this.addLog('error', 'Error when adding an item to the project. Unable to determine item type. Tested for a folder and a request.');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async addProjectFolder(current: HttpProject | ProjectFolder, group: PostmanItemGroup): Promise<void> {
|
|
176
|
+
const { description, name='Unnamed folder', item } = group;
|
|
177
|
+
const created = current.addFolder(name);
|
|
178
|
+
if (description) {
|
|
179
|
+
created.info.description = description;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (Array.isArray(item)) {
|
|
183
|
+
for (const tmp of item) {
|
|
184
|
+
await this.addProjectItem(created, tmp);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async addProjectRequest(current: HttpProject | ProjectFolder, item: PostmanItem): Promise<void> {
|
|
190
|
+
const { request, description } = item;
|
|
191
|
+
const name = item.name || 'Unnamed request';
|
|
192
|
+
let url: string;
|
|
193
|
+
if (typeof request.url === 'string') {
|
|
194
|
+
url = request.url;
|
|
195
|
+
} else if (request.url && request.url.raw) {
|
|
196
|
+
url = request.url.raw;
|
|
197
|
+
} else {
|
|
198
|
+
url = 'http://';
|
|
199
|
+
}
|
|
200
|
+
url = this.ensureVariablesSyntax(url) as string;
|
|
201
|
+
let method = request.method || 'GET';
|
|
202
|
+
method = this.ensureVariablesSyntax(method) as string;
|
|
203
|
+
|
|
204
|
+
const header = this.ensureVarsRecursively(request.header);
|
|
205
|
+
const headers = this.computeHeaders(header);
|
|
206
|
+
|
|
207
|
+
const created = current.addRequest(url);
|
|
208
|
+
created.info.name = name;
|
|
209
|
+
if (request.description) {
|
|
210
|
+
created.info.description = request.description;
|
|
211
|
+
} else if (description) {
|
|
212
|
+
created.info.description = description;
|
|
213
|
+
}
|
|
214
|
+
created.expects.method = method;
|
|
215
|
+
if (headers) {
|
|
216
|
+
created.expects.headers = headers;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
await this.addRequestBody(created, request.body);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Computes headers string from item's headers.
|
|
224
|
+
*
|
|
225
|
+
* @param headers Postman Request.header model.
|
|
226
|
+
* @return Computed value of headers.
|
|
227
|
+
*/
|
|
228
|
+
computeHeaders(headers?: string|PostmanParameter[]): string {
|
|
229
|
+
if (typeof headers === 'string') {
|
|
230
|
+
return headers;
|
|
231
|
+
}
|
|
232
|
+
if (!Array.isArray(headers)) {
|
|
233
|
+
return '';
|
|
234
|
+
}
|
|
235
|
+
const tmp = headers.filter((h) => !h.disabled);
|
|
236
|
+
return tmp.map((item) => `${item.key}: ${item.value}`).join('\n');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async addRequestBody(created: ProjectRequest, body?: PostmanBody): Promise<void> {
|
|
240
|
+
if (!body) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
switch (body.mode) {
|
|
244
|
+
case 'file': return this.addBinaryBody(created, body);
|
|
245
|
+
case 'urlencoded': return this.addUrlencodedBody(created, body);
|
|
246
|
+
case 'formdata': return this.addParamsBody(created, body);
|
|
247
|
+
case 'raw': return this.addRawBody(created, body);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async addBinaryBody(created: ProjectRequest, body: PostmanBody): Promise<void> {
|
|
252
|
+
// Postman sets the `body.file.src` property with the path to the file
|
|
253
|
+
// but not data itself. Because of that this method is a stub that can be extended
|
|
254
|
+
// by particular implementation (like node, CLI).
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async addUrlencodedBody(created: ProjectRequest, body: PostmanBody): Promise<void> {
|
|
258
|
+
const items = body[body.mode as keyof PostmanBody] as PostmanUrlEncoded[];
|
|
259
|
+
if (!Array.isArray(items)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const data = this.ensureVarsRecursively(items) as PostmanUrlEncoded[];
|
|
263
|
+
const str = data.map(i => `${paramValue(i.key || 'missing name')}=${paramValue(i.value || '')}`).join('&');
|
|
264
|
+
await created.expects.writePayload(str);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async addParamsBody(created: ProjectRequest, body: PostmanBody): Promise<void> {
|
|
268
|
+
const items = body[body.mode as keyof PostmanBody] as PostmanFormData[];
|
|
269
|
+
if (!Array.isArray(items)) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const data = this.ensureVarsRecursively(items) as PostmanFormData[];
|
|
273
|
+
const multipartBody: IMultipartBody[] = [];
|
|
274
|
+
for (const part of data) {
|
|
275
|
+
if (part.type === 'text') {
|
|
276
|
+
await this.addParamsTextPart(multipartBody, part);
|
|
277
|
+
} else if (part.type === 'file') {
|
|
278
|
+
await this.addParamsFilePart(multipartBody, part);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
created.expects.payload = {
|
|
282
|
+
type: 'formdata',
|
|
283
|
+
data: multipartBody,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async addParamsTextPart(body: IMultipartBody[], param: PostmanFormData): Promise<void> {
|
|
288
|
+
const { key, value, disabled=false, } = param;
|
|
289
|
+
body.push({
|
|
290
|
+
isFile: false,
|
|
291
|
+
name: key || 'unnamed part',
|
|
292
|
+
value: value || '',
|
|
293
|
+
enabled: !disabled,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async addParamsFilePart(body: IMultipartBody[], param: PostmanFormData): Promise<void> {
|
|
298
|
+
// Postman sets the `value` property with the path to the file
|
|
299
|
+
// but not data itself. Because of that this method is a stub that can be extended
|
|
300
|
+
// by particular implementation (like node, CLI).
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async addRawBody(created: ProjectRequest, body: PostmanBody): Promise<void> {
|
|
304
|
+
if (body.raw) {
|
|
305
|
+
await created.expects.writePayload(body.raw);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|