@naturalcycles/nodejs-lib 12.62.0 → 12.63.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.
- package/dist/got/getGot.js +7 -1
- package/dist/got/got.model.d.ts +6 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -3
- package/dist/validation/joi/string.extensions.d.ts +0 -9
- package/dist/validation/joi/string.extensions.js +0 -34
- package/package.json +4 -6
- package/src/got/getGot.ts +9 -1
- package/src/got/got.model.ts +7 -0
- package/src/index.ts +0 -3
- package/src/validation/joi/string.extensions.ts +0 -47
- package/dist/validation/sanitize.util.d.ts +0 -8
- package/dist/validation/sanitize.util.js +0 -13
- package/src/validation/sanitize.util.ts +0 -12
package/dist/got/getGot.js
CHANGED
|
@@ -14,7 +14,7 @@ const __1 = require("..");
|
|
|
14
14
|
function getGot(opt = {}) {
|
|
15
15
|
opt.logger || (opt.logger = console);
|
|
16
16
|
if (opt.debug) {
|
|
17
|
-
opt.logStart = opt.logFinished = opt.logResponse = true;
|
|
17
|
+
opt.logStart = opt.logFinished = opt.logResponse = opt.logRequest = true;
|
|
18
18
|
}
|
|
19
19
|
return got_1.default.extend({
|
|
20
20
|
// Most-important is to set to anything non-empty (so, requests don't "hang" by default).
|
|
@@ -134,6 +134,12 @@ function gotBeforeRequestHook(opt) {
|
|
|
134
134
|
const shortUrl = getShortUrl(opt, options.url, options.prefixUrl);
|
|
135
135
|
opt.logger.log([' >>', options.method, shortUrl, retryCount && `(retry ${retryCount})`].join(' '));
|
|
136
136
|
}
|
|
137
|
+
if (opt.logRequest) {
|
|
138
|
+
const body = options.json || options.body;
|
|
139
|
+
if (body) {
|
|
140
|
+
opt.logger.log(body);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
137
143
|
};
|
|
138
144
|
}
|
|
139
145
|
// Here we log always, because it's similar to ErrorHook - we always log errors
|
package/dist/got/got.model.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -65,7 +65,6 @@ import { AnySchemaTyped, ArraySchemaTyped, BooleanSchemaTyped, NumberSchemaTyped
|
|
|
65
65
|
export * from './validation/joi/joi.shared.schemas';
|
|
66
66
|
import { JoiValidationError, JoiValidationErrorData } from './validation/joi/joi.validation.error';
|
|
67
67
|
import { convert, getValidationResult, isValid, JoiValidationResult, undefinedIfInvalid, validate } from './validation/joi/joi.validation.util';
|
|
68
|
-
import { sanitizeHTML, SanitizeHTMLOptions } from './validation/sanitize.util';
|
|
69
68
|
import { runScript, RunScriptOptions } from './script';
|
|
70
|
-
export type { RunScriptOptions, JoiValidationErrorData, JoiValidationResult, ValidationErrorItem, ExtendedJoi, SchemaTyped, AnySchema, AnySchemaTyped, ArraySchemaTyped, BooleanSchemaTyped, NumberSchemaTyped, ObjectSchemaTyped, StringSchemaTyped, IDebug, IDebugger, SlackServiceCfg, SlackMessage, SlackMessageProps, SlackApiBody, SlackMessagePrefixHook, ReadableTyped, WritableTyped, TransformTyped, PipelineFromNDJsonFileOptions, PipelineToNDJsonFileOptions, TransformJsonParseOptions, TransformToNDJsonOptions, TransformMapOptions, TransformMapSyncOptions, NDJSONStreamForEachOptions, TransformOptions, TransformMultiThreadedOptions, WorkerClassInterface, WorkerInput, WorkerOutput, TableDiffOptions, InspectAnyOptions, Got, GetGotOptions, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AjvValidationOptions, AjvSchemaCfg, AjvValidationErrorData,
|
|
71
|
-
export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, LRUMemoCache, Debug, SlackService, slackDefaultMessagePrefixHook, ndjsonStreamForEach, pipelineFromNDJsonFile, pipelineToNDJsonFile, NDJsonStats, streamToNDJsonFile, transformJsonParse, bufferReviver, transformToNDJson, transformMap, transformMapSync, transformMultiThreaded, BaseWorkerClass, tableDiff, inspectAny, inspectAnyStringifyFn, RequestError, TimeoutError, _chunkBuffer, Ajv, AjvSchema, AjvValidationError, readJsonSchemas, readAjvSchemas,
|
|
69
|
+
export type { RunScriptOptions, JoiValidationErrorData, JoiValidationResult, ValidationErrorItem, ExtendedJoi, SchemaTyped, AnySchema, AnySchemaTyped, ArraySchemaTyped, BooleanSchemaTyped, NumberSchemaTyped, ObjectSchemaTyped, StringSchemaTyped, IDebug, IDebugger, SlackServiceCfg, SlackMessage, SlackMessageProps, SlackApiBody, SlackMessagePrefixHook, ReadableTyped, WritableTyped, TransformTyped, PipelineFromNDJsonFileOptions, PipelineToNDJsonFileOptions, TransformJsonParseOptions, TransformToNDJsonOptions, TransformMapOptions, TransformMapSyncOptions, NDJSONStreamForEachOptions, TransformOptions, TransformMultiThreadedOptions, WorkerClassInterface, WorkerInput, WorkerOutput, TableDiffOptions, InspectAnyOptions, Got, GetGotOptions, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AjvValidationOptions, AjvSchemaCfg, AjvValidationErrorData, };
|
|
70
|
+
export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, LRUMemoCache, Debug, SlackService, slackDefaultMessagePrefixHook, ndjsonStreamForEach, pipelineFromNDJsonFile, pipelineToNDJsonFile, NDJsonStats, streamToNDJsonFile, transformJsonParse, bufferReviver, transformToNDJson, transformMap, transformMapSync, transformMultiThreaded, BaseWorkerClass, tableDiff, inspectAny, inspectAnyStringifyFn, RequestError, TimeoutError, _chunkBuffer, Ajv, AjvSchema, AjvValidationError, readJsonSchemas, readAjvSchemas, runScript, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runScript = exports.
|
|
3
|
+
exports.runScript = exports.readAjvSchemas = exports.readJsonSchemas = exports.AjvValidationError = exports.AjvSchema = exports.Ajv = exports._chunkBuffer = exports.TimeoutError = exports.RequestError = exports.inspectAnyStringifyFn = exports.inspectAny = exports.tableDiff = exports.BaseWorkerClass = exports.transformMultiThreaded = exports.transformMapSync = exports.transformMap = exports.transformToNDJson = exports.bufferReviver = exports.transformJsonParse = exports.streamToNDJsonFile = exports.NDJsonStats = exports.pipelineToNDJsonFile = exports.pipelineFromNDJsonFile = exports.ndjsonStreamForEach = exports.slackDefaultMessagePrefixHook = exports.SlackService = exports.Debug = exports.LRUMemoCache = exports.Joi = exports.convert = exports.undefinedIfInvalid = exports.isValid = exports.getValidationResult = exports.validate = exports.JoiValidationError = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ajv_1 = require("ajv");
|
|
6
6
|
exports.Ajv = ajv_1.default;
|
|
@@ -96,7 +96,5 @@ Object.defineProperty(exports, "getValidationResult", { enumerable: true, get: f
|
|
|
96
96
|
Object.defineProperty(exports, "isValid", { enumerable: true, get: function () { return joi_validation_util_1.isValid; } });
|
|
97
97
|
Object.defineProperty(exports, "undefinedIfInvalid", { enumerable: true, get: function () { return joi_validation_util_1.undefinedIfInvalid; } });
|
|
98
98
|
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return joi_validation_util_1.validate; } });
|
|
99
|
-
const sanitize_util_1 = require("./validation/sanitize.util");
|
|
100
|
-
Object.defineProperty(exports, "sanitizeHTML", { enumerable: true, get: function () { return sanitize_util_1.sanitizeHTML; } });
|
|
101
99
|
const script_1 = require("./script");
|
|
102
100
|
Object.defineProperty(exports, "runScript", { enumerable: true, get: function () { return script_1.runScript; } });
|
|
@@ -3,18 +3,9 @@ import * as Joi from 'joi';
|
|
|
3
3
|
import { AnySchemaTyped } from './joi.model';
|
|
4
4
|
export interface ExtendedStringSchema extends StringSchema, AnySchemaTyped<string> {
|
|
5
5
|
dateString(min?: string, max?: string): this;
|
|
6
|
-
stripHTML(opt?: JoiStripHTMLOptions): this;
|
|
7
6
|
}
|
|
8
7
|
export interface JoiDateStringOptions {
|
|
9
8
|
min?: string;
|
|
10
9
|
max?: string;
|
|
11
10
|
}
|
|
12
|
-
export interface JoiStripHTMLOptions {
|
|
13
|
-
/**
|
|
14
|
-
* 'Strict' would throw an error if it detects any HTML.
|
|
15
|
-
* Non-strict (default) does not error, but DOES convert the string to the string without HTML.
|
|
16
|
-
* Internally uses `sanitize-html` library, with allowedTags = [], and method = 'discard'.
|
|
17
|
-
*/
|
|
18
|
-
strict?: boolean;
|
|
19
|
-
}
|
|
20
11
|
export declare function stringExtensions(joi: typeof Joi): Extension;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringExtensions = void 0;
|
|
4
4
|
const time_lib_1 = require("@naturalcycles/time-lib");
|
|
5
|
-
const sanitize = require("sanitize-html");
|
|
6
5
|
function stringExtensions(joi) {
|
|
7
6
|
return {
|
|
8
7
|
type: 'string',
|
|
@@ -68,39 +67,6 @@ function stringExtensions(joi) {
|
|
|
68
67
|
return v; // validation passed
|
|
69
68
|
},
|
|
70
69
|
},
|
|
71
|
-
stripHTML: {
|
|
72
|
-
method(opt) {
|
|
73
|
-
return this.$_addRule({
|
|
74
|
-
name: 'stripHTML',
|
|
75
|
-
args: {
|
|
76
|
-
strict: false,
|
|
77
|
-
...opt,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
args: [
|
|
82
|
-
{
|
|
83
|
-
name: 'strict',
|
|
84
|
-
ref: true,
|
|
85
|
-
assert: v => typeof v === 'boolean',
|
|
86
|
-
message: 'must be a boolean',
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
validate(v, helpers, args) {
|
|
90
|
-
// console.log('!!! stripHTML', args, v)
|
|
91
|
-
const r = sanitize(v, {
|
|
92
|
-
allowedTags: [],
|
|
93
|
-
// disallowedTagsMode: 'discard' // discard is default
|
|
94
|
-
parser: {
|
|
95
|
-
decodeEntities: false, // prevent decoding/changing of &<>"'
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
if (args.strict && r !== v) {
|
|
99
|
-
return helpers.error('string.stripHTML', args);
|
|
100
|
-
}
|
|
101
|
-
return r; // return converted value (or the same, if there was nothing to sanitize)
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
70
|
},
|
|
105
71
|
};
|
|
106
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.63.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"docs-serve": "vuepress dev docs",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"@naturalcycles/js-lib": "^14.0.0",
|
|
18
18
|
"@naturalcycles/time-lib": "^3.0.1",
|
|
19
19
|
"@types/lru-cache": "^5.1.0",
|
|
20
|
-
"@types/sanitize-html": "^2.5.0",
|
|
21
20
|
"@types/through2-concurrent": "^2.0.0",
|
|
22
21
|
"ajv": "^8.6.2",
|
|
23
22
|
"ajv-formats": "^2.1.0",
|
|
@@ -27,23 +26,22 @@
|
|
|
27
26
|
"chalk": "^4.0.0",
|
|
28
27
|
"cp-file": "^9.0.0",
|
|
29
28
|
"debug": "^4.1.1",
|
|
30
|
-
"dotenv": "^
|
|
29
|
+
"dotenv": "^14.2.0",
|
|
31
30
|
"execa": "^5.0.0",
|
|
32
31
|
"fs-extra": "^10.0.0",
|
|
33
32
|
"globby": "^11.0.0",
|
|
34
33
|
"got": "^11.0.1",
|
|
35
|
-
"joi": "
|
|
34
|
+
"joi": "17.4.2",
|
|
36
35
|
"lru-cache": "^6.0.0",
|
|
37
36
|
"move-file": "^2.0.0",
|
|
38
37
|
"nanoid": "^3.0.0",
|
|
39
|
-
"sanitize-html": "^2.5.2",
|
|
40
38
|
"through2-concurrent": "^2.0.0",
|
|
41
39
|
"yargs": "^17.0.0"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
44
42
|
"@naturalcycles/bench-lib": "^1.0.7",
|
|
45
43
|
"@naturalcycles/dev-lib": "^12.0.0",
|
|
46
|
-
"@types/node": "^
|
|
44
|
+
"@types/node": "^17.0.0",
|
|
47
45
|
"@types/yargs": "^16.0.0",
|
|
48
46
|
"jest": "^27.0.1",
|
|
49
47
|
"nock": "^13.0.2",
|
package/src/got/getGot.ts
CHANGED
|
@@ -21,7 +21,7 @@ export function getGot(opt: GetGotOptions = {}): Got {
|
|
|
21
21
|
opt.logger ||= console
|
|
22
22
|
|
|
23
23
|
if (opt.debug) {
|
|
24
|
-
opt.logStart = opt.logFinished = opt.logResponse = true
|
|
24
|
+
opt.logStart = opt.logFinished = opt.logResponse = opt.logRequest = true
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
return got.extend({
|
|
@@ -153,6 +153,14 @@ function gotBeforeRequestHook(opt: GetGotOptions): BeforeRequestHook {
|
|
|
153
153
|
[' >>', options.method, shortUrl, retryCount && `(retry ${retryCount})`].join(' '),
|
|
154
154
|
)
|
|
155
155
|
}
|
|
156
|
+
|
|
157
|
+
if (opt.logRequest) {
|
|
158
|
+
const body = options.json || options.body
|
|
159
|
+
|
|
160
|
+
if (body) {
|
|
161
|
+
opt.logger!.log(body)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
156
164
|
}
|
|
157
165
|
}
|
|
158
166
|
|
package/src/got/got.model.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -107,7 +107,6 @@ import {
|
|
|
107
107
|
undefinedIfInvalid,
|
|
108
108
|
validate,
|
|
109
109
|
} from './validation/joi/joi.validation.util'
|
|
110
|
-
import { sanitizeHTML, SanitizeHTMLOptions } from './validation/sanitize.util'
|
|
111
110
|
import { runScript, RunScriptOptions } from './script'
|
|
112
111
|
|
|
113
112
|
export type {
|
|
@@ -156,7 +155,6 @@ export type {
|
|
|
156
155
|
AjvValidationOptions,
|
|
157
156
|
AjvSchemaCfg,
|
|
158
157
|
AjvValidationErrorData,
|
|
159
|
-
SanitizeHTMLOptions,
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
export {
|
|
@@ -194,6 +192,5 @@ export {
|
|
|
194
192
|
AjvValidationError,
|
|
195
193
|
readJsonSchemas,
|
|
196
194
|
readAjvSchemas,
|
|
197
|
-
sanitizeHTML,
|
|
198
195
|
runScript,
|
|
199
196
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { dayjs } from '@naturalcycles/time-lib'
|
|
2
2
|
import { Extension, StringSchema } from 'joi'
|
|
3
3
|
import * as Joi from 'joi'
|
|
4
|
-
import * as sanitize from 'sanitize-html'
|
|
5
4
|
import { AnySchemaTyped } from './joi.model'
|
|
6
5
|
|
|
7
6
|
export interface ExtendedStringSchema extends StringSchema, AnySchemaTyped<string> {
|
|
8
7
|
dateString(min?: string, max?: string): this
|
|
9
|
-
stripHTML(opt?: JoiStripHTMLOptions): this
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
export interface JoiDateStringOptions {
|
|
@@ -14,15 +12,6 @@ export interface JoiDateStringOptions {
|
|
|
14
12
|
max?: string
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
export interface JoiStripHTMLOptions {
|
|
18
|
-
/**
|
|
19
|
-
* 'Strict' would throw an error if it detects any HTML.
|
|
20
|
-
* Non-strict (default) does not error, but DOES convert the string to the string without HTML.
|
|
21
|
-
* Internally uses `sanitize-html` library, with allowedTags = [], and method = 'discard'.
|
|
22
|
-
*/
|
|
23
|
-
strict?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
15
|
export function stringExtensions(joi: typeof Joi): Extension {
|
|
27
16
|
return {
|
|
28
17
|
type: 'string',
|
|
@@ -90,42 +79,6 @@ export function stringExtensions(joi: typeof Joi): Extension {
|
|
|
90
79
|
return v // validation passed
|
|
91
80
|
},
|
|
92
81
|
},
|
|
93
|
-
stripHTML: {
|
|
94
|
-
method(opt?: JoiStripHTMLOptions) {
|
|
95
|
-
return this.$_addRule({
|
|
96
|
-
name: 'stripHTML',
|
|
97
|
-
args: {
|
|
98
|
-
strict: false,
|
|
99
|
-
...opt,
|
|
100
|
-
},
|
|
101
|
-
})
|
|
102
|
-
},
|
|
103
|
-
args: [
|
|
104
|
-
{
|
|
105
|
-
name: 'strict',
|
|
106
|
-
ref: true,
|
|
107
|
-
assert: v => typeof v === 'boolean',
|
|
108
|
-
message: 'must be a boolean',
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
validate(v: string, helpers, args: JoiStripHTMLOptions) {
|
|
112
|
-
// console.log('!!! stripHTML', args, v)
|
|
113
|
-
|
|
114
|
-
const r = sanitize(v, {
|
|
115
|
-
allowedTags: [], // no html tags allowed at all
|
|
116
|
-
// disallowedTagsMode: 'discard' // discard is default
|
|
117
|
-
parser: {
|
|
118
|
-
decodeEntities: false, // prevent decoding/changing of &<>"'
|
|
119
|
-
},
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
if (args.strict && r !== v) {
|
|
123
|
-
return helpers.error('string.stripHTML', args)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return r // return converted value (or the same, if there was nothing to sanitize)
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
82
|
},
|
|
130
83
|
}
|
|
131
84
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as sanitize from 'sanitize-html';
|
|
2
|
-
export declare type SanitizeHTMLOptions = sanitize.IOptions;
|
|
3
|
-
/**
|
|
4
|
-
* Simply a wrapper around `sanitize-html` library.
|
|
5
|
-
*
|
|
6
|
-
* @experimental
|
|
7
|
-
*/
|
|
8
|
-
export declare function sanitizeHTML(s: string, opt?: SanitizeHTMLOptions): string;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sanitizeHTML = void 0;
|
|
4
|
-
const sanitize = require("sanitize-html");
|
|
5
|
-
/**
|
|
6
|
-
* Simply a wrapper around `sanitize-html` library.
|
|
7
|
-
*
|
|
8
|
-
* @experimental
|
|
9
|
-
*/
|
|
10
|
-
function sanitizeHTML(s, opt) {
|
|
11
|
-
return sanitize(s, opt);
|
|
12
|
-
}
|
|
13
|
-
exports.sanitizeHTML = sanitizeHTML;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as sanitize from 'sanitize-html'
|
|
2
|
-
|
|
3
|
-
export type SanitizeHTMLOptions = sanitize.IOptions
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Simply a wrapper around `sanitize-html` library.
|
|
7
|
-
*
|
|
8
|
-
* @experimental
|
|
9
|
-
*/
|
|
10
|
-
export function sanitizeHTML(s: string, opt?: SanitizeHTMLOptions): string {
|
|
11
|
-
return sanitize(s, opt)
|
|
12
|
-
}
|