feature: add telemetry to the HTTP layer (#9116)
--------- Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
This commit is contained in:
co-authored by
adrien2p
parent
8c2a5fbcf2
commit
9cf0df53b5
@@ -7,7 +7,11 @@ import { NextFunction } from "express"
|
||||
import { MedusaRequest } from "../../../../types/routing"
|
||||
|
||||
export function maybeApplyPriceListsFilter() {
|
||||
return async (req: MedusaRequest, _, next: NextFunction) => {
|
||||
return async function applyPriceListsFilter(
|
||||
req: MedusaRequest,
|
||||
_,
|
||||
next: NextFunction
|
||||
) {
|
||||
const filterableFields: HttpTypes.AdminProductListParams =
|
||||
req.filterableFields
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export function maybeApplyLinkFilter({
|
||||
filterableField,
|
||||
filterByField = "id",
|
||||
}) {
|
||||
return async (req: MedusaRequest, _, next: NextFunction) => {
|
||||
return async function linkFilter(req: MedusaRequest, _, next: NextFunction) {
|
||||
const filterableFields = req.filterableFields
|
||||
|
||||
if (!filterableFields?.[filterableField]) {
|
||||
@@ -76,27 +76,26 @@ export function maybeApplyLinkFilter({
|
||||
}
|
||||
*/
|
||||
function transformFilterableFields(filterableFields: Record<string, unknown>) {
|
||||
const result = {};
|
||||
const result = {}
|
||||
for (const key of Object.keys(filterableFields)) {
|
||||
const value = filterableFields[key];
|
||||
const keys = key.split(".");
|
||||
let current = result;
|
||||
const value = filterableFields[key]
|
||||
const keys = key.split(".")
|
||||
let current = result
|
||||
|
||||
// Iterate over the keys, creating nested objects as needed
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const part = keys[i];
|
||||
current[part] ??= {};
|
||||
const part = keys[i]
|
||||
current[part] ??= {}
|
||||
|
||||
if (i === keys.length - 1) {
|
||||
// If its the last key, assign the value
|
||||
current[part] = value;
|
||||
break;
|
||||
current[part] = value
|
||||
break
|
||||
}
|
||||
|
||||
current = current[part];
|
||||
current = current[part]
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,11 @@ export function validateAndTransformBody(
|
||||
res: MedusaResponse,
|
||||
next: NextFunction
|
||||
) => Promise<void> {
|
||||
return async (req: MedusaRequest, _: MedusaResponse, next: NextFunction) => {
|
||||
return async function validateBody(
|
||||
req: MedusaRequest,
|
||||
_: MedusaResponse,
|
||||
next: NextFunction
|
||||
) {
|
||||
try {
|
||||
let schema: z.ZodObject<any, any> | z.ZodEffects<any, any>
|
||||
if (typeof zodSchema === "function") {
|
||||
|
||||
@@ -65,7 +65,11 @@ export function validateAndTransformQuery<TEntity extends BaseEntity>(
|
||||
res: MedusaResponse,
|
||||
next: NextFunction
|
||||
) => Promise<void> {
|
||||
return async (req: MedusaRequest, _: MedusaResponse, next: NextFunction) => {
|
||||
return async function validateQuery(
|
||||
req: MedusaRequest,
|
||||
_: MedusaResponse,
|
||||
next: NextFunction
|
||||
) {
|
||||
try {
|
||||
const allowed = (req.allowed ?? queryConfig.allowed ?? []) as string[]
|
||||
delete req.allowed
|
||||
|
||||
Reference in New Issue
Block a user