UNPKG

@thisisagile/easy-service

Version:

Straightforward library for building domain-driven microservice architectures

23 lines (22 loc) 810 B
import "../chunk-4N72FQFX.mjs"; // src/security/Jwt.ts import { sign, verify } from "jsonwebtoken"; import { ctx, tryTo, Jwt as JwtBase } from "@thisisagile/easy"; var Jwt = class _Jwt extends JwtBase { static of = (a) => new _Jwt(a.jwt); get isValid() { return tryTo(() => ctx.env.get("tokenPublicKey") ?? "").map((key) => verify(this.value, key)).map(() => true).orElse() ?? false; } static sign = (token, options) => tryTo(() => ctx.env.get("tokenPrivateKey") ?? "").is.not.empty().map( (key) => sign(token, key, { ...options, expiresIn: ctx.env.get("tokenExpiresIn") ?? "1h", keyid: ctx.env.get("tokenKeyid") ?? "easy", algorithm: ctx.env.get("tokenAlgorithm", "RS256") }) ).map((s) => new _Jwt(s)).value; }; export { Jwt }; //# sourceMappingURL=Jwt.mjs.map