@mondart/nestjs-common-module-core 3.2.13 → 3.2.15

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.
@@ -4,4 +4,6 @@ export * from './is-not-empty-string.decorator';
4
4
  export * from './is-one-of-property.decorator';
5
5
  export * from './depend-on-property.decorator';
6
6
  export * from './sanitize-html.decorator';
7
+ export * from './sanitize-text.decorator';
8
+ export * from './sanitize-by.decorator';
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/decorators/validations/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/decorators/validations/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC"}
@@ -20,4 +20,6 @@ __exportStar(require("./is-not-empty-string.decorator"), exports);
20
20
  __exportStar(require("./is-one-of-property.decorator"), exports);
21
21
  __exportStar(require("./depend-on-property.decorator"), exports);
22
22
  __exportStar(require("./sanitize-html.decorator"), exports);
23
+ __exportStar(require("./sanitize-text.decorator"), exports);
24
+ __exportStar(require("./sanitize-by.decorator"), exports);
23
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/validations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,oDAAkC;AAClC,kEAAgD;AAChD,iEAA+C;AAC/C,iEAA+C;AAC/C,4DAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/validations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,oDAAkC;AAClC,kEAAgD;AAChD,iEAA+C;AAC/C,iEAA+C;AAC/C,4DAA0C;AAC1C,4DAA0C;AAC1C,0DAAwC"}
@@ -0,0 +1,4 @@
1
+ import type { IOptions } from 'sanitize-html';
2
+ export type SanitizeMode = 'html' | 'text';
3
+ export declare function SanitizeBy(mode: (obj: Record<string, any>) => SanitizeMode, htmlOptions?: IOptions): PropertyDecorator;
4
+ //# sourceMappingURL=sanitize-by.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-by.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/validations/sanitize-by.decorator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAO3C,wBAAgB,UAAU,CACxB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,YAAY,EAChD,WAAW,CAAC,EAAE,QAAQ,GACrB,iBAAiB,CAQnB"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SanitizeBy = SanitizeBy;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const helpers_1 = require("../../helpers");
6
+ function SanitizeBy(mode, htmlOptions) {
7
+ return (0, class_transformer_1.Transform)(({ value, obj }) => mode(obj ?? {}) === 'text'
8
+ ? (0, helpers_1.sanitizeText)(value)
9
+ : (0, helpers_1.sanitizeHtml)(value, htmlOptions), { toClassOnly: true });
10
+ }
11
+ //# sourceMappingURL=sanitize-by.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-by.decorator.js","sourceRoot":"","sources":["../../../src/decorators/validations/sanitize-by.decorator.ts"],"names":[],"mappings":";;AAWA,gCAWC;AAtBD,yDAA8C;AAE9C,2CAA2D;AAS3D,SAAgB,UAAU,CACxB,IAAgD,EAChD,WAAsB;IAEtB,OAAO,IAAA,6BAAS,EACd,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CACjB,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,MAAM;QACxB,CAAC,CAAC,IAAA,sBAAY,EAAC,KAAK,CAAC;QACrB,CAAC,CAAC,IAAA,sBAAY,EAAC,KAAK,EAAE,WAAW,CAAC,EACtC,EAAE,WAAW,EAAE,IAAI,EAAE,CACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function SanitizeText(): PropertyDecorator;
2
+ //# sourceMappingURL=sanitize-text.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-text.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/validations/sanitize-text.decorator.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,IAAI,iBAAiB,CAEhD"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SanitizeText = SanitizeText;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const helpers_1 = require("../../helpers");
6
+ function SanitizeText() {
7
+ return (0, class_transformer_1.Transform)(({ value }) => (0, helpers_1.sanitizeText)(value), { toClassOnly: true });
8
+ }
9
+ //# sourceMappingURL=sanitize-text.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-text.decorator.js","sourceRoot":"","sources":["../../../src/decorators/validations/sanitize-text.decorator.ts"],"names":[],"mappings":";;AAIA,oCAEC;AAND,yDAA8C;AAC9C,2CAA6C;AAG7C,SAAgB,YAAY;IAC1B,OAAO,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,IAAA,sBAAY,EAAC,KAAK,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9E,CAAC"}
@@ -1,3 +1,4 @@
1
1
  import sanitizeHtmlLib from 'sanitize-html';
2
2
  export declare function sanitizeHtml(value: unknown, options?: sanitizeHtmlLib.IOptions): unknown;
3
+ export declare function sanitizeText(value: unknown): unknown;
3
4
  //# sourceMappingURL=html-sanitizer.helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"html-sanitizer.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/html-sanitizer.helper.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,eAAe,CAAC;AAE5C,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,eAAe,CAAC,QAAQ,GACjC,OAAO,CAsBT"}
1
+ {"version":3,"file":"html-sanitizer.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/html-sanitizer.helper.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,eAAe,CAAC;AAE5C,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,eAAe,CAAC,QAAQ,GACjC,OAAO,CAsBT;AAmBD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAapD"}
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.sanitizeHtml = sanitizeHtml;
7
+ exports.sanitizeText = sanitizeText;
7
8
  const sanitize_html_1 = __importDefault(require("sanitize-html"));
8
9
  function sanitizeHtml(value, options) {
9
10
  if (typeof value !== 'string')
@@ -28,4 +29,24 @@ function sanitizeHtml(value, options) {
28
29
  ...options,
29
30
  }).trim();
30
31
  }
32
+ const TEXT_ENTITIES = {
33
+ '&amp;': '&',
34
+ '&lt;': '<',
35
+ '&gt;': '>',
36
+ '&quot;': '"',
37
+ '&#39;': "'",
38
+ };
39
+ const decodeTextEntities = (text) => text.replace(/&(?:amp|lt|gt|quot|#39);/g, (entity) => TEXT_ENTITIES[entity]);
40
+ function sanitizeText(value) {
41
+ if (typeof value !== 'string')
42
+ return value;
43
+ let text = value;
44
+ for (let pass = 0; pass < 5; pass++) {
45
+ const next = decodeTextEntities((0, sanitize_html_1.default)(text, { allowedTags: [], allowedAttributes: {} }));
46
+ if (next === text)
47
+ break;
48
+ text = next;
49
+ }
50
+ return text.trim();
51
+ }
31
52
  //# sourceMappingURL=html-sanitizer.helper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"html-sanitizer.helper.js","sourceRoot":"","sources":["../../src/helpers/html-sanitizer.helper.ts"],"names":[],"mappings":";;;;;AAEA,oCAyBC;AA3BD,kEAA4C;AAE5C,SAAgB,YAAY,CAC1B,KAAc,EACd,OAAkC;IAElC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5C,OAAO,IAAA,uBAAe,EAAC,KAAK,EAAE;QAC5B,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC;QACzE,iBAAiB,EAAE;YACjB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC;SACtC;QACD,cAAc,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC;QAC3C,qBAAqB,EAAE,KAAK;QAC5B,mBAAmB,EAAE,IAAI;QACzB,aAAa,EAAE;YACb,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;gBACzB,OAAO,EAAE,GAAG;gBACZ,OAAO,EAAE;oBACP,GAAG,OAAO;oBACV,GAAG,EAAE,8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AAO,CAAC,2BAA2B,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AAQ/E,SAAgB,YAAY,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5C,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,kBAAkB,CAC7B,IAAA,uBAAe,EAAC,IAAI,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAClE,CAAC;QACF,IAAI,IAAI,KAAK,IAAI;YAAE,MAAM;QACzB,IAAI,GAAG,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;AACrB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mondart/nestjs-common-module-core",
3
- "version": "3.2.13",
3
+ "version": "3.2.15",
4
4
  "description": "Core utilities, DTOs, decorators, entities, filters, validators and helpers for NestJS.",
5
5
  "author": {
6
6
  "name": "Mondart"