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 ADDED
@@ -0,0 +1,3 @@
1
+ PORT=3000
2
+ DB="mongodb+srv://USERNAME:PASSWORD@mongo.9bdgpey.mongodb.net/node_backpack"
3
+ JWT_SIGNATURE=node_backpack
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
+ };