formflux 0.1.1 → 0.1.2

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.
Files changed (64) hide show
  1. package/dist/cjs/EventHandlers.js +16 -0
  2. package/dist/cjs/EventHandlers.js.map +1 -0
  3. package/dist/cjs/ExtractContent.js +146 -0
  4. package/dist/cjs/ExtractContent.js.map +1 -0
  5. package/dist/cjs/FormFlux.Types.js +2 -0
  6. package/dist/cjs/FormFlux.Types.js.map +1 -0
  7. package/dist/cjs/FormFlux.js +480 -0
  8. package/dist/cjs/FormFlux.js.map +1 -0
  9. package/dist/cjs/FormFluxError.js +14 -0
  10. package/dist/cjs/FormFluxError.js.map +1 -0
  11. package/dist/cjs/SetBodyContentToReq.js +100 -0
  12. package/dist/cjs/SetBodyContentToReq.js.map +1 -0
  13. package/dist/cjs/SetFileContentToReqFile.js +64 -0
  14. package/dist/cjs/SetFileContentToReqFile.js.map +1 -0
  15. package/dist/cjs/WriteFileContent.js +139 -0
  16. package/dist/cjs/WriteFileContent.js.map +1 -0
  17. package/dist/cjs/defaultOptions.js +14 -0
  18. package/dist/cjs/defaultOptions.js.map +1 -0
  19. package/dist/cjs/helpers/resBodyMaker.js +33 -0
  20. package/dist/cjs/helpers/resBodyMaker.js.map +1 -0
  21. package/dist/cjs/setDatatoReqobj.js +24 -0
  22. package/dist/cjs/setDatatoReqobj.js.map +1 -0
  23. package/dist/cjs/setFileNameToBody.js +103 -0
  24. package/dist/cjs/setFileNameToBody.js.map +1 -0
  25. package/dist/declarations/EventHandlers.d.ts +7 -0
  26. package/dist/declarations/ExtractContent.d.ts +11 -0
  27. package/dist/declarations/FormFlux.Types.d.ts +51 -0
  28. package/dist/declarations/FormFlux.d.ts +16 -0
  29. package/dist/declarations/FormFluxError.d.ts +5 -0
  30. package/dist/declarations/SetBodyContentToReq.d.ts +10 -0
  31. package/dist/declarations/SetFileContentToReqFile.d.ts +11 -0
  32. package/dist/declarations/WriteFileContent.d.ts +17 -0
  33. package/dist/declarations/defaultOptions.d.ts +2 -0
  34. package/dist/declarations/helpers/resBodyMaker.d.ts +1 -0
  35. package/dist/declarations/setDatatoReqobj.d.ts +7 -0
  36. package/dist/declarations/setFileNameToBody.d.ts +10 -0
  37. package/dist/esm/EventHandlers.js +11 -0
  38. package/dist/esm/EventHandlers.js.map +1 -0
  39. package/dist/esm/ExtractContent.js +141 -0
  40. package/dist/esm/ExtractContent.js.map +1 -0
  41. package/dist/esm/FormFlux.Types.js +2 -0
  42. package/dist/esm/FormFlux.Types.js.map +1 -0
  43. package/dist/esm/FormFlux.js +475 -0
  44. package/dist/esm/FormFlux.js.map +1 -0
  45. package/dist/esm/FormFluxError.js +10 -0
  46. package/dist/esm/FormFluxError.js.map +1 -0
  47. package/dist/esm/SetBodyContentToReq.js +95 -0
  48. package/dist/esm/SetBodyContentToReq.js.map +1 -0
  49. package/dist/esm/SetFileContentToReqFile.js +59 -0
  50. package/dist/esm/SetFileContentToReqFile.js.map +1 -0
  51. package/dist/esm/WriteFileContent.js +134 -0
  52. package/dist/esm/WriteFileContent.js.map +1 -0
  53. package/dist/esm/defaultOptions.js +10 -0
  54. package/dist/esm/defaultOptions.js.map +1 -0
  55. package/dist/esm/helpers/resBodyMaker.js +29 -0
  56. package/dist/esm/helpers/resBodyMaker.js.map +1 -0
  57. package/dist/esm/setDatatoReqobj.js +20 -0
  58. package/dist/esm/setDatatoReqobj.js.map +1 -0
  59. package/dist/esm/setFileNameToBody.js +98 -0
  60. package/dist/esm/setFileNameToBody.js.map +1 -0
  61. package/dist/package.json +61 -0
  62. package/package.json +13 -3
  63. package/script/babel-package.js +3 -0
  64. package/script/babel-preset.js +21 -0
@@ -0,0 +1,51 @@
1
+ import { Request } from "express";
2
+ import FormfluxError from "./FormFluxError";
3
+ export interface reqObj {
4
+ "originalReq": string;
5
+ "modifiedReq": Buffer;
6
+ "data": Array<string>;
7
+ "content": Array<Buffer>;
8
+ "contentBody": Array<string>;
9
+ "metaData": Array<string>;
10
+ "mimeType": Array<string>;
11
+ "fieldNameBody": Array<string>;
12
+ "fileName": Array<string>;
13
+ "modifiedFileName": Array<string>;
14
+ "fieldNameFile": Array<string>;
15
+ "filePath": Array<string>;
16
+ "filesize": Array<number>;
17
+ "streams": Array<any>;
18
+ }
19
+ export interface File {
20
+ mimetype: string;
21
+ originalname: string;
22
+ filesize: number;
23
+ fieldname: string;
24
+ }
25
+ export interface options {
26
+ attachFileToReqBody?: boolean;
27
+ maxFileCount?: number;
28
+ maxFileSize?: number;
29
+ maxFields?: number;
30
+ minFileCount?: number;
31
+ filename: (req: Request, file: File, cb: (error: FormfluxError | null, filename: string) => void) => void;
32
+ destination: (req: Request, file: File, cb: (error: FormfluxError | null, filepath: string) => void) => void;
33
+ fileFilter?: (req: Request, file: File, cb: (error: Error | null, bool: boolean) => void) => void;
34
+ }
35
+ export interface optionSingle {
36
+ attachFileToReqBody?: boolean;
37
+ maxFileCount?: number;
38
+ maxFileSize?: number;
39
+ maxFields?: number;
40
+ minFileCount?: number;
41
+ filename: (req: Request, file: File, cb: (error: FormfluxError | null, filename: string) => void) => void;
42
+ fileFilter?: (req: Request, file: File, cb: (error: Error | null, bool: boolean) => void) => void;
43
+ }
44
+ interface fieldObject {
45
+ name: string;
46
+ maxFileCount?: number;
47
+ maxFileSize?: number;
48
+ minFileCount?: number;
49
+ }
50
+ export type optionFields = [fieldObject, ...fieldObject[]];
51
+ export {};
@@ -0,0 +1,16 @@
1
+ import { NextFunction, Request, Response } from "express";
2
+ import { options, optionFields, optionSingle } from "./FormFlux.Types";
3
+ declare class Formflux {
4
+ static diskStorage(options: options): {
5
+ any(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
6
+ fields(optionFields: optionFields): (req: Request, res: Response, next: NextFunction) => Promise<void>;
7
+ single(field: string): (req: Request, res: Response, next: NextFunction) => Promise<void>;
8
+ };
9
+ static memoryStorage(options: optionSingle): {
10
+ any(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
11
+ fields(optionFields: optionFields): (req: Request, res: Response, next: NextFunction) => Promise<void>;
12
+ single(field: string): (req: Request, res: Response, next: NextFunction) => Promise<void>;
13
+ };
14
+ bodyParser(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
15
+ }
16
+ export default Formflux;
@@ -0,0 +1,5 @@
1
+ declare class FormfluxError extends Error {
2
+ private statusCode;
3
+ constructor(message: string, statusCode?: number);
4
+ }
5
+ export default FormfluxError;
@@ -0,0 +1,10 @@
1
+ import { reqObj } from "./FormFlux.Types";
2
+ import { Request } from "express";
3
+ declare class setContentToBody {
4
+ private obj;
5
+ constructor(obj: reqObj);
6
+ setBody(req: Request): void;
7
+ nestedData(req: Request, fieldName: string, data: any): void;
8
+ getNestedField(req: Request, obj: object, posArr: Array<any>, keySearch: any, data: any, i: number, prevObj: object): void;
9
+ }
10
+ export default setContentToBody;
@@ -0,0 +1,11 @@
1
+ import { Request } from "express";
2
+ import { reqObj } from "./FormFlux.Types";
3
+ declare class setFileContentToReq {
4
+ private obj;
5
+ private req;
6
+ private for;
7
+ private storage;
8
+ constructor(req: Request, obj: reqObj, forReason: "any" | "fields" | "single", storage: "memory" | "disk");
9
+ setFileNames(fileObj: any, field: string | null): void;
10
+ }
11
+ export default setFileContentToReq;
@@ -0,0 +1,17 @@
1
+ import { Request } from "express";
2
+ import { options, optionSingle, reqObj } from "./FormFlux.Types";
3
+ import FormfluxError from "./FormFluxError";
4
+ declare class writeFileContent {
5
+ private obj;
6
+ private options;
7
+ private req;
8
+ private for;
9
+ private storage;
10
+ constructor(req: Request, obj: reqObj, options: options | optionSingle, forReason: "any" | "fields" | "single", storage: "memory" | "disk");
11
+ writeContent(): void;
12
+ singleFile(count: number, metaData: string, content: Buffer, filesize: number, fieldname: string): void;
13
+ callBackFilename(error: FormfluxError | null, fileName: string): void;
14
+ callBackfilepath(error: FormfluxError | null, filepath: string): void;
15
+ callBackFilter(error: FormfluxError | null, bool: boolean): boolean;
16
+ }
17
+ export default writeFileContent;
@@ -0,0 +1,2 @@
1
+ import { options } from "./FormFlux.Types";
2
+ export declare let defaultOptions: options;
@@ -0,0 +1 @@
1
+ export default function createNewBody(posArr: Array<string>, j: number, data: any): object;
@@ -0,0 +1,7 @@
1
+ import { reqObj } from "./FormFlux.Types";
2
+ declare class populateReqObj {
3
+ obj: reqObj;
4
+ constructor(obj: reqObj);
5
+ populate(): void;
6
+ }
7
+ export default populateReqObj;
@@ -0,0 +1,10 @@
1
+ import { Request } from "express";
2
+ import { reqObj } from "./FormFlux.Types";
3
+ declare class setFileNameToBody {
4
+ private obj;
5
+ constructor(obj: reqObj);
6
+ setFileNames(req: Request): void;
7
+ nestedData(req: Request, fieldName: string, data: any): void;
8
+ getNestedField(req: Request, obj: object, posArr: Array<any>, keySearch: any, data: any, i: number, prevObj: object): void;
9
+ }
10
+ export default setFileNameToBody;
@@ -0,0 +1,11 @@
1
+ import EventEmitter from "node:events";
2
+ class EventHandlers extends EventEmitter {
3
+ constructor() {
4
+ super();
5
+ }
6
+ emitMessage(eventName, message) {
7
+ this.emit(eventName, message);
8
+ }
9
+ }
10
+ export default new EventHandlers();
11
+ //# sourceMappingURL=EventHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventHandlers.js","names":["EventEmitter","EventHandlers","constructor","emitMessage","eventName","message","emit"],"sources":["../../src/EventHandlers.ts"],"sourcesContent":["import EventEmitter from \"node:events\";\n\n class EventHandlers extends EventEmitter {\n constructor() {\n super();\n }\n\n emitMessage(eventName: string, message: string | object) {\n this.emit(eventName, message);\n }\n}\n\nexport default new EventHandlers();"],"mappings":"AAAA,OAAOA,YAAY,MAAM,aAAa;AAErC,MAAMC,aAAa,SAASD,YAAY,CAAC;EACtCE,WAAWA,CAAA,EAAG;IACV,KAAK,CAAC,CAAC;EACX;EAEAC,WAAWA,CAACC,SAAiB,EAAEC,OAAwB,EAAE;IACrD,IAAI,CAACC,IAAI,CAACF,SAAS,EAAEC,OAAO,CAAC;EACjC;AACJ;AAEA,eAAe,IAAIJ,aAAa,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,141 @@
1
+ import FormfluxError from "./FormFluxError";
2
+ class ExtractFileContent {
3
+ constructor(obj, options, fieldArr, singleObj) {
4
+ this.obj = void 0;
5
+ this.options = void 0;
6
+ this.events = void 0;
7
+ this.fieldArr = void 0;
8
+ this.singleObj = void 0;
9
+ this.obj = obj;
10
+ this.options = options;
11
+ this.fieldArr = fieldArr;
12
+ this.singleObj = singleObj;
13
+ }
14
+ extraction() {
15
+ var _this$options, _this$options3, _this$fieldArr, _this$options6;
16
+ for (let val of this.obj.data) {
17
+ if (val.includes("\r\n\r\n") && val.includes("Content-Type")) {
18
+ const [meta, content] = val.split("\r\n\r\n");
19
+ this.obj.fieldNameFile.push(val.split(`name="`)[1].substring(0, val.split(`name="`)[1].indexOf(`"`)));
20
+ this.obj.content.push(Buffer.from(content, "binary"));
21
+ if (this.options && this.options["maxFileSize"] && Buffer.from(content, "binary").length > this.options["maxFileSize"]) throw new FormfluxError("File size exceeded limit", 400);
22
+ this.obj.metaData.push(meta);
23
+ } else if (!val.includes("Content-Type")) {
24
+ this.obj.fieldNameBody.push(val.split(`name="`)[1].substring(0, val.split(`name="`)[1].indexOf(`"`)));
25
+ this.obj.contentBody.push(val == null ? void 0 : val.split("\r\n\r\n")[1].substring(0, val == null ? void 0 : val.split("\r\n\r\n")[1].indexOf("\r\n")));
26
+ }
27
+ }
28
+
29
+ // for single file checks
30
+ if (this.singleObj) {
31
+ let count = 0;
32
+ for (let val of this.obj.metaData) {
33
+ if (val.includes("filename") && val.split(`name="`)[1].substring(0, val.split(`name="`)[1].indexOf(`"`)) == this.singleObj) {
34
+ count++;
35
+ if (count > 1) throw new FormfluxError("Too many files", 429);
36
+ } else if (val.includes("filename") && val.split(`name="`)[1].substring(0, val.split(`name="`)[1].indexOf(`"`)) != this.singleObj) throw new FormfluxError("Unexpected field", 400);
37
+ }
38
+ }
39
+ // check maxfileCount
40
+ if (this.options && (_this$options = this.options) != null && _this$options.maxFileCount) {
41
+ var _this$options2;
42
+ if (this.options.minFileCount && this.options.minFileCount > this.options.maxFileCount) throw new FormfluxError("minFileCount should be less than maxFileCount", 500);
43
+ if (this.obj.content.length > ((_this$options2 = this.options) == null ? void 0 : _this$options2.maxFileCount)) throw new FormfluxError("Too many files", 429);
44
+ }
45
+
46
+ //check minfileCount
47
+ if (this.options && (_this$options3 = this.options) != null && _this$options3.minFileCount) {
48
+ var _this$options4, _this$options5;
49
+ if (this.options.maxFileCount < this.options.minFileCount) throw new FormfluxError("minFileCount should be less than maxFileCount", 500);
50
+ if (this.obj.content.length < ((_this$options4 = this.options) == null ? void 0 : _this$options4.minFileCount)) throw new FormfluxError(`At least ${(_this$options5 = this.options) == null ? void 0 : _this$options5.minFileCount} file(s) required`, 400);
51
+ }
52
+
53
+ //check each fields
54
+ if (this.fieldArr && ((_this$fieldArr = this.fieldArr) == null ? void 0 : _this$fieldArr.length) != 0) {
55
+ let fieldStart = 0;
56
+ let fieldEnd = this.fieldArr.length - 1;
57
+ let fieldObj = {};
58
+ let isCountField = false;
59
+ while (fieldStart <= fieldEnd) {
60
+ fieldObj[`${this.fieldArr[fieldStart].name}`] = [];
61
+ fieldObj[`${this.fieldArr[fieldStart].name}Check`] = false;
62
+ if (fieldStart == fieldEnd) break;
63
+ fieldObj[`${this.fieldArr[fieldEnd].name}`] = [];
64
+ fieldObj[`${this.fieldArr[fieldEnd].name}Check`] = false;
65
+ fieldStart++;
66
+ fieldEnd--;
67
+ }
68
+ if (this.obj.metaData.length != 0) {
69
+ let header;
70
+ for (let val of this.obj.metaData) {
71
+ let count = 0;
72
+ if (val.includes("filename")) {
73
+ for (let item of this.fieldArr) {
74
+ header = val.split(`name="`)[1];
75
+ if (header.substring(0, header.indexOf(`"`)) == item.name) {
76
+ fieldObj[item.name].push(1);
77
+ count++;
78
+
79
+ // check if min is greater then max count
80
+ if (item.minFileCount && item.maxFileCount && item.maxFileCount < item.minFileCount) throw new FormfluxError("minFileCount should be less than maxFileCount", 500);
81
+ if (item.maxFileCount && fieldObj[item.name].length > item.maxFileCount) throw new FormfluxError("Too may files", 429);
82
+
83
+ // set the minCountfield
84
+ if (item.minFileCount && !fieldObj[`${item.name}minCount`]) {
85
+ isCountField = true;
86
+ }
87
+
88
+ // each field filesize check
89
+ if (item.maxFileSize && !fieldObj[`${item.name}Check`]) {
90
+ let rawContent = this.obj.data.filter(x => x.includes(`name="${item.name}"`) && x.includes("Content-Type"));
91
+ rawContent.forEach(cont => {
92
+ if (Buffer.from(cont.split("\r\n\r\n")[1], "binary").length > item.maxFileSize) throw new FormfluxError("File size exceeded limit", 400);
93
+ });
94
+ fieldObj[`${item.name}Check`] = true;
95
+ }
96
+ }
97
+ }
98
+ if (count <= 0) throw new FormfluxError("Unexpected Field", 400); // invalid field
99
+ }
100
+ }
101
+ if (isCountField) {
102
+ let i = 0;
103
+ let filterKeyVals = Object.entries(fieldObj).filter(x => !x[0].includes("Check"));
104
+ for (let _i = 0; _i < filterKeyVals.length; _i++) {
105
+ if (this.fieldArr[_i].minFileCount && filterKeyVals[_i][1]["length"] < this.fieldArr[_i].minFileCount) throw new FormfluxError(`At least ${this.fieldArr[_i].minFileCount} file(s) required for ${this.fieldArr[_i].name} field`, 400);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ this.obj.data = null; //*******emptying*******
111
+
112
+ //********maxFields validation*******
113
+ if (this.options && (_this$options6 = this.options) != null && _this$options6.maxFields) {
114
+ let countFileFields = 0;
115
+ let countBodyFields = 0;
116
+ if (this.obj.fieldNameFile.length > 0) {
117
+ let obj = {};
118
+ for (let field of this.obj.fieldNameFile) {
119
+ if (!Object.keys(obj).includes(`${field}`)) {
120
+ obj[`${field}`] = 1;
121
+ countFileFields += 1;
122
+ } else continue;
123
+ }
124
+ if (countFileFields > this.options.maxFields) throw new FormfluxError("Too many fields", 429);
125
+ }
126
+ if (this.obj.fieldNameBody.length > 0) {
127
+ let obj = {};
128
+ for (let field of this.obj.fieldNameBody) {
129
+ if (!Object.keys(obj).includes(`${field}`)) {
130
+ obj[`${field}`] = 1;
131
+ countBodyFields += 1;
132
+ } else continue;
133
+ }
134
+ if (countBodyFields > this.options.maxFields) throw new FormfluxError("Too many fields", 429);
135
+ }
136
+ if (countBodyFields + countFileFields > this.options.maxFields) throw new FormfluxError("Too many fields", 429);
137
+ }
138
+ }
139
+ }
140
+ export default ExtractFileContent;
141
+ //# sourceMappingURL=ExtractContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtractContent.js","names":["FormfluxError","ExtractFileContent","constructor","obj","options","fieldArr","singleObj","events","extraction","_this$options","_this$options3","_this$fieldArr","_this$options6","val","data","includes","meta","content","split","fieldNameFile","push","substring","indexOf","Buffer","from","length","metaData","fieldNameBody","contentBody","count","maxFileCount","_this$options2","minFileCount","_this$options4","_this$options5","fieldStart","fieldEnd","fieldObj","isCountField","name","header","item","maxFileSize","rawContent","filter","x","forEach","cont","i","filterKeyVals","Object","entries","maxFields","countFileFields","countBodyFields","field","keys"],"sources":["../../src/ExtractContent.ts"],"sourcesContent":["import EventEmitter from \"node:events\";\nimport { optionFields, options, optionSingle, reqObj } from \"./FormFlux.Types\";\nimport FormfluxError from \"./FormFluxError\";\n\nclass ExtractFileContent {\n private obj: reqObj;\n private options: options | optionSingle | null\n private events: EventEmitter;\n private fieldArr: optionFields | null;\n private singleObj: string | null;\n constructor(obj: reqObj, options: options | optionSingle, fieldArr: optionFields | null, singleObj: string | null) {\n\n this.obj = obj;\n this.options = options;\n this.fieldArr = fieldArr;\n this.singleObj = singleObj;\n }\n extraction(): void {\n for (let val of this.obj.data) {\n if (val.includes(\"\\r\\n\\r\\n\") && val.includes(\"Content-Type\")) {\n const [meta, content] = val.split(\"\\r\\n\\r\\n\");\n this.obj.fieldNameFile.push(val.split(`name=\"`)[1].substring(0, val.split(`name=\"`)[1].indexOf(`\"`)));\n this.obj.content.push(Buffer.from(content, \"binary\"));\n\n if (this.options && this.options[\"maxFileSize\"] && Buffer.from(content, \"binary\").length > this.options[\"maxFileSize\"])\n throw new FormfluxError(\"File size exceeded limit\", 400);\n this.obj.metaData.push(meta);\n } else if (!val.includes(\"Content-Type\")) {\n this.obj.fieldNameBody.push(val.split(`name=\"`)[1].substring(0, val.split(`name=\"`)[1].indexOf(`\"`)));\n this.obj.contentBody.push(val?.split(\"\\r\\n\\r\\n\")[1].substring(0, val?.split(\"\\r\\n\\r\\n\")[1].indexOf(\"\\r\\n\")));\n }\n }\n\n // for single file checks\n if (this.singleObj) {\n let count = 0;\n for (let val of this.obj.metaData) {\n if (\n val.includes(\"filename\") &&\n val.split(`name=\"`)[1].substring(0, val.split(`name=\"`)[1].indexOf(`\"`)) == this.singleObj\n ) {\n count++;\n if (count > 1)\n throw new FormfluxError(\"Too many files\", 429);\n }\n else if (val.includes(\"filename\") && val.split(`name=\"`)[1].substring(0, val.split(`name=\"`)[1].indexOf(`\"`)) != this.singleObj)\n throw new FormfluxError(\"Unexpected field\", 400);\n }\n }\n // check maxfileCount\n if (this.options && this.options?.maxFileCount) {\n if (this.options.minFileCount && this.options.minFileCount > this.options.maxFileCount)\n throw new FormfluxError(\"minFileCount should be less than maxFileCount\", 500);\n\n if (this.obj.content.length > this.options?.maxFileCount)\n throw new FormfluxError(\"Too many files\", 429);\n }\n\n //check minfileCount\n if (this.options && this.options?.minFileCount) {\n if (this.options.maxFileCount < this.options.minFileCount)\n throw new FormfluxError(\"minFileCount should be less than maxFileCount\", 500);\n\n if (this.obj.content.length < this.options?.minFileCount)\n throw new FormfluxError(`At least ${this.options?.minFileCount} file(s) required`, 400);\n }\n\n //check each fields\n if (this.fieldArr && this.fieldArr?.length != 0) {\n let fieldStart = 0;\n let fieldEnd = this.fieldArr.length - 1;\n let fieldObj = {};\n let isCountField: boolean = false;\n while (fieldStart <= fieldEnd) {\n fieldObj[`${this.fieldArr[fieldStart].name}`] = [];\n fieldObj[`${this.fieldArr[fieldStart].name}Check`] = false;\n if (fieldStart == fieldEnd) break;\n fieldObj[`${this.fieldArr[fieldEnd].name}`] = [];\n fieldObj[`${this.fieldArr[fieldEnd].name}Check`] = false;\n fieldStart++;\n fieldEnd--;\n }\n\n if (this.obj.metaData.length != 0) {\n let header: string;\n for (let val of this.obj.metaData) {\n let count: number = 0;\n if (val.includes(\"filename\")) {\n for (let item of this.fieldArr) {\n header = val.split(`name=\"`)[1];\n if (header.substring(0, header.indexOf(`\"`)) == item.name) {\n fieldObj[item.name].push(1);\n count++;\n\n // check if min is greater then max count\n if (item.minFileCount && item.maxFileCount && item.maxFileCount < item.minFileCount)\n throw new FormfluxError(\"minFileCount should be less than maxFileCount\", 500);\n\n if (item.maxFileCount && fieldObj[item.name].length > item.maxFileCount)\n throw new FormfluxError(\"Too may files\", 429);\n\n // set the minCountfield\n if (item.minFileCount && !fieldObj[`${item.name}minCount`]) {\n isCountField = true;\n }\n\n // each field filesize check\n if (item.maxFileSize && !fieldObj[`${item.name}Check`]) {\n let rawContent = this.obj.data.filter(x => x.includes(`name=\"${item.name}\"`) && x.includes(\"Content-Type\"));\n rawContent.forEach(cont => {\n\n if (Buffer.from(cont.split(\"\\r\\n\\r\\n\")[1], \"binary\").length > item.maxFileSize)\n throw new FormfluxError(\"File size exceeded limit\", 400);\n });\n fieldObj[`${item.name}Check`] = true;\n }\n }\n }\n if (count <= 0) throw new FormfluxError(\"Unexpected Field\", 400); // invalid field\n }\n }\n\n if (isCountField) {\n let i = 0;\n let filterKeyVals = Object.entries(fieldObj).filter(x => !x[0].includes(\"Check\"));\n for (let i = 0; i < filterKeyVals.length; i++) {\n if (this.fieldArr[i].minFileCount && filterKeyVals[i][1][\"length\"] < this.fieldArr[i].minFileCount)\n throw new FormfluxError(`At least ${this.fieldArr[i].minFileCount} file(s) required for ${this.fieldArr[i].name} field`, 400);\n }\n }\n }\n }\n this.obj.data = null;//*******emptying*******\n\n //********maxFields validation*******\n if (this.options && this.options?.maxFields) {\n let countFileFields = 0;\n let countBodyFields = 0;\n if (this.obj.fieldNameFile.length > 0) {\n\n let obj = {};\n for (let field of this.obj.fieldNameFile) {\n if (!Object.keys(obj).includes(`${field}`)) {\n obj[`${field}`] = 1;\n countFileFields += 1;\n }\n else continue;\n }\n if (countFileFields > this.options.maxFields)\n throw new FormfluxError(\"Too many fields\", 429);\n }\n if (this.obj.fieldNameBody.length > 0) {\n let obj = {};\n for (let field of this.obj.fieldNameBody) {\n if (!Object.keys(obj).includes(`${field}`)) {\n obj[`${field}`] = 1;\n countBodyFields += 1;\n }\n else continue;\n }\n if (countBodyFields > this.options.maxFields)\n throw new FormfluxError(\"Too many fields\", 429);\n }\n if (countBodyFields + countFileFields > this.options.maxFields)\n throw new FormfluxError(\"Too many fields\", 429);\n }\n }\n}\n\nexport default ExtractFileContent;"],"mappings":"AAEA,OAAOA,aAAa,MAAM,iBAAiB;AAE3C,MAAMC,kBAAkB,CAAC;EAMrBC,WAAWA,CAACC,GAAW,EAAEC,OAA+B,EAAEC,QAA6B,EAAEC,SAAwB,EAAE;IAAA,KAL3GH,GAAG;IAAA,KACHC,OAAO;IAAA,KACPG,MAAM;IAAA,KACNF,QAAQ;IAAA,KACRC,SAAS;IAGb,IAAI,CAACH,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,SAAS,GAAGA,SAAS;EAC9B;EACAE,UAAUA,CAAA,EAAS;IAAA,IAAAC,aAAA,EAAAC,cAAA,EAAAC,cAAA,EAAAC,cAAA;IACf,KAAK,IAAIC,GAAG,IAAI,IAAI,CAACV,GAAG,CAACW,IAAI,EAAE;MAC3B,IAAID,GAAG,CAACE,QAAQ,CAAC,UAAU,CAAC,IAAIF,GAAG,CAACE,QAAQ,CAAC,cAAc,CAAC,EAAE;QAC1D,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGJ,GAAG,CAACK,KAAK,CAAC,UAAU,CAAC;QAC7C,IAAI,CAACf,GAAG,CAACgB,aAAa,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IAAI,CAACG,GAAG,CAACwB,aAAa,CAACF,MAAM,GAAG,CAAC,EAAE;QACnC,IAAItB,GAAG,GAAG,CAAC,CAAC;QACZ,KAAK,IAAIoD,KAAK,IAAI,IAAI,CAACpD,GAAG,CAACwB,aAAa,EAAE;UACtC,IAAI,CAACuB,MAAM,CAACM,IAAI,CAACrD,GAAG,CAAC,CAACY,QAAQ,CAAC,GAAGwC,KAAK,EAAE,CAAC,EAAE;YACxCpD,GAAG,CAAC,GAAGoD,KAAK,EAAE,CAAC,GAAG,CAAC;YACnBD,eAAe,IAAI,CAAC;UACxB,CAAC,MACI;QACT;QACA,IAAIA,eAAe,GAAG,IAAI,CAAClD,OAAO,CAACgD,SAAS,EACxC,MAAM,IAAIpD,aAAa,CAAC,iBAAiB,EAAE,GAAG,CAAC;MACvD;MACA,IAAIsD,eAAe,GAAGD,eAAe,GAAG,IAAI,CAACjD,OAAO,CAACgD,SAAS,EAC1D,MAAM,IAAIpD,aAAa,CAAC,iBAAiB,EAAE,GAAG,CAAC;IACvD;EACJ;AACJ;AAEA,eAAeC,kBAAkB","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=FormFlux.Types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFlux.Types.js","names":[],"sources":["../../src/FormFlux.Types.ts"],"sourcesContent":["import { Request } from \"express\";\nimport FormfluxError from \"./FormFluxError\";\n\nexport interface reqObj {\n \"originalReq\": string;\n \"modifiedReq\": Buffer;\n \"data\": Array<string>;\n \"content\": Array<Buffer>,\n \"contentBody\": Array<string>,\n \"metaData\": Array<string>,\n \"mimeType\": Array<string>,\n \"fieldNameBody\": Array<string>,\n \"fileName\": Array<string>,\n \"modifiedFileName\": Array<string>,\n \"fieldNameFile\": Array<string>,\n \"filePath\": Array<string>,\n \"filesize\": Array<number>,\n \"streams\": Array<any>\n}\nexport interface File {\n mimetype: string,\n originalname: string,\n filesize: number,\n fieldname: string\n}\n\nexport interface options {\n attachFileToReqBody?: boolean,\n maxFileCount?: number,\n maxFileSize?: number,\n maxFields?: number,\n minFileCount?: number\n filename: (\n req: Request,\n file: File,\n cb: (error: FormfluxError | null, filename: string) => void\n ) => void,\n destination: (\n req: Request,\n file: File,\n cb: (error: FormfluxError | null, filepath: string) => void\n ) => void,\n fileFilter?: (\n req: Request,\n file: File,\n cb: (error: Error | null, bool: boolean) => void\n ) => void\n\n}\n\nexport interface optionSingle {\n attachFileToReqBody?: boolean,\n maxFileCount?: number,\n maxFileSize?: number,\n maxFields?: number,\n minFileCount?: number\n filename: (\n req: Request,\n file: File,\n cb: (error: FormfluxError | null, filename: string) => void\n ) => void,\n fileFilter?: (\n req: Request,\n file: File,\n cb: (error: Error | null, bool: boolean) => void\n ) => void\n\n}\n\ninterface fieldObject {\n name: string,\n maxFileCount?: number,\n maxFileSize?: number,\n minFileCount?: number\n}\n\nexport type optionFields = [fieldObject, ...fieldObject[]];"],"mappings":"","ignoreList":[]}