formflux 0.1.0 → 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/EventHandlers.d.ts +7 -0
  2. package/dist/ExtractContent.d.ts +11 -0
  3. package/dist/FormFlux.Types.d.ts +51 -0
  4. package/dist/FormFlux.d.ts +16 -0
  5. package/dist/FormFluxError.d.ts +5 -0
  6. package/dist/SetBodyContentToReq.d.ts +10 -0
  7. package/dist/SetFileContentToReqFile.d.ts +11 -0
  8. package/dist/WriteFileContent.d.ts +17 -0
  9. package/dist/cjs/EventHandlers.js +16 -0
  10. package/dist/cjs/EventHandlers.js.map +1 -0
  11. package/dist/cjs/ExtractContent.js +146 -0
  12. package/dist/cjs/ExtractContent.js.map +1 -0
  13. package/dist/cjs/FormFlux.Types.js +2 -0
  14. package/dist/cjs/FormFlux.Types.js.map +1 -0
  15. package/dist/cjs/FormFlux.js +480 -0
  16. package/dist/cjs/FormFlux.js.map +1 -0
  17. package/dist/cjs/FormFluxError.js +14 -0
  18. package/dist/cjs/FormFluxError.js.map +1 -0
  19. package/dist/cjs/SetBodyContentToReq.js +100 -0
  20. package/dist/cjs/SetBodyContentToReq.js.map +1 -0
  21. package/dist/cjs/SetFileContentToReqFile.js +64 -0
  22. package/dist/cjs/SetFileContentToReqFile.js.map +1 -0
  23. package/dist/cjs/WriteFileContent.js +139 -0
  24. package/dist/cjs/WriteFileContent.js.map +1 -0
  25. package/dist/cjs/defaultOptions.js +14 -0
  26. package/dist/cjs/defaultOptions.js.map +1 -0
  27. package/dist/cjs/helpers/resBodyMaker.js +33 -0
  28. package/dist/cjs/helpers/resBodyMaker.js.map +1 -0
  29. package/dist/cjs/setDatatoReqobj.js +24 -0
  30. package/dist/cjs/setDatatoReqobj.js.map +1 -0
  31. package/dist/cjs/setFileNameToBody.js +103 -0
  32. package/dist/cjs/setFileNameToBody.js.map +1 -0
  33. package/dist/defaultOptions.d.ts +2 -0
  34. package/dist/esm/EventHandlers.js +11 -0
  35. package/dist/esm/EventHandlers.js.map +1 -0
  36. package/dist/esm/ExtractContent.js +141 -0
  37. package/dist/esm/ExtractContent.js.map +1 -0
  38. package/dist/esm/FormFlux.Types.js +2 -0
  39. package/dist/esm/FormFlux.Types.js.map +1 -0
  40. package/dist/esm/FormFlux.js +475 -0
  41. package/dist/esm/FormFlux.js.map +1 -0
  42. package/dist/esm/FormFluxError.js +10 -0
  43. package/dist/esm/FormFluxError.js.map +1 -0
  44. package/dist/esm/SetBodyContentToReq.js +95 -0
  45. package/dist/esm/SetBodyContentToReq.js.map +1 -0
  46. package/dist/esm/SetFileContentToReqFile.js +59 -0
  47. package/dist/esm/SetFileContentToReqFile.js.map +1 -0
  48. package/dist/esm/WriteFileContent.js +134 -0
  49. package/dist/esm/WriteFileContent.js.map +1 -0
  50. package/dist/esm/defaultOptions.js +10 -0
  51. package/dist/esm/defaultOptions.js.map +1 -0
  52. package/dist/esm/helpers/resBodyMaker.js +29 -0
  53. package/dist/esm/helpers/resBodyMaker.js.map +1 -0
  54. package/dist/esm/setDatatoReqobj.js +20 -0
  55. package/dist/esm/setDatatoReqobj.js.map +1 -0
  56. package/dist/esm/setFileNameToBody.js +98 -0
  57. package/dist/esm/setFileNameToBody.js.map +1 -0
  58. package/dist/helpers/resBodyMaker.d.ts +1 -0
  59. package/dist/package.json +61 -0
  60. package/dist/setDatatoReqobj.d.ts +7 -0
  61. package/dist/setFileNameToBody.d.ts +10 -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,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,CAACC,IAAI,CAACP,GAAG,CAACK,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAACG,SAAS,CAAC,CAAC,EAAER,GAAG,CAACK,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAACI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QACrG,IAAI,CAACnB,GAAG,CAACc,OAAO,CAACG,IAAI,CAACG,MAAM,CAACC,IAAI,CAACP,O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CpD,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":[]}
@@ -0,0 +1,475 @@
1
+ import ExtractFileContent from "./ExtractContent";
2
+ import writeFileContent from "./WriteFileContent";
3
+ import setContentToBody from "./SetBodyContentToReq";
4
+ import setFileNameToBody from "./setFileNameToBody";
5
+ import populateReqObj from "./setDatatoReqobj";
6
+ import EventHandlers from "./EventHandlers";
7
+ import FormfluxError from "./FormFluxError";
8
+ class Formflux {
9
+ static diskStorage(options) {
10
+ return {
11
+ any() {
12
+ return async function (req, res, next) {
13
+ var _req$headers$content;
14
+ let obj = {
15
+ "originalReq": "",
16
+ "modifiedReq": Buffer.from(""),
17
+ "data": [],
18
+ "content": [],
19
+ "metaData": [],
20
+ "mimeType": [],
21
+ "fieldNameBody": [],
22
+ "fileName": [],
23
+ "modifiedFileName": [],
24
+ "contentBody": [],
25
+ "fieldNameFile": [],
26
+ "filePath": [],
27
+ "filesize": [],
28
+ "streams": []
29
+ };
30
+ let buff = [];
31
+ let reqType = req.headers["content-type"];
32
+ if (reqType && !reqType.includes("multipart/form-data")) throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
33
+ let boundary = (_req$headers$content = req.headers["content-type"]) == null ? void 0 : _req$headers$content.split("boundary=")[1];
34
+ req.on("data", chunk => {
35
+ buff.push(chunk);
36
+ });
37
+ req.on("end", () => {
38
+ try {
39
+ var _obj$modifiedReq$toSt;
40
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
41
+
42
+ obj.data = (_obj$modifiedReq$toSt = obj.modifiedReq.toString("binary")) == null ? void 0 : _obj$modifiedReq$toSt.split(`--${boundary}`); // separating the boundary
43
+ obj.data.pop();
44
+ obj.data.shift();
45
+
46
+ //*****Defaults*****
47
+ //To*********extract content
48
+ new ExtractFileContent(obj, options, null, null).extraction();
49
+
50
+ //To*********SetFileDataToReqObj
51
+ new populateReqObj(obj).populate();
52
+ let writeBool = false;
53
+ let parseBool = false;
54
+ let checkCompletion = (writeComplete, parsecomplete) => {
55
+ if (writeComplete && parsecomplete) next();
56
+ };
57
+ EventHandlers.on("parseEnd", message => {
58
+ parseBool = true;
59
+ checkCompletion(writeBool, parseBool);
60
+ });
61
+ EventHandlers.on("writeEnd", message => {
62
+ writeBool = true;
63
+ checkCompletion(writeBool, parseBool);
64
+ });
65
+ new writeFileContent(req, obj, options, "any", "disk").writeContent();
66
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true) new setFileNameToBody(obj).setFileNames(req);
67
+ new setContentToBody(obj).setBody(req);
68
+ } catch (err) {
69
+ next(err);
70
+ }
71
+ });
72
+ req.on("error", () => {
73
+ next(new FormfluxError("Error in recieving request", 500));
74
+ });
75
+ };
76
+ },
77
+ fields(optionFields) {
78
+ return async function (req, res, next) {
79
+ var _req$headers$content2;
80
+ let obj = {
81
+ "originalReq": "",
82
+ "modifiedReq": Buffer.from(""),
83
+ "data": [],
84
+ "content": [],
85
+ "metaData": [],
86
+ "mimeType": [],
87
+ "fieldNameBody": [],
88
+ "fileName": [],
89
+ "modifiedFileName": [],
90
+ "contentBody": [],
91
+ "fieldNameFile": [],
92
+ "filePath": [],
93
+ "filesize": [],
94
+ "streams": []
95
+ };
96
+ let buff = [];
97
+ let reqType = req.headers["content-type"];
98
+ if (reqType && !reqType.includes("multipart/form-data")) throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
99
+ let boundary = (_req$headers$content2 = req.headers["content-type"]) == null ? void 0 : _req$headers$content2.split("boundary=")[1];
100
+ req.on("data", chunk => {
101
+ buff.push(chunk);
102
+ });
103
+ req.on("end", () => {
104
+ try {
105
+ var _obj$modifiedReq$toSt2;
106
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
107
+
108
+ obj.data = (_obj$modifiedReq$toSt2 = obj.modifiedReq.toString("binary")) == null ? void 0 : _obj$modifiedReq$toSt2.split(`--${boundary}`); // separating the boundary
109
+ obj.data.pop();
110
+ obj.data.shift();
111
+
112
+ //*****Defaults*****
113
+ //To*********extract content
114
+ new ExtractFileContent(obj, options, optionFields, null).extraction();
115
+
116
+ //To*********SetFileDataToReqObj
117
+ new populateReqObj(obj).populate();
118
+ let writeBool = false;
119
+ let parseBool = false;
120
+ let checkCompletion = (writeComplete, parsecomplete) => {
121
+ if (writeComplete && parsecomplete) next();
122
+ };
123
+ EventHandlers.on("parseEnd", message => {
124
+ parseBool = true;
125
+ checkCompletion(writeBool, parseBool);
126
+ });
127
+ EventHandlers.on("writeEnd", message => {
128
+ writeBool = true;
129
+ checkCompletion(writeBool, parseBool);
130
+ });
131
+ new writeFileContent(req, obj, options, "fields", "disk").writeContent();
132
+ // new setFileContentToReq(obj).setFileNames(req);
133
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true) new setFileNameToBody(obj).setFileNames(req);
134
+ new setContentToBody(obj).setBody(req);
135
+ } catch (err) {
136
+ next(err);
137
+ }
138
+ });
139
+ req.on("error", () => {
140
+ next(new FormfluxError("Error in recieving request", 500));
141
+ });
142
+ };
143
+ },
144
+ single(field) {
145
+ return async function (req, res, next) {
146
+ var _req$headers$content3;
147
+ let obj = {
148
+ "originalReq": "",
149
+ "modifiedReq": Buffer.from(""),
150
+ "data": [],
151
+ "content": [],
152
+ "metaData": [],
153
+ "mimeType": [],
154
+ "fieldNameBody": [],
155
+ "fileName": [],
156
+ "modifiedFileName": [],
157
+ "contentBody": [],
158
+ "fieldNameFile": [],
159
+ "filePath": [],
160
+ "filesize": [],
161
+ "streams": []
162
+ };
163
+ let buff = [];
164
+ let reqType = req.headers["content-type"];
165
+ if (reqType && !reqType.includes("multipart/form-data")) throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
166
+ let boundary = (_req$headers$content3 = req.headers["content-type"]) == null ? void 0 : _req$headers$content3.split("boundary=")[1];
167
+ req.on("data", chunk => {
168
+ buff.push(chunk);
169
+ });
170
+ req.on("end", () => {
171
+ try {
172
+ var _obj$modifiedReq$toSt3;
173
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
174
+
175
+ obj.data = (_obj$modifiedReq$toSt3 = obj.modifiedReq.toString("binary")) == null ? void 0 : _obj$modifiedReq$toSt3.split(`--${boundary}`); // separating the boundary
176
+ obj.data.pop();
177
+ obj.data.shift();
178
+
179
+ //*****Defaults*****
180
+ //To*********extract content
181
+ new ExtractFileContent(obj, options, null, field).extraction();
182
+
183
+ //To*********SetFileDataToReqObj
184
+ new populateReqObj(obj).populate();
185
+ let writeBool = false;
186
+ let parseBool = false;
187
+ let checkCompletion = (writeComplete, parsecomplete) => {
188
+ if (writeComplete && parsecomplete) next();
189
+ };
190
+ EventHandlers.on("parseEnd", message => {
191
+ parseBool = true;
192
+ checkCompletion(writeBool, parseBool);
193
+ });
194
+ EventHandlers.on("writeEnd", message => {
195
+ writeBool = true;
196
+ checkCompletion(writeBool, parseBool);
197
+ });
198
+ new writeFileContent(req, obj, options, "single", "disk").writeContent();
199
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true) new setFileNameToBody(obj).setFileNames(req);
200
+ new setContentToBody(obj).setBody(req);
201
+ } catch (err) {
202
+ next(err);
203
+ }
204
+ });
205
+ req.on("error", () => {
206
+ next(new FormfluxError("Error in recieving request", 500));
207
+ });
208
+ };
209
+ }
210
+ };
211
+ }
212
+ static memoryStorage(options) {
213
+ return {
214
+ any() {
215
+ return async function (req, res, next) {
216
+ var _req$headers$content4;
217
+ let obj = {
218
+ "originalReq": "",
219
+ "modifiedReq": Buffer.from(""),
220
+ "data": [],
221
+ "content": [],
222
+ "metaData": [],
223
+ "mimeType": [],
224
+ "fieldNameBody": [],
225
+ "fileName": [],
226
+ "modifiedFileName": [],
227
+ "contentBody": [],
228
+ "fieldNameFile": [],
229
+ "filePath": [],
230
+ "filesize": [],
231
+ "streams": []
232
+ };
233
+ let buff = [];
234
+ let reqType = req.headers["content-type"];
235
+ if (reqType && !reqType.includes("multipart/form-data")) throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
236
+ let boundary = (_req$headers$content4 = req.headers["content-type"]) == null ? void 0 : _req$headers$content4.split("boundary=")[1];
237
+ req.on("data", chunk => {
238
+ buff.push(chunk);
239
+ });
240
+ req.on("end", () => {
241
+ try {
242
+ var _obj$modifiedReq$toSt4;
243
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
244
+
245
+ obj.data = (_obj$modifiedReq$toSt4 = obj.modifiedReq.toString("binary")) == null ? void 0 : _obj$modifiedReq$toSt4.split(`--${boundary}`); // separating the boundary
246
+ obj.data.pop();
247
+ obj.data.shift();
248
+
249
+ //*****Defaults*****
250
+ //To*********extract content
251
+ new ExtractFileContent(obj, options, null, null).extraction();
252
+
253
+ //To*********SetFileDataToReqObj
254
+ new populateReqObj(obj).populate();
255
+ let writeBool = false;
256
+ let parseBool = false;
257
+ let checkCompletion = (writeComplete, parsecomplete) => {
258
+ if (writeComplete && parsecomplete) next();
259
+ };
260
+ EventHandlers.on("parseEnd", message => {
261
+ parseBool = true;
262
+ checkCompletion(writeBool, parseBool);
263
+ });
264
+ EventHandlers.on("writeEnd", message => {
265
+ writeBool = true;
266
+ checkCompletion(writeBool, parseBool);
267
+ });
268
+ new writeFileContent(req, obj, options, "any", "memory").writeContent();
269
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true) new setFileNameToBody(obj).setFileNames(req);
270
+ new setContentToBody(obj).setBody(req);
271
+ } catch (err) {
272
+ next(err);
273
+ }
274
+ });
275
+ req.on("error", () => {
276
+ next(new FormfluxError("Error in recieving request", 500));
277
+ });
278
+ };
279
+ },
280
+ fields(optionFields) {
281
+ return async function (req, res, next) {
282
+ var _req$headers$content5;
283
+ let obj = {
284
+ "originalReq": "",
285
+ "modifiedReq": Buffer.from(""),
286
+ "data": [],
287
+ "content": [],
288
+ "metaData": [],
289
+ "mimeType": [],
290
+ "fieldNameBody": [],
291
+ "fileName": [],
292
+ "modifiedFileName": [],
293
+ "contentBody": [],
294
+ "fieldNameFile": [],
295
+ "filePath": [],
296
+ "filesize": [],
297
+ "streams": []
298
+ };
299
+ let buff = [];
300
+ let reqType = req.headers["content-type"];
301
+ if (reqType && !reqType.includes("multipart/form-data")) throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
302
+ let boundary = (_req$headers$content5 = req.headers["content-type"]) == null ? void 0 : _req$headers$content5.split("boundary=")[1];
303
+ req.on("data", chunk => {
304
+ buff.push(chunk);
305
+ });
306
+ req.on("end", () => {
307
+ try {
308
+ var _obj$modifiedReq$toSt5;
309
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
310
+
311
+ obj.data = (_obj$modifiedReq$toSt5 = obj.modifiedReq.toString("binary")) == null ? void 0 : _obj$modifiedReq$toSt5.split(`--${boundary}`); // separating the boundary
312
+ obj.data.pop();
313
+ obj.data.shift();
314
+
315
+ //*****Defaults*****
316
+ //To*********extract content
317
+ new ExtractFileContent(obj, options, optionFields, null).extraction();
318
+
319
+ //To*********SetFileDataToReqObj
320
+ new populateReqObj(obj).populate();
321
+ let writeBool = false;
322
+ let parseBool = false;
323
+ let checkCompletion = (writeComplete, parsecomplete) => {
324
+ if (writeComplete && parsecomplete) next();
325
+ };
326
+ EventHandlers.on("parseEnd", message => {
327
+ parseBool = true;
328
+ checkCompletion(writeBool, parseBool);
329
+ });
330
+ EventHandlers.on("writeEnd", message => {
331
+ writeBool = true;
332
+ checkCompletion(writeBool, parseBool);
333
+ });
334
+ new writeFileContent(req, obj, options, "fields", "memory").writeContent();
335
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true) new setFileNameToBody(obj).setFileNames(req);
336
+ new setContentToBody(obj).setBody(req);
337
+ } catch (err) {
338
+ next(err);
339
+ }
340
+ });
341
+ req.on("error", () => {
342
+ next(new FormfluxError("Error in recieving request", 500));
343
+ });
344
+ };
345
+ },
346
+ single(field) {
347
+ return async function (req, res, next) {
348
+ var _req$headers$content6;
349
+ let obj = {
350
+ "originalReq": "",
351
+ "modifiedReq": Buffer.from(""),
352
+ "data": [],
353
+ "content": [],
354
+ "metaData": [],
355
+ "mimeType": [],
356
+ "fieldNameBody": [],
357
+ "fileName": [],
358
+ "modifiedFileName": [],
359
+ "contentBody": [],
360
+ "fieldNameFile": [],
361
+ "filePath": [],
362
+ "filesize": [],
363
+ "streams": []
364
+ };
365
+ let buff = [];
366
+ let reqType = req.headers["content-type"];
367
+ if (reqType && !reqType.includes("multipart/form-data")) throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
368
+ let boundary = (_req$headers$content6 = req.headers["content-type"]) == null ? void 0 : _req$headers$content6.split("boundary=")[1];
369
+ req.on("data", chunk => {
370
+ buff.push(chunk);
371
+ });
372
+ req.on("end", () => {
373
+ try {
374
+ var _obj$modifiedReq$toSt6;
375
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
376
+
377
+ obj.data = (_obj$modifiedReq$toSt6 = obj.modifiedReq.toString("binary")) == null ? void 0 : _obj$modifiedReq$toSt6.split(`--${boundary}`); // separating the boundary
378
+ obj.data.pop();
379
+ obj.data.shift();
380
+
381
+ //*****Defaults*****
382
+ //To*********extract content
383
+ new ExtractFileContent(obj, options, null, field).extraction();
384
+
385
+ //To*********SetFileDataToReqObj
386
+ new populateReqObj(obj).populate();
387
+ let writeBool = false;
388
+ let parseBool = false;
389
+ let checkCompletion = (writeComplete, parsecomplete) => {
390
+ if (writeComplete && parsecomplete) next();
391
+ };
392
+ EventHandlers.on("parseEnd", message => {
393
+ parseBool = true;
394
+ checkCompletion(writeBool, parseBool);
395
+ });
396
+ EventHandlers.on("writeEnd", message => {
397
+ writeBool = true;
398
+ checkCompletion(writeBool, parseBool);
399
+ });
400
+ new writeFileContent(req, obj, options, "single", "memory").writeContent();
401
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true) new setFileNameToBody(obj).setFileNames(req);
402
+ new setContentToBody(obj).setBody(req);
403
+ } catch (err) {
404
+ next(err);
405
+ }
406
+ });
407
+ req.on("error", () => {
408
+ next(new FormfluxError("Error in recieving request", 500));
409
+ });
410
+ };
411
+ }
412
+ };
413
+ }
414
+ bodyParser() {
415
+ return async function (req, res, next) {
416
+ var _req$headers$content7;
417
+ let obj = {
418
+ "originalReq": "",
419
+ "modifiedReq": Buffer.from(""),
420
+ "data": [],
421
+ "content": [],
422
+ "metaData": [],
423
+ "mimeType": [],
424
+ "fieldNameBody": [],
425
+ "fileName": [],
426
+ "modifiedFileName": [],
427
+ "contentBody": [],
428
+ "fieldNameFile": [],
429
+ "filePath": [],
430
+ "filesize": [],
431
+ "streams": []
432
+ };
433
+ let buff = [];
434
+ let reqType = req.headers["content-type"];
435
+ if (reqType && !reqType.includes("multipart/form-data")) throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
436
+ let boundary = (_req$headers$content7 = req.headers["content-type"]) == null ? void 0 : _req$headers$content7.split("boundary=")[1];
437
+ req.on("data", chunk => {
438
+ buff.push(chunk);
439
+ });
440
+ req.on("end", () => {
441
+ try {
442
+ var _obj$modifiedReq$toSt7;
443
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
444
+
445
+ obj.data = (_obj$modifiedReq$toSt7 = obj.modifiedReq.toString("binary")) == null ? void 0 : _obj$modifiedReq$toSt7.split(`--${boundary}`); // separating the boundary
446
+ obj.data.pop();
447
+ obj.data.shift();
448
+
449
+ //*****Defaults*****
450
+ //To*********extract content
451
+ new ExtractFileContent(obj, null, null, null).extraction();
452
+
453
+ //To*********SetFileDataToReqObj
454
+ let writeBool = false;
455
+ let parseBool = false;
456
+ let checkCompletion = (writeComplete, parsecomplete) => {
457
+ if (writeComplete && parsecomplete) next();
458
+ };
459
+ EventHandlers.on("parseEnd", message => {
460
+ parseBool = true;
461
+ next();
462
+ });
463
+ new setContentToBody(obj).setBody(req);
464
+ } catch (err) {
465
+ next(err);
466
+ }
467
+ });
468
+ req.on("error", () => {
469
+ next(new FormfluxError("Error in recieving request", 500));
470
+ });
471
+ };
472
+ }
473
+ }
474
+ export default Formflux;
475
+ //# sourceMappingURL=FormFlux.js.map