@api-client/core 0.3.3 → 0.3.4
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/package.json +1 -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/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/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/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/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 +101 -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/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 +1064 -0
- package/src/runtime/http-engine/Errors.ts +13 -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 +787 -0
- package/src/runtime/http-engine/NodeEngineDirect.ts +476 -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/ProjectRunner.ts +275 -0
- package/src/runtime/node/RequestFactory.ts +422 -0
- package/src/runtime/node/VariablesStore.ts +25 -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
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Lorem, Random, Types, Utils } from '@pawel-up/data-mock';
|
|
2
|
+
import { ArcDataMockInit } from '../LegacyInterfaces.js';
|
|
3
|
+
import { Certificate, CertificateIndex, ClientCertificate } from '../../models/legacy/models/ClientCertificate.js';
|
|
4
|
+
import { ExportArcClientCertificateData } from '../../models/legacy/DataExport.js';
|
|
5
|
+
|
|
6
|
+
export declare interface CertificateCreateInit {
|
|
7
|
+
binary?: boolean;
|
|
8
|
+
noPassphrase?: boolean;
|
|
9
|
+
noKey?: boolean;
|
|
10
|
+
noCreated?: boolean;
|
|
11
|
+
type?: 'p12' | 'pem';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class Certificates {
|
|
15
|
+
lorem: Lorem;
|
|
16
|
+
types: Types;
|
|
17
|
+
random: Random;
|
|
18
|
+
|
|
19
|
+
constructor(init: ArcDataMockInit={}) {
|
|
20
|
+
this.lorem = new Lorem(init);
|
|
21
|
+
this.types = new Types(init.seed);
|
|
22
|
+
this.random = new Random(init.seed);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a certificate definition.
|
|
27
|
+
*/
|
|
28
|
+
certificate(opts: CertificateCreateInit = {}): Certificate {
|
|
29
|
+
const data = this.lorem.paragraph();
|
|
30
|
+
const result: Certificate = {
|
|
31
|
+
data,
|
|
32
|
+
};
|
|
33
|
+
if (opts.binary) {
|
|
34
|
+
result.data = Utils.strToBuffer(data);
|
|
35
|
+
}
|
|
36
|
+
if (!opts.noPassphrase) {
|
|
37
|
+
result.passphrase = this.lorem.word();
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generates a Client Certificate index object.
|
|
44
|
+
* @param opts Create options
|
|
45
|
+
*/
|
|
46
|
+
certificateIndex(opts: CertificateCreateInit = {}): CertificateIndex {
|
|
47
|
+
const type = opts.type ? opts.type : this.random.pickOne(['p12', 'pem']);
|
|
48
|
+
const result: CertificateIndex = {
|
|
49
|
+
type,
|
|
50
|
+
name: this.lorem.word(),
|
|
51
|
+
};
|
|
52
|
+
if (!opts.noCreated) {
|
|
53
|
+
result.created = this.types.datetime().getTime();
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param opts Create options
|
|
60
|
+
*/
|
|
61
|
+
requestCertificate(opts: CertificateCreateInit = {}): ClientCertificate {
|
|
62
|
+
const type = opts.type ? opts.type : this.random.pickOne(['p12', 'pem']);
|
|
63
|
+
const cert = this.certificate(opts);
|
|
64
|
+
const name = this.lorem.word();
|
|
65
|
+
const result: ClientCertificate = {
|
|
66
|
+
type,
|
|
67
|
+
name,
|
|
68
|
+
cert,
|
|
69
|
+
};
|
|
70
|
+
if (!opts.noKey) {
|
|
71
|
+
result.key = this.certificate(opts);
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Creates a ClientCertificate object that is used to create a new certificate.
|
|
78
|
+
* @param opts Create options
|
|
79
|
+
*/
|
|
80
|
+
clientCertificate(opts: CertificateCreateInit = {}): ClientCertificate {
|
|
81
|
+
const index = this.certificateIndex(opts);
|
|
82
|
+
const data = this.requestCertificate(opts) as any;
|
|
83
|
+
const result: ClientCertificate = {
|
|
84
|
+
...index,
|
|
85
|
+
cert: data.cert,
|
|
86
|
+
};
|
|
87
|
+
if (data.key) {
|
|
88
|
+
result.key = data.key;
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Creates a list of ClientCertificate objects that are used to create a new certificates.
|
|
95
|
+
*
|
|
96
|
+
* @param size The number of certificates to generate.
|
|
97
|
+
* @param opts Create options
|
|
98
|
+
*/
|
|
99
|
+
clientCertificates(size = 15, opts: CertificateCreateInit = {}): ClientCertificate[] {
|
|
100
|
+
const result = [];
|
|
101
|
+
for (let i = 0; i < size; i++) {
|
|
102
|
+
result[result.length] = this.clientCertificate(opts);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Creates a ClientCertificate transformed to the export object.
|
|
109
|
+
*/
|
|
110
|
+
exportClientCertificate(opts: CertificateCreateInit = {}): ExportArcClientCertificateData {
|
|
111
|
+
const item = (this.clientCertificate(opts)) as any;
|
|
112
|
+
if (item.key) {
|
|
113
|
+
item.pKey = item.key;
|
|
114
|
+
}
|
|
115
|
+
item.key = this.types.uuid();
|
|
116
|
+
item.kind = 'ARC#ClientCertificate';
|
|
117
|
+
return item;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Creates a list of ClientCertificates transformed for the export object.
|
|
122
|
+
*/
|
|
123
|
+
exportClientCertificates(size = 15, opts: CertificateCreateInit = {}): ExportArcClientCertificateData[] {
|
|
124
|
+
const result: ExportArcClientCertificateData[] = [];
|
|
125
|
+
for (let i = 0; i < size; i++) {
|
|
126
|
+
result[result.length] = this.exportClientCertificate(opts);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param cert Certificate definition. See class description.
|
|
133
|
+
*/
|
|
134
|
+
toStore(cert: Certificate|Certificate[]): Certificate|Certificate[] {
|
|
135
|
+
if (Array.isArray(cert)) {
|
|
136
|
+
return (cert.map(info => this.toStore(info))) as Certificate[];
|
|
137
|
+
}
|
|
138
|
+
if (typeof cert.data === 'string') {
|
|
139
|
+
return cert;
|
|
140
|
+
}
|
|
141
|
+
const data = Utils.bufferToBase64(cert.data);
|
|
142
|
+
const copy = { ...cert, type: 'buffer', data };
|
|
143
|
+
return copy;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Lorem, Types, Internet } from '@pawel-up/data-mock';
|
|
2
|
+
import { ArcDataMockInit } from '../LegacyInterfaces.js';
|
|
3
|
+
import { ARCCookie } from '../../models/legacy/models/Cookies.js';
|
|
4
|
+
|
|
5
|
+
export class Cookies {
|
|
6
|
+
types: Types;
|
|
7
|
+
lorem: Lorem;
|
|
8
|
+
internet: Internet;
|
|
9
|
+
|
|
10
|
+
constructor(init: ArcDataMockInit={}) {
|
|
11
|
+
this.types = new Types(init.seed);
|
|
12
|
+
this.lorem = new Lorem(init);
|
|
13
|
+
this.internet = new Internet(init);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generates random Cookie data
|
|
18
|
+
*/
|
|
19
|
+
cookie(): ARCCookie {
|
|
20
|
+
const time = this.types.datetime().getTime();
|
|
21
|
+
const result = {
|
|
22
|
+
created: time,
|
|
23
|
+
updated: time,
|
|
24
|
+
expires: this.types.datetime().getTime(),
|
|
25
|
+
maxAge: this.types.number({ min: 100, max: 1000 }),
|
|
26
|
+
name: this.lorem.word(),
|
|
27
|
+
value: this.lorem.word(),
|
|
28
|
+
_id: this.types.uuid(),
|
|
29
|
+
domain: this.internet.domain(),
|
|
30
|
+
hostOnly: this.types.boolean(),
|
|
31
|
+
httpOnly: this.types.boolean(),
|
|
32
|
+
lastAccess: time,
|
|
33
|
+
path: this.types.boolean() ? '/' : `/${this.lorem.word()}`,
|
|
34
|
+
persistent: this.types.boolean(),
|
|
35
|
+
};
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generates a list of cookies
|
|
41
|
+
*
|
|
42
|
+
* @return List of datastore entries.
|
|
43
|
+
*/
|
|
44
|
+
cookies(size = 25): ARCCookie[] {
|
|
45
|
+
const result = [];
|
|
46
|
+
for (let i = 0; i < size; i++) {
|
|
47
|
+
result.push(this.cookie());
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Lorem, Types, Internet } from '@pawel-up/data-mock';
|
|
2
|
+
import { ArcDataMockInit } from '../LegacyInterfaces.js';
|
|
3
|
+
import { ARCHostRule } from '../../models/legacy/models/HostRule.js';
|
|
4
|
+
|
|
5
|
+
export class HostRules {
|
|
6
|
+
types: Types;
|
|
7
|
+
lorem: Lorem;
|
|
8
|
+
internet: Internet;
|
|
9
|
+
|
|
10
|
+
constructor(init: ArcDataMockInit = {}) {
|
|
11
|
+
this.types = new Types(init.seed);
|
|
12
|
+
this.lorem = new Lorem(init);
|
|
13
|
+
this.internet = new Internet(init);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generates random host rule data object.
|
|
18
|
+
*/
|
|
19
|
+
rule(): ARCHostRule {
|
|
20
|
+
const result: ARCHostRule = {
|
|
21
|
+
_id: this.types.uuid(),
|
|
22
|
+
from: this.internet.uri(),
|
|
23
|
+
to: this.internet.uri(),
|
|
24
|
+
enabled: this.types.boolean(),
|
|
25
|
+
comment: this.lorem.paragraph(),
|
|
26
|
+
};
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Generates a list of host rules.
|
|
32
|
+
*
|
|
33
|
+
* @param size Number of items to generate. Default to 25.
|
|
34
|
+
* @return List of datastore entries.
|
|
35
|
+
*/
|
|
36
|
+
rules(size = 25): ARCHostRule[] {
|
|
37
|
+
const result = [];
|
|
38
|
+
for (let i = 0; i < size; i++) {
|
|
39
|
+
result.push(this.rule());
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { Http as Base, Types, Lorem, Time, HttpRequestInit } from '@pawel-up/data-mock';
|
|
2
|
+
import { randomValue } from '@pawel-up/data-mock/src/lib/Http.js';
|
|
3
|
+
import { ArcDataMockInit } from '../LegacyInterfaces.js';
|
|
4
|
+
import { HttpResponse } from './HttpResponse.js';
|
|
5
|
+
import { ARCHistoryRequest, ARCSavedRequest, TransportRequest } from '../../models/legacy/request/ArcRequest.js';
|
|
6
|
+
import { ARCProject } from '../../models/legacy/models/ArcLegacyProject.js';
|
|
7
|
+
|
|
8
|
+
export interface RequestHistoryInit extends HttpRequestInit {
|
|
9
|
+
noId?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RequestSavedInit extends HttpRequestInit {
|
|
13
|
+
forceDescription?: boolean;
|
|
14
|
+
noDescription?: boolean;
|
|
15
|
+
project?: string;
|
|
16
|
+
projects?: ARCProject[];
|
|
17
|
+
forceProject?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ProjectCreateInit {
|
|
21
|
+
/**
|
|
22
|
+
* Request id to add to `requests` array
|
|
23
|
+
*/
|
|
24
|
+
requestId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* If set it generates request ID to add to `requests` array
|
|
27
|
+
*/
|
|
28
|
+
autoRequestId?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare interface GenerateSavedResult {
|
|
32
|
+
projects: ARCProject[];
|
|
33
|
+
requests: ARCSavedRequest[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TransportRequestInit extends HttpRequestInit {
|
|
37
|
+
noHttpMessage?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class Http extends Base {
|
|
41
|
+
LAST_TIME: number;
|
|
42
|
+
types: Types;
|
|
43
|
+
lorem: Lorem;
|
|
44
|
+
response: HttpResponse;
|
|
45
|
+
time: Time;
|
|
46
|
+
|
|
47
|
+
constructor(init: ArcDataMockInit={}) {
|
|
48
|
+
super(init);
|
|
49
|
+
this.LAST_TIME = Date.now();
|
|
50
|
+
this.types = new Types(init.seed);
|
|
51
|
+
this.lorem = new Lorem(init);
|
|
52
|
+
this.response = new HttpResponse(init);
|
|
53
|
+
this.time = new Time(init);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
history(opts: RequestHistoryInit={}): ARCHistoryRequest {
|
|
57
|
+
const base = this.request(opts);
|
|
58
|
+
this.LAST_TIME -= this.types.datetime().getTime();
|
|
59
|
+
const midnight = this.time.midnight(this.LAST_TIME);
|
|
60
|
+
|
|
61
|
+
const item: ARCHistoryRequest = {
|
|
62
|
+
...base,
|
|
63
|
+
created: this.LAST_TIME,
|
|
64
|
+
updated: this.LAST_TIME,
|
|
65
|
+
type: 'history',
|
|
66
|
+
midnight,
|
|
67
|
+
};
|
|
68
|
+
if (!opts.noId) {
|
|
69
|
+
item._id = this.types.uuid();
|
|
70
|
+
}
|
|
71
|
+
return item;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
saved(opts: RequestSavedInit={}): ARCSavedRequest {
|
|
75
|
+
const base = this.request(opts);
|
|
76
|
+
const time = this.types.datetime().getTime();
|
|
77
|
+
const requestName = this.lorem.words(2);
|
|
78
|
+
const description = this.description(opts);
|
|
79
|
+
const midnight = this.time.midnight(this.LAST_TIME);
|
|
80
|
+
const item: ARCSavedRequest = {
|
|
81
|
+
...base,
|
|
82
|
+
created: time,
|
|
83
|
+
updated: time,
|
|
84
|
+
type: 'saved',
|
|
85
|
+
name: requestName,
|
|
86
|
+
midnight,
|
|
87
|
+
};
|
|
88
|
+
if (description) {
|
|
89
|
+
item.description = description;
|
|
90
|
+
}
|
|
91
|
+
item._id = this.types.uuid();
|
|
92
|
+
if (opts.project) {
|
|
93
|
+
item.projects = [opts.project];
|
|
94
|
+
}
|
|
95
|
+
return item;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Generates a description for a request.
|
|
100
|
+
*
|
|
101
|
+
* @param opts Configuration options
|
|
102
|
+
* @returns Items description.
|
|
103
|
+
*/
|
|
104
|
+
description(opts: RequestSavedInit={}): string|undefined {
|
|
105
|
+
const { noDescription, forceDescription } = opts;
|
|
106
|
+
if (noDescription) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
if (forceDescription) {
|
|
110
|
+
return this.lorem.paragraph();
|
|
111
|
+
}
|
|
112
|
+
return this.types.boolean({ likelihood: 70 }) ? this.lorem.paragraph() : undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param size The number of requests to generate.
|
|
117
|
+
* @param init History init options.
|
|
118
|
+
*/
|
|
119
|
+
listHistory(size = 25, init: RequestHistoryInit={}): ARCHistoryRequest[] {
|
|
120
|
+
const result = [];
|
|
121
|
+
for (let i = 0; i < size; i++) {
|
|
122
|
+
result.push(this.history(init));
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param size The number of requests to generate.
|
|
129
|
+
* @param init Saved init options
|
|
130
|
+
*/
|
|
131
|
+
listSaved(size = 25, init: RequestSavedInit = {}): ARCSavedRequest[] {
|
|
132
|
+
const list = [];
|
|
133
|
+
for (let i = 0; i < size; i++) {
|
|
134
|
+
const project = this.pickProject(init);
|
|
135
|
+
const opts = { ...init };
|
|
136
|
+
if (project && project._id) {
|
|
137
|
+
opts.project = project._id;
|
|
138
|
+
}
|
|
139
|
+
const item = this.saved(opts);
|
|
140
|
+
if (project) {
|
|
141
|
+
if (!project.requests) {
|
|
142
|
+
project.requests = [];
|
|
143
|
+
}
|
|
144
|
+
project.requests.push(item._id as string);
|
|
145
|
+
}
|
|
146
|
+
list.push(item);
|
|
147
|
+
}
|
|
148
|
+
return list;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Picks a random project from the list of passed in `opts` projects.
|
|
153
|
+
*
|
|
154
|
+
* @param opts
|
|
155
|
+
* @returns A project or undefined.
|
|
156
|
+
*/
|
|
157
|
+
pickProject(opts: RequestSavedInit = {}): ARCProject|undefined {
|
|
158
|
+
if (!opts.projects || !opts.projects.length) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
let allow;
|
|
162
|
+
if (opts.forceProject) {
|
|
163
|
+
allow = true;
|
|
164
|
+
} else {
|
|
165
|
+
allow = this.types.boolean();
|
|
166
|
+
}
|
|
167
|
+
if (allow) {
|
|
168
|
+
return this[randomValue].pickOne(opts.projects);
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
project(init: ProjectCreateInit={}): ARCProject {
|
|
174
|
+
const project: ARCProject = {
|
|
175
|
+
_id: this.types.uuid(),
|
|
176
|
+
name: this.lorem.sentence({ words: 2 }),
|
|
177
|
+
order: 0,
|
|
178
|
+
description: this.lorem.paragraph(),
|
|
179
|
+
requests: [],
|
|
180
|
+
};
|
|
181
|
+
if (init.requestId) {
|
|
182
|
+
project.requests!.push(init.requestId);
|
|
183
|
+
} else if (init.autoRequestId) {
|
|
184
|
+
project.requests!.push(this.types.uuid());
|
|
185
|
+
}
|
|
186
|
+
return project;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
listProjects(size = 5, init: ProjectCreateInit = {}): ARCProject[] {
|
|
190
|
+
const result = [];
|
|
191
|
+
for (let i = 0; i < size; i++) {
|
|
192
|
+
result.push(this.project(init));
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @returns A map with `projects` and `requests` arrays.
|
|
199
|
+
*/
|
|
200
|
+
savedData(requestsSize = 25, projectsSize = 5, requestsInit: RequestSavedInit = {}, projectInit: ProjectCreateInit = {}): GenerateSavedResult {
|
|
201
|
+
const projects = this.listProjects(projectsSize, projectInit);
|
|
202
|
+
const rCopy = { ...requestsInit };
|
|
203
|
+
rCopy.projects = projects;
|
|
204
|
+
const requests = this.listSaved(requestsSize, rCopy);
|
|
205
|
+
return {
|
|
206
|
+
requests,
|
|
207
|
+
projects,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Generates a transport request object.
|
|
213
|
+
* @param opts Generate options
|
|
214
|
+
* @returns The transport request object
|
|
215
|
+
*/
|
|
216
|
+
transportRequest(opts: TransportRequestInit={}): TransportRequest {
|
|
217
|
+
const base = this.request(opts);
|
|
218
|
+
const request: TransportRequest = {
|
|
219
|
+
...base,
|
|
220
|
+
startTime: Date.now() - 1000,
|
|
221
|
+
endTime: Date.now(),
|
|
222
|
+
httpMessage: '',
|
|
223
|
+
};
|
|
224
|
+
if (!opts.noHttpMessage) {
|
|
225
|
+
request.httpMessage = `GET / HTTP 1.1\n${request.headers}\n`;
|
|
226
|
+
if (request.payload) {
|
|
227
|
+
request.httpMessage += `\n${request.payload}\n`;
|
|
228
|
+
}
|
|
229
|
+
request.httpMessage += '\n';
|
|
230
|
+
} else {
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
delete request.httpMessage;
|
|
233
|
+
}
|
|
234
|
+
return request;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { HttpResponse as Base, headersValue, payloadValue, typesValue, loremValue } from '@pawel-up/data-mock/src/lib/http/HttpResponse.js';
|
|
2
|
+
import { Har, DataMockLocale } from '@pawel-up/data-mock';
|
|
3
|
+
import { ArcDataMockInit, HttpResponseArcInit, HttpResponseRedirectInit } from '../LegacyInterfaces.js';
|
|
4
|
+
import { ResponseRedirect, Response, ErrorResponse } from '../../models/legacy/request/ArcResponse.js';
|
|
5
|
+
|
|
6
|
+
export class HttpResponse extends Base {
|
|
7
|
+
har: Har;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param init The library init options.
|
|
11
|
+
*/
|
|
12
|
+
constructor(init: ArcDataMockInit={}) {
|
|
13
|
+
super(init);
|
|
14
|
+
this.har = new Har(init);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
seed(value?: number): void {
|
|
18
|
+
super.seed(value);
|
|
19
|
+
this.har.seed(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param locale The locale to set. When nothing is passed then it uses the default locale.
|
|
24
|
+
*/
|
|
25
|
+
locale(locale?: DataMockLocale): void {
|
|
26
|
+
super.locale(locale);
|
|
27
|
+
this.har.locale(locale);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @returns Generated redirect response.
|
|
32
|
+
*/
|
|
33
|
+
redirectResponse(init: HttpResponseRedirectInit={}): ResponseRedirect {
|
|
34
|
+
const ct = init.body ? this[headersValue].contentType() : undefined;
|
|
35
|
+
let headers = this[headersValue].headers('response', { mime: ct });
|
|
36
|
+
const url = this[headersValue].link();
|
|
37
|
+
headers += `\nlocation: ${url}`;
|
|
38
|
+
const { code, status } = this.redirectStatus(init);
|
|
39
|
+
const body = init.body ? this[payloadValue].payload(ct) : undefined;
|
|
40
|
+
const startTime = this[typesValue].datetime().getTime();
|
|
41
|
+
const duration = this[typesValue].number({ min: 10, max: 4000 });
|
|
42
|
+
const result: ResponseRedirect = {
|
|
43
|
+
url: '',
|
|
44
|
+
response: {
|
|
45
|
+
status: code,
|
|
46
|
+
statusText: status,
|
|
47
|
+
headers,
|
|
48
|
+
},
|
|
49
|
+
startTime,
|
|
50
|
+
endTime: startTime + duration,
|
|
51
|
+
};
|
|
52
|
+
if (body) {
|
|
53
|
+
result.response.payload = body;
|
|
54
|
+
}
|
|
55
|
+
if (init.timings) {
|
|
56
|
+
result.timings = this.har.timing(init);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
arcResponse(init: HttpResponseArcInit = {}): Response {
|
|
62
|
+
const ct = init.noBody ? undefined : this[headersValue].contentType();
|
|
63
|
+
const body = init.noBody ? undefined : this[payloadValue].payload(ct);
|
|
64
|
+
const headers = this[headersValue].headers('response', { mime: ct });
|
|
65
|
+
const statusGroup = init.statusGroup ? init.statusGroup : this[typesValue].number({ min: 2, max: 5 });
|
|
66
|
+
const sCode = this[typesValue].number({ min: 0, max: 99 }).toString();
|
|
67
|
+
const code = Number(`${statusGroup}${sCode.padStart(2, '0')}`);
|
|
68
|
+
const status = this[loremValue].word();
|
|
69
|
+
const length = this[typesValue].number({ min: 10, max: 4000 });
|
|
70
|
+
const result: Response = {
|
|
71
|
+
status: code,
|
|
72
|
+
statusText: status,
|
|
73
|
+
headers,
|
|
74
|
+
loadingTime: length,
|
|
75
|
+
};
|
|
76
|
+
if (init.timings) {
|
|
77
|
+
result.timings = this.har.timing(init);
|
|
78
|
+
}
|
|
79
|
+
if (!init.noBody) {
|
|
80
|
+
result.payload = body;
|
|
81
|
+
}
|
|
82
|
+
if (!init.noSize) {
|
|
83
|
+
const hSize = headers.length;
|
|
84
|
+
const bSize = body ? body.length : 0;
|
|
85
|
+
result.size = {
|
|
86
|
+
request: this[typesValue].number({ min: 10 }),
|
|
87
|
+
response: hSize + bSize,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (init.redirects) {
|
|
91
|
+
const size = this[typesValue].number({ min: 1, max: 4 });
|
|
92
|
+
const cnf = { timings: init.timings, body: true };
|
|
93
|
+
result.redirects = new Array(size).fill(0).map(() => this.redirectResponse(cnf));
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
arcErrorResponse(): ErrorResponse {
|
|
99
|
+
const error = new Error(this[loremValue].paragraph());
|
|
100
|
+
const result: ErrorResponse = {
|
|
101
|
+
status: 0,
|
|
102
|
+
error,
|
|
103
|
+
};
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Lorem, Types, Internet } from '@pawel-up/data-mock';
|
|
2
|
+
import { ArcDataMockInit, RestApiIndexInit } from '../LegacyInterfaces.js';
|
|
3
|
+
import { ARCRestApi, ARCRestApiIndex } from '../../models/legacy/models/RestApi.js';
|
|
4
|
+
|
|
5
|
+
export class RestApi {
|
|
6
|
+
types: Types;
|
|
7
|
+
lorem: Lorem;
|
|
8
|
+
internet: Internet;
|
|
9
|
+
|
|
10
|
+
constructor(init: ArcDataMockInit={}) {
|
|
11
|
+
this.types = new Types(init.seed);
|
|
12
|
+
this.lorem = new Lorem(init);
|
|
13
|
+
this.internet = new Internet(init);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
apiIndex(opts: RestApiIndexInit = {}): ARCRestApiIndex {
|
|
17
|
+
const result: ARCRestApiIndex = {
|
|
18
|
+
order: opts.order || 0,
|
|
19
|
+
title: this.lorem.sentence({ words: 2 }),
|
|
20
|
+
type: 'RAML 1.0',
|
|
21
|
+
_id: this.internet.uri(),
|
|
22
|
+
versions: [],
|
|
23
|
+
latest: '',
|
|
24
|
+
};
|
|
25
|
+
const versionsSize = opts.versionSize ? opts.versionSize : this.types.number({ min: 1, max: 5 });
|
|
26
|
+
const versions = [];
|
|
27
|
+
let last = '';
|
|
28
|
+
for (let i = 0; i < versionsSize; i++) {
|
|
29
|
+
last = `v${i}`;
|
|
30
|
+
versions[versions.length] = last;
|
|
31
|
+
}
|
|
32
|
+
result.versions = versions;
|
|
33
|
+
result.latest = last;
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
apiIndexList(size=25, opts: RestApiIndexInit = {}): ARCRestApiIndex[] {
|
|
38
|
+
const result = [];
|
|
39
|
+
for (let i = 0; i < size; i++) {
|
|
40
|
+
result.push(this.apiIndex({ ...opts, order: i }));
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
apiData(index: ARCRestApiIndex): ARCRestApi[] {
|
|
46
|
+
const result: ARCRestApi[] = [];
|
|
47
|
+
index.versions.forEach((version) => {
|
|
48
|
+
const item: ARCRestApi = {
|
|
49
|
+
data: '[{}]',
|
|
50
|
+
indexId: index._id || '',
|
|
51
|
+
version,
|
|
52
|
+
_id: `${index._id}|${version}`,
|
|
53
|
+
};
|
|
54
|
+
result[result.length] = item;
|
|
55
|
+
});
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
apiDataList(indexes: ARCRestApiIndex[]): ARCRestApi[] {
|
|
60
|
+
const size = indexes.length;
|
|
61
|
+
let result: ARCRestApi[] = [];
|
|
62
|
+
for (let i = 0; i < size; i++) {
|
|
63
|
+
const data = this.apiData(indexes[i]);
|
|
64
|
+
result = result.concat(data);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Internet, Types, Time } from '@pawel-up/data-mock';
|
|
2
|
+
import { ArcDataMockInit } from '../LegacyInterfaces.js';
|
|
3
|
+
import { ARCUrlHistory } from '../../models/legacy/models/UrlHistory.js';
|
|
4
|
+
|
|
5
|
+
export class Urls {
|
|
6
|
+
types: Types;
|
|
7
|
+
internet: Internet;
|
|
8
|
+
time: Time;
|
|
9
|
+
|
|
10
|
+
constructor(init: ArcDataMockInit={}) {
|
|
11
|
+
this.types = new Types(init.seed);
|
|
12
|
+
this.internet = new Internet(init);
|
|
13
|
+
this.time = new Time(init);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generates a single ARC URL model item.
|
|
18
|
+
*/
|
|
19
|
+
url(): ARCUrlHistory {
|
|
20
|
+
const url = this.internet.uri();
|
|
21
|
+
const time = this.types.datetime().getTime();
|
|
22
|
+
const result: ARCUrlHistory = {
|
|
23
|
+
time,
|
|
24
|
+
cnt: this.types.number({ min: 100, max: 1000 }),
|
|
25
|
+
_id: url,
|
|
26
|
+
url,
|
|
27
|
+
midnight: this.time.midnight(time),
|
|
28
|
+
};
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generates list of ARC URL models.
|
|
34
|
+
*
|
|
35
|
+
* @returns List of datastore entries.
|
|
36
|
+
*/
|
|
37
|
+
urls(size = 25): ARCUrlHistory[] {
|
|
38
|
+
const result = [];
|
|
39
|
+
for (let i = 0; i < size; i++) {
|
|
40
|
+
result.push(this.url());
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
}
|