fix: Remove medusa v2 flag from the medusa app package (#7295)
This commit is contained in:
@@ -8,7 +8,6 @@ import { MedusaError, isDefined } from "medusa-core-utils"
|
||||
import { RequestQueryFields } from "@medusajs/types"
|
||||
import { BaseEntity } from "../interfaces"
|
||||
import { featureFlagRouter } from "../loaders/feature-flags"
|
||||
import MedusaV2 from "../loaders/feature-flags/medusa-v2"
|
||||
import { FindConfig, QueryConfig } from "../types/common"
|
||||
|
||||
export function pickByConfig<TModel extends BaseEntity>(
|
||||
@@ -31,8 +30,6 @@ export function prepareListQuery<
|
||||
T extends RequestQueryFields,
|
||||
TEntity extends BaseEntity
|
||||
>(validated: T, queryConfig: QueryConfig<TEntity> = {}) {
|
||||
const isMedusaV2 = featureFlagRouter.isFeatureEnabled(MedusaV2.key)
|
||||
|
||||
// TODO: this function will be simplified a lot once we drop support for the old api
|
||||
const { order, fields, limit = 50, expand, offset = 0 } = validated
|
||||
let {
|
||||
@@ -190,10 +187,6 @@ export function prepareListQuery<
|
||||
`Order field ${orderField} is not valid`
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if (!isMedusaV2) {
|
||||
orderBy["created_at"] = "DESC"
|
||||
}
|
||||
}
|
||||
|
||||
const finalOrder = isPresent(orderBy) ? orderBy : undefined
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("transformQuery", () => {
|
||||
offset: number
|
||||
limit: number
|
||||
inputOrder: string | undefined
|
||||
transformedOrder: Record<string, "ASC" | "DESC">
|
||||
transformedOrder?: Record<string, "ASC" | "DESC">
|
||||
relations?: string[]
|
||||
}) => {
|
||||
expect(mockRequest.validatedQuery).toEqual({
|
||||
@@ -115,9 +115,6 @@ describe("transformQuery", () => {
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
inputOrder: undefined,
|
||||
transformedOrder: {
|
||||
created_at: "DESC",
|
||||
},
|
||||
})
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
@@ -1,34 +1,11 @@
|
||||
import { ContainerRegistrationKeys, MedusaV2Flag } from "@medusajs/utils"
|
||||
import { NextFunction, Request, RequestHandler, Response } from "express"
|
||||
|
||||
import passport from "passport"
|
||||
|
||||
// TODO: See how this should look like for v2.
|
||||
// Optional customer authentication
|
||||
// If authenticated, middleware attaches customer to request (as user) otherwise we pass through
|
||||
// If you want to require authentication, use `requireCustomerAuthentication` in `packages/medusa/src/api/middlewares/require-customer-authentication.ts`
|
||||
export default (): RequestHandler => {
|
||||
return (req: Request, res: Response, next: NextFunction): void => {
|
||||
const featureFlagRouter = req.scope.resolve(
|
||||
ContainerRegistrationKeys.FEATURE_FLAG_ROUTER
|
||||
)
|
||||
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
|
||||
return next()
|
||||
}
|
||||
|
||||
passport.authenticate(
|
||||
["store-session", "store-bearer"],
|
||||
{ session: false },
|
||||
(err, user) => {
|
||||
if (err) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
if (user) {
|
||||
req.user = user
|
||||
}
|
||||
|
||||
return next()
|
||||
}
|
||||
)(req, res, next)
|
||||
return next()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
import { ContainerRegistrationKeys, MedusaV2Flag } from "@medusajs/utils"
|
||||
import { NextFunction, Request, RequestHandler, Response } from "express"
|
||||
|
||||
import passport from "passport"
|
||||
|
||||
// TODO: See how this should look like for v2.
|
||||
export default (): RequestHandler => {
|
||||
return (req: Request, res: Response, next: NextFunction): void => {
|
||||
const featureFlagRouter = req.scope.resolve(
|
||||
ContainerRegistrationKeys.FEATURE_FLAG_ROUTER
|
||||
)
|
||||
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
|
||||
return next()
|
||||
}
|
||||
passport.authenticate(
|
||||
["admin-session", "admin-bearer", "admin-api-token"],
|
||||
{ session: false }
|
||||
)(req, res, next)
|
||||
return next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user