@naturalcycles/nodejs-lib 12.98.0 → 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.
- package/dist/fs/json2env.js +3 -3
- package/dist/infra/process.util.js +0 -1
- package/dist/jwt/jwt.service.js +4 -2
- package/package.json +2 -2
- package/src/fs/json2env.ts +3 -3
- package/src/infra/process.util.ts +19 -5
- package/src/jwt/jwt.service.ts +5 -10
- package/src/stream/sizeStack.ts +4 -1
- package/src/util/env.util.ts +9 -6
- package/src/validation/ajv/ajvSchema.ts +4 -1
package/dist/fs/json2env.js
CHANGED
|
@@ -42,11 +42,11 @@ function json2env(opt) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
if (bashEnv) {
|
|
45
|
-
appendToBashEnv(json);
|
|
45
|
+
appendToBashEnv(json, prefix);
|
|
46
46
|
}
|
|
47
47
|
if (githubEnv) {
|
|
48
|
-
appendToGithubEnv(json);
|
|
49
|
-
appendToGithubOutput(json);
|
|
48
|
+
appendToGithubEnv(json, prefix);
|
|
49
|
+
appendToGithubOutput(json, prefix);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
exports.json2env = json2env;
|
|
@@ -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 {
|
package/dist/jwt/jwt.service.js
CHANGED
|
@@ -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
|
|
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.
|
|
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": "^
|
|
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"
|
package/src/fs/json2env.ts
CHANGED
|
@@ -81,12 +81,12 @@ export function json2env(opt: Json2EnvOptions): void {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
if (bashEnv) {
|
|
84
|
-
appendToBashEnv(json)
|
|
84
|
+
appendToBashEnv(json, prefix)
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (githubEnv) {
|
|
88
|
-
appendToGithubEnv(json)
|
|
89
|
-
appendToGithubOutput(json)
|
|
88
|
+
appendToGithubEnv(json, prefix)
|
|
89
|
+
appendToGithubOutput(json, prefix)
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as os from 'node:os'
|
|
2
2
|
import { _mb } from '@naturalcycles/js-lib'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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) => {
|
package/src/jwt/jwt.service.ts
CHANGED
|
@@ -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
|
|
136
|
+
_assert(data?.payload, 'invalid token, decoded value is empty', {
|
|
142
137
|
...this.cfg.errorData,
|
|
143
138
|
})
|
|
144
139
|
|
package/src/stream/sizeStack.ts
CHANGED
|
@@ -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(
|
|
6
|
+
constructor(
|
|
7
|
+
public name: string,
|
|
8
|
+
size: number,
|
|
9
|
+
) {
|
|
7
10
|
super(size)
|
|
8
11
|
}
|
|
9
12
|
|
package/src/util/env.util.ts
CHANGED
|
@@ -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(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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(
|
|
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,
|