@api-client/core 0.6.28 → 0.6.31
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/src/events/BaseEvents.d.ts +30 -28
- package/build/src/events/BaseEvents.js +15 -15
- package/build/src/events/BaseEvents.js.map +1 -1
- package/build/src/events/models/ClientCertificateEvents.d.ts +4 -4
- package/build/src/events/models/ClientCertificateEvents.js +6 -6
- package/build/src/events/models/ClientCertificateEvents.js.map +1 -1
- package/build/src/events/transport/TransportEvents.js.map +1 -1
- package/build/src/mocking/ProjectMock.d.ts +2 -0
- package/build/src/mocking/ProjectMock.js +3 -0
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/Arc.d.ts +9 -0
- package/build/src/mocking/lib/Arc.js +24 -0
- package/build/src/mocking/lib/Arc.js.map +1 -0
- package/build/src/mocking/lib/Certificates.js +4 -1
- package/build/src/mocking/lib/Certificates.js.map +1 -1
- package/build/src/mocking/lib/Request.js +5 -2
- package/build/src/mocking/lib/Request.js.map +1 -1
- package/build/src/models/ClientCertificate.d.ts +2 -2
- package/build/src/models/ClientCertificate.js +10 -7
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/arc/ArcHttpRequest.d.ts +1 -0
- package/build/src/models/arc/ArcHttpRequest.js +20 -12
- package/build/src/models/arc/ArcHttpRequest.js.map +1 -1
- package/build/src/models/arc/ArcProject.js +5 -0
- package/build/src/models/arc/ArcProject.js.map +1 -1
- package/build/src/runtime/http-engine/HttpEngine.js +7 -5
- package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/events/BaseEvents.ts +33 -33
- package/src/events/models/ClientCertificateEvents.ts +6 -6
- package/src/events/transport/TransportEvents.ts +2 -0
- package/src/mocking/ProjectMock.ts +3 -0
- package/src/mocking/lib/Arc.ts +28 -0
- package/src/mocking/lib/Certificates.ts +4 -1
- package/src/mocking/lib/Request.ts +6 -3
- package/src/models/ClientCertificate.ts +12 -9
- package/src/models/arc/ArcHttpRequest.ts +20 -12
- package/src/models/arc/ArcProject.ts +5 -0
- package/src/runtime/http-engine/HttpEngine.ts +8 -6
|
@@ -6,12 +6,12 @@ export class ClientCertificateEvents {
|
|
|
6
6
|
/**
|
|
7
7
|
* Dispatches an event handled by the data store to read the client certificate.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param key The key of the client certificate
|
|
10
10
|
* @param target A node on which to dispatch the event.
|
|
11
11
|
* @returns Promise resolved to a client certificate model.
|
|
12
12
|
*/
|
|
13
|
-
static async read(
|
|
14
|
-
const e = new ContextReadEvent<HttpCertificate>(ModelEventTypes.ClientCertificate.read,
|
|
13
|
+
static async read(key: string, target: EventTarget = window): Promise<HttpCertificate | undefined> {
|
|
14
|
+
const e = new ContextReadEvent<HttpCertificate>(ModelEventTypes.ClientCertificate.read, key);
|
|
15
15
|
target.dispatchEvent(e);
|
|
16
16
|
return e.detail.result;
|
|
17
17
|
}
|
|
@@ -32,12 +32,12 @@ export class ClientCertificateEvents {
|
|
|
32
32
|
/**
|
|
33
33
|
* Dispatches an event handled by the data store to delete a client certificate
|
|
34
34
|
*
|
|
35
|
-
* @param
|
|
35
|
+
* @param key The key of the project to delete.
|
|
36
36
|
* @param target A node on which to dispatch the event.
|
|
37
37
|
* @returns Promise resolved to a new revision after delete.
|
|
38
38
|
*/
|
|
39
|
-
static async delete(
|
|
40
|
-
const e = new ContextDeleteEvent(ModelEventTypes.ClientCertificate.delete,
|
|
39
|
+
static async delete(key: string, target: EventTarget = window): Promise<ContextDeleteRecord | undefined> {
|
|
40
|
+
const e = new ContextDeleteEvent(ModelEventTypes.ClientCertificate.delete, key, undefined);
|
|
41
41
|
target.dispatchEvent(e);
|
|
42
42
|
return e.detail.result;
|
|
43
43
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
3
|
import { IRequestAuthorization } from "../../models/RequestAuthorization.js";
|
|
2
4
|
import { IHttpRequest } from "../../models/HttpRequest.js";
|
|
3
5
|
import { IRequestBaseConfig } from "../../models/RequestConfig.js";
|
|
@@ -6,6 +6,7 @@ import { History } from './lib/History.js';
|
|
|
6
6
|
import { Url } from './lib/Url.js';
|
|
7
7
|
import { Certificates } from './lib/Certificates.js';
|
|
8
8
|
import { HostRules } from './lib/HostRules.js';
|
|
9
|
+
import { Arc } from './lib/Arc.js';
|
|
9
10
|
|
|
10
11
|
export { IRequestLogInit } from './lib/Request.js';
|
|
11
12
|
export { IResponseInit } from './lib/Response.js';
|
|
@@ -20,6 +21,7 @@ export class ProjectMock extends DataMock {
|
|
|
20
21
|
url: Url;
|
|
21
22
|
certificates: Certificates;
|
|
22
23
|
hostRules: HostRules;
|
|
24
|
+
arc: Arc;
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* @param init The library init options.
|
|
@@ -33,5 +35,6 @@ export class ProjectMock extends DataMock {
|
|
|
33
35
|
this.url = new Url(init);
|
|
34
36
|
this.certificates = new Certificates(init);
|
|
35
37
|
this.hostRules = new HostRules(init);
|
|
38
|
+
this.arc = new Arc(init);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IDataMockInit, IHttpRequestInit } from '@pawel-up/data-mock';
|
|
2
|
+
import { IArcHttpRequest, Kind as ArcHttpRequestKind } from '../../models/arc/ArcHttpRequest.js';
|
|
3
|
+
import { Request } from './Request.js';
|
|
4
|
+
|
|
5
|
+
export class Arc {
|
|
6
|
+
protected request: Request;
|
|
7
|
+
|
|
8
|
+
constructor(init: IDataMockInit={}) {
|
|
9
|
+
this.request = new Request(init);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
arcRequest(init?: IHttpRequestInit): IArcHttpRequest {
|
|
13
|
+
const request = this.request.request(init);
|
|
14
|
+
return {
|
|
15
|
+
key: new Date(request.created || Date.now()).toJSON(),
|
|
16
|
+
...request,
|
|
17
|
+
kind: ArcHttpRequestKind,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
arcRequests(size = 25, init?: IHttpRequestInit): IArcHttpRequest[] {
|
|
22
|
+
const result: IArcHttpRequest[] = [];
|
|
23
|
+
for (let i = 0; i < size; i++) {
|
|
24
|
+
result.push(this.arcRequest(init));
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -28,8 +28,10 @@ export class Certificates {
|
|
|
28
28
|
let instance: Certificate;
|
|
29
29
|
if (type === 'p12') {
|
|
30
30
|
instance = Certificate.fromP12(cert, this.lorem.word());
|
|
31
|
+
} else if (type === 'pem') {
|
|
32
|
+
instance = Certificate.fromPem(cert, cert, this.lorem.word());
|
|
31
33
|
} else {
|
|
32
|
-
|
|
34
|
+
throw new Error(`Invalid certificate type.`);
|
|
33
35
|
}
|
|
34
36
|
if (!opts.noPassphrase) {
|
|
35
37
|
instance.cert.passphrase = this.lorem.word();
|
|
@@ -38,6 +40,7 @@ export class Certificates {
|
|
|
38
40
|
key.passphrase = this.lorem.word();
|
|
39
41
|
}
|
|
40
42
|
}
|
|
43
|
+
|
|
41
44
|
return instance.toJSON();
|
|
42
45
|
}
|
|
43
46
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Http, Types, Lorem, Time, IDataMockInit, IHttpRequestInit } from '@pawel-up/data-mock';
|
|
2
2
|
// import { randomValue } from '@pawel-up/data-mock/src/lib/Http.js';
|
|
3
3
|
import { IHttpRequest, Kind as HttpRequestKind } from '../../models/HttpRequest.js';
|
|
4
|
-
import { IRequest, Kind as RequestKind } from '../../models/Request.js';
|
|
4
|
+
import { IRequest, Kind as RequestKind, Request as RequestModel } from '../../models/Request.js';
|
|
5
5
|
import { ISentRequest } from '../../models/SentRequest.js';
|
|
6
6
|
import { IRequestLog, Kind as RequestLogKind } from '../../models/RequestLog.js';
|
|
7
7
|
import { IResponseInit, Response } from './Response.js';
|
|
@@ -45,14 +45,17 @@ export class Request {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
request(init?: IHttpRequestInit): IRequest {
|
|
48
|
-
|
|
48
|
+
const schema = {
|
|
49
49
|
kind: RequestKind,
|
|
50
50
|
expects: this.httpRequest(init),
|
|
51
51
|
info: {
|
|
52
52
|
name: this.lorem.words(2),
|
|
53
53
|
description: this.lorem.paragraph(),
|
|
54
54
|
},
|
|
55
|
-
|
|
55
|
+
created: this.time.timestamp(),
|
|
56
|
+
};
|
|
57
|
+
const instance = new RequestModel(schema);
|
|
58
|
+
return instance.toJSON();
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
httpRequest(init?: IHttpRequestInit): IHttpRequest {
|
|
@@ -71,7 +71,7 @@ export interface IPemCertificate extends ICertificate {
|
|
|
71
71
|
certKey: ICertificateData;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export type HttpCertificate = IP12Certificate | IPemCertificate;
|
|
74
|
+
export type HttpCertificate = IP12Certificate | IPemCertificate | ICertificate;
|
|
75
75
|
|
|
76
76
|
export interface IPemCreateOptions {
|
|
77
77
|
type: 'p12';
|
|
@@ -128,7 +128,7 @@ export class Certificate {
|
|
|
128
128
|
* Timestamp when the certificate was inserted into the data store.
|
|
129
129
|
* Required when returning a result. Auto-generated when inserting, if missing.
|
|
130
130
|
*/
|
|
131
|
-
created
|
|
131
|
+
created = 0;
|
|
132
132
|
/**
|
|
133
133
|
* Certificate type. Either `p12` or `pem`.
|
|
134
134
|
*/
|
|
@@ -162,6 +162,7 @@ export class Certificate {
|
|
|
162
162
|
key: v4(),
|
|
163
163
|
name,
|
|
164
164
|
type: 'pem',
|
|
165
|
+
created: Date.now(),
|
|
165
166
|
};
|
|
166
167
|
if (keyPassphrase) {
|
|
167
168
|
init.certKey.passphrase = keyPassphrase;
|
|
@@ -185,6 +186,7 @@ export class Certificate {
|
|
|
185
186
|
key: v4(),
|
|
186
187
|
name,
|
|
187
188
|
type: 'p12',
|
|
189
|
+
created: Date.now(),
|
|
188
190
|
};
|
|
189
191
|
if (passphrase) {
|
|
190
192
|
init.cert.passphrase = passphrase;
|
|
@@ -224,6 +226,7 @@ export class Certificate {
|
|
|
224
226
|
key: _id,
|
|
225
227
|
name,
|
|
226
228
|
type: 'p12',
|
|
229
|
+
created,
|
|
227
230
|
};
|
|
228
231
|
return new Certificate(init);
|
|
229
232
|
}
|
|
@@ -231,16 +234,15 @@ export class Certificate {
|
|
|
231
234
|
}
|
|
232
235
|
|
|
233
236
|
constructor(certificate: HttpCertificate) {
|
|
234
|
-
const { type, cert, key = v4(), name = '', created } = certificate;
|
|
237
|
+
const { type, cert, key = v4(), name = '', created = Date.now() } = certificate;
|
|
235
238
|
this.key = key;
|
|
236
239
|
this.name = name;
|
|
237
240
|
this.type = type;
|
|
238
241
|
this.cert = Certificate.fromStore(cert);
|
|
239
|
-
|
|
240
|
-
this.created = created;
|
|
241
|
-
}
|
|
242
|
+
this.created = created;
|
|
242
243
|
if (type === 'pem') {
|
|
243
|
-
|
|
244
|
+
const typed = certificate as IPemCertificate;
|
|
245
|
+
this.certKey = Certificate.fromStore(typed.certKey);
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
|
|
@@ -288,12 +290,13 @@ export class Certificate {
|
|
|
288
290
|
}
|
|
289
291
|
|
|
290
292
|
toJSON(): HttpCertificate {
|
|
291
|
-
const result:
|
|
293
|
+
const result: HttpCertificate = {
|
|
292
294
|
kind: Kind,
|
|
293
295
|
key: this.key,
|
|
294
296
|
cert: Certificate.toStore(this.cert),
|
|
295
297
|
name: this.name,
|
|
296
|
-
type:
|
|
298
|
+
type: this.type,
|
|
299
|
+
created: this.created,
|
|
297
300
|
};
|
|
298
301
|
|
|
299
302
|
if (this.type === 'pem' && this.certKey) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IRequest, Request } from "../Request.js";
|
|
2
|
-
import v4 from "../../lib/uuid.js";
|
|
3
2
|
import { HttpRequest, IHttpRequest } from "../HttpRequest.js";
|
|
4
3
|
import { Thing } from "../Thing.js";
|
|
5
4
|
|
|
@@ -15,6 +14,7 @@ export class ArcHttpRequest extends Request {
|
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* The identifier of the request.
|
|
17
|
+
* The key is related to the `created` property. It is the `new Date(created).toJSON()` value.
|
|
18
18
|
*/
|
|
19
19
|
key = '';
|
|
20
20
|
|
|
@@ -24,9 +24,10 @@ export class ArcHttpRequest extends Request {
|
|
|
24
24
|
* @param url The Request URL. This is required.
|
|
25
25
|
*/
|
|
26
26
|
static fromUrl(url: string): ArcHttpRequest {
|
|
27
|
-
const
|
|
27
|
+
const d = new Date();
|
|
28
|
+
const now: number = d.getTime();
|
|
28
29
|
const request = new ArcHttpRequest({
|
|
29
|
-
key:
|
|
30
|
+
key: d.toJSON(),
|
|
30
31
|
kind: Kind,
|
|
31
32
|
created: now,
|
|
32
33
|
updated: now,
|
|
@@ -42,9 +43,10 @@ export class ArcHttpRequest extends Request {
|
|
|
42
43
|
* @param name The Request name.
|
|
43
44
|
*/
|
|
44
45
|
static fromName(name: string): ArcHttpRequest {
|
|
45
|
-
const
|
|
46
|
+
const d = new Date();
|
|
47
|
+
const now: number = d.getTime();
|
|
46
48
|
const request = new ArcHttpRequest({
|
|
47
|
-
key:
|
|
49
|
+
key: d.toJSON(),
|
|
48
50
|
kind: Kind,
|
|
49
51
|
created: now,
|
|
50
52
|
updated: now,
|
|
@@ -60,9 +62,10 @@ export class ArcHttpRequest extends Request {
|
|
|
60
62
|
* @param info The request data.
|
|
61
63
|
*/
|
|
62
64
|
static fromHttpRequest(info: IHttpRequest): ArcHttpRequest {
|
|
63
|
-
const
|
|
65
|
+
const d = new Date();
|
|
66
|
+
const now: number = d.getTime();
|
|
64
67
|
const request = new ArcHttpRequest({
|
|
65
|
-
key:
|
|
68
|
+
key: d.toJSON(),
|
|
66
69
|
kind: Kind,
|
|
67
70
|
created: now,
|
|
68
71
|
updated: now,
|
|
@@ -76,11 +79,13 @@ export class ArcHttpRequest extends Request {
|
|
|
76
79
|
* Creates a request for a schema of a Request.
|
|
77
80
|
*/
|
|
78
81
|
static fromRequest(request: IArcHttpRequest): ArcHttpRequest {
|
|
79
|
-
const
|
|
82
|
+
const d = new Date(request.created || Date.now());
|
|
83
|
+
const now: number = d.getTime();
|
|
80
84
|
const init: IArcHttpRequest = {
|
|
81
85
|
...request,
|
|
82
|
-
key,
|
|
83
|
-
kind: Kind
|
|
86
|
+
key: d.toJSON(),
|
|
87
|
+
kind: Kind,
|
|
88
|
+
created: now,
|
|
84
89
|
};
|
|
85
90
|
const result = new ArcHttpRequest(init);
|
|
86
91
|
return result;
|
|
@@ -96,7 +101,10 @@ export class ArcHttpRequest extends Request {
|
|
|
96
101
|
init = input;
|
|
97
102
|
}
|
|
98
103
|
if (init) {
|
|
99
|
-
this.key = init.key
|
|
104
|
+
this.key = init.key;
|
|
105
|
+
}
|
|
106
|
+
if (!this.key) {
|
|
107
|
+
this.key = new Date(this.created || Date.now()).toJSON();
|
|
100
108
|
}
|
|
101
109
|
this.kind = Kind;
|
|
102
110
|
}
|
|
@@ -105,7 +113,7 @@ export class ArcHttpRequest extends Request {
|
|
|
105
113
|
super.new(init);
|
|
106
114
|
|
|
107
115
|
const { key } = init;
|
|
108
|
-
this.key = key ||
|
|
116
|
+
this.key = key || new Date(init.created || Date.now()).toJSON();
|
|
109
117
|
this.kind = Kind;
|
|
110
118
|
}
|
|
111
119
|
|
|
@@ -951,12 +951,15 @@ export class ArcProject extends ArcProjectParent {
|
|
|
951
951
|
init.kind = ArcProjectKind;
|
|
952
952
|
}
|
|
953
953
|
} else {
|
|
954
|
+
const now = Date.now();
|
|
954
955
|
init = {
|
|
955
956
|
kind: ArcProjectKind,
|
|
956
957
|
key: v4(),
|
|
957
958
|
definitions: {},
|
|
958
959
|
items: [],
|
|
959
960
|
info: Thing.fromName('').toJSON(),
|
|
961
|
+
created: now,
|
|
962
|
+
updated: now,
|
|
960
963
|
}
|
|
961
964
|
}
|
|
962
965
|
this.new(init);
|
|
@@ -1001,6 +1004,8 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1001
1004
|
definitions: {},
|
|
1002
1005
|
items: [],
|
|
1003
1006
|
info: this.info.toJSON(),
|
|
1007
|
+
created: this.created,
|
|
1008
|
+
updated: this.updated,
|
|
1004
1009
|
};
|
|
1005
1010
|
if (Array.isArray(this.definitions.requests) && this.definitions.requests.length) {
|
|
1006
1011
|
result.definitions.requests = this.definitions.requests.map(i => i.toJSON());
|
|
@@ -10,7 +10,7 @@ import { IHttpRequest, HttpRequest } from '../../models/HttpRequest.js';
|
|
|
10
10
|
import { IRequestBaseConfig } from '../../models/RequestConfig.js';
|
|
11
11
|
import { IRequestAuthorization } from '../../models/RequestAuthorization.js';
|
|
12
12
|
import { HostRule } from '../../models/HostRule.js';
|
|
13
|
-
import { HttpCertificate } from '../../models/ClientCertificate.js';
|
|
13
|
+
import { HttpCertificate, IPemCertificate } from '../../models/ClientCertificate.js';
|
|
14
14
|
import { SentRequest } from '../../models/SentRequest.js';
|
|
15
15
|
import { Response } from '../../models/Response.js';
|
|
16
16
|
import { ErrorResponse } from '../../models/ErrorResponse.js';
|
|
@@ -645,6 +645,7 @@ Check your request parameters.`);
|
|
|
645
645
|
this.finalizeRequest(result);
|
|
646
646
|
} catch (e) {
|
|
647
647
|
const error = e as Error;
|
|
648
|
+
// eslint-disable-next-line no-console
|
|
648
649
|
console.error(error);
|
|
649
650
|
this._errorRequest({
|
|
650
651
|
message: (error && error.message) || 'Unknown error occurred',
|
|
@@ -797,6 +798,7 @@ Check your request parameters.`);
|
|
|
797
798
|
}
|
|
798
799
|
options.pfx.push(struct);
|
|
799
800
|
} else if (cert.type === 'pem') {
|
|
801
|
+
const typed = cert as IPemCertificate;
|
|
800
802
|
if (!options.cert) {
|
|
801
803
|
options.cert = [];
|
|
802
804
|
}
|
|
@@ -807,9 +809,9 @@ Check your request parameters.`);
|
|
|
807
809
|
options.cert = [];
|
|
808
810
|
}
|
|
809
811
|
}
|
|
810
|
-
const added = Buffer.from(
|
|
812
|
+
const added = Buffer.from(typed.cert.data as string);
|
|
811
813
|
options.cert.push(added);
|
|
812
|
-
if (
|
|
814
|
+
if (typed.certKey) {
|
|
813
815
|
if (!Array.isArray(options.key)) {
|
|
814
816
|
if (options.key) {
|
|
815
817
|
options.key = [options.key];
|
|
@@ -818,10 +820,10 @@ Check your request parameters.`);
|
|
|
818
820
|
}
|
|
819
821
|
}
|
|
820
822
|
const struct: tls.KeyObject = {
|
|
821
|
-
pem: Buffer.from(
|
|
823
|
+
pem: Buffer.from(typed.certKey.data as string),
|
|
822
824
|
};
|
|
823
|
-
if (
|
|
824
|
-
struct.passphrase =
|
|
825
|
+
if (typed.certKey.passphrase) {
|
|
826
|
+
struct.passphrase = typed.certKey.passphrase;
|
|
825
827
|
}
|
|
826
828
|
options.key.push(struct);
|
|
827
829
|
}
|