jose 6.0.8 → 6.0.10

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.
@@ -1,76 +0,0 @@
1
- import epoch from '../lib/epoch.js';
2
- import isObject from '../lib/is_object.js';
3
- import secs from '../lib/secs.js';
4
- function validateInput(label, input) {
5
- if (!Number.isFinite(input)) {
6
- throw new TypeError(`Invalid ${label} input`);
7
- }
8
- return input;
9
- }
10
- export class ProduceJWT {
11
- _payload;
12
- constructor(payload = {}) {
13
- if (!isObject(payload)) {
14
- throw new TypeError('JWT Claims Set MUST be an object');
15
- }
16
- this._payload = payload;
17
- }
18
- setIssuer(issuer) {
19
- this._payload = { ...this._payload, iss: issuer };
20
- return this;
21
- }
22
- setSubject(subject) {
23
- this._payload = { ...this._payload, sub: subject };
24
- return this;
25
- }
26
- setAudience(audience) {
27
- this._payload = { ...this._payload, aud: audience };
28
- return this;
29
- }
30
- setJti(jwtId) {
31
- this._payload = { ...this._payload, jti: jwtId };
32
- return this;
33
- }
34
- setNotBefore(input) {
35
- if (typeof input === 'number') {
36
- this._payload = { ...this._payload, nbf: validateInput('setNotBefore', input) };
37
- }
38
- else if (input instanceof Date) {
39
- this._payload = { ...this._payload, nbf: validateInput('setNotBefore', epoch(input)) };
40
- }
41
- else {
42
- this._payload = { ...this._payload, nbf: epoch(new Date()) + secs(input) };
43
- }
44
- return this;
45
- }
46
- setExpirationTime(input) {
47
- if (typeof input === 'number') {
48
- this._payload = { ...this._payload, exp: validateInput('setExpirationTime', input) };
49
- }
50
- else if (input instanceof Date) {
51
- this._payload = { ...this._payload, exp: validateInput('setExpirationTime', epoch(input)) };
52
- }
53
- else {
54
- this._payload = { ...this._payload, exp: epoch(new Date()) + secs(input) };
55
- }
56
- return this;
57
- }
58
- setIssuedAt(input) {
59
- if (typeof input === 'undefined') {
60
- this._payload = { ...this._payload, iat: epoch(new Date()) };
61
- }
62
- else if (input instanceof Date) {
63
- this._payload = { ...this._payload, iat: validateInput('setIssuedAt', epoch(input)) };
64
- }
65
- else if (typeof input === 'string') {
66
- this._payload = {
67
- ...this._payload,
68
- iat: validateInput('setIssuedAt', epoch(new Date()) + secs(input)),
69
- };
70
- }
71
- else {
72
- this._payload = { ...this._payload, iat: validateInput('setIssuedAt', input) };
73
- }
74
- return this;
75
- }
76
- }