jose 5.1.3 → 5.2.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/browser/jwks/remote.js +1 -1
- package/dist/browser/jwt/produce.js +6 -0
- package/dist/browser/lib/secs.js +21 -10
- package/dist/node/cjs/jwks/remote.js +1 -1
- package/dist/node/cjs/jwt/produce.js +6 -0
- package/dist/node/cjs/lib/secs.js +21 -10
- package/dist/node/esm/jwks/remote.js +1 -1
- package/dist/node/esm/jwt/produce.js +6 -0
- package/dist/node/esm/lib/secs.js +21 -10
- package/dist/types/jwt/produce.d.ts +59 -9
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
|
|
|
9
9
|
let USER_AGENT;
|
|
10
10
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
11
11
|
const NAME = 'jose';
|
|
12
|
-
const VERSION = 'v5.
|
|
12
|
+
const VERSION = 'v5.2.0';
|
|
13
13
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
14
|
}
|
|
15
15
|
class RemoteJWKSet extends LocalJWKSet {
|
|
@@ -61,6 +61,12 @@ export class ProduceJWT {
|
|
|
61
61
|
else if (input instanceof Date) {
|
|
62
62
|
this._payload = { ...this._payload, iat: validateInput('setIssuedAt', epoch(input)) };
|
|
63
63
|
}
|
|
64
|
+
else if (typeof input === 'string') {
|
|
65
|
+
this._payload = {
|
|
66
|
+
...this._payload,
|
|
67
|
+
iat: validateInput('setIssuedAt', epoch(new Date()) + secs(input)),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
64
70
|
else {
|
|
65
71
|
this._payload = { ...this._payload, iat: validateInput('setIssuedAt', input) };
|
|
66
72
|
}
|
package/dist/browser/lib/secs.js
CHANGED
|
@@ -3,42 +3,53 @@ const hour = minute * 60;
|
|
|
3
3
|
const day = hour * 24;
|
|
4
4
|
const week = day * 7;
|
|
5
5
|
const year = day * 365.25;
|
|
6
|
-
const REGEX = /^(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)
|
|
6
|
+
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
7
7
|
export default (str) => {
|
|
8
8
|
const matched = REGEX.exec(str);
|
|
9
|
-
if (!matched) {
|
|
9
|
+
if (!matched || (matched[4] && matched[1])) {
|
|
10
10
|
throw new TypeError('Invalid time period format');
|
|
11
11
|
}
|
|
12
|
-
const value = parseFloat(matched[
|
|
13
|
-
const unit = matched[
|
|
12
|
+
const value = parseFloat(matched[2]);
|
|
13
|
+
const unit = matched[3].toLowerCase();
|
|
14
|
+
let numericDate;
|
|
14
15
|
switch (unit) {
|
|
15
16
|
case 'sec':
|
|
16
17
|
case 'secs':
|
|
17
18
|
case 'second':
|
|
18
19
|
case 'seconds':
|
|
19
20
|
case 's':
|
|
20
|
-
|
|
21
|
+
numericDate = Math.round(value);
|
|
22
|
+
break;
|
|
21
23
|
case 'minute':
|
|
22
24
|
case 'minutes':
|
|
23
25
|
case 'min':
|
|
24
26
|
case 'mins':
|
|
25
27
|
case 'm':
|
|
26
|
-
|
|
28
|
+
numericDate = Math.round(value * minute);
|
|
29
|
+
break;
|
|
27
30
|
case 'hour':
|
|
28
31
|
case 'hours':
|
|
29
32
|
case 'hr':
|
|
30
33
|
case 'hrs':
|
|
31
34
|
case 'h':
|
|
32
|
-
|
|
35
|
+
numericDate = Math.round(value * hour);
|
|
36
|
+
break;
|
|
33
37
|
case 'day':
|
|
34
38
|
case 'days':
|
|
35
39
|
case 'd':
|
|
36
|
-
|
|
40
|
+
numericDate = Math.round(value * day);
|
|
41
|
+
break;
|
|
37
42
|
case 'week':
|
|
38
43
|
case 'weeks':
|
|
39
44
|
case 'w':
|
|
40
|
-
|
|
45
|
+
numericDate = Math.round(value * week);
|
|
46
|
+
break;
|
|
41
47
|
default:
|
|
42
|
-
|
|
48
|
+
numericDate = Math.round(value * year);
|
|
49
|
+
break;
|
|
43
50
|
}
|
|
51
|
+
if (matched[1] === '-' || matched[4] === 'ago') {
|
|
52
|
+
return -numericDate;
|
|
53
|
+
}
|
|
54
|
+
return numericDate;
|
|
44
55
|
};
|
|
@@ -12,7 +12,7 @@ function isCloudflareWorkers() {
|
|
|
12
12
|
let USER_AGENT;
|
|
13
13
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
14
14
|
const NAME = 'jose';
|
|
15
|
-
const VERSION = 'v5.
|
|
15
|
+
const VERSION = 'v5.2.0';
|
|
16
16
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
17
17
|
}
|
|
18
18
|
class RemoteJWKSet extends local_js_1.LocalJWKSet {
|
|
@@ -65,6 +65,12 @@ class ProduceJWT {
|
|
|
65
65
|
else if (input instanceof Date) {
|
|
66
66
|
this._payload = { ...this._payload, iat: validateInput('setIssuedAt', (0, epoch_js_1.default)(input)) };
|
|
67
67
|
}
|
|
68
|
+
else if (typeof input === 'string') {
|
|
69
|
+
this._payload = {
|
|
70
|
+
...this._payload,
|
|
71
|
+
iat: validateInput('setIssuedAt', (0, epoch_js_1.default)(new Date()) + (0, secs_js_1.default)(input)),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
68
74
|
else {
|
|
69
75
|
this._payload = { ...this._payload, iat: validateInput('setIssuedAt', input) };
|
|
70
76
|
}
|
|
@@ -5,42 +5,53 @@ const hour = minute * 60;
|
|
|
5
5
|
const day = hour * 24;
|
|
6
6
|
const week = day * 7;
|
|
7
7
|
const year = day * 365.25;
|
|
8
|
-
const REGEX = /^(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)
|
|
8
|
+
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
9
9
|
exports.default = (str) => {
|
|
10
10
|
const matched = REGEX.exec(str);
|
|
11
|
-
if (!matched) {
|
|
11
|
+
if (!matched || (matched[4] && matched[1])) {
|
|
12
12
|
throw new TypeError('Invalid time period format');
|
|
13
13
|
}
|
|
14
|
-
const value = parseFloat(matched[
|
|
15
|
-
const unit = matched[
|
|
14
|
+
const value = parseFloat(matched[2]);
|
|
15
|
+
const unit = matched[3].toLowerCase();
|
|
16
|
+
let numericDate;
|
|
16
17
|
switch (unit) {
|
|
17
18
|
case 'sec':
|
|
18
19
|
case 'secs':
|
|
19
20
|
case 'second':
|
|
20
21
|
case 'seconds':
|
|
21
22
|
case 's':
|
|
22
|
-
|
|
23
|
+
numericDate = Math.round(value);
|
|
24
|
+
break;
|
|
23
25
|
case 'minute':
|
|
24
26
|
case 'minutes':
|
|
25
27
|
case 'min':
|
|
26
28
|
case 'mins':
|
|
27
29
|
case 'm':
|
|
28
|
-
|
|
30
|
+
numericDate = Math.round(value * minute);
|
|
31
|
+
break;
|
|
29
32
|
case 'hour':
|
|
30
33
|
case 'hours':
|
|
31
34
|
case 'hr':
|
|
32
35
|
case 'hrs':
|
|
33
36
|
case 'h':
|
|
34
|
-
|
|
37
|
+
numericDate = Math.round(value * hour);
|
|
38
|
+
break;
|
|
35
39
|
case 'day':
|
|
36
40
|
case 'days':
|
|
37
41
|
case 'd':
|
|
38
|
-
|
|
42
|
+
numericDate = Math.round(value * day);
|
|
43
|
+
break;
|
|
39
44
|
case 'week':
|
|
40
45
|
case 'weeks':
|
|
41
46
|
case 'w':
|
|
42
|
-
|
|
47
|
+
numericDate = Math.round(value * week);
|
|
48
|
+
break;
|
|
43
49
|
default:
|
|
44
|
-
|
|
50
|
+
numericDate = Math.round(value * year);
|
|
51
|
+
break;
|
|
45
52
|
}
|
|
53
|
+
if (matched[1] === '-' || matched[4] === 'ago') {
|
|
54
|
+
return -numericDate;
|
|
55
|
+
}
|
|
56
|
+
return numericDate;
|
|
46
57
|
};
|
|
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
|
|
|
9
9
|
let USER_AGENT;
|
|
10
10
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
11
11
|
const NAME = 'jose';
|
|
12
|
-
const VERSION = 'v5.
|
|
12
|
+
const VERSION = 'v5.2.0';
|
|
13
13
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
14
|
}
|
|
15
15
|
class RemoteJWKSet extends LocalJWKSet {
|
|
@@ -62,6 +62,12 @@ export class ProduceJWT {
|
|
|
62
62
|
else if (input instanceof Date) {
|
|
63
63
|
this._payload = { ...this._payload, iat: validateInput('setIssuedAt', epoch(input)) };
|
|
64
64
|
}
|
|
65
|
+
else if (typeof input === 'string') {
|
|
66
|
+
this._payload = {
|
|
67
|
+
...this._payload,
|
|
68
|
+
iat: validateInput('setIssuedAt', epoch(new Date()) + secs(input)),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
65
71
|
else {
|
|
66
72
|
this._payload = { ...this._payload, iat: validateInput('setIssuedAt', input) };
|
|
67
73
|
}
|
|
@@ -3,42 +3,53 @@ const hour = minute * 60;
|
|
|
3
3
|
const day = hour * 24;
|
|
4
4
|
const week = day * 7;
|
|
5
5
|
const year = day * 365.25;
|
|
6
|
-
const REGEX = /^(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)
|
|
6
|
+
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
7
7
|
export default (str) => {
|
|
8
8
|
const matched = REGEX.exec(str);
|
|
9
|
-
if (!matched) {
|
|
9
|
+
if (!matched || (matched[4] && matched[1])) {
|
|
10
10
|
throw new TypeError('Invalid time period format');
|
|
11
11
|
}
|
|
12
|
-
const value = parseFloat(matched[
|
|
13
|
-
const unit = matched[
|
|
12
|
+
const value = parseFloat(matched[2]);
|
|
13
|
+
const unit = matched[3].toLowerCase();
|
|
14
|
+
let numericDate;
|
|
14
15
|
switch (unit) {
|
|
15
16
|
case 'sec':
|
|
16
17
|
case 'secs':
|
|
17
18
|
case 'second':
|
|
18
19
|
case 'seconds':
|
|
19
20
|
case 's':
|
|
20
|
-
|
|
21
|
+
numericDate = Math.round(value);
|
|
22
|
+
break;
|
|
21
23
|
case 'minute':
|
|
22
24
|
case 'minutes':
|
|
23
25
|
case 'min':
|
|
24
26
|
case 'mins':
|
|
25
27
|
case 'm':
|
|
26
|
-
|
|
28
|
+
numericDate = Math.round(value * minute);
|
|
29
|
+
break;
|
|
27
30
|
case 'hour':
|
|
28
31
|
case 'hours':
|
|
29
32
|
case 'hr':
|
|
30
33
|
case 'hrs':
|
|
31
34
|
case 'h':
|
|
32
|
-
|
|
35
|
+
numericDate = Math.round(value * hour);
|
|
36
|
+
break;
|
|
33
37
|
case 'day':
|
|
34
38
|
case 'days':
|
|
35
39
|
case 'd':
|
|
36
|
-
|
|
40
|
+
numericDate = Math.round(value * day);
|
|
41
|
+
break;
|
|
37
42
|
case 'week':
|
|
38
43
|
case 'weeks':
|
|
39
44
|
case 'w':
|
|
40
|
-
|
|
45
|
+
numericDate = Math.round(value * week);
|
|
46
|
+
break;
|
|
41
47
|
default:
|
|
42
|
-
|
|
48
|
+
numericDate = Math.round(value * year);
|
|
49
|
+
break;
|
|
43
50
|
}
|
|
51
|
+
if (matched[1] === '-' || matched[4] === 'ago') {
|
|
52
|
+
return -numericDate;
|
|
53
|
+
}
|
|
54
|
+
return numericDate;
|
|
44
55
|
};
|
|
@@ -31,24 +31,74 @@ export declare class ProduceJWT {
|
|
|
31
31
|
/**
|
|
32
32
|
* Set the "nbf" (Not Before) Claim.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* - If a `number` is passed as an argument it is used as the claim directly.
|
|
35
|
+
* - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the
|
|
36
|
+
* claim.
|
|
37
|
+
* - If a `string` is passed as an argument it is resolved to a time span, and then added to the
|
|
38
|
+
* current unix timestamp and used as the claim.
|
|
39
|
+
*
|
|
40
|
+
* Format used for time span should be a number followed by a unit, such as "5 minutes" or "1
|
|
41
|
+
* day".
|
|
42
|
+
*
|
|
43
|
+
* Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins",
|
|
44
|
+
* "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year",
|
|
45
|
+
* "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an
|
|
46
|
+
* alias for a year.
|
|
47
|
+
*
|
|
48
|
+
* If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets
|
|
49
|
+
* subtracted from the current unix timestamp. A "from now" suffix can also be used for
|
|
50
|
+
* readability when adding to the current unix timestamp.
|
|
51
|
+
*
|
|
52
|
+
* @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set.
|
|
37
53
|
*/
|
|
38
54
|
setNotBefore(input: number | string | Date): this;
|
|
39
55
|
/**
|
|
40
56
|
* Set the "exp" (Expiration Time) Claim.
|
|
41
57
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
58
|
+
* - If a `number` is passed as an argument it is used as the claim directly.
|
|
59
|
+
* - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the
|
|
60
|
+
* claim.
|
|
61
|
+
* - If a `string` is passed as an argument it is resolved to a time span, and then added to the
|
|
62
|
+
* current unix timestamp and used as the claim.
|
|
63
|
+
*
|
|
64
|
+
* Format used for time span should be a number followed by a unit, such as "5 minutes" or "1
|
|
65
|
+
* day".
|
|
66
|
+
*
|
|
67
|
+
* Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins",
|
|
68
|
+
* "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year",
|
|
69
|
+
* "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an
|
|
70
|
+
* alias for a year.
|
|
71
|
+
*
|
|
72
|
+
* If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets
|
|
73
|
+
* subtracted from the current unix timestamp. A "from now" suffix can also be used for
|
|
74
|
+
* readability when adding to the current unix timestamp.
|
|
75
|
+
*
|
|
76
|
+
* @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set.
|
|
45
77
|
*/
|
|
46
78
|
setExpirationTime(input: number | string | Date): this;
|
|
47
79
|
/**
|
|
48
80
|
* Set the "iat" (Issued At) Claim.
|
|
49
81
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
82
|
+
* - If no argument is used the current unix timestamp is used as the claim.
|
|
83
|
+
* - If a `number` is passed as an argument it is used as the claim directly.
|
|
84
|
+
* - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the
|
|
85
|
+
* claim.
|
|
86
|
+
* - If a `string` is passed as an argument it is resolved to a time span, and then added to the
|
|
87
|
+
* current unix timestamp and used as the claim.
|
|
88
|
+
*
|
|
89
|
+
* Format used for time span should be a number followed by a unit, such as "5 minutes" or "1
|
|
90
|
+
* day".
|
|
91
|
+
*
|
|
92
|
+
* Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins",
|
|
93
|
+
* "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year",
|
|
94
|
+
* "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an
|
|
95
|
+
* alias for a year.
|
|
96
|
+
*
|
|
97
|
+
* If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets
|
|
98
|
+
* subtracted from the current unix timestamp. A "from now" suffix can also be used for
|
|
99
|
+
* readability when adding to the current unix timestamp.
|
|
100
|
+
*
|
|
101
|
+
* @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set.
|
|
52
102
|
*/
|
|
53
|
-
setIssuedAt(input?: number | Date): this;
|
|
103
|
+
setIssuedAt(input?: number | string | Date): this;
|
|
54
104
|
}
|
package/package.json
CHANGED