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

nestjs-form-data

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-form-data - npm Package Compare versions

Comparing version 1.9.1 to 1.9.2

6

dist/classes/FormReader.js

@@ -18,3 +18,3 @@ "use strict";

this.files = [];
this.busboy = busboy_1.default({
this.busboy = (0, busboy_1.default)({
headers: req.headers,

@@ -43,3 +43,3 @@ limits: (config && config.limits) ? config.limits : {},

proceedField(fieldName, value, fieldNameTruncated, valueTruncated) {
node_append_field_1.default(this.result, fieldName, value);
(0, node_append_field_1.default)(this.result, fieldName, value);
}

@@ -59,3 +59,3 @@ proceedFile(fieldName, fileStream, info) {

this.files.push(f);
node_append_field_1.default(this.result, fieldName, f);
(0, node_append_field_1.default)(this.result, fieldName, f);
}

@@ -62,0 +62,0 @@ }).catch(err => {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -42,3 +46,3 @@ if (k2 === undefined) k2 = k;

outStream.on('finish', () => {
const file = class_transformer_1.plainToClass(FileSystemStoredFile, {
const file = (0, class_transformer_1.plainToClass)(FileSystemStoredFile, {
originalName: busboyFileMeta.originalName,

@@ -57,3 +61,3 @@ encoding: busboyFileMeta.encoding,

const parsed = path_1.default.parse(originalName);
return `${parsed.name}-${uid_1.uid(6)}${parsed.ext}`;
return `${parsed.name}-${(0, uid_1.uid)(6)}${parsed.ext}`;
}

@@ -60,0 +64,0 @@ delete() {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

/// <reference types="node" />
/// <reference types="node" />
import { StoredFile } from './StoredFile';

@@ -3,0 +4,0 @@ import { FormDataInterceptorConfig } from '../../interfaces/FormDataInterceptorConfig';

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

return new Promise((res, rej) => {
stream.pipe(concat_stream_1.default({ encoding: 'buffer' }, (buffer) => {
const file = class_transformer_1.plainToClass(MemoryStoredFile, {
stream.pipe((0, concat_stream_1.default)({ encoding: 'buffer' }, (buffer) => {
const file = (0, class_transformer_1.plainToClass)(MemoryStoredFile, {
originalName: busboyFileMeta.originalName,

@@ -17,0 +17,0 @@ encoding: busboyFileMeta.encoding,

@@ -8,5 +8,5 @@ "use strict";

function FormDataRequest(config) {
return common_1.applyDecorators(common_1.SetMetadata(exports.FORM_DATA_REQUEST_METADATA_KEY, config), common_1.UseInterceptors(FormData_interceptor_1.FormDataInterceptor));
return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(exports.FORM_DATA_REQUEST_METADATA_KEY, config), (0, common_1.UseInterceptors)(FormData_interceptor_1.FormDataInterceptor));
}
exports.FormDataRequest = FormDataRequest;
//# sourceMappingURL=form-data.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -8,3 +8,3 @@ "use strict";

function HasExtension(allowedExtensions, strictSource, validationOptions) {
return class_validator_1.ValidateBy({
return (0, class_validator_1.ValidateBy)({
name: 'HasExtension',

@@ -14,7 +14,7 @@ constraints: [allowedExtensions, strictSource],

validate(value, args) {
const allowedExtensions = toArray_1.toArray(args.constraints[0]);
const allowedExtensions = (0, toArray_1.toArray)(args.constraints[0]);
const strictSource = (typeof args.constraints[1] === 'string')
? args.constraints[1]
: undefined;
if (is_file_validator_1.isFile(value)) {
if ((0, is_file_validator_1.isFile)(value)) {
const ext = value.extensionWithSource;

@@ -26,3 +26,3 @@ return allowedExtensions.includes(ext.value) && (!strictSource || strictSource === ext.source);

defaultMessage(validationArguments) {
const allowedExtensions = toArray_1.toArray(validationArguments.constraints[0]);
const allowedExtensions = (0, toArray_1.toArray)(validationArguments.constraints[0]);
return `File must be of one of the extensions ${allowedExtensions.join(', ')}`;

@@ -29,0 +29,0 @@ },

@@ -8,3 +8,3 @@ "use strict";

function HasMimeType(allowedMimeTypes, strictSource, validationOptions) {
return class_validator_1.ValidateBy({
return (0, class_validator_1.ValidateBy)({
name: 'HasMimeType',

@@ -14,7 +14,7 @@ constraints: [allowedMimeTypes],

validate(value, args) {
const allowedMimeTypes = toArray_1.toArray(args.constraints[0]) || [];
const allowedMimeTypes = (0, toArray_1.toArray)(args.constraints[0]) || [];
const strictSource = (typeof args.constraints[1] === 'string')
? args.constraints[1]
: undefined;
if (is_file_validator_1.isFile(value)) {
if ((0, is_file_validator_1.isFile)(value)) {
const mimeWithSource = value.mimeTypeWithSource;

@@ -26,3 +26,3 @@ return allowedMimeTypes.includes(mimeWithSource.value) && (!strictSource || strictSource === mimeWithSource.source);

defaultMessage(validationArguments) {
const allowedMimeTypes = toArray_1.toArray(validationArguments.constraints[0]) || [];
const allowedMimeTypes = (0, toArray_1.toArray)(validationArguments.constraints[0]) || [];
return `File must be of one of the types ${allowedMimeTypes.join(', ')}`;

@@ -29,0 +29,0 @@ },

@@ -13,3 +13,3 @@ "use strict";

function IsFile(validationOptions) {
const isFileValidator = class_validator_1.ValidateBy({
const isFileValidator = (0, class_validator_1.ValidateBy)({
name: 'IsFile',

@@ -27,3 +27,3 @@ constraints: [],

if (validationOptions === null || validationOptions === void 0 ? void 0 : validationOptions.each) {
return common_1.applyDecorators(class_transformer_1.Transform((params) => {
return (0, common_1.applyDecorators)((0, class_transformer_1.Transform)((params) => {
if (!Array.isArray(params.value)) {

@@ -33,3 +33,3 @@ return [params.value];

return params.value;
}), isFileValidator, class_validator_1.IsArray(Object.assign({}, validationOptions || {}, { each: false })));
}), isFileValidator, (0, class_validator_1.IsArray)(Object.assign({}, validationOptions || {}, { each: false })));
}

@@ -36,0 +36,0 @@ return isFileValidator;

@@ -7,5 +7,5 @@ "use strict";

function IsFiles(validationOptions) {
return common_1.applyDecorators(is_file_validator_1.IsFile(Object.assign(validationOptions || {}, { each: true })));
return (0, common_1.applyDecorators)((0, is_file_validator_1.IsFile)(Object.assign(validationOptions || {}, { each: true })));
}
exports.IsFiles = IsFiles;
//# sourceMappingURL=is-files.validator.js.map

@@ -7,3 +7,3 @@ "use strict";

function MaxFileSize(maxSizeBytes, validationOptions) {
return class_validator_1.ValidateBy({
return (0, class_validator_1.ValidateBy)({
name: 'MaxFileSize',

@@ -14,3 +14,3 @@ constraints: [maxSizeBytes],

const size = args.constraints[0];
if (is_file_validator_1.isFile(value)) {
if ((0, is_file_validator_1.isFile)(value)) {
return value.size <= size;

@@ -17,0 +17,0 @@ }

@@ -7,3 +7,3 @@ "use strict";

function MinFileSize(minSizeBytes, validationOptions) {
return class_validator_1.ValidateBy({
return (0, class_validator_1.ValidateBy)({
name: 'MinFileSize',

@@ -14,3 +14,3 @@ constraints: [minSizeBytes],

const size = args.constraints[0];
if (is_file_validator_1.isFile(value)) {
if ((0, is_file_validator_1.isFile)(value)) {
return value.size >= size;

@@ -17,0 +17,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -31,17 +31,22 @@ "use strict";

async intercept(context, next) {
const req = context.switchToHttp().getRequest();
const httpRequest = context.switchToHttp().getRequest();
/**
* fastify always have raw property in the request
*/
const isFastify = !!httpRequest.raw;
const req = isFastify ? httpRequest.raw : httpRequest;
/** if the request is not multipart, skip **/
if (!type_is_1.is(req, ['multipart']))
if (!(0, type_is_1.is)(httpRequest, ['multipart']))
return next.handle();
/** merge global config with method level config **/
const config = check_config_1.checkConfig(this.reflector.get(form_data_1.FORM_DATA_REQUEST_METADATA_KEY, context.getHandler()) || {}, this.globalConfig);
const config = (0, check_config_1.checkConfig)(this.reflector.get(form_data_1.FORM_DATA_REQUEST_METADATA_KEY, context.getHandler()) || {}, this.globalConfig);
const formReader = new FormReader_1.FormReader(req, config);
return rxjs_1.from(formReader.handle()).pipe(rxjs_1.mergeMap((formReaderResult) => {
req.body = formReaderResult;
return (0, rxjs_1.from)(formReader.handle()).pipe((0, rxjs_1.mergeMap)((formReaderResult) => {
httpRequest.body = formReaderResult;
return next.handle();
}), rxjs_1.catchError(err => {
}), (0, rxjs_1.catchError)((err) => {
if (config.autoDeleteFile)
formReader.deleteFiles();
return rxjs_1.throwError(err);
}), operators_1.tap(res => {
return (0, rxjs_1.throwError)(err);
}), (0, operators_1.tap)((res) => {
if (config.autoDeleteFile)

@@ -53,4 +58,4 @@ formReader.deleteFiles();

FormDataInterceptor = __decorate([
common_1.Injectable(),
__param(0, common_1.Inject(global_config_inject_token_config_1.GLOBAL_CONFIG_INJECT_TOKEN)),
(0, common_1.Injectable)(),
__param(0, (0, common_1.Inject)(global_config_inject_token_config_1.GLOBAL_CONFIG_INJECT_TOKEN)),
__metadata("design:paramtypes", [Object])

@@ -57,0 +62,0 @@ ], FormDataInterceptor);

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -9,5 +9,5 @@ "use strict";

function appendField(store, key, value) {
const steps = parse_path_1.default(key);
const steps = (0, parse_path_1.default)(key);
steps.reduce((context, step) => {
return set_value_1.default(context, step, context[step.key], value);
return (0, set_value_1.default)(context, step, context[step.key], value);
}, store);

@@ -14,0 +14,0 @@ }

@@ -24,3 +24,3 @@ "use strict";

provide: global_config_inject_token_config_1.GLOBAL_CONFIG_INJECT_TOKEN,
useValue: check_config_1.checkConfig(config),
useValue: (0, check_config_1.checkConfig)(config),
},

@@ -55,3 +55,3 @@ ],

useFactory: async (...args) => {
return check_config_1.checkConfig(await options.useFactory(...args));
return (0, check_config_1.checkConfig)(await options.useFactory(...args));
},

@@ -65,3 +65,3 @@ inject: options.inject || [],

const config = await optionsFactory.configAsync();
return check_config_1.checkConfig(config);
return (0, check_config_1.checkConfig)(config);
},

@@ -73,3 +73,3 @@ inject: [options.useExisting || options.useClass],

NestjsFormDataModule = NestjsFormDataModule_1 = __decorate([
common_1.Module({
(0, common_1.Module)({
providers: [

@@ -76,0 +76,0 @@ FormData_interceptor_1.FormDataInterceptor,

{
"name": "nestjs-form-data",
"version": "1.9.1",
"version": "1.9.2",
"description": "NestJS middleware for handling multipart/form-data, which is primarily used for uploading files",

@@ -24,8 +24,10 @@ "main": "dist/index",

"devDependencies": {
"@fastify/multipart": "^8.0.0",
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.2.9",
"@nestjs/testing": "^10.0.0",
"@types/busboy": "^1.5.0",
"@types/jest": "^26.0.23",
"@types/jest": "^29.5.8",
"@types/mkdirp": "^1.0.1",

@@ -37,3 +39,4 @@ "@types/node": "^14.14.41",

"class-validator": "^0.14.0",
"jest": "^26.6.3",
"fastify": "^4.24.3",
"jest": "^29.7.0",
"reflect-metadata": "^0.1.13",

@@ -43,3 +46,3 @@ "rimraf": "^3.0.2",

"supertest": "6.1.3",
"ts-jest": "^26.5.6",
"ts-jest": "^29.1.1",
"typescript": "^4.2.4"

@@ -46,0 +49,0 @@ },

@@ -60,2 +60,28 @@ [![npm version](https://badge.fury.io/js/nestjs-form-data.svg)](https://badge.fury.io/js/nestjs-form-data)

```
## Fastify
Need to install [@fastify/multipart](https://www.npmjs.com/package/@fastify/multipart).
```ts
// main.ts
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import multipart from '@fastify/multipart'
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter()
);
app.register(multipart);
await app.listen(3000);
}
```
## Configuration

@@ -62,0 +88,0 @@ ### Static configuration

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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