From 530deff4a61fe02727d9d06dd3bd4ead7b619440 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger <11753867+big-kahuna-burger@users.noreply.github.com> Date: Sat, 23 Dec 2023 12:31:35 +0100 Subject: [PATCH 1/8] docs: adds jsdocs to timestamp helpers --- src/jwt/produce.ts | 60 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/src/jwt/produce.ts b/src/jwt/produce.ts index e6d356336a..9708b455ae 100644 --- a/src/jwt/produce.ts +++ b/src/jwt/produce.ts @@ -66,9 +66,22 @@ export class ProduceJWT { /** * Set the "nbf" (Not Before) Claim. * - * @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed - * that is used as a value, when string is passed it is resolved to a time span and added to the - * current timestamp. + * @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. + * + * - If a `number` is passed as an argument, it's used as the `nbf` claim directly. + * + * - If a `Date` object is passed, the value is converted to unix timestamp and used as `nbf` claim. + * + * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. + * + * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". + * + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", + * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years". + * + * If the string is suffixed with "ago" or "from now", or prefixed with a "-", the resulting number of seconds gets subtracted from the current unix timestamp. + * + * @throws {TypeError} When input string is in bad format or numeric input is infinite. */ setNotBefore(input: number | string | Date) { if (typeof input === 'number') { @@ -82,11 +95,24 @@ export class ProduceJWT { } /** - * Set the "exp" (Expiration Time) Claim. - * - * @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is - * passed that is used as a value, when string is passed it is resolved to a time span and added - * to the current timestamp. + * Set the `exp` (Expiration Time) Claim. + * + * @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. + * + * - If a `number` is passed as an argument, it's used as the `exp` claim directly. + * + * - If a `Date` object is passed, the value is converted to unix timestamp and used as `exp` claim. + * + * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. + * + * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". + * + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", + * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years". + * + * If the string is suffixed with "ago" or "from now", or prefixed with a "-", the resulting number of seconds gets subtracted from the current unix timestamp. + * + * @throws {TypeError} When input string is in bad format or numeric input is infinite. */ setExpirationTime(input: number | string | Date) { if (typeof input === 'number') { @@ -102,8 +128,22 @@ export class ProduceJWT { /** * Set the "iat" (Issued At) Claim. * - * @param input "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current - * timestamp. + * @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set. + * + * - If a `number` is passed as an argument, it's used as the `iat` claim directly. + * + * - If a `Date` object is passed, the value is converted to unix timestamp and used as `iat` claim. + * + * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. + * + * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". + * + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", + * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years". + * + * If the string is suffixed with "ago" or "from now", or prefixed with a "-", the resulting number of seconds gets subtracted from the current unix timestamp. + * + * @throws {TypeError} When input string is in bad format or numeric input is infinite. */ setIssuedAt(input?: number | string | Date) { if (typeof input === 'undefined') { From b95c224a3e56c321d03f0d4a648ab7266b195f0e Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 24 Dec 2023 09:34:35 +0000 Subject: [PATCH 2/8] Apply suggestions from code review --- src/jwt/produce.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/jwt/produce.ts b/src/jwt/produce.ts index 9708b455ae..2af2c0eb33 100644 --- a/src/jwt/produce.ts +++ b/src/jwt/produce.ts @@ -77,11 +77,9 @@ export class ProduceJWT { * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". * * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", - * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years". + * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". * - * If the string is suffixed with "ago" or "from now", or prefixed with a "-", the resulting number of seconds gets subtracted from the current unix timestamp. - * - * @throws {TypeError} When input string is in bad format or numeric input is infinite. + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability. */ setNotBefore(input: number | string | Date) { if (typeof input === 'number') { @@ -108,11 +106,9 @@ export class ProduceJWT { * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". * * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", - * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years". + * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". * - * If the string is suffixed with "ago" or "from now", or prefixed with a "-", the resulting number of seconds gets subtracted from the current unix timestamp. - * - * @throws {TypeError} When input string is in bad format or numeric input is infinite. + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability. */ setExpirationTime(input: number | string | Date) { if (typeof input === 'number') { @@ -129,7 +125,8 @@ export class ProduceJWT { * Set the "iat" (Issued At) Claim. * * @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set. - * + * - If no argument is used the current unix timestamp is used as the `iat` claim. + * * - If a `number` is passed as an argument, it's used as the `iat` claim directly. * * - If a `Date` object is passed, the value is converted to unix timestamp and used as `iat` claim. @@ -139,11 +136,9 @@ export class ProduceJWT { * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". * * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", - * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years". + * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". * - * If the string is suffixed with "ago" or "from now", or prefixed with a "-", the resulting number of seconds gets subtracted from the current unix timestamp. - * - * @throws {TypeError} When input string is in bad format or numeric input is infinite. + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability. */ setIssuedAt(input?: number | string | Date) { if (typeof input === 'undefined') { From 5dfc728abc7c0f88cc3678e6019167ab6d755ea5 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 24 Dec 2023 09:36:53 +0000 Subject: [PATCH 3/8] Apply suggestions from code review --- src/jwt/produce.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jwt/produce.ts b/src/jwt/produce.ts index 2af2c0eb33..85a2a51292 100644 --- a/src/jwt/produce.ts +++ b/src/jwt/produce.ts @@ -70,7 +70,7 @@ export class ProduceJWT { * * - If a `number` is passed as an argument, it's used as the `nbf` claim directly. * - * - If a `Date` object is passed, the value is converted to unix timestamp and used as `nbf` claim. + * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `nbf` claim. * * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. * @@ -99,7 +99,7 @@ export class ProduceJWT { * * - If a `number` is passed as an argument, it's used as the `exp` claim directly. * - * - If a `Date` object is passed, the value is converted to unix timestamp and used as `exp` claim. + * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `exp` claim. * * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. * @@ -129,7 +129,7 @@ export class ProduceJWT { * * - If a `number` is passed as an argument, it's used as the `iat` claim directly. * - * - If a `Date` object is passed, the value is converted to unix timestamp and used as `iat` claim. + * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `iat` claim. * * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. * From 82ca893bef98b3faf25a29e5540b65565b7cc3f2 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 24 Dec 2023 09:38:38 +0000 Subject: [PATCH 4/8] Apply suggestions from code review --- src/jwt/produce.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jwt/produce.ts b/src/jwt/produce.ts index 85a2a51292..cd9acbfd4a 100644 --- a/src/jwt/produce.ts +++ b/src/jwt/produce.ts @@ -79,7 +79,7 @@ export class ProduceJWT { * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability. + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability when adding to the current unix timestamp. */ setNotBefore(input: number | string | Date) { if (typeof input === 'number') { @@ -108,7 +108,7 @@ export class ProduceJWT { * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability. + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability when adding to the current unix timestamp. */ setExpirationTime(input: number | string | Date) { if (typeof input === 'number') { @@ -138,7 +138,7 @@ export class ProduceJWT { * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability. + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability when adding to the current unix timestamp. */ setIssuedAt(input?: number | string | Date) { if (typeof input === 'undefined') { From 4df108190a16f3706d6b51f4deaeb02c67b3d376 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 24 Dec 2023 14:23:11 +0100 Subject: [PATCH 5/8] code review --- src/jwt/produce.ts | 85 +++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/src/jwt/produce.ts b/src/jwt/produce.ts index cd9acbfd4a..15c250946e 100644 --- a/src/jwt/produce.ts +++ b/src/jwt/produce.ts @@ -66,20 +66,23 @@ export class ProduceJWT { /** * Set the "nbf" (Not Before) Claim. * - * @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. - * + * @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. + * * - If a `number` is passed as an argument, it's used as the `nbf` claim directly. - * - * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `nbf` claim. - * - * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. - * + * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `nbf` + * claim. + * - If a `string` is passed it is resolved to a time span, and then added to the current unix + * timestamp. + * * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". - * - * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", - * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". - * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability when adding to the current unix timestamp. + * + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", + * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", + * "years", "yr", "yrs", and "y". + * + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets + * subtracted from the current unix timestamp. A "from now" suffix can also be used for + * readability when adding to the current unix timestamp. */ setNotBefore(input: number | string | Date) { if (typeof input === 'number') { @@ -93,22 +96,25 @@ export class ProduceJWT { } /** - * Set the `exp` (Expiration Time) Claim. - * - * @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. - * + * Set the "exp" (Expiration Time) Claim. + * + * @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. + * * - If a `number` is passed as an argument, it's used as the `exp` claim directly. - * - * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `exp` claim. - * - * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. - * + * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `exp` + * claim. + * - If a `string` is passed it is resolved to a time span, and then added to the current unix + * timestamp. + * * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". - * - * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", - * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". - * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability when adding to the current unix timestamp. + * + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", + * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", + * "years", "yr", "yrs", and "y". + * + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets + * subtracted from the current unix timestamp. A "from now" suffix can also be used for + * readability when adding to the current unix timestamp. */ setExpirationTime(input: number | string | Date) { if (typeof input === 'number') { @@ -124,21 +130,24 @@ export class ProduceJWT { /** * Set the "iat" (Issued At) Claim. * - * @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set. - * - If no argument is used the current unix timestamp is used as the `iat` claim. + * @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set. * + * - If no argument is used the current unix timestamp is used as the `iat` claim. * - If a `number` is passed as an argument, it's used as the `iat` claim directly. - * - * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `iat` claim. - * - * - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp. - * + * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `iat` + * claim. + * - If a `string` is passed it is resolved to a time span, and then added to the current unix + * timestamp. + * * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". - * - * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", - * "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y". - * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability when adding to the current unix timestamp. + * + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", + * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", + * "years", "yr", "yrs", and "y". + * + * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets + * subtracted from the current unix timestamp. A "from now" suffix can also be used for + * readability when adding to the current unix timestamp. */ setIssuedAt(input?: number | string | Date) { if (typeof input === 'undefined') { From ae33b6fd56fc1bc25befbd192cc91937d956a710 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 24 Dec 2023 14:38:10 +0100 Subject: [PATCH 6/8] reformat, re-run docs --- docs/classes/jwt_encrypt.EncryptJWT.md | 58 ++++++++++++++- docs/classes/jwt_produce.ProduceJWT.md | 58 ++++++++++++++- docs/classes/jwt_sign.SignJWT.md | 58 ++++++++++++++- docs/classes/jwt_unsecured.UnsecuredJWT.md | 58 ++++++++++++++- src/jwt/produce.ts | 83 +++++++++++----------- 5 files changed, 263 insertions(+), 52 deletions(-) diff --git a/docs/classes/jwt_encrypt.EncryptJWT.md b/docs/classes/jwt_encrypt.EncryptJWT.md index fd3ee09652..e2c01e60b0 100644 --- a/docs/classes/jwt_encrypt.EncryptJWT.md +++ b/docs/classes/jwt_encrypt.EncryptJWT.md @@ -176,11 +176,28 @@ ___ Set the "exp" (Expiration Time) Claim. +- If a `number` is passed as an argument, it's used as the `exp` claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. | +| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "exp" (Expiration Time) Claim value to set on the JWT Claims Set. | #### Returns @@ -218,11 +235,29 @@ ___ Set the "iat" (Issued At) Claim. +- If no argument is used the current unix timestamp is used as the `iat` claim. +- If a `number` is passed as an argument, it's used as the `iat` claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input?` | `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current timestamp. | +| `input?` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "iat" (Expiration Time) Claim value to set on the JWT Claims Set. | #### Returns @@ -293,11 +328,28 @@ ___ Set the "nbf" (Not Before) Claim. +- If a `number` is passed as an argument, it's used as the claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. | +| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "nbf" (Not Before) Claim value to set on the JWT Claims Set. | #### Returns diff --git a/docs/classes/jwt_produce.ProduceJWT.md b/docs/classes/jwt_produce.ProduceJWT.md index e874b68b6f..ea1d85e388 100644 --- a/docs/classes/jwt_produce.ProduceJWT.md +++ b/docs/classes/jwt_produce.ProduceJWT.md @@ -62,11 +62,28 @@ ___ Set the "exp" (Expiration Time) Claim. +- If a `number` is passed as an argument, it's used as the `exp` claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. | +| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "exp" (Expiration Time) Claim value to set on the JWT Claims Set. | #### Returns @@ -80,11 +97,29 @@ ___ Set the "iat" (Issued At) Claim. +- If no argument is used the current unix timestamp is used as the `iat` claim. +- If a `number` is passed as an argument, it's used as the `iat` claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input?` | `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current timestamp. | +| `input?` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "iat" (Expiration Time) Claim value to set on the JWT Claims Set. | #### Returns @@ -134,11 +169,28 @@ ___ Set the "nbf" (Not Before) Claim. +- If a `number` is passed as an argument, it's used as the claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. | +| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "nbf" (Not Before) Claim value to set on the JWT Claims Set. | #### Returns diff --git a/docs/classes/jwt_sign.SignJWT.md b/docs/classes/jwt_sign.SignJWT.md index 50faca2993..4b2738cafc 100644 --- a/docs/classes/jwt_sign.SignJWT.md +++ b/docs/classes/jwt_sign.SignJWT.md @@ -162,11 +162,28 @@ ___ Set the "exp" (Expiration Time) Claim. +- If a `number` is passed as an argument, it's used as the `exp` claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. | +| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "exp" (Expiration Time) Claim value to set on the JWT Claims Set. | #### Returns @@ -180,11 +197,29 @@ ___ Set the "iat" (Issued At) Claim. +- If no argument is used the current unix timestamp is used as the `iat` claim. +- If a `number` is passed as an argument, it's used as the `iat` claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input?` | `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current timestamp. | +| `input?` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "iat" (Expiration Time) Claim value to set on the JWT Claims Set. | #### Returns @@ -234,11 +269,28 @@ ___ Set the "nbf" (Not Before) Claim. +- If a `number` is passed as an argument, it's used as the claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. | +| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "nbf" (Not Before) Claim value to set on the JWT Claims Set. | #### Returns diff --git a/docs/classes/jwt_unsecured.UnsecuredJWT.md b/docs/classes/jwt_unsecured.UnsecuredJWT.md index feb3164945..56fe5cc825 100644 --- a/docs/classes/jwt_unsecured.UnsecuredJWT.md +++ b/docs/classes/jwt_unsecured.UnsecuredJWT.md @@ -129,11 +129,28 @@ ___ Set the "exp" (Expiration Time) Claim. +- If a `number` is passed as an argument, it's used as the `exp` claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. | +| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "exp" (Expiration Time) Claim value to set on the JWT Claims Set. | #### Returns @@ -147,11 +164,29 @@ ___ Set the "iat" (Issued At) Claim. +- If no argument is used the current unix timestamp is used as the `iat` claim. +- If a `number` is passed as an argument, it's used as the `iat` claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input?` | `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current timestamp. | +| `input?` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "iat" (Expiration Time) Claim value to set on the JWT Claims Set. | #### Returns @@ -201,11 +236,28 @@ ___ Set the "nbf" (Not Before) Claim. +- If a `number` is passed as an argument, it's used as the claim directly. +- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + used as the claim. +- If a `string` is passed as an argument it is resolved to a time span, and then added to the + current unix timestamp and used as the claim. + +Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 +day". + +Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", +"m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", +"years", "yr", "yrs", and "y". + +If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets +subtracted from the current unix timestamp. A "from now" suffix can also be used for +readability when adding to the current unix timestamp. + #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. | +| `input` | `string` \| `number` \| [`Date`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date ) | "nbf" (Not Before) Claim value to set on the JWT Claims Set. | #### Returns diff --git a/src/jwt/produce.ts b/src/jwt/produce.ts index 15c250946e..df708b2d64 100644 --- a/src/jwt/produce.ts +++ b/src/jwt/produce.ts @@ -66,23 +66,24 @@ export class ProduceJWT { /** * Set the "nbf" (Not Before) Claim. * - * @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. + * - If a `number` is passed as an argument, it's used as the claim directly. + * - If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + * used as the claim. + * - If a `string` is passed as an argument it is resolved to a time span, and then added to the + * current unix timestamp and used as the claim. * - * - If a `number` is passed as an argument, it's used as the `nbf` claim directly. - * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `nbf` - * claim. - * - If a `string` is passed it is resolved to a time span, and then added to the current unix - * timestamp. + * Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 + * day". * - * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", + * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", + * "years", "yr", "yrs", and "y". * - * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", - * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", - * "years", "yr", "yrs", and "y". + * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets + * subtracted from the current unix timestamp. A "from now" suffix can also be used for + * readability when adding to the current unix timestamp. * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets - * subtracted from the current unix timestamp. A "from now" suffix can also be used for - * readability when adding to the current unix timestamp. + * @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. */ setNotBefore(input: number | string | Date) { if (typeof input === 'number') { @@ -98,23 +99,24 @@ export class ProduceJWT { /** * Set the "exp" (Expiration Time) Claim. * - * @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. + * - If a `number` is passed as an argument, it's used as the `exp` claim directly. + * - If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + * used as the claim. + * - If a `string` is passed as an argument it is resolved to a time span, and then added to the + * current unix timestamp and used as the claim. * - * - If a `number` is passed as an argument, it's used as the `exp` claim directly. - * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `exp` - * claim. - * - If a `string` is passed it is resolved to a time span, and then added to the current unix - * timestamp. + * Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 + * day". * - * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", + * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", + * "years", "yr", "yrs", and "y". * - * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", - * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", - * "years", "yr", "yrs", and "y". + * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets + * subtracted from the current unix timestamp. A "from now" suffix can also be used for + * readability when adding to the current unix timestamp. * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets - * subtracted from the current unix timestamp. A "from now" suffix can also be used for - * readability when adding to the current unix timestamp. + * @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. */ setExpirationTime(input: number | string | Date) { if (typeof input === 'number') { @@ -130,24 +132,25 @@ export class ProduceJWT { /** * Set the "iat" (Issued At) Claim. * - * @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set. + * - If no argument is used the current unix timestamp is used as the `iat` claim. + * - If a `number` is passed as an argument, it's used as the `iat` claim directly. + * - If a `Date` instance is passed as an argument, the value is converted to unix timestamp and + * used as the claim. + * - If a `string` is passed as an argument it is resolved to a time span, and then added to the + * current unix timestamp and used as the claim. * - * - If no argument is used the current unix timestamp is used as the `iat` claim. - * - If a `number` is passed as an argument, it's used as the `iat` claim directly. - * - If a `Date` instance is passed, the value is converted to unix timestamp and used as `iat` - * claim. - * - If a `string` is passed it is resolved to a time span, and then added to the current unix - * timestamp. + * Format used for time span should be a number followed by a unit, such as "5 minutes" or "1 + * day". * - * Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day". + * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", + * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", + * "years", "yr", "yrs", and "y". * - * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", - * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", - * "years", "yr", "yrs", and "y". + * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets + * subtracted from the current unix timestamp. A "from now" suffix can also be used for + * readability when adding to the current unix timestamp. * - * If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets - * subtracted from the current unix timestamp. A "from now" suffix can also be used for - * readability when adding to the current unix timestamp. + * @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set. */ setIssuedAt(input?: number | string | Date) { if (typeof input === 'undefined') { From e05e410ea4d43c9a1eb67e3c3448e29a45f141c2 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 24 Dec 2023 14:42:48 +0100 Subject: [PATCH 7/8] code review --- docs/classes/jwt_encrypt.EncryptJWT.md | 20 ++++++++++---------- docs/classes/jwt_produce.ProduceJWT.md | 20 ++++++++++---------- docs/classes/jwt_sign.SignJWT.md | 20 ++++++++++---------- docs/classes/jwt_unsecured.UnsecuredJWT.md | 20 ++++++++++---------- src/jwt/produce.ts | 20 ++++++++++---------- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/docs/classes/jwt_encrypt.EncryptJWT.md b/docs/classes/jwt_encrypt.EncryptJWT.md index e2c01e60b0..6ee4a6b715 100644 --- a/docs/classes/jwt_encrypt.EncryptJWT.md +++ b/docs/classes/jwt_encrypt.EncryptJWT.md @@ -176,9 +176,9 @@ ___ Set the "exp" (Expiration Time) Claim. -- If a `number` is passed as an argument, it's used as the `exp` claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. @@ -235,10 +235,10 @@ ___ Set the "iat" (Issued At) Claim. -- If no argument is used the current unix timestamp is used as the `iat` claim. -- If a `number` is passed as an argument, it's used as the `iat` claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If no argument is used the current unix timestamp is used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. @@ -328,9 +328,9 @@ ___ Set the "nbf" (Not Before) Claim. -- If a `number` is passed as an argument, it's used as the claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. diff --git a/docs/classes/jwt_produce.ProduceJWT.md b/docs/classes/jwt_produce.ProduceJWT.md index ea1d85e388..26dd53c9f6 100644 --- a/docs/classes/jwt_produce.ProduceJWT.md +++ b/docs/classes/jwt_produce.ProduceJWT.md @@ -62,9 +62,9 @@ ___ Set the "exp" (Expiration Time) Claim. -- If a `number` is passed as an argument, it's used as the `exp` claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. @@ -97,10 +97,10 @@ ___ Set the "iat" (Issued At) Claim. -- If no argument is used the current unix timestamp is used as the `iat` claim. -- If a `number` is passed as an argument, it's used as the `iat` claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If no argument is used the current unix timestamp is used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. @@ -169,9 +169,9 @@ ___ Set the "nbf" (Not Before) Claim. -- If a `number` is passed as an argument, it's used as the claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. diff --git a/docs/classes/jwt_sign.SignJWT.md b/docs/classes/jwt_sign.SignJWT.md index 4b2738cafc..2fc5c84d5b 100644 --- a/docs/classes/jwt_sign.SignJWT.md +++ b/docs/classes/jwt_sign.SignJWT.md @@ -162,9 +162,9 @@ ___ Set the "exp" (Expiration Time) Claim. -- If a `number` is passed as an argument, it's used as the `exp` claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. @@ -197,10 +197,10 @@ ___ Set the "iat" (Issued At) Claim. -- If no argument is used the current unix timestamp is used as the `iat` claim. -- If a `number` is passed as an argument, it's used as the `iat` claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If no argument is used the current unix timestamp is used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. @@ -269,9 +269,9 @@ ___ Set the "nbf" (Not Before) Claim. -- If a `number` is passed as an argument, it's used as the claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. diff --git a/docs/classes/jwt_unsecured.UnsecuredJWT.md b/docs/classes/jwt_unsecured.UnsecuredJWT.md index 56fe5cc825..035b5fc182 100644 --- a/docs/classes/jwt_unsecured.UnsecuredJWT.md +++ b/docs/classes/jwt_unsecured.UnsecuredJWT.md @@ -129,9 +129,9 @@ ___ Set the "exp" (Expiration Time) Claim. -- If a `number` is passed as an argument, it's used as the `exp` claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. @@ -164,10 +164,10 @@ ___ Set the "iat" (Issued At) Claim. -- If no argument is used the current unix timestamp is used as the `iat` claim. -- If a `number` is passed as an argument, it's used as the `iat` claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If no argument is used the current unix timestamp is used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. @@ -236,9 +236,9 @@ ___ Set the "nbf" (Not Before) Claim. -- If a `number` is passed as an argument, it's used as the claim directly. -- If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - used as the claim. +- If a `number` is passed as an argument it is used as the claim directly. +- If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + claim. - If a `string` is passed as an argument it is resolved to a time span, and then added to the current unix timestamp and used as the claim. diff --git a/src/jwt/produce.ts b/src/jwt/produce.ts index df708b2d64..1c29c050ed 100644 --- a/src/jwt/produce.ts +++ b/src/jwt/produce.ts @@ -66,9 +66,9 @@ export class ProduceJWT { /** * Set the "nbf" (Not Before) Claim. * - * - If a `number` is passed as an argument, it's used as the claim directly. - * - If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - * used as the claim. + * - If a `number` is passed as an argument it is used as the claim directly. + * - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + * claim. * - If a `string` is passed as an argument it is resolved to a time span, and then added to the * current unix timestamp and used as the claim. * @@ -99,9 +99,9 @@ export class ProduceJWT { /** * Set the "exp" (Expiration Time) Claim. * - * - If a `number` is passed as an argument, it's used as the `exp` claim directly. - * - If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - * used as the claim. + * - If a `number` is passed as an argument it is used as the claim directly. + * - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + * claim. * - If a `string` is passed as an argument it is resolved to a time span, and then added to the * current unix timestamp and used as the claim. * @@ -132,10 +132,10 @@ export class ProduceJWT { /** * Set the "iat" (Issued At) Claim. * - * - If no argument is used the current unix timestamp is used as the `iat` claim. - * - If a `number` is passed as an argument, it's used as the `iat` claim directly. - * - If a `Date` instance is passed as an argument, the value is converted to unix timestamp and - * used as the claim. + * - If no argument is used the current unix timestamp is used as the claim. + * - If a `number` is passed as an argument it is used as the claim directly. + * - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the + * claim. * - If a `string` is passed as an argument it is resolved to a time span, and then added to the * current unix timestamp and used as the claim. * From e83c073fb06d073cb73c161170e549136dabc983 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 24 Dec 2023 14:44:41 +0100 Subject: [PATCH 8/8] code review --- docs/classes/jwt_encrypt.EncryptJWT.md | 9 ++++++--- docs/classes/jwt_produce.ProduceJWT.md | 9 ++++++--- docs/classes/jwt_sign.SignJWT.md | 9 ++++++--- docs/classes/jwt_unsecured.UnsecuredJWT.md | 9 ++++++--- src/jwt/produce.ts | 9 ++++++--- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/docs/classes/jwt_encrypt.EncryptJWT.md b/docs/classes/jwt_encrypt.EncryptJWT.md index 6ee4a6b715..2b77f63dd6 100644 --- a/docs/classes/jwt_encrypt.EncryptJWT.md +++ b/docs/classes/jwt_encrypt.EncryptJWT.md @@ -187,7 +187,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -247,7 +248,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -339,7 +341,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for diff --git a/docs/classes/jwt_produce.ProduceJWT.md b/docs/classes/jwt_produce.ProduceJWT.md index 26dd53c9f6..05bcd4a5da 100644 --- a/docs/classes/jwt_produce.ProduceJWT.md +++ b/docs/classes/jwt_produce.ProduceJWT.md @@ -73,7 +73,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -109,7 +110,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -180,7 +182,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for diff --git a/docs/classes/jwt_sign.SignJWT.md b/docs/classes/jwt_sign.SignJWT.md index 2fc5c84d5b..ad55364efe 100644 --- a/docs/classes/jwt_sign.SignJWT.md +++ b/docs/classes/jwt_sign.SignJWT.md @@ -173,7 +173,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -209,7 +210,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -280,7 +282,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for diff --git a/docs/classes/jwt_unsecured.UnsecuredJWT.md b/docs/classes/jwt_unsecured.UnsecuredJWT.md index 035b5fc182..e8b4a8fd1b 100644 --- a/docs/classes/jwt_unsecured.UnsecuredJWT.md +++ b/docs/classes/jwt_unsecured.UnsecuredJWT.md @@ -140,7 +140,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -176,7 +177,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -247,7 +249,8 @@ day". Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", -"years", "yr", "yrs", and "y". +"years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an +alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for diff --git a/src/jwt/produce.ts b/src/jwt/produce.ts index 1c29c050ed..cb54962d87 100644 --- a/src/jwt/produce.ts +++ b/src/jwt/produce.ts @@ -77,7 +77,8 @@ export class ProduceJWT { * * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", - * "years", "yr", "yrs", and "y". + * "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an + * alias for a year. * * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets * subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -110,7 +111,8 @@ export class ProduceJWT { * * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", - * "years", "yr", "yrs", and "y". + * "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an + * alias for a year. * * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets * subtracted from the current unix timestamp. A "from now" suffix can also be used for @@ -144,7 +146,8 @@ export class ProduceJWT { * * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", - * "years", "yr", "yrs", and "y". + * "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an + * alias for a year. * * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets * subtracted from the current unix timestamp. A "from now" suffix can also be used for