@naturalcycles/nodejs-lib 15.120.0 → 15.121.1

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.
@@ -182,9 +182,11 @@ export class JWTService {
182
182
  if (err instanceof errors.JOSEError) {
183
183
  return new JWTInvalidError(err.message, errorData);
184
184
  }
185
- if (this.cfg.verifyAlgorithms && err instanceof TypeError) {
185
+ if (this.cfg.verifyAlgorithms && (err instanceof TypeError || err instanceof DOMException)) {
186
186
  // With multiple verifyAlgorithms, a token/key algorithm mismatch is reachable
187
- // by untrusted input, and jose reports it as TypeError - treat it as an invalid token
187
+ // by untrusted input, and jose reports it as TypeError, or (since jose 6.2.6,
188
+ // which prepares keys via Node's KeyObject.toCryptoKey) as DOMException
189
+ // "DataError: Invalid key type" - treat it as an invalid token
188
190
  return new JWTInvalidError(err.message, errorData);
189
191
  }
190
192
  return err;
@@ -271,7 +271,16 @@ export declare class JString<OUT extends string | undefined = string, Opt extend
271
271
  ipv4(): this;
272
272
  ipv6(): this;
273
273
  slug(): this;
274
+ /**
275
+ * Validates the 3-part semver format: `major.minor.patch`, e.g `1.2.3`.
276
+ */
274
277
  semVer(): this;
278
+ /**
279
+ * Validates the 4-part version format: `major.minor.patch.build`, e.g `1.2.3.4`.
280
+ *
281
+ * Not a semver by the spec, but is used by e.g .NET and some mobile app versions.
282
+ */
283
+ semVer4(): this;
275
284
  languageTag(): this;
276
285
  countryCode(): this;
277
286
  currency(): this;
@@ -5,7 +5,7 @@ import { _deepCopy, _filterNullishValues, _sortObject } from '@naturalcycles/js-
5
5
  import { _substringBefore } from '@naturalcycles/js-lib/string';
6
6
  import { _objectAssign, _typeCast, JWT_REGEX } from '@naturalcycles/js-lib/types';
7
7
  import { _inspect } from '../../string/inspect.js';
8
- import { BASE64URL_REGEX, COUNTRY_CODE_REGEX, CURRENCY_REGEX, IPV4_REGEX, IPV6_REGEX, LANGUAGE_TAG_REGEX, SEMVER_REGEX, SLUG_REGEX, URL_REGEX, UUID_REGEX, } from '../regexes.js';
8
+ import { BASE64URL_REGEX, COUNTRY_CODE_REGEX, CURRENCY_REGEX, IPV4_REGEX, IPV6_REGEX, LANGUAGE_TAG_REGEX, SEMVER4_REGEX, SEMVER_REGEX, SLUG_REGEX, URL_REGEX, UUID_REGEX, } from '../regexes.js';
9
9
  import { TIMEZONES } from '../timezones.js';
10
10
  import { AjvValidationError } from './ajvValidationError.js';
11
11
  import { getAjv } from './getAjv.js';
@@ -623,9 +623,20 @@ export class JString extends JBuilder {
623
623
  slug() {
624
624
  return this.regex(SLUG_REGEX, { msg: 'is not a valid slug format' });
625
625
  }
626
+ /**
627
+ * Validates the 3-part semver format: `major.minor.patch`, e.g `1.2.3`.
628
+ */
626
629
  semVer() {
627
630
  return this.regex(SEMVER_REGEX, { msg: 'is not a valid semver format' });
628
631
  }
632
+ /**
633
+ * Validates the 4-part version format: `major.minor.patch.build`, e.g `1.2.3.4`.
634
+ *
635
+ * Not a semver by the spec, but is used by e.g .NET and some mobile app versions.
636
+ */
637
+ semVer4() {
638
+ return this.regex(SEMVER4_REGEX, { msg: 'is not a valid 4-part semver format' });
639
+ }
629
640
  languageTag() {
630
641
  return this.regex(LANGUAGE_TAG_REGEX, { msg: 'is not a valid language format' });
631
642
  }
@@ -17,5 +17,6 @@ export declare const IPV6_REGEX: RegExp;
17
17
  export declare const LANGUAGE_TAG_REGEX: RegExp;
18
18
  export declare const MAC_ADDRESS_REGEX: RegExp;
19
19
  export declare const SEMVER_REGEX: RegExp;
20
+ export declare const SEMVER4_REGEX: RegExp;
20
21
  export declare const SLUG_REGEX: RegExp;
21
22
  export declare const URL_REGEX: RegExp;
@@ -22,6 +22,8 @@ export const IPV6_REGEX = /^((([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:))|(([0-9
22
22
  export const LANGUAGE_TAG_REGEX = /^[a-z]{2}(-[A-Z]{2})?$/;
23
23
  export const MAC_ADDRESS_REGEX = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
24
24
  export const SEMVER_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+$/;
25
+ // 4-part version (major.minor.patch.build)
26
+ export const SEMVER4_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/;
25
27
  export const SLUG_REGEX = /^[a-z0-9-]+$/;
26
28
  // URL regex based on `ajv-formats`, but without flags for JSON Schema compatibility.
27
29
  // Uses [a-zA-Z] instead of [a-z] with i flag. Simplified to not require unicode flag.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.120.0",
4
+ "version": "15.121.1",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
@@ -379,9 +379,11 @@ export class JWTService<T extends AnyObject = AnyObject> {
379
379
  if (err instanceof errors.JOSEError) {
380
380
  return new JWTInvalidError(err.message, errorData)
381
381
  }
382
- if (this.cfg.verifyAlgorithms && err instanceof TypeError) {
382
+ if (this.cfg.verifyAlgorithms && (err instanceof TypeError || err instanceof DOMException)) {
383
383
  // With multiple verifyAlgorithms, a token/key algorithm mismatch is reachable
384
- // by untrusted input, and jose reports it as TypeError - treat it as an invalid token
384
+ // by untrusted input, and jose reports it as TypeError, or (since jose 6.2.6,
385
+ // which prepares keys via Node's KeyObject.toCryptoKey) as DOMException
386
+ // "DataError: Invalid key type" - treat it as an invalid token
385
387
  return new JWTInvalidError(err.message, errorData)
386
388
  }
387
389
  return err as Error
@@ -36,6 +36,7 @@ import {
36
36
  IPV4_REGEX,
37
37
  IPV6_REGEX,
38
38
  LANGUAGE_TAG_REGEX,
39
+ SEMVER4_REGEX,
39
40
  SEMVER_REGEX,
40
41
  SLUG_REGEX,
41
42
  URL_REGEX,
@@ -831,10 +832,22 @@ export class JString<
831
832
  return this.regex(SLUG_REGEX, { msg: 'is not a valid slug format' })
832
833
  }
833
834
 
835
+ /**
836
+ * Validates the 3-part semver format: `major.minor.patch`, e.g `1.2.3`.
837
+ */
834
838
  semVer(): this {
835
839
  return this.regex(SEMVER_REGEX, { msg: 'is not a valid semver format' })
836
840
  }
837
841
 
842
+ /**
843
+ * Validates the 4-part version format: `major.minor.patch.build`, e.g `1.2.3.4`.
844
+ *
845
+ * Not a semver by the spec, but is used by e.g .NET and some mobile app versions.
846
+ */
847
+ semVer4(): this {
848
+ return this.regex(SEMVER4_REGEX, { msg: 'is not a valid 4-part semver format' })
849
+ }
850
+
838
851
  languageTag(): this {
839
852
  return this.regex(LANGUAGE_TAG_REGEX, { msg: 'is not a valid language format' })
840
853
  }
@@ -23,6 +23,8 @@ export const IPV6_REGEX =
23
23
  export const LANGUAGE_TAG_REGEX = /^[a-z]{2}(-[A-Z]{2})?$/
24
24
  export const MAC_ADDRESS_REGEX = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/
25
25
  export const SEMVER_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+$/
26
+ // 4-part version (major.minor.patch.build)
27
+ export const SEMVER4_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
26
28
  export const SLUG_REGEX = /^[a-z0-9-]+$/
27
29
  // URL regex based on `ajv-formats`, but without flags for JSON Schema compatibility.
28
30
  // Uses [a-zA-Z] instead of [a-z] with i flag. Simplified to not require unicode flag.