@thisisagile/easy 12.8.0 → 12.10.0
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/dist/http/RequestOptions.d.ts +8 -6
- package/dist/http/RequestOptions.js +5 -12
- package/dist/http/RequestOptions.js.map +1 -1
- package/dist/services/ApiGateway.d.ts +14 -0
- package/dist/services/ApiGateway.js +41 -0
- package/dist/services/ApiGateway.js.map +1 -0
- package/dist/services/RouteGateway.d.ts +3 -10
- package/dist/services/RouteGateway.js +3 -30
- package/dist/services/RouteGateway.js.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/index.js.map +1 -1
- package/package.json +2 -2
- package/src/http/RequestOptions.ts +17 -21
- package/src/services/ApiGateway.ts +53 -0
- package/src/services/RouteGateway.ts +5 -48
- package/src/services/index.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Enum, PageOptions, Text } from '../types';
|
|
1
|
+
import { Enum, Id, PageOptions, Text } from '../types';
|
|
2
2
|
import { ContentType } from './ContentType';
|
|
3
3
|
export declare const toPageOptions: (options?: RequestOptions | PageOptions) => PageOptions | undefined;
|
|
4
4
|
export declare class RequestOptions extends Enum {
|
|
@@ -7,11 +7,6 @@ export declare class RequestOptions extends Enum {
|
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
};
|
|
9
9
|
pageOptions?: PageOptions | undefined;
|
|
10
|
-
static get Form(): RequestOptions;
|
|
11
|
-
static get Json(): RequestOptions;
|
|
12
|
-
static get Stream(): RequestOptions;
|
|
13
|
-
static get Text(): RequestOptions;
|
|
14
|
-
static get Xml(): RequestOptions;
|
|
15
10
|
requestOptions: {
|
|
16
11
|
maxRedirects?: number;
|
|
17
12
|
validateStatus?: (status: number) => boolean;
|
|
@@ -19,9 +14,16 @@ export declare class RequestOptions extends Enum {
|
|
|
19
14
|
constructor(type?: ContentType, headers?: {
|
|
20
15
|
[key: string]: any;
|
|
21
16
|
}, pageOptions?: PageOptions | undefined);
|
|
17
|
+
static get Form(): RequestOptions;
|
|
18
|
+
static get Json(): RequestOptions;
|
|
19
|
+
static get Stream(): RequestOptions;
|
|
20
|
+
static get Text(): RequestOptions;
|
|
21
|
+
static get Xml(): RequestOptions;
|
|
22
22
|
page: (options: PageOptions) => this;
|
|
23
23
|
authorization: (auth: string) => this;
|
|
24
24
|
apiKey: (apiKey: string) => this;
|
|
25
|
+
setHeader: (key: string, value: Id | boolean) => this;
|
|
26
|
+
setHeaderUnlessPresent: (key: string, value?: Id | boolean) => this;
|
|
25
27
|
accept: (type: ContentType) => this;
|
|
26
28
|
bearer: (jwt: Text) => this;
|
|
27
29
|
basic: (username: Text, password: Text) => this;
|
|
@@ -17,18 +17,11 @@ class RequestOptions extends types_1.Enum {
|
|
|
17
17
|
this.pageOptions = options;
|
|
18
18
|
return this;
|
|
19
19
|
};
|
|
20
|
-
this.authorization = (auth) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
this.headers.apiKey = apiKey;
|
|
26
|
-
return this;
|
|
27
|
-
};
|
|
28
|
-
this.accept = (type) => {
|
|
29
|
-
this.headers.Accept = type.id;
|
|
30
|
-
return this;
|
|
31
|
-
};
|
|
20
|
+
this.authorization = (auth) => this.setHeader('Authorization', auth);
|
|
21
|
+
this.apiKey = (apiKey) => this.setHeader('apiKey', apiKey);
|
|
22
|
+
this.setHeader = (key, value) => (0, types_1.on)(this, t => t.headers[key] = value);
|
|
23
|
+
this.setHeaderUnlessPresent = (key, value) => value ? this.setHeader(key, this.headers[key] ?? value) : this;
|
|
24
|
+
this.accept = (type) => this.setHeader('Accept', type.id);
|
|
32
25
|
this.bearer = (jwt) => {
|
|
33
26
|
return (0, types_1.isNotEmpty)(jwt) ? this.authorization(`Bearer ${jwt}`) : this;
|
|
34
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestOptions.js","sourceRoot":"","sources":["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IAAI;QACb,OAAO,IAAI,cAAc,CAAC,yBAAW,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,KAAK,IAAI;QACb,OAAO,IAAI,cAAc,CAAC,yBAAW,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,KAAK,MAAM;QACf,OAAO,IAAI,cAAc,CAAC,yBAAW,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,KAAK,IAAI;QACb,OAAO,IAAI,cAAc,CAAC,yBAAW,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,KAAK,GAAG;QACZ,OAAO,IAAI,cAAc,CAAC,yBAAW,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;CAoCF;AA/DD,wCA+DC;AAEM,MAAM,gBAAgB,GAAG,CAAC,CAAW,EAAuB,EAAE,CAAC,IAAA,iBAAS,EAAC,CAAC,CAAC,IAAI,CAAC,YAAY,cAAc,CAAC;AAArG,QAAA,gBAAgB,oBAAqF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Api, RouteOptions } from './Api';
|
|
2
|
+
import { FetchOptions, Gateway, Json, PageList, Uri } from '../types';
|
|
3
|
+
import { RequestOptions } from '../http';
|
|
4
|
+
export declare class ApiGateway extends Gateway<RouteOptions> {
|
|
5
|
+
readonly api: Api;
|
|
6
|
+
constructor(api?: Api);
|
|
7
|
+
get(uri: Uri, options?: RouteOptions): Promise<PageList<Json>>;
|
|
8
|
+
getOne(uri: Uri, options?: RouteOptions): Promise<Json | undefined>;
|
|
9
|
+
post(uri: Uri, item?: Json, options?: RouteOptions): Promise<Json>;
|
|
10
|
+
postSearch(uri: Uri, options?: RequestOptions | FetchOptions): Promise<PageList<Json>>;
|
|
11
|
+
patch(uri: Uri, item: Json, options?: RouteOptions): Promise<Json>;
|
|
12
|
+
put(uri: Uri, item: Json, options?: RouteOptions): Promise<Json>;
|
|
13
|
+
delete(uri: Uri, options?: RouteOptions): Promise<boolean>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiGateway = void 0;
|
|
4
|
+
const Api_1 = require("./Api");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const http_1 = require("../http");
|
|
7
|
+
class ApiGateway extends types_1.Gateway {
|
|
8
|
+
constructor(api = new Api_1.Api()) {
|
|
9
|
+
super();
|
|
10
|
+
this.api = api;
|
|
11
|
+
}
|
|
12
|
+
get(uri, options) {
|
|
13
|
+
return this.api.get(uri, options).then(r => (0, types_1.toPageList)(r.body.data?.items, (0, http_1.toPageOptions)(options) && {
|
|
14
|
+
total: r.body.data?.totalItems,
|
|
15
|
+
filters: r.body.data?.meta?.filters,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
getOne(uri, options) {
|
|
19
|
+
return this.get(uri, options).then(r => r.first());
|
|
20
|
+
}
|
|
21
|
+
post(uri, item, options) {
|
|
22
|
+
return this.api.post(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
23
|
+
}
|
|
24
|
+
postSearch(uri, options) {
|
|
25
|
+
return this.api.post(uri, options).then(r => (0, types_1.toPageList)(r.body.data?.items, (0, http_1.toPageOptions)(options) && {
|
|
26
|
+
total: r.body.data?.totalItems,
|
|
27
|
+
filters: r.body.data?.meta?.filters,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
patch(uri, item, options) {
|
|
31
|
+
return this.api.patch(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
32
|
+
}
|
|
33
|
+
put(uri, item, options) {
|
|
34
|
+
return this.api.put(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
35
|
+
}
|
|
36
|
+
delete(uri, options) {
|
|
37
|
+
return this.api.delete(uri, options).then(() => true);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.ApiGateway = ApiGateway;
|
|
41
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
import {
|
|
4
|
-
export declare class RouteGateway extends
|
|
2
|
+
import { Func, Id, Json, JsonValue, PageList, Uri } from '../types';
|
|
3
|
+
import { ApiGateway } from './ApiGateway';
|
|
4
|
+
export declare class RouteGateway extends ApiGateway {
|
|
5
5
|
readonly route: Func<Uri>;
|
|
6
6
|
readonly routeId: Func<Uri>;
|
|
7
7
|
readonly api: Api;
|
|
8
8
|
constructor(route: Func<Uri>, routeId: Func<Uri>, api?: Api);
|
|
9
|
-
get(uri: Uri, options?: RouteOptions): Promise<PageList<Json>>;
|
|
10
|
-
getOne(uri: Uri, options?: RouteOptions): Promise<Json | undefined>;
|
|
11
9
|
all(options?: RouteOptions): Promise<PageList<Json>>;
|
|
12
10
|
byId(id: Id, options?: RouteOptions): Promise<Json | undefined>;
|
|
13
11
|
search(q: JsonValue, options?: RouteOptions): Promise<PageList<Json>>;
|
|
@@ -17,9 +15,4 @@ export declare class RouteGateway extends Gateway<RouteOptions> {
|
|
|
17
15
|
update(item: Json, options?: RouteOptions): Promise<Json>;
|
|
18
16
|
upsert(item: Json, options?: RouteOptions): Promise<Json>;
|
|
19
17
|
remove(id: Id, options?: RouteOptions): Promise<boolean>;
|
|
20
|
-
post(uri: Uri, item?: Json, options?: RouteOptions): Promise<Json>;
|
|
21
|
-
postSearch(uri: Uri, options?: RequestOptions | FetchOptions): Promise<PageList<Json>>;
|
|
22
|
-
patch(uri: Uri, item: Json, options?: RouteOptions): Promise<Json>;
|
|
23
|
-
put(uri: Uri, item: Json, options?: RouteOptions): Promise<Json>;
|
|
24
|
-
delete(uri: Uri, options?: RouteOptions): Promise<boolean>;
|
|
25
18
|
}
|
|
@@ -2,24 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RouteGateway = void 0;
|
|
4
4
|
const Api_1 = require("./Api");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
5
|
const http_1 = require("../http");
|
|
7
|
-
|
|
6
|
+
const ApiGateway_1 = require("./ApiGateway");
|
|
7
|
+
class RouteGateway extends ApiGateway_1.ApiGateway {
|
|
8
8
|
constructor(route, routeId, api = new Api_1.Api()) {
|
|
9
|
-
super();
|
|
9
|
+
super(api);
|
|
10
10
|
this.route = route;
|
|
11
11
|
this.routeId = routeId;
|
|
12
12
|
this.api = api;
|
|
13
13
|
}
|
|
14
|
-
get(uri, options) {
|
|
15
|
-
return this.api.get(uri, options).then(r => (0, types_1.toPageList)(r.body.data?.items, (0, http_1.toPageOptions)(options) && {
|
|
16
|
-
total: r.body.data?.totalItems,
|
|
17
|
-
filters: r.body.data?.meta?.filters,
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
getOne(uri, options) {
|
|
21
|
-
return this.get(uri, options).then(r => r.first());
|
|
22
|
-
}
|
|
23
14
|
all(options) {
|
|
24
15
|
return this.get(this.route(), options);
|
|
25
16
|
}
|
|
@@ -49,24 +40,6 @@ class RouteGateway extends types_1.Gateway {
|
|
|
49
40
|
remove(id, options) {
|
|
50
41
|
return this.delete(this.routeId().id(id), options);
|
|
51
42
|
}
|
|
52
|
-
post(uri, item, options) {
|
|
53
|
-
return this.api.post(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
54
|
-
}
|
|
55
|
-
postSearch(uri, options) {
|
|
56
|
-
return this.api.post(uri, options).then(r => (0, types_1.toPageList)(r.body.data?.items, (0, http_1.toPageOptions)(options) && {
|
|
57
|
-
total: r.body.data?.totalItems,
|
|
58
|
-
filters: r.body.data?.meta?.filters,
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
patch(uri, item, options) {
|
|
62
|
-
return this.api.patch(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
63
|
-
}
|
|
64
|
-
put(uri, item, options) {
|
|
65
|
-
return this.api.put(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
66
|
-
}
|
|
67
|
-
delete(uri, options) {
|
|
68
|
-
return this.api.delete(uri, options).then(() => true);
|
|
69
|
-
}
|
|
70
43
|
}
|
|
71
44
|
exports.RouteGateway = RouteGateway;
|
|
72
45
|
//# sourceMappingURL=RouteGateway.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteGateway.js","sourceRoot":"","sources":["../../src/services/RouteGateway.ts"],"names":[],"mappings":";;;AAAA,+BAA0C;
|
|
1
|
+
{"version":3,"file":"RouteGateway.js","sourceRoot":"","sources":["../../src/services/RouteGateway.ts"],"names":[],"mappings":";;;AAAA,+BAA0C;AAE1C,kCAAqC;AACrC,6CAA0C;AAE1C,MAAa,YAAa,SAAQ,uBAAU;IAC1C,YAAqB,KAAgB,EAAW,OAAkB,EAAW,MAAW,IAAI,SAAG,EAAE;QAC/F,KAAK,CAAC,GAAG,CAAC,CAAC;QADQ,UAAK,GAAL,KAAK,CAAW;QAAW,YAAO,GAAP,OAAO,CAAW;QAAW,QAAG,GAAH,GAAG,CAAiB;IAEjG,CAAC;IAED,GAAG,CAAC,OAAsB;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,EAAM,EAAE,OAAsB;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,CAAY,EAAE,OAAsB;QACzC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,EAAM,EAAE,OAAsB;QACnC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;aACnC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;aACzB,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,iBAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpF,CAAC;IAED,GAAG,CAAC,IAAU,EAAE,OAAsB;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,OAAsB;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,IAAU,EAAE,OAAsB;QACvC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,CAAC,IAAU,EAAE,OAAsB;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,CAAC,EAAM,EAAE,OAAsB;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;CACF;AA1CD,oCA0CC"}
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Api"), exports);
|
|
18
|
+
__exportStar(require("./ApiGateway"), exports);
|
|
18
19
|
__exportStar(require("./AxiosProvider"), exports);
|
|
19
20
|
__exportStar(require("./MappedRouteGateway"), exports);
|
|
20
21
|
__exportStar(require("./RouteGateway"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,kDAAgC;AAChC,uDAAqC;AACrC,iDAA+B;AAC/B,qDAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,+CAA6B;AAC7B,kDAAgC;AAChC,uDAAqC;AACrC,iDAA+B;AAC/B,qDAAmC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.10.0",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@thisisagile/easy-test": "12.
|
|
34
|
+
"@thisisagile/easy-test": "12.10.0",
|
|
35
35
|
"@types/form-urlencoded": "^4.4.0",
|
|
36
36
|
"@types/jsonwebtoken": "^8.5.9",
|
|
37
37
|
"@types/luxon": "3.0.2",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ctx, Enum, isDefined, isNotEmpty, PageOptions, Text, toUuid } from '../types';
|
|
1
|
+
import { ctx, Enum, Id, isDefined, isNotEmpty, on, PageOptions, Text, toUuid } from '../types';
|
|
2
2
|
import { HttpHeader } from './HttpHeader';
|
|
3
3
|
import { ContentType } from './ContentType';
|
|
4
4
|
|
|
@@ -6,6 +6,14 @@ export const toPageOptions = (options?: RequestOptions | PageOptions): PageOptio
|
|
|
6
6
|
options instanceof RequestOptions ? options.pageOptions : options;
|
|
7
7
|
|
|
8
8
|
export class RequestOptions extends Enum {
|
|
9
|
+
public requestOptions: { maxRedirects?: number; validateStatus?: (status: number) => boolean } = {};
|
|
10
|
+
|
|
11
|
+
constructor(readonly type: ContentType = ContentType.Json, readonly headers: { [key: string]: any } = {}, public pageOptions?: PageOptions) {
|
|
12
|
+
super(type.name);
|
|
13
|
+
this.headers['Content-Type'] = type.id;
|
|
14
|
+
this.headers[HttpHeader.Correlation] = ctx.request.correlationId ?? toUuid();
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
static get Form(): RequestOptions {
|
|
10
18
|
return new RequestOptions(ContentType.Form);
|
|
11
19
|
}
|
|
@@ -26,33 +34,21 @@ export class RequestOptions extends Enum {
|
|
|
26
34
|
return new RequestOptions(ContentType.Xml);
|
|
27
35
|
}
|
|
28
36
|
|
|
29
|
-
public requestOptions: { maxRedirects?: number; validateStatus?: (status: number) => boolean } = {};
|
|
30
|
-
|
|
31
|
-
constructor(readonly type: ContentType = ContentType.Json, readonly headers: { [key: string]: any } = {}, public pageOptions?: PageOptions) {
|
|
32
|
-
super(type.name);
|
|
33
|
-
this.headers['Content-Type'] = type.id;
|
|
34
|
-
this.headers[HttpHeader.Correlation] = ctx.request.correlationId ?? toUuid();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
37
|
page = (options: PageOptions): this => {
|
|
38
38
|
this.pageOptions = options;
|
|
39
39
|
return this;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
authorization = (auth: string): this =>
|
|
43
|
-
this.headers.Authorization = auth;
|
|
44
|
-
return this;
|
|
45
|
-
};
|
|
42
|
+
authorization = (auth: string): this => this.setHeader('Authorization', auth);
|
|
46
43
|
|
|
47
|
-
apiKey = (apiKey: string): this =>
|
|
48
|
-
this.headers.apiKey = apiKey;
|
|
49
|
-
return this;
|
|
50
|
-
};
|
|
44
|
+
apiKey = (apiKey: string): this => this.setHeader('apiKey', apiKey);
|
|
51
45
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
setHeader = (key: string, value: Id | boolean): this => on(this, t => t.headers[key]= value)
|
|
47
|
+
|
|
48
|
+
setHeaderUnlessPresent = (key: string, value?: Id | boolean): this =>
|
|
49
|
+
value ? this.setHeader(key, this.headers[key] ?? value) : this;
|
|
50
|
+
|
|
51
|
+
accept = (type: ContentType): this => this.setHeader('Accept', type.id)
|
|
56
52
|
|
|
57
53
|
bearer = (jwt: Text): this => {
|
|
58
54
|
return isNotEmpty(jwt) ? this.authorization(`Bearer ${jwt}`) : this;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Api, RouteOptions } from './Api';
|
|
2
|
+
import { FetchOptions, Filter, Gateway, Json, PageList, toPageList, Uri } from '../types';
|
|
3
|
+
import { RequestOptions, toPageOptions } from '../http';
|
|
4
|
+
|
|
5
|
+
export class ApiGateway extends Gateway<RouteOptions> {
|
|
6
|
+
constructor(readonly api: Api = new Api()) {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get(uri: Uri, options?: RouteOptions): Promise<PageList<Json>> {
|
|
11
|
+
return this.api.get(uri, options).then(r =>
|
|
12
|
+
toPageList<Json>(
|
|
13
|
+
r.body.data?.items,
|
|
14
|
+
toPageOptions(options) && {
|
|
15
|
+
total: r.body.data?.totalItems,
|
|
16
|
+
filters: r.body.data?.meta?.filters as Filter[],
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getOne(uri: Uri, options?: RouteOptions): Promise<Json | undefined> {
|
|
23
|
+
return this.get(uri, options).then(r => r.first());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
post(uri: Uri, item?: Json, options?: RouteOptions): Promise<Json> {
|
|
27
|
+
return this.api.post(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
postSearch(uri: Uri, options?: RequestOptions | FetchOptions): Promise<PageList<Json>> {
|
|
31
|
+
return this.api.post(uri, options).then(r =>
|
|
32
|
+
toPageList<Json>(
|
|
33
|
+
r.body.data?.items,
|
|
34
|
+
toPageOptions(options) && {
|
|
35
|
+
total: r.body.data?.totalItems,
|
|
36
|
+
filters: r.body.data?.meta?.filters as Filter[],
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
patch(uri: Uri, item: Json, options?: RouteOptions): Promise<Json> {
|
|
43
|
+
return this.api.patch(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
put(uri: Uri, item: Json, options?: RouteOptions): Promise<Json> {
|
|
47
|
+
return this.api.put(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
delete(uri: Uri, options?: RouteOptions): Promise<boolean> {
|
|
51
|
+
return this.api.delete(uri, options).then(() => true);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import { Api, RouteOptions } from './Api';
|
|
2
|
-
import {
|
|
3
|
-
import { HttpStatus
|
|
2
|
+
import { Func, Id, Json, JsonValue, PageList, Uri } from '../types';
|
|
3
|
+
import { HttpStatus } from '../http';
|
|
4
|
+
import { ApiGateway } from './ApiGateway';
|
|
4
5
|
|
|
5
|
-
export class RouteGateway extends
|
|
6
|
+
export class RouteGateway extends ApiGateway {
|
|
6
7
|
constructor(readonly route: Func<Uri>, readonly routeId: Func<Uri>, readonly api: Api = new Api()) {
|
|
7
|
-
super();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get(uri: Uri, options?: RouteOptions): Promise<PageList<Json>> {
|
|
11
|
-
return this.api.get(uri, options).then(r =>
|
|
12
|
-
toPageList<Json>(
|
|
13
|
-
r.body.data?.items,
|
|
14
|
-
toPageOptions(options) && {
|
|
15
|
-
total: r.body.data?.totalItems,
|
|
16
|
-
filters: r.body.data?.meta?.filters as Filter[],
|
|
17
|
-
}
|
|
18
|
-
)
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getOne(uri: Uri, options?: RouteOptions): Promise<Json | undefined> {
|
|
23
|
-
return this.get(uri, options).then(r => r.first());
|
|
8
|
+
super(api);
|
|
24
9
|
}
|
|
25
10
|
|
|
26
11
|
all(options?: RouteOptions): Promise<PageList<Json>> {
|
|
@@ -60,32 +45,4 @@ export class RouteGateway extends Gateway<RouteOptions> {
|
|
|
60
45
|
remove(id: Id, options?: RouteOptions): Promise<boolean> {
|
|
61
46
|
return this.delete(this.routeId().id(id), options);
|
|
62
47
|
}
|
|
63
|
-
|
|
64
|
-
post(uri: Uri, item?: Json, options?: RouteOptions): Promise<Json> {
|
|
65
|
-
return this.api.post(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
postSearch(uri: Uri, options?: RequestOptions | FetchOptions): Promise<PageList<Json>> {
|
|
69
|
-
return this.api.post(uri, options).then(r =>
|
|
70
|
-
toPageList<Json>(
|
|
71
|
-
r.body.data?.items,
|
|
72
|
-
toPageOptions(options) && {
|
|
73
|
-
total: r.body.data?.totalItems,
|
|
74
|
-
filters: r.body.data?.meta?.filters as Filter[],
|
|
75
|
-
}
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
patch(uri: Uri, item: Json, options?: RouteOptions): Promise<Json> {
|
|
81
|
-
return this.api.patch(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
put(uri: Uri, item: Json, options?: RouteOptions): Promise<Json> {
|
|
85
|
-
return this.api.put(uri, item, options).then(r => r.body.data?.items.first() ?? {});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
delete(uri: Uri, options?: RouteOptions): Promise<boolean> {
|
|
89
|
-
return this.api.delete(uri, options).then(() => true);
|
|
90
|
-
}
|
|
91
48
|
}
|