nodejs-backpack 0.0.1-security → 2.0.28
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.
Potentially problematic release.
This version of nodejs-backpack might be problematic. Click here for more details.
- package/.sample-env +3 -0
- package/helper.js +76 -0
- package/index.js +676 -0
- package/package.json +53 -6
- package/readme.md +155 -0
- package/sample-app.js +41 -0
- package/sample-auth-controller.js +217 -0
- package/sample-auth-middleware.js +44 -0
- package/sample-auth-route.js +19 -0
- package/sample-config-mailer.js +10 -0
- package/sample-controller.js +174 -0
- package/sample-env +4 -0
- package/sample-file-uploader.js +27 -0
- package/sample-form-parser.js +5 -0
- package/sample-helper.js +138 -0
- package/sample-index-route.js +7 -0
- package/sample-package.json +29 -0
- package/sample-route.js +20 -0
- package/sample-schema-ResetToken.js +26 -0
- package/sample-schema-User.js +51 -0
- package/sample-schema.js +49 -0
- package/sample-validation.js +4 -0
- package/typing.gif +0 -0
- package/README.md +0 -5
package/.sample-env
ADDED
package/helper.js
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
|
3
|
+
function convertToKebabCase(string) {
|
4
|
+
// Convert the first character to lowercase
|
5
|
+
string = string.charAt(0).toLowerCase() + string.slice(1);
|
6
|
+
|
7
|
+
// Add a hyphen before each uppercase letter
|
8
|
+
string = string.replace(/([A-Z])/g, "-$1").toLowerCase();
|
9
|
+
|
10
|
+
return string;
|
11
|
+
}
|
12
|
+
function loadSchemaFromFile(filePath) {
|
13
|
+
// Load the model from the file path
|
14
|
+
const model = require(filePath);
|
15
|
+
// Access the schema from the model
|
16
|
+
const schema = model.schema;
|
17
|
+
return schema;
|
18
|
+
}
|
19
|
+
|
20
|
+
function searchableFields(Model) {
|
21
|
+
var formFields = modelsParams(Model);
|
22
|
+
var uploadFieldArray = [];
|
23
|
+
var searchFields = [];
|
24
|
+
if (
|
25
|
+
formFields &&
|
26
|
+
formFields?.filteredFormFields &&
|
27
|
+
formFields?.filteredFormFields.length
|
28
|
+
) {
|
29
|
+
searchFields = formFields?.filteredFormFields;
|
30
|
+
return searchFields;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
function modelsParams(Schema) {
|
35
|
+
// Obtain the schema parameters object
|
36
|
+
const paths = Schema.paths;
|
37
|
+
let parameters = [];
|
38
|
+
let all = [];
|
39
|
+
let required = [];
|
40
|
+
let optional = [];
|
41
|
+
// Loop over the paths and log each field's name and type
|
42
|
+
for (const path in paths) {
|
43
|
+
let isRequired = paths[path]?.options?.required ? true : false;
|
44
|
+
parameters.push({
|
45
|
+
field: path,
|
46
|
+
is_required: isRequired,
|
47
|
+
});
|
48
|
+
if (isRequired) {
|
49
|
+
required.push(path);
|
50
|
+
} else {
|
51
|
+
optional.push(path);
|
52
|
+
}
|
53
|
+
all.push(path);
|
54
|
+
}
|
55
|
+
const unwantedProps = ["_id", "createdAt", "updatedAt", "__v"];
|
56
|
+
const filteredFormData = all.filter((prop) => !unwantedProps.includes(prop));
|
57
|
+
return {
|
58
|
+
parameters: parameters,
|
59
|
+
allFields: all,
|
60
|
+
requiredFields: required,
|
61
|
+
optionalFields: optional,
|
62
|
+
filteredFormFields: filteredFormData,
|
63
|
+
};
|
64
|
+
}
|
65
|
+
|
66
|
+
function capitalize(str) {
|
67
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
68
|
+
}
|
69
|
+
|
70
|
+
module.exports = {
|
71
|
+
convertToKebabCase,
|
72
|
+
loadSchemaFromFile,
|
73
|
+
modelsParams,
|
74
|
+
capitalize,
|
75
|
+
searchableFields,
|
76
|
+
};
|