produce.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ProduceJWT = void 0;
  4. const epoch_js_1 = require("../lib/epoch.js");
  5. const is_object_js_1 = require("../lib/is_object.js");
  6. const secs_js_1 = require("../lib/secs.js");
  7. class ProduceJWT {
  8. constructor(payload) {
  9. if (!(0, is_object_js_1.default)(payload)) {
  10. throw new TypeError('JWT Claims Set MUST be an object');
  11. }
  12. this._payload = payload;
  13. }
  14. setIssuer(issuer) {
  15. this._payload = { ...this._payload, iss: issuer };
  16. return this;
  17. }
  18. setSubject(subject) {
  19. this._payload = { ...this._payload, sub: subject };
  20. return this;
  21. }
  22. setAudience(audience) {
  23. this._payload = { ...this._payload, aud: audience };
  24. return this;
  25. }
  26. setJti(jwtId) {
  27. this._payload = { ...this._payload, jti: jwtId };
  28. return this;
  29. }
  30. setNotBefore(input) {
  31. if (typeof input === 'number') {
  32. this._payload = { ...this._payload, nbf: input };
  33. }
  34. else {
  35. this._payload = { ...this._payload, nbf: (0, epoch_js_1.default)(new Date()) + (0, secs_js_1.default)(input) };
  36. }
  37. return this;
  38. }
  39. setExpirationTime(input) {
  40. if (typeof input === 'number') {
  41. this._payload = { ...this._payload, exp: input };
  42. }
  43. else {
  44. this._payload = { ...this._payload, exp: (0, epoch_js_1.default)(new Date()) + (0, secs_js_1.default)(input) };
  45. }
  46. return this;
  47. }
  48. setIssuedAt(input) {
  49. if (typeof input === 'undefined') {
  50. this._payload = { ...this._payload, iat: (0, epoch_js_1.default)(new Date()) };
  51. }
  52. else {
  53. this._payload = { ...this._payload, iat: input };
  54. }
  55. return this;
  56. }
  57. }
  58. exports.ProduceJWT = ProduceJWT;