@seip/bluebird-js 0.2.0 → 0.2.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.
package/core/cli/route.js CHANGED
@@ -36,7 +36,7 @@ class RouteCLI {
36
36
  const singularName = routeName.endsWith("s") ? routeName.slice(0, -1) : routeName;
37
37
  const pascalName = routeName.charAt(0).toUpperCase() + routeName.slice(1);
38
38
  const routerVarName = `router${pascalName}`;
39
- const basePath = `/${routeName}`;
39
+ const basePath = `/api/${routeName}`;
40
40
 
41
41
  const routesFolder = path.resolve(process.cwd(), "app/routes");
42
42
  if (!fs.existsSync(routesFolder)) {
@@ -59,7 +59,10 @@ class RouteCLI {
59
59
  const content = `import Router from "@seip/bluebird-js/core/router.js";
60
60
  import Validator from "@seip/bluebird-js/core/validate.js";
61
61
  import Cache from "@seip/bluebird-js/core/cache.js";
62
- ${authImport}const ${routerVarName} = new Router("${basePath}");
62
+ import Csrf from "@seip/bluebird-js/core/csrf.js";
63
+ ${authImport}
64
+ const ${routerVarName} = new Router("${basePath}");
65
+ ${routerVarName}.use(Csrf.middleware());
63
66
 
64
67
  const ${singularName}Schema = {
65
68
  name: { required: true, min: 2, max: 255 },
@@ -81,7 +84,7 @@ ${routerVarName}.get("/:id", Cache.middleware(60), (req, res) => {
81
84
  ${routerVarName}.post("/", ${authProtect}validate${pascalName}.middleware(), async (req, res) => {
82
85
  const data = req.body;
83
86
 
84
- await Cache.delete("${basePath}");
87
+ await Cache.invalidateRoute("${basePath}");
85
88
 
86
89
  res.created({ ${singularName}: data }, "${pascalName} created successfully");
87
90
  });
@@ -90,8 +93,7 @@ ${routerVarName}.put("/:id", ${authProtect}validate${pascalName}.middleware(), a
90
93
  const { id } = req.params;
91
94
  const data = req.body;
92
95
 
93
- await Cache.delete("${basePath}");
94
- await Cache.delete(\`${basePath}/\${id}\`);
96
+ await Cache.invalidateRoute("${basePath}");
95
97
 
96
98
  res.ok({ ${singularName}: { id, ...data } }, "${pascalName} updated successfully");
97
99
  });
@@ -99,8 +101,7 @@ ${routerVarName}.put("/:id", ${authProtect}validate${pascalName}.middleware(), a
99
101
  ${routerVarName}.delete("/:id", ${authProtect}async (req, res) => {
100
102
  const { id } = req.params;
101
103
 
102
- await Cache.delete("${basePath}");
103
- await Cache.delete(\`${basePath}/\${id}\`);
104
+ await Cache.invalidateRoute("${basePath}");
104
105
 
105
106
  res.ok({ id }, "${pascalName} deleted successfully");
106
107
  });