@cryptexlabs/codex-nodejs-common 0.2.2 → 0.2.3
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 +1 -1
- package/lib/src/pipe/uuidv4.array.validation.pipe.d.ts +6 -0
- package/lib/src/pipe/uuidv4.array.validation.pipe.js +32 -0
- package/lib/src/pipe/uuidv4.array.validation.pipe.js.map +1 -0
- package/lib/src/util/string.util.d.ts +5 -4
- package/lib/src/util/string.util.js +3 -0
- package/lib/src/util/string.util.js.map +1 -1
- package/package.json +1 -1
- package/src/pipe/uuidv4.array.validation.pipe.ts +23 -0
- package/src/util/string.util.ts +8 -4
package/lib/package.json
CHANGED
|
@@ -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.Uuidv4ArrayValidationPipe = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const Joi = require("joi");
|
|
15
|
+
let Uuidv4ArrayValidationPipe = class Uuidv4ArrayValidationPipe {
|
|
16
|
+
constructor() {
|
|
17
|
+
this._schema = Joi.array().items(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
|
+
Uuidv4ArrayValidationPipe = __decorate([
|
|
28
|
+
common_1.Injectable(),
|
|
29
|
+
__metadata("design:paramtypes", [])
|
|
30
|
+
], Uuidv4ArrayValidationPipe);
|
|
31
|
+
exports.Uuidv4ArrayValidationPipe = Uuidv4ArrayValidationPipe;
|
|
32
|
+
//# sourceMappingURL=uuidv4.array.validation.pipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuidv4.array.validation.pipe.js","sourceRoot":"","sources":["../../../src/pipe/uuidv4.array.validation.pipe.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,2BAA2B;AAG3B,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAEpC;QACE,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC7E,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,yBAAyB;IADrC,mBAAU,EAAE;;GACA,yBAAyB,CAarC;AAbY,8DAAyB"}
|
|
@@ -2,8 +2,9 @@ export declare class StringUtil {
|
|
|
2
2
|
private constructor();
|
|
3
3
|
static isRegexString(str: string): boolean;
|
|
4
4
|
static stringMatches(test: string, str: string): boolean;
|
|
5
|
-
static insecureMd5(str:
|
|
6
|
-
static insecureSha1(str:
|
|
7
|
-
static sha256(str:
|
|
8
|
-
static sha512(str:
|
|
5
|
+
static insecureMd5(str: string): string;
|
|
6
|
+
static insecureSha1(str: string): string;
|
|
7
|
+
static sha256(str: string): string;
|
|
8
|
+
static sha512(str: string): string;
|
|
9
|
+
static byteArray(str: string): number[];
|
|
9
10
|
}
|
|
@@ -32,6 +32,9 @@ class StringUtil {
|
|
|
32
32
|
static sha512(str) {
|
|
33
33
|
return crypto.createHash("sha512").update(str).digest("hex");
|
|
34
34
|
}
|
|
35
|
+
static byteArray(str) {
|
|
36
|
+
return [...Buffer.from(str)];
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
39
|
exports.StringUtil = StringUtil;
|
|
37
40
|
//# sourceMappingURL=string.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.util.js","sourceRoot":"","sources":["../../../src/util/string.util.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,MAAa,UAAU;IACrB,gBAAuB,CAAC;IACjB,MAAM,CAAC,aAAa,CAAC,GAAW;QACrC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC;IAC3E,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,IAAY,EAAE,GAAW;QACnD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAChC,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,IAAI,EAAE,EAAE;YAC9B,OAAO,IAAI,CAAC;SACb;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,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,GAAW;QACpC,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,GAAW;QAC9B,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,GAAW;QAC9B,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,GAAW;QACjC,OAAO,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,CAAC;CACF;AA3CD,gCA2CC"}
|
package/package.json
CHANGED
|
@@ -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 Uuidv4ArrayValidationPipe implements PipeTransform {
|
|
11
|
+
private _schema: Joi.ArraySchema;
|
|
12
|
+
constructor() {
|
|
13
|
+
this._schema = Joi.array().items(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
|
+
}
|
package/src/util/string.util.ts
CHANGED
|
@@ -23,19 +23,23 @@ export class StringUtil {
|
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public static insecureMd5(str) {
|
|
26
|
+
public static insecureMd5(str: string) {
|
|
27
27
|
return crypto.createHash("md5").update(str).digest("hex");
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
public static insecureSha1(str) {
|
|
30
|
+
public static insecureSha1(str: string) {
|
|
31
31
|
return crypto.createHash("sha1").update(str).digest("hex");
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
public static sha256(str) {
|
|
34
|
+
public static sha256(str: string) {
|
|
35
35
|
return crypto.createHash("sha256").update(str).digest("hex");
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
public static sha512(str) {
|
|
38
|
+
public static sha512(str: string) {
|
|
39
39
|
return crypto.createHash("sha512").update(str).digest("hex");
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
public static byteArray(str: string): number[] {
|
|
43
|
+
return [...Buffer.from(str)];
|
|
44
|
+
}
|
|
41
45
|
}
|