@thisisagile/easy-service 17.26.1 → 17.26.2
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/chunk-2XMYNSTI.mjs +11 -0
- package/dist/chunk-2XMYNSTI.mjs.map +1 -0
- package/dist/chunk-4N72FQFX.mjs +16 -0
- package/dist/chunk-4N72FQFX.mjs.map +1 -0
- package/dist/chunk-B37TXK4C.mjs +40 -0
- package/dist/chunk-B37TXK4C.mjs.map +1 -0
- package/dist/chunk-W62PBGRF.mjs +31 -0
- package/dist/chunk-W62PBGRF.mjs.map +1 -0
- package/dist/health/HealthResource.mjs +28 -0
- package/dist/health/HealthResource.mjs.map +1 -0
- package/dist/health/HealthUri.mjs +8 -0
- package/dist/health/HealthUri.mjs.map +1 -0
- package/dist/http/OriginatedError.mjs +21 -0
- package/dist/http/OriginatedError.mjs.map +1 -0
- package/dist/http/Verb.mjs +22 -0
- package/dist/http/Verb.mjs.map +1 -0
- package/dist/index.mjs +10 -183
- package/dist/index.mjs.map +1 -1
- package/dist/resources/AppProvider.mjs +1 -0
- package/dist/resources/AppProvider.mjs.map +1 -0
- package/dist/resources/Requires.mjs +26 -0
- package/dist/resources/Requires.mjs.map +1 -0
- package/dist/resources/Resource.mjs +1 -0
- package/dist/resources/Resource.mjs.map +1 -0
- package/dist/resources/Route.mjs +10 -0
- package/dist/resources/Route.mjs.map +1 -0
- package/dist/resources/Service.mjs +28 -0
- package/dist/resources/Service.mjs.map +1 -0
- package/dist/security/Jwt.mjs +23 -0
- package/dist/security/Jwt.mjs.map +1 -0
- package/package.json +5 -14
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/health/HealthUri.ts
|
|
2
|
+
import { EasyUri, uri } from "@thisisagile/easy";
|
|
3
|
+
var HealthUri = class _HealthUri extends EasyUri {
|
|
4
|
+
static health = uri.segment("health");
|
|
5
|
+
static Health = new _HealthUri([_HealthUri.health]);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
HealthUri
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=chunk-2XMYNSTI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/health/HealthUri.ts"],"sourcesContent":["import { EasyUri, uri } from '@thisisagile/easy';\n\nexport class HealthUri extends EasyUri {\n static readonly health = uri.segment('health');\n static readonly Health = new HealthUri([HealthUri.health]);\n}\n"],"mappings":";AAAA,SAAS,SAAS,WAAW;AAEtB,IAAM,YAAN,MAAM,mBAAkB,QAAQ;AAAA,EACrC,OAAgB,SAAS,IAAI,QAAQ,QAAQ;AAAA,EAC7C,OAAgB,SAAS,IAAI,WAAU,CAAC,WAAU,MAAM,CAAC;AAC3D;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
__decorateClass
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chunk-4N72FQFX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/resources/Route.ts
|
|
2
|
+
import { meta, tryTo } from "@thisisagile/easy";
|
|
3
|
+
var route = (uri) => (subject) => {
|
|
4
|
+
meta(subject).set("route", uri);
|
|
5
|
+
};
|
|
6
|
+
var toRoute = (endpoint, requires, verb, middleware, name = "") => tryTo(verb).is.defined().map((verb2) => ({ verb: verb2, name, endpoint, requires, middleware: middleware ?? [] })).orElse();
|
|
7
|
+
var Router = class {
|
|
8
|
+
constructor(resource) {
|
|
9
|
+
this.resource = resource;
|
|
10
|
+
}
|
|
11
|
+
get route() {
|
|
12
|
+
return meta(this.resource).get("route");
|
|
13
|
+
}
|
|
14
|
+
get middleware() {
|
|
15
|
+
return meta(this.resource).get("middleware") ?? [];
|
|
16
|
+
}
|
|
17
|
+
get endpoints() {
|
|
18
|
+
return meta(this.resource).properties("verb").mapDefined(
|
|
19
|
+
(v) => toRoute(
|
|
20
|
+
this.resource[v.property],
|
|
21
|
+
{
|
|
22
|
+
labCoat: v.get("labCoat") ?? false,
|
|
23
|
+
token: v.get("token") ?? false,
|
|
24
|
+
scope: v.get("scope"),
|
|
25
|
+
uc: v.get("uc")
|
|
26
|
+
},
|
|
27
|
+
v.get("verb"),
|
|
28
|
+
v.get("middleware"),
|
|
29
|
+
v.property.toString()
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var routes = (resource) => new Router(resource);
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
route,
|
|
38
|
+
routes
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=chunk-B37TXK4C.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/resources/Route.ts"],"sourcesContent":["import { List, meta, Optional, tryTo, Uri, Scope, UseCase, Req } from '@thisisagile/easy';\nimport { Resource } from './Resource';\nimport { RequestHandler } from 'express';\nimport { Verb } from '../http/Verb';\n\nexport const route =\n (uri: Uri): ClassDecorator =>\n (subject: unknown): void => {\n meta(subject).set('route', uri);\n };\n\nexport type Endpoint<T = unknown> = (re: Req) => Promise<T | List<T>>;\nexport type RouteRequires = { token: boolean; labCoat: boolean; scope?: Scope; uc?: UseCase };\nexport type Route = { verb: Verb; name: string, endpoint: Endpoint; requires: RouteRequires; middleware: RequestHandler[] };\nexport type Routes = { route: Uri; middleware: RequestHandler[]; endpoints: List<Route> };\n\nconst toRoute = (endpoint: Endpoint, requires: RouteRequires, verb?: Verb, middleware?: RequestHandler[], name = ''): Optional<Route> =>\n tryTo(verb)\n .is.defined()\n .map(verb => ({ verb, name, endpoint, requires, middleware: middleware ?? [] }) as Route)\n .orElse();\n\nclass Router implements Routes {\n constructor(readonly resource: Resource) {}\n\n get route(): Uri {\n return meta(this.resource).get('route');\n }\n\n get middleware(): RequestHandler[] {\n return meta(this.resource).get<RequestHandler[]>('middleware') ?? [];\n }\n\n get endpoints(): List<Route> {\n return meta(this.resource)\n .properties('verb')\n .mapDefined(v =>\n toRoute(\n this.resource[v.property],\n {\n labCoat: v.get<boolean>('labCoat') ?? false,\n token: v.get<boolean>('token') ?? false,\n scope: v.get<Scope>('scope'),\n uc: v.get<UseCase>('uc'),\n },\n v.get<Verb>('verb'),\n v.get<RequestHandler[]>('middleware'),\n v.property.toString(),\n )\n );\n }\n}\n\nexport const routes = (resource: Resource): Routes => new Router(resource);\n"],"mappings":";AAAA,SAAe,MAAgB,aAAuC;AAK/D,IAAM,QACX,CAAC,QACD,CAAC,YAA2B;AAC1B,OAAK,OAAO,EAAE,IAAI,SAAS,GAAG;AAChC;AAOF,IAAM,UAAU,CAAC,UAAoB,UAAyB,MAAa,YAA+B,OAAO,OAC/G,MAAM,IAAI,EACP,GAAG,QAAQ,EACX,IAAI,CAAAA,WAAS,EAAE,MAAAA,OAAM,MAAM,UAAU,UAAU,YAAY,cAAc,CAAC,EAAE,EAAW,EACvF,OAAO;AAEZ,IAAM,SAAN,MAA+B;AAAA,EAC7B,YAAqB,UAAoB;AAApB;AAAA,EAAqB;AAAA,EAE1C,IAAI,QAAa;AACf,WAAO,KAAK,KAAK,QAAQ,EAAE,IAAI,OAAO;AAAA,EACxC;AAAA,EAEA,IAAI,aAA+B;AACjC,WAAO,KAAK,KAAK,QAAQ,EAAE,IAAsB,YAAY,KAAK,CAAC;AAAA,EACrE;AAAA,EAEA,IAAI,YAAyB;AAC3B,WAAO,KAAK,KAAK,QAAQ,EACtB,WAAW,MAAM,EACjB;AAAA,MAAW,OACV;AAAA,QACE,KAAK,SAAS,EAAE,QAAQ;AAAA,QACxB;AAAA,UACE,SAAS,EAAE,IAAa,SAAS,KAAK;AAAA,UACtC,OAAO,EAAE,IAAa,OAAO,KAAK;AAAA,UAClC,OAAO,EAAE,IAAW,OAAO;AAAA,UAC3B,IAAI,EAAE,IAAa,IAAI;AAAA,QACzB;AAAA,QACA,EAAE,IAAU,MAAM;AAAA,QAClB,EAAE,IAAsB,YAAY;AAAA,QACpC,EAAE,SAAS,SAAS;AAAA,MACtB;AAAA,IACF;AAAA,EACJ;AACF;AAEO,IAAM,SAAS,CAAC,aAA+B,IAAI,OAAO,QAAQ;","names":["verb"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/http/Verb.ts
|
|
2
|
+
import { meta, CacheControl, ContentType, HttpStatus, HttpVerb } from "@thisisagile/easy";
|
|
3
|
+
var toVerbOptions = (options) => ({
|
|
4
|
+
onOk: options?.onOk ?? HttpStatus.Ok,
|
|
5
|
+
onNotFound: options?.onNotFound ?? HttpStatus.NotFound,
|
|
6
|
+
onError: options?.onError ?? HttpStatus.BadRequest,
|
|
7
|
+
type: options?.type ?? ContentType.Json,
|
|
8
|
+
cache: options?.cache ?? CacheControl.disabled()
|
|
9
|
+
});
|
|
10
|
+
var toVerb = (verb, options) => (subject, property) => {
|
|
11
|
+
meta(subject).property(property).set("verb", { verb, options });
|
|
12
|
+
};
|
|
13
|
+
var get = (options) => toVerb(HttpVerb.Get, options);
|
|
14
|
+
var search = (options) => toVerb(HttpVerb.Get, { onNotFound: HttpStatus.Ok, ...options });
|
|
15
|
+
var put = (options) => toVerb(HttpVerb.Put, options);
|
|
16
|
+
var patch = (options) => toVerb(HttpVerb.Patch, options);
|
|
17
|
+
var post = (options) => toVerb(HttpVerb.Post, { onOk: HttpStatus.Created, ...options });
|
|
18
|
+
var del = (options) => toVerb(HttpVerb.Delete, { onOk: HttpStatus.NoContent, ...options });
|
|
19
|
+
var stream = (options) => toVerb(HttpVerb.Get, { type: ContentType.Stream, ...options });
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
toVerbOptions,
|
|
23
|
+
get,
|
|
24
|
+
search,
|
|
25
|
+
put,
|
|
26
|
+
patch,
|
|
27
|
+
post,
|
|
28
|
+
del,
|
|
29
|
+
stream
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=chunk-W62PBGRF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/http/Verb.ts"],"sourcesContent":["import { meta, CacheControl, ContentType, HttpStatus, HttpVerb } from '@thisisagile/easy';\n\nexport type VerbOptions = { onOk?: HttpStatus; onNotFound?: HttpStatus; onError?: HttpStatus; type?: ContentType; cache?: CacheControl };\nexport type Verb = { verb: HttpVerb; options: VerbOptions };\n\nexport const toVerbOptions = (options?: VerbOptions): Required<VerbOptions> => ({\n onOk: options?.onOk ?? HttpStatus.Ok,\n onNotFound: options?.onNotFound ?? HttpStatus.NotFound,\n onError: options?.onError ?? HttpStatus.BadRequest,\n type: options?.type ?? ContentType.Json,\n cache: options?.cache ?? CacheControl.disabled(),\n});\n\nconst toVerb =\n <T>(verb: HttpVerb, options?: VerbOptions): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('verb', { verb, options });\n };\n\nexport const get = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, options);\n\nexport const search = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, { onNotFound: HttpStatus.Ok, ...options });\n\nexport const put = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Put, options);\n\nexport const patch = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Patch, options);\n\nexport const post = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Post, { onOk: HttpStatus.Created, ...options });\n\nexport const del = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Delete, { onOk: HttpStatus.NoContent, ...options });\n\nexport const stream = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, { type: ContentType.Stream, ...options });\n"],"mappings":";AAAA,SAAS,MAAM,cAAc,aAAa,YAAY,gBAAgB;AAK/D,IAAM,gBAAgB,CAAC,aAAkD;AAAA,EAC9E,MAAM,SAAS,QAAQ,WAAW;AAAA,EAClC,YAAY,SAAS,cAAc,WAAW;AAAA,EAC9C,SAAS,SAAS,WAAW,WAAW;AAAA,EACxC,MAAM,SAAS,QAAQ,YAAY;AAAA,EACnC,OAAO,SAAS,SAAS,aAAa,SAAS;AACjD;AAEA,IAAM,SACJ,CAAI,MAAgB,YACpB,CAAC,SAAkB,aAAoC;AACrD,OAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAChE;AAEK,IAAM,MAAM,CAAC,YAA6C,OAAO,SAAS,KAAK,OAAO;AAEtF,IAAM,SAAS,CAAC,YAA6C,OAAO,SAAS,KAAK,EAAE,YAAY,WAAW,IAAI,GAAG,QAAQ,CAAC;AAE3H,IAAM,MAAM,CAAC,YAA6C,OAAO,SAAS,KAAK,OAAO;AAEtF,IAAM,QAAQ,CAAC,YAA6C,OAAO,SAAS,OAAO,OAAO;AAE1F,IAAM,OAAO,CAAC,YAA6C,OAAO,SAAS,MAAM,EAAE,MAAM,WAAW,SAAS,GAAG,QAAQ,CAAC;AAEzH,IAAM,MAAM,CAAC,YAA6C,OAAO,SAAS,QAAQ,EAAE,MAAM,WAAW,WAAW,GAAG,QAAQ,CAAC;AAE5H,IAAM,SAAS,CAAC,YAA6C,OAAO,SAAS,KAAK,EAAE,MAAM,YAAY,QAAQ,GAAG,QAAQ,CAAC;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HealthUri
|
|
3
|
+
} from "../chunk-2XMYNSTI.mjs";
|
|
4
|
+
import {
|
|
5
|
+
get
|
|
6
|
+
} from "../chunk-W62PBGRF.mjs";
|
|
7
|
+
import {
|
|
8
|
+
route
|
|
9
|
+
} from "../chunk-B37TXK4C.mjs";
|
|
10
|
+
import {
|
|
11
|
+
__decorateClass
|
|
12
|
+
} from "../chunk-4N72FQFX.mjs";
|
|
13
|
+
|
|
14
|
+
// src/health/HealthResource.ts
|
|
15
|
+
import { resolve } from "@thisisagile/easy";
|
|
16
|
+
var HealthResource = class {
|
|
17
|
+
ok = () => resolve({ state: "Service is healthy." });
|
|
18
|
+
};
|
|
19
|
+
__decorateClass([
|
|
20
|
+
get()
|
|
21
|
+
], HealthResource.prototype, "ok", 2);
|
|
22
|
+
HealthResource = __decorateClass([
|
|
23
|
+
route(HealthUri.Health)
|
|
24
|
+
], HealthResource);
|
|
25
|
+
export {
|
|
26
|
+
HealthResource
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=HealthResource.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/health/HealthResource.ts"],"sourcesContent":["import { resolve, Json } from '@thisisagile/easy';\nimport { HealthUri } from './HealthUri';\nimport { Resource } from '../resources/Resource';\nimport { route } from '../resources/Route';\nimport { get } from '../http/Verb';\n\n@route(HealthUri.Health)\nexport class HealthResource implements Resource {\n @get()\n ok = (): Promise<Json> => resolve({ state: 'Service is healthy.' });\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,eAAqB;AAOvB,IAAM,iBAAN,MAAyC;AAAA,EAE9C,KAAK,MAAqB,QAAQ,EAAE,OAAO,sBAAsB,CAAC;AACpE;AADE;AAAA,EADC,IAAI;AAAA,GADM,eAEX;AAFW,iBAAN;AAAA,EADN,MAAM,UAAU,MAAM;AAAA,GACV;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../chunk-4N72FQFX.mjs";
|
|
2
|
+
|
|
3
|
+
// src/http/OriginatedError.ts
|
|
4
|
+
import { isError } from "@thisisagile/easy";
|
|
5
|
+
var OriginatedError = class extends Error {
|
|
6
|
+
constructor(origin, options) {
|
|
7
|
+
super();
|
|
8
|
+
this.origin = origin;
|
|
9
|
+
this.options = options;
|
|
10
|
+
if (isError(origin))
|
|
11
|
+
this.stack = origin.stack;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var isOriginatedError = (e) => isError(e) && e instanceof OriginatedError;
|
|
15
|
+
var toOriginatedError = (e, options) => isOriginatedError(e) ? e : new OriginatedError(e, options);
|
|
16
|
+
export {
|
|
17
|
+
OriginatedError,
|
|
18
|
+
isOriginatedError,
|
|
19
|
+
toOriginatedError
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=OriginatedError.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/http/OriginatedError.ts"],"sourcesContent":["import { ErrorOrigin, isError } from '@thisisagile/easy';\nimport { VerbOptions } from './Verb';\n\nexport class OriginatedError extends Error {\n constructor(\n readonly origin: ErrorOrigin,\n readonly options?: VerbOptions\n ) {\n super();\n if (isError(origin)) this.stack = origin.stack;\n }\n}\n\nexport const isOriginatedError = (e?: unknown): e is OriginatedError => isError(e) && e instanceof OriginatedError;\n\nexport const toOriginatedError = (e: unknown, options?: VerbOptions): OriginatedError =>\n isOriginatedError(e) ? e : new OriginatedError(e as ErrorOrigin, options);\n"],"mappings":";;;AAAA,SAAsB,eAAe;AAG9B,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YACW,QACA,SACT;AACA,UAAM;AAHG;AACA;AAGT,QAAI,QAAQ,MAAM;AAAG,WAAK,QAAQ,OAAO;AAAA,EAC3C;AACF;AAEO,IAAM,oBAAoB,CAAC,MAAsC,QAAQ,CAAC,KAAK,aAAa;AAE5F,IAAM,oBAAoB,CAAC,GAAY,YAC5C,kBAAkB,CAAC,IAAI,IAAI,IAAI,gBAAgB,GAAkB,OAAO;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
del,
|
|
3
|
+
get,
|
|
4
|
+
patch,
|
|
5
|
+
post,
|
|
6
|
+
put,
|
|
7
|
+
search,
|
|
8
|
+
stream,
|
|
9
|
+
toVerbOptions
|
|
10
|
+
} from "../chunk-W62PBGRF.mjs";
|
|
11
|
+
import "../chunk-4N72FQFX.mjs";
|
|
12
|
+
export {
|
|
13
|
+
del,
|
|
14
|
+
get,
|
|
15
|
+
patch,
|
|
16
|
+
post,
|
|
17
|
+
put,
|
|
18
|
+
search,
|
|
19
|
+
stream,
|
|
20
|
+
toVerbOptions
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=Verb.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,184 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// src/health/HealthResource.ts
|
|
14
|
-
import { resolve } from "@thisisagile/easy";
|
|
15
|
-
|
|
16
|
-
// src/health/HealthUri.ts
|
|
17
|
-
import { EasyUri, uri } from "@thisisagile/easy";
|
|
18
|
-
var HealthUri = class _HealthUri extends EasyUri {
|
|
19
|
-
static health = uri.segment("health");
|
|
20
|
-
static Health = new _HealthUri([_HealthUri.health]);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// src/resources/Route.ts
|
|
24
|
-
import { meta, tryTo } from "@thisisagile/easy";
|
|
25
|
-
var route = (uri2) => (subject) => {
|
|
26
|
-
meta(subject).set("route", uri2);
|
|
27
|
-
};
|
|
28
|
-
var toRoute = (endpoint, requires2, verb, middleware, name = "") => tryTo(verb).is.defined().map((verb2) => ({ verb: verb2, name, endpoint, requires: requires2, middleware: middleware ?? [] })).orElse();
|
|
29
|
-
var Router = class {
|
|
30
|
-
constructor(resource) {
|
|
31
|
-
this.resource = resource;
|
|
32
|
-
}
|
|
33
|
-
get route() {
|
|
34
|
-
return meta(this.resource).get("route");
|
|
35
|
-
}
|
|
36
|
-
get middleware() {
|
|
37
|
-
return meta(this.resource).get("middleware") ?? [];
|
|
38
|
-
}
|
|
39
|
-
get endpoints() {
|
|
40
|
-
return meta(this.resource).properties("verb").mapDefined(
|
|
41
|
-
(v) => toRoute(
|
|
42
|
-
this.resource[v.property],
|
|
43
|
-
{
|
|
44
|
-
labCoat: v.get("labCoat") ?? false,
|
|
45
|
-
token: v.get("token") ?? false,
|
|
46
|
-
scope: v.get("scope"),
|
|
47
|
-
uc: v.get("uc")
|
|
48
|
-
},
|
|
49
|
-
v.get("verb"),
|
|
50
|
-
v.get("middleware"),
|
|
51
|
-
v.property.toString()
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
var routes = (resource) => new Router(resource);
|
|
57
|
-
|
|
58
|
-
// src/http/Verb.ts
|
|
59
|
-
import { meta as meta2, CacheControl, ContentType, HttpStatus, HttpVerb } from "@thisisagile/easy";
|
|
60
|
-
var toVerbOptions = (options) => ({
|
|
61
|
-
onOk: options?.onOk ?? HttpStatus.Ok,
|
|
62
|
-
onNotFound: options?.onNotFound ?? HttpStatus.NotFound,
|
|
63
|
-
onError: options?.onError ?? HttpStatus.BadRequest,
|
|
64
|
-
type: options?.type ?? ContentType.Json,
|
|
65
|
-
cache: options?.cache ?? CacheControl.disabled()
|
|
66
|
-
});
|
|
67
|
-
var toVerb = (verb, options) => (subject, property) => {
|
|
68
|
-
meta2(subject).property(property).set("verb", { verb, options });
|
|
69
|
-
};
|
|
70
|
-
var get = (options) => toVerb(HttpVerb.Get, options);
|
|
71
|
-
var search = (options) => toVerb(HttpVerb.Get, { onNotFound: HttpStatus.Ok, ...options });
|
|
72
|
-
var put = (options) => toVerb(HttpVerb.Put, options);
|
|
73
|
-
var patch = (options) => toVerb(HttpVerb.Patch, options);
|
|
74
|
-
var post = (options) => toVerb(HttpVerb.Post, { onOk: HttpStatus.Created, ...options });
|
|
75
|
-
var del = (options) => toVerb(HttpVerb.Delete, { onOk: HttpStatus.NoContent, ...options });
|
|
76
|
-
var stream = (options) => toVerb(HttpVerb.Get, { type: ContentType.Stream, ...options });
|
|
77
|
-
|
|
78
|
-
// src/health/HealthResource.ts
|
|
79
|
-
var HealthResource = class {
|
|
80
|
-
ok = () => resolve({ state: "Service is healthy." });
|
|
81
|
-
};
|
|
82
|
-
__decorateClass([
|
|
83
|
-
get()
|
|
84
|
-
], HealthResource.prototype, "ok", 2);
|
|
85
|
-
HealthResource = __decorateClass([
|
|
86
|
-
route(HealthUri.Health)
|
|
87
|
-
], HealthResource);
|
|
88
|
-
|
|
89
|
-
// src/http/OriginatedError.ts
|
|
90
|
-
import { isError } from "@thisisagile/easy";
|
|
91
|
-
var OriginatedError = class extends Error {
|
|
92
|
-
constructor(origin, options) {
|
|
93
|
-
super();
|
|
94
|
-
this.origin = origin;
|
|
95
|
-
this.options = options;
|
|
96
|
-
if (isError(origin))
|
|
97
|
-
this.stack = origin.stack;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
var isOriginatedError = (e) => isError(e) && e instanceof OriginatedError;
|
|
101
|
-
var toOriginatedError = (e, options) => isOriginatedError(e) ? e : new OriginatedError(e, options);
|
|
102
|
-
|
|
103
|
-
// src/resources/Requires.ts
|
|
104
|
-
import { meta as meta3 } from "@thisisagile/easy";
|
|
105
|
-
var Requires = class {
|
|
106
|
-
labCoat = () => (subject, property) => {
|
|
107
|
-
meta3(subject).property(property).set("labCoat", true);
|
|
108
|
-
};
|
|
109
|
-
token = () => (subject, property) => {
|
|
110
|
-
meta3(subject).property(property).set("token", true);
|
|
111
|
-
};
|
|
112
|
-
scope = (scope) => (subject, property) => {
|
|
113
|
-
meta3(subject).property(property).set("token", true);
|
|
114
|
-
meta3(subject).property(property).set("scope", scope);
|
|
115
|
-
};
|
|
116
|
-
useCase = (uc) => (subject, property) => {
|
|
117
|
-
meta3(subject).property(property).set("token", true);
|
|
118
|
-
meta3(subject).property(property).set("uc", uc);
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
var requires = new Requires();
|
|
122
|
-
|
|
123
|
-
// src/resources/Service.ts
|
|
124
|
-
import { Enum, toList, tryTo as tryTo2 } from "@thisisagile/easy";
|
|
125
|
-
var Service = class extends Enum {
|
|
126
|
-
constructor(name, app, resources = toList()) {
|
|
127
|
-
super(name);
|
|
128
|
-
this.name = name;
|
|
129
|
-
this.app = app;
|
|
130
|
-
this.resources = resources;
|
|
131
|
-
}
|
|
132
|
-
port = 8080;
|
|
133
|
-
pre = () => [];
|
|
134
|
-
post = () => [];
|
|
135
|
-
with(...resources) {
|
|
136
|
-
return tryTo2(this).accept((t) => t.resources.add(resources.map((r) => new r()))).value;
|
|
137
|
-
}
|
|
138
|
-
atPort(port) {
|
|
139
|
-
return tryTo2(this).accept((t) => t.port = port).value;
|
|
140
|
-
}
|
|
141
|
-
start(message = `Service ${this.name} listening on port ${this.port} with ${this.resources.length} resources.`) {
|
|
142
|
-
tryTo2(this).accept((t) => t.pre().forEach((h) => this.app.use(h))).accept((t) => t.resources.forEach((r) => this.app.route(this, r))).accept((t) => t.post().forEach((h) => this.app.use(h))).accept((t) => t.app.listen(this.port, message));
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// src/security/Jwt.ts
|
|
147
|
-
import { sign, verify } from "jsonwebtoken";
|
|
148
|
-
import { ctx, tryTo as tryTo3, Jwt as JwtBase } from "@thisisagile/easy";
|
|
149
|
-
var Jwt = class _Jwt extends JwtBase {
|
|
150
|
-
static of = (a) => new _Jwt(a.jwt);
|
|
151
|
-
get isValid() {
|
|
152
|
-
return tryTo3(() => ctx.env.get("tokenPublicKey") ?? "").map((key) => verify(this.value, key)).map(() => true).orElse() ?? false;
|
|
153
|
-
}
|
|
154
|
-
static sign = (token, options) => tryTo3(() => ctx.env.get("tokenPrivateKey") ?? "").is.not.empty().map(
|
|
155
|
-
(key) => sign(token, key, {
|
|
156
|
-
...options,
|
|
157
|
-
expiresIn: ctx.env.get("tokenExpiresIn") ?? "1h",
|
|
158
|
-
keyid: ctx.env.get("tokenKeyid") ?? "easy",
|
|
159
|
-
algorithm: ctx.env.get("tokenAlgorithm", "RS256")
|
|
160
|
-
})
|
|
161
|
-
).map((s) => new _Jwt(s)).value;
|
|
162
|
-
};
|
|
163
|
-
export {
|
|
164
|
-
HealthResource,
|
|
165
|
-
HealthUri,
|
|
166
|
-
Jwt,
|
|
167
|
-
OriginatedError,
|
|
168
|
-
Requires,
|
|
169
|
-
Service,
|
|
170
|
-
del,
|
|
171
|
-
get,
|
|
172
|
-
isOriginatedError,
|
|
173
|
-
patch,
|
|
174
|
-
post,
|
|
175
|
-
put,
|
|
176
|
-
requires,
|
|
177
|
-
route,
|
|
178
|
-
routes,
|
|
179
|
-
search,
|
|
180
|
-
stream,
|
|
181
|
-
toOriginatedError,
|
|
182
|
-
toVerbOptions
|
|
183
|
-
};
|
|
1
|
+
export * from "./health/HealthResource";
|
|
2
|
+
export * from "./health/HealthUri";
|
|
3
|
+
export * from "./http/OriginatedError";
|
|
4
|
+
export * from "./http/Verb";
|
|
5
|
+
export * from "./resources/AppProvider";
|
|
6
|
+
export * from "./resources/Requires";
|
|
7
|
+
export * from "./resources/Resource";
|
|
8
|
+
export * from "./resources/Route";
|
|
9
|
+
export * from "./resources/Service";
|
|
10
|
+
export * from "./security/Jwt";
|
|
184
11
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/health/HealthResource.ts","../src/health/HealthUri.ts","../src/resources/Route.ts","../src/http/Verb.ts","../src/http/OriginatedError.ts","../src/resources/Requires.ts","../src/resources/Service.ts","../src/security/Jwt.ts"],"sourcesContent":["import { resolve, Json } from '@thisisagile/easy';\nimport { HealthUri } from './HealthUri';\nimport { Resource } from '../resources/Resource';\nimport { route } from '../resources/Route';\nimport { get } from '../http/Verb';\n\n@route(HealthUri.Health)\nexport class HealthResource implements Resource {\n @get()\n ok = (): Promise<Json> => resolve({ state: 'Service is healthy.' });\n}\n","import { EasyUri, uri } from '@thisisagile/easy';\n\nexport class HealthUri extends EasyUri {\n static readonly health = uri.segment('health');\n static readonly Health = new HealthUri([HealthUri.health]);\n}\n","import { List, meta, Optional, tryTo, Uri, Scope, UseCase, Req } from '@thisisagile/easy';\nimport { Resource } from './Resource';\nimport { RequestHandler } from 'express';\nimport { Verb } from '../http/Verb';\n\nexport const route =\n (uri: Uri): ClassDecorator =>\n (subject: unknown): void => {\n meta(subject).set('route', uri);\n };\n\nexport type Endpoint<T = unknown> = (re: Req) => Promise<T | List<T>>;\nexport type RouteRequires = { token: boolean; labCoat: boolean; scope?: Scope; uc?: UseCase };\nexport type Route = { verb: Verb; name: string, endpoint: Endpoint; requires: RouteRequires; middleware: RequestHandler[] };\nexport type Routes = { route: Uri; middleware: RequestHandler[]; endpoints: List<Route> };\n\nconst toRoute = (endpoint: Endpoint, requires: RouteRequires, verb?: Verb, middleware?: RequestHandler[], name = ''): Optional<Route> =>\n tryTo(verb)\n .is.defined()\n .map(verb => ({ verb, name, endpoint, requires, middleware: middleware ?? [] }) as Route)\n .orElse();\n\nclass Router implements Routes {\n constructor(readonly resource: Resource) {}\n\n get route(): Uri {\n return meta(this.resource).get('route');\n }\n\n get middleware(): RequestHandler[] {\n return meta(this.resource).get<RequestHandler[]>('middleware') ?? [];\n }\n\n get endpoints(): List<Route> {\n return meta(this.resource)\n .properties('verb')\n .mapDefined(v =>\n toRoute(\n this.resource[v.property],\n {\n labCoat: v.get<boolean>('labCoat') ?? false,\n token: v.get<boolean>('token') ?? false,\n scope: v.get<Scope>('scope'),\n uc: v.get<UseCase>('uc'),\n },\n v.get<Verb>('verb'),\n v.get<RequestHandler[]>('middleware'),\n v.property.toString(),\n )\n );\n }\n}\n\nexport const routes = (resource: Resource): Routes => new Router(resource);\n","import { meta, CacheControl, ContentType, HttpStatus, HttpVerb } from '@thisisagile/easy';\n\nexport type VerbOptions = { onOk?: HttpStatus; onNotFound?: HttpStatus; onError?: HttpStatus; type?: ContentType; cache?: CacheControl };\nexport type Verb = { verb: HttpVerb; options: VerbOptions };\n\nexport const toVerbOptions = (options?: VerbOptions): Required<VerbOptions> => ({\n onOk: options?.onOk ?? HttpStatus.Ok,\n onNotFound: options?.onNotFound ?? HttpStatus.NotFound,\n onError: options?.onError ?? HttpStatus.BadRequest,\n type: options?.type ?? ContentType.Json,\n cache: options?.cache ?? CacheControl.disabled(),\n});\n\nconst toVerb =\n <T>(verb: HttpVerb, options?: VerbOptions): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('verb', { verb, options });\n };\n\nexport const get = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, options);\n\nexport const search = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, { onNotFound: HttpStatus.Ok, ...options });\n\nexport const put = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Put, options);\n\nexport const patch = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Patch, options);\n\nexport const post = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Post, { onOk: HttpStatus.Created, ...options });\n\nexport const del = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Delete, { onOk: HttpStatus.NoContent, ...options });\n\nexport const stream = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, { type: ContentType.Stream, ...options });\n","import { ErrorOrigin, isError } from '@thisisagile/easy';\nimport { VerbOptions } from './Verb';\n\nexport class OriginatedError extends Error {\n constructor(\n readonly origin: ErrorOrigin,\n readonly options?: VerbOptions\n ) {\n super();\n if (isError(origin)) this.stack = origin.stack;\n }\n}\n\nexport const isOriginatedError = (e?: unknown): e is OriginatedError => isError(e) && e instanceof OriginatedError;\n\nexport const toOriginatedError = (e: unknown, options?: VerbOptions): OriginatedError =>\n isOriginatedError(e) ? e : new OriginatedError(e as ErrorOrigin, options);\n","import { meta } from '@thisisagile/easy';\nimport { Scope, UseCase } from '@thisisagile/easy';\n\nexport class Requires {\n readonly labCoat =\n (): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('labCoat', true);\n };\n\n readonly token =\n (): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n };\n\n readonly scope =\n (scope: Scope): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n meta(subject).property(property).set('scope', scope);\n };\n\n readonly useCase =\n (uc: UseCase): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n meta(subject).property(property).set('uc', uc);\n };\n}\n\nexport const requires = new Requires();\n","import { AppProvider, Handler } from './AppProvider';\nimport { Constructor, Enum, List, toList, tryTo } from '@thisisagile/easy';\nimport { Resource } from './Resource';\n\nexport class Service extends Enum {\n protected port = 8080;\n\n constructor(\n readonly name: string,\n protected app: AppProvider,\n protected resources: List<Resource> = toList()\n ) {\n super(name);\n }\n\n pre = (): Handler[] => [];\n post = (): Handler[] => [];\n\n with(...resources: Constructor<Resource>[]): this {\n return tryTo(this).accept(t => t.resources.add(resources.map(r => new r()))).value;\n }\n\n atPort(port: number): this {\n return tryTo(this).accept(t => (t.port = port)).value;\n }\n\n start(message = `Service ${this.name} listening on port ${this.port} with ${this.resources.length} resources.`): void {\n tryTo(this)\n .accept(t => t.pre().forEach(h => this.app.use(h)))\n .accept(t => t.resources.forEach(r => this.app.route(this, r)))\n .accept(t => t.post().forEach(h => this.app.use(h)))\n .accept(t => t.app.listen(this.port, message));\n }\n}\n","import { Algorithm, sign, verify } from 'jsonwebtoken';\nimport { ctx, Json, OneOrMore, Optional, tryTo, Validatable, Jwt as JwtBase } from '@thisisagile/easy';\n\ninterface SignOptions {\n audience?: Optional<OneOrMore<string>>;\n issuer?: Optional<string>;\n}\nexport class Jwt extends JwtBase implements Validatable {\n static of = (a: { jwt: string }): Jwt => new Jwt(a.jwt);\n\n get isValid(): boolean {\n return (\n tryTo(() => ctx.env.get('tokenPublicKey') ?? '')\n .map(key => verify(this.value, key))\n .map(() => true)\n .orElse() ?? false\n );\n }\n\n static sign = (token: Json, options?: SignOptions): Jwt =>\n tryTo(() => ctx.env.get('tokenPrivateKey') ?? '')\n .is.not.empty()\n .map(key =>\n sign(token, key, {\n ...options,\n expiresIn: ctx.env.get('tokenExpiresIn') as any ?? '1h',\n keyid: ctx.env.get('tokenKeyid') ?? 'easy',\n algorithm: ctx.env.get('tokenAlgorithm', 'RS256') as Algorithm,\n })\n )\n .map(s => new Jwt(s)).value;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,eAAqB;;;ACA9B,SAAS,SAAS,WAAW;AAEtB,IAAM,YAAN,MAAM,mBAAkB,QAAQ;AAAA,EACrC,OAAgB,SAAS,IAAI,QAAQ,QAAQ;AAAA,EAC7C,OAAgB,SAAS,IAAI,WAAU,CAAC,WAAU,MAAM,CAAC;AAC3D;;;ACLA,SAAe,MAAgB,aAAuC;AAK/D,IAAM,QACX,CAACA,SACD,CAAC,YAA2B;AAC1B,OAAK,OAAO,EAAE,IAAI,SAASA,IAAG;AAChC;AAOF,IAAM,UAAU,CAAC,UAAoBC,WAAyB,MAAa,YAA+B,OAAO,OAC/G,MAAM,IAAI,EACP,GAAG,QAAQ,EACX,IAAI,CAAAC,WAAS,EAAE,MAAAA,OAAM,MAAM,UAAU,UAAAD,WAAU,YAAY,cAAc,CAAC,EAAE,EAAW,EACvF,OAAO;AAEZ,IA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jD,OAAO,OAAK,EAAE,UAAU,QAAQ,OAAK,KAAK,IAAI,MAAM,MAAM,CAAC,CAAC,CAAC,EAC7D,OAAO,OAAK,EAAE,KAAK,EAAE,QAAQ,OAAK,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAClD,OAAO,OAAK,EAAE,IAAI,OAAO,KAAK,MAAM,OAAO,CAAC;AAAA,EACjD;AACF;;;ACjCA,SAAoB,MAAM,cAAc;AACxC,SAAS,KAAgC,SAAAC,QAAoB,OAAO,eAAe;AAM5E,IAAM,MAAN,MAAM,aAAY,QAA+B;AAAA,EACtD,OAAO,KAAK,CAAC,MAA4B,IAAI,KAAI,EAAE,GAAG;AAAA,EAEtD,IAAI,UAAmB;AACrB,WACEA,OAAM,MAAM,IAAI,IAAI,IAAI,gBAAgB,KAAK,EAAE,EAC5C,IAAI,SAAO,OAAO,KAAK,OAAO,GAAG,CAAC,EAClC,IAAI,MAAM,IAAI,EACd,OAAO,KAAK;AAAA,EAEnB;AAAA,EAEA,OAAO,OAAO,CAAC,OAAa,YAC1BA,OAAM,MAAM,IAAI,IAAI,IAAI,iBAAiB,KAAK,EAAE,EAC7C,GAAG,IAAI,MAAM,EACb;AAAA,IAAI,SACH,KAAK,OAAO,KAAK;AAAA,MACf,GAAG;AAAA,MACH,WAAW,IAAI,IAAI,IAAI,gBAAgB,KAAY;AAAA,MACnD,OAAO,IAAI,IAAI,IAAI,YAAY,KAAK;AAAA,MACpC,WAAW,IAAI,IAAI,IAAI,kBAAkB,OAAO;AAAA,IAClD,CAAC;AAAA,EACH,EACC,IAAI,OAAK,IAAI,KAAI,CAAC,CAAC,EAAE;AAC5B;","names":["uri","requires","verb","meta","meta","tryTo","tryTo"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './health/HealthResource';\nexport * from './health/HealthUri';\nexport * from './http/OriginatedError';\nexport * from './http/Verb';\nexport * from './resources/AppProvider';\nexport * from './resources/Requires';\nexport * from './resources/Resource';\nexport * from './resources/Route';\nexport * from './resources/Service';\nexport * from './security/Jwt';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=AppProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "../chunk-4N72FQFX.mjs";
|
|
2
|
+
|
|
3
|
+
// src/resources/Requires.ts
|
|
4
|
+
import { meta } from "@thisisagile/easy";
|
|
5
|
+
var Requires = class {
|
|
6
|
+
labCoat = () => (subject, property) => {
|
|
7
|
+
meta(subject).property(property).set("labCoat", true);
|
|
8
|
+
};
|
|
9
|
+
token = () => (subject, property) => {
|
|
10
|
+
meta(subject).property(property).set("token", true);
|
|
11
|
+
};
|
|
12
|
+
scope = (scope) => (subject, property) => {
|
|
13
|
+
meta(subject).property(property).set("token", true);
|
|
14
|
+
meta(subject).property(property).set("scope", scope);
|
|
15
|
+
};
|
|
16
|
+
useCase = (uc) => (subject, property) => {
|
|
17
|
+
meta(subject).property(property).set("token", true);
|
|
18
|
+
meta(subject).property(property).set("uc", uc);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var requires = new Requires();
|
|
22
|
+
export {
|
|
23
|
+
Requires,
|
|
24
|
+
requires
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=Requires.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/Requires.ts"],"sourcesContent":["import { meta } from '@thisisagile/easy';\nimport { Scope, UseCase } from '@thisisagile/easy';\n\nexport class Requires {\n readonly labCoat =\n (): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('labCoat', true);\n };\n\n readonly token =\n (): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n };\n\n readonly scope =\n (scope: Scope): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n meta(subject).property(property).set('scope', scope);\n };\n\n readonly useCase =\n (uc: UseCase): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n meta(subject).property(property).set('uc', uc);\n };\n}\n\nexport const requires = new Requires();\n"],"mappings":";;;AAAA,SAAS,YAAY;AAGd,IAAM,WAAN,MAAe;AAAA,EACX,UACP,MACA,CAAC,SAAkB,aAAoC;AACrD,SAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAI,WAAW,IAAI;AAAA,EACtD;AAAA,EAEO,QACP,MACA,CAAC,SAAkB,aAAoC;AACrD,SAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAI,SAAS,IAAI;AAAA,EACpD;AAAA,EAEO,QACP,CAAC,UACD,CAAC,SAAkB,aAAoC;AACrD,SAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAI,SAAS,IAAI;AAClD,SAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAI,SAAS,KAAK;AAAA,EACrD;AAAA,EAEO,UACP,CAAC,OACD,CAAC,SAAkB,aAAoC;AACrD,SAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAI,SAAS,IAAI;AAClD,SAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAI,MAAM,EAAE;AAAA,EAC/C;AACJ;AAEO,IAAM,WAAW,IAAI,SAAS;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=Resource.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "../chunk-4N72FQFX.mjs";
|
|
2
|
+
|
|
3
|
+
// src/resources/Service.ts
|
|
4
|
+
import { Enum, toList, tryTo } from "@thisisagile/easy";
|
|
5
|
+
var Service = class extends Enum {
|
|
6
|
+
constructor(name, app, resources = toList()) {
|
|
7
|
+
super(name);
|
|
8
|
+
this.name = name;
|
|
9
|
+
this.app = app;
|
|
10
|
+
this.resources = resources;
|
|
11
|
+
}
|
|
12
|
+
port = 8080;
|
|
13
|
+
pre = () => [];
|
|
14
|
+
post = () => [];
|
|
15
|
+
with(...resources) {
|
|
16
|
+
return tryTo(this).accept((t) => t.resources.add(resources.map((r) => new r()))).value;
|
|
17
|
+
}
|
|
18
|
+
atPort(port) {
|
|
19
|
+
return tryTo(this).accept((t) => t.port = port).value;
|
|
20
|
+
}
|
|
21
|
+
start(message = `Service ${this.name} listening on port ${this.port} with ${this.resources.length} resources.`) {
|
|
22
|
+
tryTo(this).accept((t) => t.pre().forEach((h) => this.app.use(h))).accept((t) => t.resources.forEach((r) => this.app.route(this, r))).accept((t) => t.post().forEach((h) => this.app.use(h))).accept((t) => t.app.listen(this.port, message));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
Service
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=Service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/Service.ts"],"sourcesContent":["import { AppProvider, Handler } from './AppProvider';\nimport { Constructor, Enum, List, toList, tryTo } from '@thisisagile/easy';\nimport { Resource } from './Resource';\n\nexport class Service extends Enum {\n protected port = 8080;\n\n constructor(\n readonly name: string,\n protected app: AppProvider,\n protected resources: List<Resource> = toList()\n ) {\n super(name);\n }\n\n pre = (): Handler[] => [];\n post = (): Handler[] => [];\n\n with(...resources: Constructor<Resource>[]): this {\n return tryTo(this).accept(t => t.resources.add(resources.map(r => new r()))).value;\n }\n\n atPort(port: number): this {\n return tryTo(this).accept(t => (t.port = port)).value;\n }\n\n start(message = `Service ${this.name} listening on port ${this.port} with ${this.resources.length} resources.`): void {\n tryTo(this)\n .accept(t => t.pre().forEach(h => this.app.use(h)))\n .accept(t => t.resources.forEach(r => this.app.route(this, r)))\n .accept(t => t.post().forEach(h => this.app.use(h)))\n .accept(t => t.app.listen(this.port, message));\n }\n}\n"],"mappings":";;;AACA,SAAsB,MAAY,QAAQ,aAAa;AAGhD,IAAM,UAAN,cAAsB,KAAK;AAAA,EAGhC,YACW,MACC,KACA,YAA4B,OAAO,GAC7C;AACA,UAAM,IAAI;AAJD;AACC;AACA;AAAA,EAGZ;AAAA,EARU,OAAO;AAAA,EAUjB,MAAM,MAAiB,CAAC;AAAA,EACxB,OAAO,MAAiB,CAAC;AAAA,EAEzB,QAAQ,WAA0C;AAChD,WAAO,MAAM,IAAI,EAAE,OAAO,OAAK,EAAE,UAAU,IAAI,UAAU,IAAI,OAAK,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;AAAA,EAC/E;AAAA,EAEA,OAAO,MAAoB;AACzB,WAAO,MAAM,IAAI,EAAE,OAAO,OAAM,EAAE,OAAO,IAAK,EAAE;AAAA,EAClD;AAAA,EAEA,MAAM,UAAU,WAAW,KAAK,IAAI,sBAAsB,KAAK,IAAI,SAAS,KAAK,UAAU,MAAM,eAAqB;AACpH,UAAM,IAAI,EACP,OAAO,OAAK,EAAE,IAAI,EAAE,QAAQ,OAAK,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EACjD,OAAO,OAAK,EAAE,UAAU,QAAQ,OAAK,KAAK,IAAI,MAAM,MAAM,CAAC,CAAC,CAAC,EAC7D,OAAO,OAAK,EAAE,KAAK,EAAE,QAAQ,OAAK,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAClD,OAAO,OAAK,EAAE,IAAI,OAAO,KAAK,MAAM,OAAO,CAAC;AAAA,EACjD;AACF;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "../chunk-4N72FQFX.mjs";
|
|
2
|
+
|
|
3
|
+
// src/security/Jwt.ts
|
|
4
|
+
import { sign, verify } from "jsonwebtoken";
|
|
5
|
+
import { ctx, tryTo, Jwt as JwtBase } from "@thisisagile/easy";
|
|
6
|
+
var Jwt = class _Jwt extends JwtBase {
|
|
7
|
+
static of = (a) => new _Jwt(a.jwt);
|
|
8
|
+
get isValid() {
|
|
9
|
+
return tryTo(() => ctx.env.get("tokenPublicKey") ?? "").map((key) => verify(this.value, key)).map(() => true).orElse() ?? false;
|
|
10
|
+
}
|
|
11
|
+
static sign = (token, options) => tryTo(() => ctx.env.get("tokenPrivateKey") ?? "").is.not.empty().map(
|
|
12
|
+
(key) => sign(token, key, {
|
|
13
|
+
...options,
|
|
14
|
+
expiresIn: ctx.env.get("tokenExpiresIn") ?? "1h",
|
|
15
|
+
keyid: ctx.env.get("tokenKeyid") ?? "easy",
|
|
16
|
+
algorithm: ctx.env.get("tokenAlgorithm", "RS256")
|
|
17
|
+
})
|
|
18
|
+
).map((s) => new _Jwt(s)).value;
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
Jwt
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=Jwt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/security/Jwt.ts"],"sourcesContent":["import { Algorithm, sign, verify } from 'jsonwebtoken';\nimport { ctx, Json, OneOrMore, Optional, tryTo, Validatable, Jwt as JwtBase } from '@thisisagile/easy';\n\ninterface SignOptions {\n audience?: Optional<OneOrMore<string>>;\n issuer?: Optional<string>;\n}\nexport class Jwt extends JwtBase implements Validatable {\n static of = (a: { jwt: string }): Jwt => new Jwt(a.jwt);\n\n get isValid(): boolean {\n return (\n tryTo(() => ctx.env.get('tokenPublicKey') ?? '')\n .map(key => verify(this.value, key))\n .map(() => true)\n .orElse() ?? false\n );\n }\n\n static sign = (token: Json, options?: SignOptions): Jwt =>\n tryTo(() => ctx.env.get('tokenPrivateKey') ?? '')\n .is.not.empty()\n .map(key =>\n sign(token, key, {\n ...options,\n expiresIn: ctx.env.get('tokenExpiresIn') as any ?? '1h',\n keyid: ctx.env.get('tokenKeyid') ?? 'easy',\n algorithm: ctx.env.get('tokenAlgorithm', 'RS256') as Algorithm,\n })\n )\n .map(s => new Jwt(s)).value;\n}\n"],"mappings":";;;AAAA,SAAoB,MAAM,cAAc;AACxC,SAAS,KAAgC,OAAoB,OAAO,eAAe;AAM5E,IAAM,MAAN,MAAM,aAAY,QAA+B;AAAA,EACtD,OAAO,KAAK,CAAC,MAA4B,IAAI,KAAI,EAAE,GAAG;AAAA,EAEtD,IAAI,UAAmB;AACrB,WACE,MAAM,MAAM,IAAI,IAAI,IAAI,gBAAgB,KAAK,EAAE,EAC5C,IAAI,SAAO,OAAO,KAAK,OAAO,GAAG,CAAC,EAClC,IAAI,MAAM,IAAI,EACd,OAAO,KAAK;AAAA,EAEnB;AAAA,EAEA,OAAO,OAAO,CAAC,OAAa,YAC1B,MAAM,MAAM,IAAI,IAAI,IAAI,iBAAiB,KAAK,EAAE,EAC7C,GAAG,IAAI,MAAM,EACb;AAAA,IAAI,SACH,KAAK,OAAO,KAAK;AAAA,MACf,GAAG;AAAA,MACH,WAAW,IAAI,IAAI,IAAI,gBAAgB,KAAY;AAAA,MACnD,OAAO,IAAI,IAAI,IAAI,YAAY,KAAK;AAAA,MACpC,WAAW,IAAI,IAAI,IAAI,kBAAkB,OAAO;AAAA,IAClD,CAAC;AAAA,EACH,EACC,IAAI,OAAK,IAAI,KAAI,CAAC,CAAC,EAAE;AAC5B;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy-service",
|
|
3
|
-
"version": "17.26.
|
|
3
|
+
"version": "17.26.2",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "
|
|
8
|
-
"module": "
|
|
9
|
-
"types": "
|
|
10
|
-
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"node": "./dist/index.js",
|
|
14
|
-
"import": "./dist/index.mjs",
|
|
15
|
-
"require": "./dist/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./package.json": "./package.json"
|
|
18
|
-
},
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
19
10
|
"repository": {
|
|
20
11
|
"type": "git",
|
|
21
12
|
"url": "git@github.com:thisisagile/easy.git"
|
|
@@ -46,7 +37,7 @@
|
|
|
46
37
|
"@thisisagile/easy-test": "*"
|
|
47
38
|
},
|
|
48
39
|
"dependencies": {
|
|
49
|
-
"@thisisagile/easy": "^17.26.
|
|
40
|
+
"@thisisagile/easy": "^17.26.2",
|
|
50
41
|
"jsonwebtoken": "^9.0.2"
|
|
51
42
|
}
|
|
52
43
|
}
|