@bluemarble/bm-components 1.2.0 → 1.4.0

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/dist/index.mjs CHANGED
@@ -3972,6 +3972,17 @@ var HttpError = class extends Error {
3972
3972
  };
3973
3973
 
3974
3974
  // src/helpers/apiHelper/index.ts
3975
+ var VALID_METHODS = [
3976
+ "GET",
3977
+ "HEAD",
3978
+ "POST",
3979
+ "PUT",
3980
+ "DELETE",
3981
+ "CONNECT",
3982
+ "OPTIONS",
3983
+ "TRACE",
3984
+ "PATCH"
3985
+ ];
3975
3986
  var ApiHelper = class _ApiHelper {
3976
3987
  onFinally(req, res) {
3977
3988
  return __async(this, null, function* () {
@@ -3983,9 +3994,9 @@ var ApiHelper = class _ApiHelper {
3983
3994
  }
3984
3995
  constructor(props) {
3985
3996
  this.middlewares = ((props == null ? void 0 : props.middlewares) || []).reverse();
3986
- this.onFinally = props.onFinally || (() => __async(this, null, function* () {
3997
+ this.onFinally = (props == null ? void 0 : props.onFinally) || (() => __async(this, null, function* () {
3987
3998
  }));
3988
- this.onError = props.onError || (() => __async(this, null, function* () {
3999
+ this.onError = (props == null ? void 0 : props.onError) || (() => __async(this, null, function* () {
3989
4000
  }));
3990
4001
  }
3991
4002
  setMiddlewares(middlewares) {
@@ -3994,12 +4005,14 @@ var ApiHelper = class _ApiHelper {
3994
4005
  }
3995
4006
  createMethods(methods) {
3996
4007
  return (req, res) => __async(this, null, function* () {
3997
- const currentMethod = methods[req.method];
4008
+ const currentMethod = methods[req.method] || methods.ALL;
3998
4009
  if (req.method === "OPTIONS")
3999
4010
  return res.status(200).end();
4000
4011
  try {
4001
- if (!currentMethod)
4012
+ if (!VALID_METHODS.includes(req.method))
4002
4013
  throw new HttpError(405, "M\xE9todo inv\xE1lido");
4014
+ if (!currentMethod)
4015
+ throw new HttpError(500, "M\xE9todo n\xE3o encontrado");
4003
4016
  const methodWithMiddlewares = this.middlewares.reduce(
4004
4017
  (acc, fn) => fn(acc),
4005
4018
  currentMethod