@cryptexlabs/codex-nodejs-common 0.2.3 → 0.2.4

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/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptexlabs/codex-nodejs-common",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Common code for Assistant applications",
5
5
  "main": "lib/src/index.js",
6
6
  "repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
@@ -0,0 +1,6 @@
1
+ import { ArgumentMetadata, PipeTransform } from "@nestjs/common";
2
+ export declare class Uuidv4ValidationPipe implements PipeTransform {
3
+ private _schema;
4
+ constructor();
5
+ transform(value: any, metadata: ArgumentMetadata): any;
6
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Uuidv4ValidationPipe = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const Joi = require("joi");
15
+ let Uuidv4ValidationPipe = class Uuidv4ValidationPipe {
16
+ constructor() {
17
+ this._schema = Joi.string().uuid({ version: "uuidv4" });
18
+ }
19
+ transform(value, metadata) {
20
+ const { error } = this._schema.validate(value.data);
21
+ if (error) {
22
+ throw new common_1.BadRequestException(error.message);
23
+ }
24
+ return value;
25
+ }
26
+ };
27
+ Uuidv4ValidationPipe = __decorate([
28
+ common_1.Injectable(),
29
+ __metadata("design:paramtypes", [])
30
+ ], Uuidv4ValidationPipe);
31
+ exports.Uuidv4ValidationPipe = Uuidv4ValidationPipe;
32
+ //# sourceMappingURL=uuidv4.validation.pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuidv4.validation.pipe.js","sourceRoot":"","sources":["../../../src/pipe/uuidv4.validation.pipe.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,2BAA2B;AAG3B,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAE/B;QACE,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;IAEM,SAAS,CAAC,KAAU,EAAE,QAA0B;QACrD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,KAAK,EAAE;YACT,MAAM,IAAI,4BAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SAC9C;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAbY,oBAAoB;IADhC,mBAAU,EAAE;;GACA,oBAAoB,CAahC;AAbY,oDAAoB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptexlabs/codex-nodejs-common",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Common code for Assistant applications",
5
5
  "main": "lib/src/index.js",
6
6
  "repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
@@ -0,0 +1,23 @@
1
+ import {
2
+ ArgumentMetadata,
3
+ BadRequestException,
4
+ Injectable,
5
+ PipeTransform,
6
+ } from "@nestjs/common";
7
+ import * as Joi from "joi";
8
+
9
+ @Injectable()
10
+ export class Uuidv4ValidationPipe implements PipeTransform {
11
+ private _schema: Joi.Schema;
12
+ constructor() {
13
+ this._schema = Joi.string().uuid({ version: "uuidv4" });
14
+ }
15
+
16
+ public transform(value: any, metadata: ArgumentMetadata): any {
17
+ const { error } = this._schema.validate(value.data);
18
+ if (error) {
19
+ throw new BadRequestException(error.message);
20
+ }
21
+ return value;
22
+ }
23
+ }