sprint-es 0.0.138 → 0.0.139
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/cjs/index.cjs +6 -12
- package/dist/esm/index.js +6 -12
- package/dist/types/middleware.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -908,7 +908,8 @@ function createSchemaValidationMiddleware(schema) {
|
|
|
908
908
|
if (!authValue) errors.push({ location: "sprint.authorization", path: "authorization", message: "Authorization header or query parameter not found" });
|
|
909
909
|
else req.sprint.authorization = authValue;
|
|
910
910
|
}
|
|
911
|
-
|
|
911
|
+
const errorCode = schema.sprint?.authorization && errors.find((e) => e.location === "sprint.authorization") ? 401 : 400;
|
|
912
|
+
if (errors.length > 0) return res.status(errorCode).json({ error: "Validation failed", details: errors });
|
|
912
913
|
next();
|
|
913
914
|
};
|
|
914
915
|
}
|
|
@@ -920,22 +921,15 @@ function defineMiddleware(config) {
|
|
|
920
921
|
};
|
|
921
922
|
};
|
|
922
923
|
const handlers = [];
|
|
923
|
-
if (config.schema)
|
|
924
|
-
handlers.push(createSchemaValidationMiddleware(config.schema));
|
|
925
|
-
}
|
|
924
|
+
if (config.schema) handlers.push(createSchemaValidationMiddleware(config.schema));
|
|
926
925
|
const originalHandler = config.handler;
|
|
927
|
-
if (Array.isArray(originalHandler))
|
|
928
|
-
|
|
929
|
-
} else {
|
|
930
|
-
handlers.push(wrapHandler(originalHandler));
|
|
931
|
-
}
|
|
926
|
+
if (Array.isArray(originalHandler)) handlers.push(...originalHandler.map(wrapHandler));
|
|
927
|
+
else handlers.push(wrapHandler(originalHandler));
|
|
932
928
|
const finalConfig = {
|
|
933
929
|
...config,
|
|
934
930
|
handler: handlers
|
|
935
931
|
};
|
|
936
|
-
if (config.schema)
|
|
937
|
-
finalConfig.__sprintMiddlewareSchema = config.schema;
|
|
938
|
-
}
|
|
932
|
+
if (config.schema) finalConfig.__sprintMiddlewareSchema = config.schema;
|
|
939
933
|
return finalConfig;
|
|
940
934
|
}
|
|
941
935
|
const Router = () => express.Router();
|
package/dist/esm/index.js
CHANGED
|
@@ -883,7 +883,8 @@ function createSchemaValidationMiddleware(schema) {
|
|
|
883
883
|
if (!authValue) errors.push({ location: "sprint.authorization", path: "authorization", message: "Authorization header or query parameter not found" });
|
|
884
884
|
else req.sprint.authorization = authValue;
|
|
885
885
|
}
|
|
886
|
-
|
|
886
|
+
const errorCode = schema.sprint?.authorization && errors.find((e) => e.location === "sprint.authorization") ? 401 : 400;
|
|
887
|
+
if (errors.length > 0) return res.status(errorCode).json({ error: "Validation failed", details: errors });
|
|
887
888
|
next();
|
|
888
889
|
};
|
|
889
890
|
}
|
|
@@ -895,22 +896,15 @@ function defineMiddleware(config) {
|
|
|
895
896
|
};
|
|
896
897
|
};
|
|
897
898
|
const handlers = [];
|
|
898
|
-
if (config.schema)
|
|
899
|
-
handlers.push(createSchemaValidationMiddleware(config.schema));
|
|
900
|
-
}
|
|
899
|
+
if (config.schema) handlers.push(createSchemaValidationMiddleware(config.schema));
|
|
901
900
|
const originalHandler = config.handler;
|
|
902
|
-
if (Array.isArray(originalHandler))
|
|
903
|
-
|
|
904
|
-
} else {
|
|
905
|
-
handlers.push(wrapHandler(originalHandler));
|
|
906
|
-
}
|
|
901
|
+
if (Array.isArray(originalHandler)) handlers.push(...originalHandler.map(wrapHandler));
|
|
902
|
+
else handlers.push(wrapHandler(originalHandler));
|
|
907
903
|
const finalConfig = {
|
|
908
904
|
...config,
|
|
909
905
|
handler: handlers
|
|
910
906
|
};
|
|
911
|
-
if (config.schema)
|
|
912
|
-
finalConfig.__sprintMiddlewareSchema = config.schema;
|
|
913
|
-
}
|
|
907
|
+
if (config.schema) finalConfig.__sprintMiddlewareSchema = config.schema;
|
|
914
908
|
return finalConfig;
|
|
915
909
|
}
|
|
916
910
|
const Router = () => Router$1();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAyC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAyC,MAAM,SAAS,CAAC;AAiGlF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAwB3E"}
|