@naturalcycles/nodejs-lib 15.37.2 → 15.38.0
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/security/nanoid.js
CHANGED
|
@@ -4,7 +4,7 @@ This file is "vendored" from Nanoid, all credit is to Nanoid authors:
|
|
|
4
4
|
https://github.com/ai/nanoid/
|
|
5
5
|
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
// oxlint-disable no-bitwise -- NanoID implementation relies on bitwise operations
|
|
8
8
|
import { randomFillSync } from 'node:crypto';
|
|
9
9
|
export const ALPHABET_NONAMBIGUOUS = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
|
|
10
10
|
export const ALPHABET_NUMBER = '0123456789';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/prefer-string-starts-ends-with */
|
|
2
|
-
/* eslint-disable unicorn/prefer-code-point */
|
|
3
1
|
import { _lazyValue } from '@naturalcycles/js-lib';
|
|
4
|
-
import { Ajv } from 'ajv';
|
|
2
|
+
import { _, Ajv } from 'ajv';
|
|
5
3
|
import ajvFormats from 'ajv-formats';
|
|
6
|
-
|
|
4
|
+
/* eslint-disable @typescript-eslint/prefer-string-starts-ends-with */
|
|
5
|
+
// oxlint-disable unicorn/prefer-code-point
|
|
7
6
|
const AJV_OPTIONS = {
|
|
8
7
|
removeAdditional: true,
|
|
9
8
|
allErrors: true,
|
|
@@ -51,17 +50,56 @@ export function createAjv(opt) {
|
|
|
51
50
|
// https://ajv.js.org/guide/formats.html
|
|
52
51
|
// @ts-expect-error types are wrong
|
|
53
52
|
ajvFormats(ajv);
|
|
54
|
-
// https://ajv.js.org/packages/ajv-keywords.html
|
|
55
|
-
// @ts-expect-error types are wrong
|
|
56
|
-
ajvKeywords(ajv, [
|
|
57
|
-
'transform', // trim, toLowerCase, etc.
|
|
58
|
-
'uniqueItemProperties',
|
|
59
|
-
'instanceof',
|
|
60
|
-
]);
|
|
61
53
|
// Adds $merge, $patch keywords
|
|
62
54
|
// https://github.com/ajv-validator/ajv-merge-patch
|
|
63
55
|
// Kirill: temporarily disabled, as it creates a noise of CVE warnings
|
|
64
56
|
// require('ajv-merge-patch')(ajv)
|
|
57
|
+
ajv.addKeyword({
|
|
58
|
+
keyword: 'transform',
|
|
59
|
+
type: 'string',
|
|
60
|
+
modifying: true,
|
|
61
|
+
schemaType: 'object',
|
|
62
|
+
code(cxt) {
|
|
63
|
+
const { gen, data, schema, it } = cxt;
|
|
64
|
+
const { parentData, parentDataProperty } = it;
|
|
65
|
+
if (schema.trim) {
|
|
66
|
+
gen.assign(_ `${data}`, _ `${data}.trim()`);
|
|
67
|
+
}
|
|
68
|
+
if (schema.toLowerCase) {
|
|
69
|
+
gen.assign(_ `${data}`, _ `${data}.toLowerCase()`);
|
|
70
|
+
}
|
|
71
|
+
if (schema.toUpperCase) {
|
|
72
|
+
gen.assign(_ `${data}`, _ `${data}.toUpperCase()`);
|
|
73
|
+
}
|
|
74
|
+
if (typeof schema.truncate === 'number' && schema.truncate >= 0) {
|
|
75
|
+
gen.assign(_ `${data}`, _ `${data}.slice(0, ${schema.truncate})`);
|
|
76
|
+
if (schema.trim) {
|
|
77
|
+
gen.assign(_ `${data}`, _ `${data}.trim()`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
gen.if(_ `${parentData} !== undefined`, () => {
|
|
81
|
+
gen.assign(_ `${parentData}[${parentDataProperty}]`, data);
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
ajv.addKeyword({
|
|
86
|
+
keyword: 'instanceof',
|
|
87
|
+
modifying: true,
|
|
88
|
+
schemaType: 'string',
|
|
89
|
+
validate(instanceOf, data, _schema, _ctx) {
|
|
90
|
+
if (typeof data !== 'object')
|
|
91
|
+
return false;
|
|
92
|
+
if (data === null)
|
|
93
|
+
return false;
|
|
94
|
+
let proto = Object.getPrototypeOf(data);
|
|
95
|
+
while (proto) {
|
|
96
|
+
if (proto.constructor?.name === instanceOf)
|
|
97
|
+
return true;
|
|
98
|
+
proto = Object.getPrototypeOf(proto);
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
},
|
|
102
|
+
});
|
|
65
103
|
return ajv;
|
|
66
104
|
}
|
|
67
105
|
const TS_2500 = 16725225600; // 2500-01-01
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.38.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@types/js-yaml": "^4",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"@types/yargs": "^16",
|
|
10
10
|
"ajv": "^8",
|
|
11
11
|
"ajv-formats": "^3",
|
|
12
|
-
"ajv-keywords": "^5",
|
|
13
12
|
"chalk": "^5",
|
|
14
13
|
"dotenv": "^17",
|
|
15
14
|
"joi": "^18",
|
package/src/security/nanoid.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/prefer-string-starts-ends-with */
|
|
2
|
-
/* eslint-disable unicorn/prefer-code-point */
|
|
3
1
|
import { _lazyValue } from '@naturalcycles/js-lib'
|
|
4
2
|
import type { Options } from 'ajv'
|
|
5
|
-
import { Ajv } from 'ajv'
|
|
3
|
+
import { _, Ajv } from 'ajv'
|
|
6
4
|
import ajvFormats from 'ajv-formats'
|
|
7
|
-
|
|
5
|
+
|
|
6
|
+
/* eslint-disable @typescript-eslint/prefer-string-starts-ends-with */
|
|
7
|
+
// oxlint-disable unicorn/prefer-code-point
|
|
8
8
|
|
|
9
9
|
const AJV_OPTIONS: Options = {
|
|
10
10
|
removeAdditional: true,
|
|
@@ -60,19 +60,64 @@ export function createAjv(opt?: Options): Ajv {
|
|
|
60
60
|
// @ts-expect-error types are wrong
|
|
61
61
|
ajvFormats(ajv)
|
|
62
62
|
|
|
63
|
-
// https://ajv.js.org/packages/ajv-keywords.html
|
|
64
|
-
// @ts-expect-error types are wrong
|
|
65
|
-
ajvKeywords(ajv, [
|
|
66
|
-
'transform', // trim, toLowerCase, etc.
|
|
67
|
-
'uniqueItemProperties',
|
|
68
|
-
'instanceof',
|
|
69
|
-
])
|
|
70
|
-
|
|
71
63
|
// Adds $merge, $patch keywords
|
|
72
64
|
// https://github.com/ajv-validator/ajv-merge-patch
|
|
73
65
|
// Kirill: temporarily disabled, as it creates a noise of CVE warnings
|
|
74
66
|
// require('ajv-merge-patch')(ajv)
|
|
75
67
|
|
|
68
|
+
ajv.addKeyword({
|
|
69
|
+
keyword: 'transform',
|
|
70
|
+
type: 'string',
|
|
71
|
+
modifying: true,
|
|
72
|
+
schemaType: 'object',
|
|
73
|
+
code(cxt) {
|
|
74
|
+
const { gen, data, schema, it } = cxt
|
|
75
|
+
const { parentData, parentDataProperty } = it
|
|
76
|
+
|
|
77
|
+
if (schema.trim) {
|
|
78
|
+
gen.assign(_`${data}`, _`${data}.trim()`)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (schema.toLowerCase) {
|
|
82
|
+
gen.assign(_`${data}`, _`${data}.toLowerCase()`)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (schema.toUpperCase) {
|
|
86
|
+
gen.assign(_`${data}`, _`${data}.toUpperCase()`)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof schema.truncate === 'number' && schema.truncate >= 0) {
|
|
90
|
+
gen.assign(_`${data}`, _`${data}.slice(0, ${schema.truncate})`)
|
|
91
|
+
|
|
92
|
+
if (schema.trim) {
|
|
93
|
+
gen.assign(_`${data}`, _`${data}.trim()`)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
gen.if(_`${parentData} !== undefined`, () => {
|
|
98
|
+
gen.assign(_`${parentData}[${parentDataProperty}]`, data)
|
|
99
|
+
})
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
ajv.addKeyword({
|
|
104
|
+
keyword: 'instanceof',
|
|
105
|
+
modifying: true,
|
|
106
|
+
schemaType: 'string',
|
|
107
|
+
validate(instanceOf: string, data: unknown, _schema, _ctx) {
|
|
108
|
+
if (typeof data !== 'object') return false
|
|
109
|
+
if (data === null) return false
|
|
110
|
+
|
|
111
|
+
let proto = Object.getPrototypeOf(data)
|
|
112
|
+
while (proto) {
|
|
113
|
+
if (proto.constructor?.name === instanceOf) return true
|
|
114
|
+
proto = Object.getPrototypeOf(proto)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return false
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
|
|
76
121
|
return ajv
|
|
77
122
|
}
|
|
78
123
|
|
|
@@ -5,9 +5,9 @@ import type { StringSchema } from './string.extensions.js'
|
|
|
5
5
|
import { stringExtensions } from './string.extensions.js'
|
|
6
6
|
|
|
7
7
|
export interface ExtendedJoi extends JoiLib.Root {
|
|
8
|
-
// eslint-disable-next-line id-
|
|
8
|
+
// eslint-disable-next-line id-denylist
|
|
9
9
|
string: <TSchema = string>() => StringSchema<TSchema>
|
|
10
|
-
// eslint-disable-next-line id-
|
|
10
|
+
// eslint-disable-next-line id-denylist
|
|
11
11
|
number: <TSchema = number>() => NumberSchema<TSchema>
|
|
12
12
|
}
|
|
13
13
|
|