@naturalcycles/nodejs-lib 12.61.0 → 12.63.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/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/util/zip.util.d.ts +9 -9
- package/dist/util/zip.util.js +21 -23
- 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/util/zip.util.ts +19 -21
- 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; } });
|
package/dist/util/zip.util.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ZlibOptions } from 'zlib';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* deflateBuffer uses `deflate`.
|
|
5
5
|
* It's 9 bytes shorter than `gzip`.
|
|
6
6
|
*/
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function deflateBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
|
|
8
|
+
export declare function inflateBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
|
|
9
|
+
/**
|
|
10
|
+
* deflateString uses `deflate`.
|
|
11
|
+
* It's 9 bytes shorter than `gzip`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function deflateString(s: string, options?: ZlibOptions): Promise<Buffer>;
|
|
14
|
+
export declare function inflateToString(buf: Buffer, options?: ZlibOptions): Promise<string>;
|
|
8
15
|
/**
|
|
9
16
|
* gzipBuffer uses `gzip`
|
|
10
17
|
* It's 9 bytes longer than `deflate`.
|
|
11
18
|
*/
|
|
12
19
|
export declare function gzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
|
|
13
|
-
export declare function unzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
|
|
14
20
|
export declare function gunzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
|
|
15
|
-
/**
|
|
16
|
-
* zipString uses `deflate`.
|
|
17
|
-
* It's 9 bytes shorter than `gzip`.
|
|
18
|
-
*/
|
|
19
|
-
export declare function zipString(s: string, options?: ZlibOptions): Promise<Buffer>;
|
|
20
21
|
/**
|
|
21
22
|
* gzipString uses `gzip`.
|
|
22
23
|
* It's 9 bytes longer than `deflate`.
|
|
23
24
|
*/
|
|
24
25
|
export declare function gzipString(s: string, options?: ZlibOptions): Promise<Buffer>;
|
|
25
|
-
export declare function unzipToString(buf: Buffer, options?: ZlibOptions): Promise<string>;
|
|
26
26
|
export declare function gunzipToString(buf: Buffer, options?: ZlibOptions): Promise<string>;
|
package/dist/util/zip.util.js
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gunzipToString = exports.
|
|
3
|
+
exports.gunzipToString = exports.gzipString = exports.gunzipBuffer = exports.gzipBuffer = exports.inflateToString = exports.deflateString = exports.inflateBuffer = exports.deflateBuffer = void 0;
|
|
4
4
|
const util_1 = require("util");
|
|
5
5
|
const zlib = require("zlib");
|
|
6
6
|
const deflate = (0, util_1.promisify)(zlib.deflate.bind(zlib));
|
|
7
7
|
const inflate = (0, util_1.promisify)(zlib.inflate.bind(zlib));
|
|
8
8
|
const gzip = (0, util_1.promisify)(zlib.gzip.bind(zlib));
|
|
9
9
|
const gunzip = (0, util_1.promisify)(zlib.gunzip.bind(zlib));
|
|
10
|
-
// string >
|
|
10
|
+
// string > compressed buffer
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* deflateBuffer uses `deflate`.
|
|
13
13
|
* It's 9 bytes shorter than `gzip`.
|
|
14
14
|
*/
|
|
15
|
-
async function
|
|
15
|
+
async function deflateBuffer(buf, options = {}) {
|
|
16
16
|
return await deflate(buf, options);
|
|
17
17
|
}
|
|
18
|
-
exports.
|
|
18
|
+
exports.deflateBuffer = deflateBuffer;
|
|
19
|
+
async function inflateBuffer(buf, options = {}) {
|
|
20
|
+
return await inflate(buf, options);
|
|
21
|
+
}
|
|
22
|
+
exports.inflateBuffer = inflateBuffer;
|
|
23
|
+
/**
|
|
24
|
+
* deflateString uses `deflate`.
|
|
25
|
+
* It's 9 bytes shorter than `gzip`.
|
|
26
|
+
*/
|
|
27
|
+
async function deflateString(s, options) {
|
|
28
|
+
return await deflateBuffer(Buffer.from(s), options);
|
|
29
|
+
}
|
|
30
|
+
exports.deflateString = deflateString;
|
|
31
|
+
async function inflateToString(buf, options) {
|
|
32
|
+
return (await inflateBuffer(buf, options)).toString();
|
|
33
|
+
}
|
|
34
|
+
exports.inflateToString = inflateToString;
|
|
19
35
|
/**
|
|
20
36
|
* gzipBuffer uses `gzip`
|
|
21
37
|
* It's 9 bytes longer than `deflate`.
|
|
@@ -24,23 +40,10 @@ async function gzipBuffer(buf, options = {}) {
|
|
|
24
40
|
return await gzip(buf, options);
|
|
25
41
|
}
|
|
26
42
|
exports.gzipBuffer = gzipBuffer;
|
|
27
|
-
// zip > buffer
|
|
28
|
-
async function unzipBuffer(buf, options = {}) {
|
|
29
|
-
return await inflate(buf, options);
|
|
30
|
-
}
|
|
31
|
-
exports.unzipBuffer = unzipBuffer;
|
|
32
43
|
async function gunzipBuffer(buf, options = {}) {
|
|
33
44
|
return await gunzip(buf, options);
|
|
34
45
|
}
|
|
35
46
|
exports.gunzipBuffer = gunzipBuffer;
|
|
36
|
-
/**
|
|
37
|
-
* zipString uses `deflate`.
|
|
38
|
-
* It's 9 bytes shorter than `gzip`.
|
|
39
|
-
*/
|
|
40
|
-
async function zipString(s, options) {
|
|
41
|
-
return await zipBuffer(Buffer.from(s), options);
|
|
42
|
-
}
|
|
43
|
-
exports.zipString = zipString;
|
|
44
47
|
/**
|
|
45
48
|
* gzipString uses `gzip`.
|
|
46
49
|
* It's 9 bytes longer than `deflate`.
|
|
@@ -49,11 +52,6 @@ async function gzipString(s, options) {
|
|
|
49
52
|
return await gzipBuffer(Buffer.from(s), options);
|
|
50
53
|
}
|
|
51
54
|
exports.gzipString = gzipString;
|
|
52
|
-
// convenience
|
|
53
|
-
async function unzipToString(buf, options) {
|
|
54
|
-
return (await unzipBuffer(buf, options)).toString();
|
|
55
|
-
}
|
|
56
|
-
exports.unzipToString = unzipToString;
|
|
57
55
|
async function gunzipToString(buf, options) {
|
|
58
56
|
return (await gunzipBuffer(buf, options)).toString();
|
|
59
57
|
}
|
|
@@ -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.0",
|
|
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": "^11.0.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
|
}
|
package/src/util/zip.util.ts
CHANGED
|
@@ -7,16 +7,32 @@ const inflate = promisify(zlib.inflate.bind(zlib))
|
|
|
7
7
|
const gzip = promisify(zlib.gzip.bind(zlib))
|
|
8
8
|
const gunzip = promisify(zlib.gunzip.bind(zlib))
|
|
9
9
|
|
|
10
|
-
// string >
|
|
10
|
+
// string > compressed buffer
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* deflateBuffer uses `deflate`.
|
|
14
14
|
* It's 9 bytes shorter than `gzip`.
|
|
15
15
|
*/
|
|
16
|
-
export async function
|
|
16
|
+
export async function deflateBuffer(buf: Buffer, options: ZlibOptions = {}): Promise<Buffer> {
|
|
17
17
|
return await deflate(buf, options)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export async function inflateBuffer(buf: Buffer, options: ZlibOptions = {}): Promise<Buffer> {
|
|
21
|
+
return await inflate(buf, options)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* deflateString uses `deflate`.
|
|
26
|
+
* It's 9 bytes shorter than `gzip`.
|
|
27
|
+
*/
|
|
28
|
+
export async function deflateString(s: string, options?: ZlibOptions): Promise<Buffer> {
|
|
29
|
+
return await deflateBuffer(Buffer.from(s), options)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function inflateToString(buf: Buffer, options?: ZlibOptions): Promise<string> {
|
|
33
|
+
return (await inflateBuffer(buf, options)).toString()
|
|
34
|
+
}
|
|
35
|
+
|
|
20
36
|
/**
|
|
21
37
|
* gzipBuffer uses `gzip`
|
|
22
38
|
* It's 9 bytes longer than `deflate`.
|
|
@@ -25,23 +41,10 @@ export async function gzipBuffer(buf: Buffer, options: ZlibOptions = {}): Promis
|
|
|
25
41
|
return await gzip(buf, options)
|
|
26
42
|
}
|
|
27
43
|
|
|
28
|
-
// zip > buffer
|
|
29
|
-
export async function unzipBuffer(buf: Buffer, options: ZlibOptions = {}): Promise<Buffer> {
|
|
30
|
-
return await inflate(buf, options)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
44
|
export async function gunzipBuffer(buf: Buffer, options: ZlibOptions = {}): Promise<Buffer> {
|
|
34
45
|
return await gunzip(buf, options)
|
|
35
46
|
}
|
|
36
47
|
|
|
37
|
-
/**
|
|
38
|
-
* zipString uses `deflate`.
|
|
39
|
-
* It's 9 bytes shorter than `gzip`.
|
|
40
|
-
*/
|
|
41
|
-
export async function zipString(s: string, options?: ZlibOptions): Promise<Buffer> {
|
|
42
|
-
return await zipBuffer(Buffer.from(s), options)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
48
|
/**
|
|
46
49
|
* gzipString uses `gzip`.
|
|
47
50
|
* It's 9 bytes longer than `deflate`.
|
|
@@ -50,11 +53,6 @@ export async function gzipString(s: string, options?: ZlibOptions): Promise<Buff
|
|
|
50
53
|
return await gzipBuffer(Buffer.from(s), options)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
// convenience
|
|
54
|
-
export async function unzipToString(buf: Buffer, options?: ZlibOptions): Promise<string> {
|
|
55
|
-
return (await unzipBuffer(buf, options)).toString()
|
|
56
|
-
}
|
|
57
|
-
|
|
58
56
|
export async function gunzipToString(buf: Buffer, options?: ZlibOptions): Promise<string> {
|
|
59
57
|
return (await gunzipBuffer(buf, options)).toString()
|
|
60
58
|
}
|
|
@@ -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
|
-
}
|