@naturalcycles/nodejs-lib 12.98.1 → 12.98.3
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.d.ts +2 -0
- package/dist/fs/json2env.js +3 -1
- package/dist/infra/process.util.js +0 -1
- package/dist/jwt/jwt.service.js +4 -2
- package/dist/util/buildInfo.util.js +0 -2
- package/package.json +2 -2
- package/src/fs/json2env.ts +3 -1
- 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/buildInfo.util.ts +0 -2
- package/src/util/env.util.ts +9 -6
- package/src/validation/ajv/ajvSchema.ts +4 -1
package/dist/fs/json2env.d.ts
CHANGED
|
@@ -55,5 +55,7 @@ export declare function objectToShellExport(obj: AnyObject, prefix?: string): st
|
|
|
55
55
|
*
|
|
56
56
|
* Quotes are important, otherwise it'll break on e.g space character in the value.
|
|
57
57
|
* Includes trailing newline for composability.
|
|
58
|
+
*
|
|
59
|
+
* UPD: Quoted values behave inconsistently, so we're trying to NOT quote now, and-see-what-happens.
|
|
58
60
|
*/
|
|
59
61
|
export declare function objectToGithubActionsEnv(obj: AnyObject, prefix?: string): string;
|
package/dist/fs/json2env.js
CHANGED
|
@@ -114,6 +114,8 @@ exports.objectToShellExport = objectToShellExport;
|
|
|
114
114
|
*
|
|
115
115
|
* Quotes are important, otherwise it'll break on e.g space character in the value.
|
|
116
116
|
* Includes trailing newline for composability.
|
|
117
|
+
*
|
|
118
|
+
* UPD: Quoted values behave inconsistently, so we're trying to NOT quote now, and-see-what-happens.
|
|
117
119
|
*/
|
|
118
120
|
function objectToGithubActionsEnv(obj, prefix = '') {
|
|
119
121
|
if (!Object.keys(obj).length)
|
|
@@ -121,7 +123,7 @@ function objectToGithubActionsEnv(obj, prefix = '') {
|
|
|
121
123
|
return (Object.entries(obj)
|
|
122
124
|
.map(([k, v]) => {
|
|
123
125
|
if (v) {
|
|
124
|
-
return `${prefix}${k}
|
|
126
|
+
return `${prefix}${k}=${v}`;
|
|
125
127
|
}
|
|
126
128
|
})
|
|
127
129
|
.filter(Boolean)
|
|
@@ -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);
|
|
@@ -7,7 +7,6 @@ const git_util_1 = require("./git.util");
|
|
|
7
7
|
function generateBuildInfo() {
|
|
8
8
|
const now = (0, js_lib_1.localTime)();
|
|
9
9
|
const ts = now.unix();
|
|
10
|
-
const tsStr = now.toPretty();
|
|
11
10
|
const rev = (0, git_util_1.gitCurrentCommitSha)();
|
|
12
11
|
const branchName = (0, git_util_1.gitCurrentBranchName)();
|
|
13
12
|
const repoName = (0, git_util_1.gitCurrentRepoName)();
|
|
@@ -27,7 +26,6 @@ function generateBuildInfo() {
|
|
|
27
26
|
return (0, js_lib_1._filterUndefinedValues)({
|
|
28
27
|
ts,
|
|
29
28
|
tsCommit,
|
|
30
|
-
tsStr,
|
|
31
29
|
repoName,
|
|
32
30
|
branchName,
|
|
33
31
|
rev,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
|
-
"version": "12.98.
|
|
3
|
+
"version": "12.98.3",
|
|
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
|
@@ -156,6 +156,8 @@ export function objectToShellExport(obj: AnyObject, prefix = ''): string {
|
|
|
156
156
|
*
|
|
157
157
|
* Quotes are important, otherwise it'll break on e.g space character in the value.
|
|
158
158
|
* Includes trailing newline for composability.
|
|
159
|
+
*
|
|
160
|
+
* UPD: Quoted values behave inconsistently, so we're trying to NOT quote now, and-see-what-happens.
|
|
159
161
|
*/
|
|
160
162
|
export function objectToGithubActionsEnv(obj: AnyObject, prefix = ''): string {
|
|
161
163
|
if (!Object.keys(obj).length) return ''
|
|
@@ -164,7 +166,7 @@ export function objectToGithubActionsEnv(obj: AnyObject, prefix = ''): string {
|
|
|
164
166
|
Object.entries(obj)
|
|
165
167
|
.map(([k, v]) => {
|
|
166
168
|
if (v) {
|
|
167
|
-
return `${prefix}${k}
|
|
169
|
+
return `${prefix}${k}=${v}`
|
|
168
170
|
}
|
|
169
171
|
})
|
|
170
172
|
.filter(Boolean)
|
|
@@ -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
|
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
export function generateBuildInfo(): BuildInfo {
|
|
11
11
|
const now = localTime()
|
|
12
12
|
const ts = now.unix()
|
|
13
|
-
const tsStr = now.toPretty()
|
|
14
13
|
|
|
15
14
|
const rev = gitCurrentCommitSha()
|
|
16
15
|
const branchName = gitCurrentBranchName()
|
|
@@ -34,7 +33,6 @@ export function generateBuildInfo(): BuildInfo {
|
|
|
34
33
|
return _filterUndefinedValues({
|
|
35
34
|
ts,
|
|
36
35
|
tsCommit,
|
|
37
|
-
tsStr,
|
|
38
36
|
repoName,
|
|
39
37
|
branchName,
|
|
40
38
|
rev,
|
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,
|