Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@men-mvc/foundation

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@men-mvc/foundation - npm Package Compare versions

Comparing version 0.89.0 to 0.90.0

12

lib/utilities/validation.d.ts

@@ -9,15 +9,3 @@ import { ExternalHelpers } from 'joi';

export declare const failValidationForField: (field: string, errorMessage: string) => never;
/**
* This function can be used to validate both multiple-file upload and single upload
*/
export declare const validateFile: <T>(value: T | null, field: string, message?: string) => void;
/**
* This function can be used to validate both multiple-file upload and single upload
*/
export declare const validateImage: <T>(value: T | null, field: string, message?: string) => void;
/**
* This function can be used to validate both multiple-file upload and single upload
*/
export declare const validateFileExtension: (value: unknown, field: string, allowedExtensions: string[], message?: string) => void;
export declare function ValidateRequest(schemaOrValidator: joi.ObjectSchema | RequestValidator): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
export declare const ValidateRequestAsync: (schemaOrValidator: joi.ObjectSchema | RequestValidator) => (scope: unknown, methodName: string, descriptor: PropertyDescriptor) => void;

97

lib/utilities/validation.js

@@ -6,6 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidateRequestAsync = exports.ValidateRequest = exports.validateFileExtension = exports.validateImage = exports.validateFile = exports.failValidationForField = exports.validateRequestAsync = exports.validateRequest = exports.resolveValidationError = exports.getValidatedFieldName = void 0;
const path_1 = __importDefault(require("path"));
exports.ValidateRequestAsync = exports.ValidateRequest = exports.failValidationForField = exports.validateRequestAsync = exports.validateRequest = exports.resolveValidationError = exports.getValidatedFieldName = void 0;
const joi_1 = __importDefault(require("joi"));
const config_1 = require("@men-mvc/config");
const types_1 = require("../types");

@@ -61,95 +59,2 @@ const response_1 = require("./response");

exports.failValidationForField = failValidationForField;
const isUploadedFile = (value) => value instanceof types_1.UploadedFile;
const isImageFile = (file) => {
let imageMimeTypes = ['image/gif', 'image/jpeg', 'image/png'];
const additionalImageMimesCsv = (0, config_1.getEnvVariable)('UPLOADED_FILE_IMAGE_MIMES', '');
if (additionalImageMimesCsv) {
const additionalMimes = additionalImageMimesCsv
.split(',')
.map((mime) => mime.toLowerCase());
imageMimeTypes = imageMimeTypes.concat(additionalMimes);
}
return imageMimeTypes.includes(file.mimetype.toLowerCase());
};
const validateImageFile = (field, value, error) => {
if (!isUploadedFile(value)) {
// input value is not a file
return (0, exports.failValidationForField)(field, error);
}
if (!isImageFile(value)) {
(0, exports.failValidationForField)(field, error);
}
};
/**
* This function can be used to validate both multiple-file upload and single upload
*/
const validateFile = (value, field, message) => {
const error = message ?? `Input value(s) must be file(s).`;
if (!value) {
// if the value is empty, it does not validate if the input is file or not
return;
}
if (Array.isArray(value)) {
const values = value;
for (let element of values) {
if (!isUploadedFile(element)) {
(0, exports.failValidationForField)(field, error);
}
}
}
else if (!isUploadedFile(value)) {
// single file upload
(0, exports.failValidationForField)(field, error);
}
};
exports.validateFile = validateFile;
/**
* This function can be used to validate both multiple-file upload and single upload
*/
const validateImage = (value, field, message) => {
const error = message ?? `Invalid image file(s).`;
if (!value) {
// when the input field is empty, it will pass.
return;
}
if (Array.isArray(value)) {
// multiple files
value.map((file) => validateImageFile(field, file, error));
}
else {
validateImageFile(field, value, error);
}
};
exports.validateImage = validateImage;
/**
* This function can be used to validate both multiple-file upload and single upload
*/
const validateFileExtension = (value, field, allowedExtensions, // including .
message) => {
if (!value) {
return;
}
if (allowedExtensions.length < 1) {
return;
}
const error = message ?? `File does not have the valid extension.`;
const validate = (singleVal) => {
if (!isUploadedFile(singleVal)) {
return false;
}
return allowedExtensions.some((ext) => ext.toLowerCase() ===
path_1.default.extname(singleVal.originalFilename).toLowerCase());
};
if (Array.isArray(value)) {
for (let file of value) {
if (!validate(file)) {
(0, exports.failValidationForField)(field, error);
}
}
}
else if (!validate(value)) {
(0, exports.failValidationForField)(field, error);
}
};
exports.validateFileExtension = validateFileExtension;
function ValidateRequest(schemaOrValidator) {

@@ -156,0 +61,0 @@ return (target, propertyKey, descriptor) => {

6

package.json
{
"name": "@men-mvc/foundation",
"version": "0.89.0",
"version": "0.90.0",
"description": "Package that includes shared variables, types and utility functions for MEN MVC framework.",

@@ -30,3 +30,3 @@ "private": false,

"dependencies": {
"@men-mvc/config": "^0.89.0",
"@men-mvc/config": "^0.90.0",
"express": "^4.18.2",

@@ -53,3 +53,3 @@ "joi": "^17.9.1",

"license": "MIT",
"gitHead": "26321add5f585cbfa2adaa71c7342faad8a90e3e"
"gitHead": "adb48a3b3865311505b6fb60dbc84e10c09089c7"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc