@naturalcycles/nodejs-lib 12.98.1 → 12.98.2

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.
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processSharedUtil = exports.memoryUsageFull = exports.memoryUsage = void 0;
4
4
  const os = require("node:os");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
7
6
  function memoryUsage() {
8
7
  const { rss, external, heapUsed, heapTotal } = process.memoryUsage();
9
8
  return {
@@ -7,6 +7,9 @@ exports.jsonwebtoken = jsonwebtoken;
7
7
  const joi_shared_schemas_1 = require("../validation/joi/joi.shared.schemas");
8
8
  const joi_validation_util_1 = require("../validation/joi/joi.validation.util");
9
9
  // todo: define JWTError and list possible options
10
+ // jwt expired (TokenExpiredError)
11
+ // jwt invalid
12
+ // jwt token is empty
10
13
  /**
11
14
  * Wraps popular `jsonwebtoken` library.
12
15
  * You should create one instance of JWTService for each pair of private/public key.
@@ -49,7 +52,6 @@ class JWTService {
49
52
  }
50
53
  catch (err) {
51
54
  if (this.cfg.errorData) {
52
- (0, js_lib_1._typeCast)(err);
53
55
  (0, js_lib_1._errorDataAppend)(err, {
54
56
  ...this.cfg.errorData,
55
57
  });
@@ -61,7 +63,7 @@ class JWTService {
61
63
  const data = jsonwebtoken.decode(token, {
62
64
  complete: true,
63
65
  });
64
- (0, js_lib_1._assert)(data, 'invalid token, decoded value is null', {
66
+ (0, js_lib_1._assert)(data?.payload, 'invalid token, decoded value is empty', {
65
67
  ...this.cfg.errorData,
66
68
  });
67
69
  (0, joi_validation_util_1.validate)(data.payload, schema || joi_shared_schemas_1.anyObjectSchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.98.1",
3
+ "version": "12.98.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -41,7 +41,7 @@
41
41
  "@types/yargs": "^16.0.0",
42
42
  "jest": "^29.0.0",
43
43
  "nock": "^13.0.2",
44
- "prettier": "^2.0.0",
44
+ "prettier": "^3.0.0",
45
45
  "vue-class-component": "^7.2.6",
46
46
  "vuepress": "^1.7.1",
47
47
  "vuepress-plugin-typescript": "^0.3.1"
@@ -1,9 +1,12 @@
1
1
  import * as os from 'node:os'
2
2
  import { _mb } from '@naturalcycles/js-lib'
3
3
 
4
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
5
-
6
- export function memoryUsage() {
4
+ export function memoryUsage(): {
5
+ rss: number
6
+ heapTotal: number
7
+ heapUsed: number
8
+ external: number
9
+ } {
7
10
  const { rss, external, heapUsed, heapTotal } = process.memoryUsage()
8
11
  return {
9
12
  rss: _mb(rss),
@@ -13,7 +16,15 @@ export function memoryUsage() {
13
16
  }
14
17
  }
15
18
 
16
- export function memoryUsageFull() {
19
+ export function memoryUsageFull(): {
20
+ rss: number
21
+ heapTotal: number
22
+ heapUsed: number
23
+ external: number
24
+ totalMem: number
25
+ freeMem: number
26
+ usedMem: number
27
+ } {
17
28
  const { rss, external, heapUsed, heapTotal } = process.memoryUsage()
18
29
  const totalMem = os.totalmem()
19
30
  const freeMem = os.freemem()
@@ -81,7 +92,10 @@ class ProcessUtil {
81
92
  })
82
93
  }
83
94
 
84
- private getCPUInfo() {
95
+ private getCPUInfo(): {
96
+ idle: number
97
+ total: number
98
+ } {
85
99
  // eslint-disable-next-line unicorn/no-array-reduce
86
100
  return os.cpus().reduce(
87
101
  (r, cpu) => {
@@ -1,11 +1,4 @@
1
- import {
2
- _assert,
3
- _errorDataAppend,
4
- _typeCast,
5
- AnyObject,
6
- ErrorData,
7
- JWTString,
8
- } from '@naturalcycles/js-lib'
1
+ import { _assert, _errorDataAppend, AnyObject, ErrorData, JWTString } from '@naturalcycles/js-lib'
9
2
  import type { Algorithm, VerifyOptions, JwtHeader, SignOptions } from 'jsonwebtoken'
10
3
  import * as jsonwebtoken from 'jsonwebtoken'
11
4
  import { AnySchemaTyped } from '../validation/joi/joi.model'
@@ -51,6 +44,9 @@ export interface JWTServiceCfg {
51
44
  }
52
45
 
53
46
  // todo: define JWTError and list possible options
47
+ // jwt expired (TokenExpiredError)
48
+ // jwt invalid
49
+ // jwt token is empty
54
50
 
55
51
  /**
56
52
  * Wraps popular `jsonwebtoken` library.
@@ -113,7 +109,6 @@ export class JWTService {
113
109
  return data
114
110
  } catch (err) {
115
111
  if (this.cfg.errorData) {
116
- _typeCast<Error>(err)
117
112
  _errorDataAppend(err, {
118
113
  ...this.cfg.errorData,
119
114
  })
@@ -138,7 +133,7 @@ export class JWTService {
138
133
  signature: string
139
134
  } | null
140
135
 
141
- _assert(data, 'invalid token, decoded value is null', {
136
+ _assert(data?.payload, 'invalid token, decoded value is empty', {
142
137
  ...this.cfg.errorData,
143
138
  })
144
139
 
@@ -3,7 +3,10 @@ import { yellow } from '../colors'
3
3
  import { gzipBuffer } from '../util/zip.util'
4
4
 
5
5
  export class SizeStack extends NumberStack {
6
- constructor(public name: string, size: number) {
6
+ constructor(
7
+ public name: string,
8
+ size: number,
9
+ ) {
7
10
  super(size)
8
11
  }
9
12
 
@@ -13,12 +13,15 @@ export function requireEnvKeys<T extends readonly string[]>(
13
13
  ...keys: T
14
14
  ): { [k in ValuesOf<T>]: string } {
15
15
  // eslint-disable-next-line unicorn/no-array-reduce
16
- return keys.reduce((r, k) => {
17
- const v = process.env[k]
18
- if (!v) throw new Error(`${k} env variable is required, but missing`)
19
- r[k as ValuesOf<T>] = v
20
- return r
21
- }, {} as { [k in ValuesOf<T>]: string })
16
+ return keys.reduce(
17
+ (r, k) => {
18
+ const v = process.env[k]
19
+ if (!v) throw new Error(`${k} env variable is required, but missing`)
20
+ r[k as ValuesOf<T>] = v
21
+ return r
22
+ },
23
+ {} as { [k in ValuesOf<T>]: string },
24
+ )
22
25
  }
23
26
 
24
27
  export function requireFileToExist(filePath: string): void {
@@ -78,7 +78,10 @@ export interface AjvSchemaCfg {
78
78
  * @experimental
79
79
  */
80
80
  export class AjvSchema<T = unknown> {
81
- private constructor(public schema: JsonSchema<T>, cfg: Partial<AjvSchemaCfg> = {}) {
81
+ private constructor(
82
+ public schema: JsonSchema<T>,
83
+ cfg: Partial<AjvSchemaCfg> = {},
84
+ ) {
82
85
  this.cfg = {
83
86
  logErrors: true,
84
87
  logger: console,