@thisisagile/easy-service 18.17.0 → 19.0.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/chunk-BTPC4SVP.mjs +1 -0
- package/dist/chunk-BTPC4SVP.mjs.map +1 -0
- package/dist/chunk-EJT7DQD6.mjs +22 -0
- package/dist/chunk-EJT7DQD6.mjs.map +1 -0
- package/dist/chunk-KHAYZJCB.mjs +29 -0
- package/dist/chunk-KHAYZJCB.mjs.map +1 -0
- package/dist/chunk-OQUQPJ6S.mjs +25 -0
- package/dist/chunk-OQUQPJ6S.mjs.map +1 -0
- package/dist/chunk-RJWBTUKZ.mjs +27 -0
- package/dist/chunk-RJWBTUKZ.mjs.map +1 -0
- package/dist/chunk-VXGHOHGY.mjs +1 -0
- package/dist/chunk-VXGHOHGY.mjs.map +1 -0
- package/dist/chunk-YB7NDS5U.mjs +20 -0
- package/dist/chunk-YB7NDS5U.mjs.map +1 -0
- package/dist/health/HealthResource.mjs +6 -23
- package/dist/health/HealthResource.mjs.map +1 -1
- package/dist/http/OriginatedError.mjs +5 -14
- package/dist/http/OriginatedError.mjs.map +1 -1
- package/dist/index.mjs +59 -10
- package/dist/index.mjs.map +1 -1
- package/dist/resources/AppProvider.mjs +1 -0
- package/dist/resources/Requires.mjs +4 -20
- package/dist/resources/Requires.mjs.map +1 -1
- package/dist/resources/Resource.mjs +1 -0
- package/dist/resources/Service.mjs +3 -23
- package/dist/resources/Service.mjs.map +1 -1
- package/dist/security/Jwt.mjs +3 -18
- package/dist/security/Jwt.mjs.map +1 -1
- package/package.json +54 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-BTPC4SVP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/security/Jwt.ts
|
|
2
|
+
import { sign, verify } from "jsonwebtoken";
|
|
3
|
+
import { ctx, tryTo, Jwt as JwtBase } from "@thisisagile/easy";
|
|
4
|
+
var Jwt = class _Jwt extends JwtBase {
|
|
5
|
+
static of = (a) => new _Jwt(a.jwt);
|
|
6
|
+
get isValid() {
|
|
7
|
+
return tryTo(() => ctx.env.get("tokenPublicKey") ?? "").map((key) => verify(this.value, key)).map(() => true).orElse() ?? false;
|
|
8
|
+
}
|
|
9
|
+
static sign = (token, options) => tryTo(() => ctx.env.get("tokenPrivateKey") ?? "").is.not.empty().map(
|
|
10
|
+
(key) => sign(token, key, {
|
|
11
|
+
...options,
|
|
12
|
+
expiresIn: ctx.env.get("tokenExpiresIn") ?? "1h",
|
|
13
|
+
keyid: ctx.env.get("tokenKeyid") ?? "easy",
|
|
14
|
+
algorithm: ctx.env.get("tokenAlgorithm", "RS256")
|
|
15
|
+
})
|
|
16
|
+
).map((s) => new _Jwt(s)).value;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
Jwt
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=chunk-EJT7DQD6.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":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
route
|
|
3
|
+
} from "./chunk-B37TXK4C.mjs";
|
|
4
|
+
import {
|
|
5
|
+
HealthUri
|
|
6
|
+
} from "./chunk-2XMYNSTI.mjs";
|
|
7
|
+
import {
|
|
8
|
+
get
|
|
9
|
+
} from "./chunk-W62PBGRF.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
|
+
|
|
26
|
+
export {
|
|
27
|
+
HealthResource
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=chunk-KHAYZJCB.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,25 @@
|
|
|
1
|
+
// src/resources/Requires.ts
|
|
2
|
+
import { meta } from "@thisisagile/easy";
|
|
3
|
+
var Requires = class {
|
|
4
|
+
labCoat = () => (subject, property) => {
|
|
5
|
+
meta(subject).property(property).set("labCoat", true);
|
|
6
|
+
};
|
|
7
|
+
token = () => (subject, property) => {
|
|
8
|
+
meta(subject).property(property).set("token", true);
|
|
9
|
+
};
|
|
10
|
+
scope = (scope) => (subject, property) => {
|
|
11
|
+
meta(subject).property(property).set("token", true);
|
|
12
|
+
meta(subject).property(property).set("scope", scope);
|
|
13
|
+
};
|
|
14
|
+
useCase = (uc) => (subject, property) => {
|
|
15
|
+
meta(subject).property(property).set("token", true);
|
|
16
|
+
meta(subject).property(property).set("uc", uc);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
var requires = new Requires();
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
Requires,
|
|
23
|
+
requires
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-OQUQPJ6S.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,27 @@
|
|
|
1
|
+
// src/resources/Service.ts
|
|
2
|
+
import { Enum, toList, tryTo } from "@thisisagile/easy";
|
|
3
|
+
var Service = class extends Enum {
|
|
4
|
+
constructor(name, app, resources = toList()) {
|
|
5
|
+
super(name);
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.app = app;
|
|
8
|
+
this.resources = resources;
|
|
9
|
+
}
|
|
10
|
+
port = 8080;
|
|
11
|
+
pre = () => [];
|
|
12
|
+
post = () => [];
|
|
13
|
+
with(...resources) {
|
|
14
|
+
return tryTo(this).accept((t) => t.resources.add(resources.map((r) => new r()))).value;
|
|
15
|
+
}
|
|
16
|
+
atPort(port) {
|
|
17
|
+
return tryTo(this).accept((t) => t.port = port).value;
|
|
18
|
+
}
|
|
19
|
+
start(message = `Service ${this.name} listening on port ${this.port} with ${this.resources.length} resources.`) {
|
|
20
|
+
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));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
Service
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-RJWBTUKZ.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 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-VXGHOHGY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/http/OriginatedError.ts
|
|
2
|
+
import { isError } from "@thisisagile/easy";
|
|
3
|
+
var OriginatedError = class extends Error {
|
|
4
|
+
constructor(origin, options) {
|
|
5
|
+
super();
|
|
6
|
+
this.origin = origin;
|
|
7
|
+
this.options = options;
|
|
8
|
+
if (isError(origin))
|
|
9
|
+
this.stack = origin.stack;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var isOriginatedError = (e) => isError(e) && e instanceof OriginatedError;
|
|
13
|
+
var toOriginatedError = (e, options) => isOriginatedError(e) ? e : new OriginatedError(e, options);
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
OriginatedError,
|
|
17
|
+
isOriginatedError,
|
|
18
|
+
toOriginatedError
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=chunk-YB7NDS5U.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":[]}
|
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
|
2
|
+
HealthResource
|
|
3
|
+
} from "../chunk-KHAYZJCB.mjs";
|
|
4
|
+
import "../chunk-B37TXK4C.mjs";
|
|
5
|
+
import "../chunk-2XMYNSTI.mjs";
|
|
6
|
+
import "../chunk-W62PBGRF.mjs";
|
|
7
|
+
import "../chunk-4N72FQFX.mjs";
|
|
25
8
|
export {
|
|
26
9
|
HealthResource
|
|
27
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OriginatedError,
|
|
3
|
+
isOriginatedError,
|
|
4
|
+
toOriginatedError
|
|
5
|
+
} from "../chunk-YB7NDS5U.mjs";
|
|
1
6
|
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
7
|
export {
|
|
17
8
|
OriginatedError,
|
|
18
9
|
isOriginatedError,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
Service
|
|
3
|
+
} from "./chunk-RJWBTUKZ.mjs";
|
|
4
|
+
import {
|
|
5
|
+
Jwt
|
|
6
|
+
} from "./chunk-EJT7DQD6.mjs";
|
|
7
|
+
import {
|
|
8
|
+
HealthResource
|
|
9
|
+
} from "./chunk-KHAYZJCB.mjs";
|
|
10
|
+
import {
|
|
11
|
+
route,
|
|
12
|
+
routes
|
|
13
|
+
} from "./chunk-B37TXK4C.mjs";
|
|
14
|
+
import {
|
|
15
|
+
HealthUri
|
|
16
|
+
} from "./chunk-2XMYNSTI.mjs";
|
|
17
|
+
import {
|
|
18
|
+
OriginatedError,
|
|
19
|
+
isOriginatedError,
|
|
20
|
+
toOriginatedError
|
|
21
|
+
} from "./chunk-YB7NDS5U.mjs";
|
|
22
|
+
import {
|
|
23
|
+
del,
|
|
24
|
+
get,
|
|
25
|
+
patch,
|
|
26
|
+
post,
|
|
27
|
+
put,
|
|
28
|
+
search,
|
|
29
|
+
stream,
|
|
30
|
+
toVerbOptions
|
|
31
|
+
} from "./chunk-W62PBGRF.mjs";
|
|
32
|
+
import "./chunk-VXGHOHGY.mjs";
|
|
33
|
+
import {
|
|
34
|
+
Requires,
|
|
35
|
+
requires
|
|
36
|
+
} from "./chunk-OQUQPJ6S.mjs";
|
|
37
|
+
import "./chunk-4N72FQFX.mjs";
|
|
38
|
+
import "./chunk-BTPC4SVP.mjs";
|
|
39
|
+
export {
|
|
40
|
+
HealthResource,
|
|
41
|
+
HealthUri,
|
|
42
|
+
Jwt,
|
|
43
|
+
OriginatedError,
|
|
44
|
+
Requires,
|
|
45
|
+
Service,
|
|
46
|
+
del,
|
|
47
|
+
get,
|
|
48
|
+
isOriginatedError,
|
|
49
|
+
patch,
|
|
50
|
+
post,
|
|
51
|
+
put,
|
|
52
|
+
requires,
|
|
53
|
+
route,
|
|
54
|
+
routes,
|
|
55
|
+
search,
|
|
56
|
+
stream,
|
|
57
|
+
toOriginatedError,
|
|
58
|
+
toVerbOptions
|
|
59
|
+
};
|
|
11
60
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Requires,
|
|
3
|
+
requires
|
|
4
|
+
} from "../chunk-OQUQPJ6S.mjs";
|
|
1
5
|
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
6
|
export {
|
|
23
7
|
Requires,
|
|
24
8
|
requires
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,27 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Service
|
|
3
|
+
} from "../chunk-RJWBTUKZ.mjs";
|
|
1
4
|
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
5
|
export {
|
|
26
6
|
Service
|
|
27
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/security/Jwt.mjs
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Jwt
|
|
3
|
+
} from "../chunk-EJT7DQD6.mjs";
|
|
1
4
|
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
5
|
export {
|
|
21
6
|
Jwt
|
|
22
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy-service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "19.0.0",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "yarn g:eslint . --ext .js,.jsx,.ts,.tsx --fix",
|
|
22
22
|
"format": "yarn g:prettier --check --write src test *.json",
|
|
23
|
-
"build": "yarn
|
|
24
|
-
"build:tsup": "yarn g:tsup
|
|
23
|
+
"build": "yarn build:tsup",
|
|
24
|
+
"build:tsup": "yarn g:tsup && yarn g:tsc --emitDeclarationOnly --declaration && node ../../scripts/check-exports.mjs",
|
|
25
25
|
"test": "yarn g:jest --coverage",
|
|
26
26
|
"prepack": "yarn g:copy-readme"
|
|
27
27
|
},
|
|
@@ -37,7 +37,57 @@
|
|
|
37
37
|
"@thisisagile/easy-test": "*"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@thisisagile/easy": "^
|
|
40
|
+
"@thisisagile/easy": "^19.0.0",
|
|
41
41
|
"jsonwebtoken": "^9.0.2"
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"import": "./dist/index.mjs",
|
|
47
|
+
"require": "./dist/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./health/HealthResource": {
|
|
50
|
+
"types": "./dist/health/HealthResource.d.ts",
|
|
51
|
+
"import": "./dist/health/HealthResource.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./health/HealthUri": {
|
|
54
|
+
"types": "./dist/health/HealthUri.d.ts",
|
|
55
|
+
"import": "./dist/health/HealthUri.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./http/OriginatedError": {
|
|
58
|
+
"types": "./dist/http/OriginatedError.d.ts",
|
|
59
|
+
"import": "./dist/http/OriginatedError.mjs"
|
|
60
|
+
},
|
|
61
|
+
"./http/Verb": {
|
|
62
|
+
"types": "./dist/http/Verb.d.ts",
|
|
63
|
+
"import": "./dist/http/Verb.mjs"
|
|
64
|
+
},
|
|
65
|
+
"./resources/AppProvider": {
|
|
66
|
+
"types": "./dist/resources/AppProvider.d.ts",
|
|
67
|
+
"import": "./dist/resources/AppProvider.mjs"
|
|
68
|
+
},
|
|
69
|
+
"./resources/Requires": {
|
|
70
|
+
"types": "./dist/resources/Requires.d.ts",
|
|
71
|
+
"import": "./dist/resources/Requires.mjs"
|
|
72
|
+
},
|
|
73
|
+
"./resources/Resource": {
|
|
74
|
+
"types": "./dist/resources/Resource.d.ts",
|
|
75
|
+
"import": "./dist/resources/Resource.mjs"
|
|
76
|
+
},
|
|
77
|
+
"./resources/Route": {
|
|
78
|
+
"types": "./dist/resources/Route.d.ts",
|
|
79
|
+
"import": "./dist/resources/Route.mjs"
|
|
80
|
+
},
|
|
81
|
+
"./resources/Service": {
|
|
82
|
+
"types": "./dist/resources/Service.d.ts",
|
|
83
|
+
"import": "./dist/resources/Service.mjs"
|
|
84
|
+
},
|
|
85
|
+
"./security/Jwt": {
|
|
86
|
+
"types": "./dist/security/Jwt.d.ts",
|
|
87
|
+
"import": "./dist/security/Jwt.mjs"
|
|
88
|
+
},
|
|
89
|
+
"./src/*": "./src/*",
|
|
90
|
+
"./dist/*": "./dist/*",
|
|
91
|
+
"./package.json": "./package.json"
|
|
42
92
|
}
|
|
43
93
|
}
|