From aa34d0fe9cca03e0433b19a7ea5fab37a9987b09 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 28 Oct 2025 11:08:32 +0200 Subject: [PATCH] chore: fixes to http and request types for inventory (#13827) * chore: fixes to http and request types for inventory * fix type error --- .../core/js-sdk/src/admin/inventory-item.ts | 2 +- .../types/src/http/inventory/admin/queries.ts | 4 ++-- .../src/http/reservation/admin/queries.ts | 20 ++++++++----------- .../location-levels/[location_id]/route.ts | 8 +++++--- .../[id]/location-levels/route.ts | 11 +++++----- .../api/admin/inventory-items/[id]/route.ts | 11 +++++----- .../src/api/admin/inventory-items/route.ts | 7 +++++-- .../src/api/admin/reservations/[id]/route.ts | 13 ++++++------ .../src/api/admin/reservations/route.ts | 5 ++++- .../[id]/fulfillment-providers/route.ts | 7 +++++-- .../[id]/fulfillment-sets/route.ts | 6 ++++-- .../api/admin/stock-locations/[id]/route.ts | 6 ++++-- .../[id]/sales-channels/route.ts | 7 +++++-- .../src/api/admin/stock-locations/route.ts | 5 ++++- 14 files changed, 64 insertions(+), 48 deletions(-) diff --git a/packages/core/js-sdk/src/admin/inventory-item.ts b/packages/core/js-sdk/src/admin/inventory-item.ts index ffb6ebbba0..fd1c0cecdb 100644 --- a/packages/core/js-sdk/src/admin/inventory-item.ts +++ b/packages/core/js-sdk/src/admin/inventory-item.ts @@ -132,7 +132,7 @@ export class InventoryItem { * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations). */ async list( - query?: HttpTypes.AdminInventoryItemParams, + query?: HttpTypes.AdminInventoryItemsParams, headers?: ClientHeaders ) { return await this.client.fetch( diff --git a/packages/core/types/src/http/inventory/admin/queries.ts b/packages/core/types/src/http/inventory/admin/queries.ts index bfc1a6274f..3a86789b75 100644 --- a/packages/core/types/src/http/inventory/admin/queries.ts +++ b/packages/core/types/src/http/inventory/admin/queries.ts @@ -1,9 +1,9 @@ import { FindParams } from "../../common" import { BaseFilterable, OperatorMap } from "../../../dal" -export interface AdminInventoryItemParams +export interface AdminInventoryItemsParams extends FindParams, - BaseFilterable { + BaseFilterable { /** * Filter by inventory item ID(s). */ diff --git a/packages/core/types/src/http/reservation/admin/queries.ts b/packages/core/types/src/http/reservation/admin/queries.ts index 0fc5621247..e89b3439bc 100644 --- a/packages/core/types/src/http/reservation/admin/queries.ts +++ b/packages/core/types/src/http/reservation/admin/queries.ts @@ -1,15 +1,11 @@ import { OperatorMap } from "../../../dal" -import { SelectParams } from "../../common" +import { FindParams, SelectParams } from "../../common" -export interface AdminGetReservationsParams { +export interface AdminGetReservationsParams extends FindParams { /** - * The maximum number of reservations to retrieve. + * A search term to search for reservations by their searchable fields. */ - limit?: number - /** - * The number of reservations to skip. - */ - offset?: number + q?: string /** * Filter by the ID(s) of the location(s) to retrieve the * reservations for. @@ -25,10 +21,6 @@ export interface AdminGetReservationsParams { * reservations for. */ line_item_id?: string | string[] - /** - * Sort the reservations by the given field. - */ - order_id?: string | string[] /** * Filter by the ID(s) of the user(s) to retrieve the * reservations they created. @@ -38,6 +30,10 @@ export interface AdminGetReservationsParams { * Filter by reservation description(s). */ description?: string | OperatorMap + /** + * Filter by reservation quantity. + */ + quantity?: OperatorMap /** * Apply filters on the reservation's creation date. */ diff --git a/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts b/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts index 04fc92fc9e..80697b61a0 100644 --- a/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts +++ b/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts @@ -10,10 +10,9 @@ import { } from "@medusajs/core-flows" import { HttpTypes } from "@medusajs/framework/types" import { refetchInventoryItem } from "../../../helpers" -import { AdminUpdateInventoryLocationLevelType } from "../../../validators" export const DELETE = async ( - req: MedusaRequest, + req: MedusaRequest<{}, HttpTypes.SelectParams>, res: MedusaResponse ) => { const { id, location_id } = req.params @@ -65,7 +64,10 @@ export const DELETE = async ( } export const POST = async ( - req: MedusaRequest, + req: MedusaRequest< + HttpTypes.AdminUpdateInventoryLevel, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id, location_id } = req.params diff --git a/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/route.ts b/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/route.ts index b3e2e201ad..f8ae4c3372 100644 --- a/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/route.ts +++ b/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/route.ts @@ -5,15 +5,14 @@ import { import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" import { createInventoryLevelsWorkflow } from "@medusajs/core-flows" -import { - AdminCreateInventoryLocationLevelType, - AdminGetInventoryLocationLevelsParamsType, -} from "../../validators" import { refetchInventoryItem } from "../../helpers" import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( - req: MedusaRequest, + req: MedusaRequest< + HttpTypes.AdminBatchCreateInventoryItemLocationLevels, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id } = req.params @@ -39,7 +38,7 @@ export const POST = async ( } export const GET = async ( - req: MedusaRequest, + req: MedusaRequest, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/inventory-items/[id]/route.ts b/packages/medusa/src/api/admin/inventory-items/[id]/route.ts index 9e92f3ec79..4b29904766 100644 --- a/packages/medusa/src/api/admin/inventory-items/[id]/route.ts +++ b/packages/medusa/src/api/admin/inventory-items/[id]/route.ts @@ -4,15 +4,11 @@ import { deleteInventoryItemWorkflow, updateInventoryItemsWorkflow, } from "@medusajs/core-flows" -import { - AdminGetInventoryItemParamsType, - AdminUpdateInventoryItemType, -} from "../validators" import { refetchInventoryItem } from "../helpers" import { HttpTypes } from "@medusajs/framework/types" export const GET = async ( - req: MedusaRequest, + req: MedusaRequest, res: MedusaResponse ) => { const { id } = req.params @@ -35,7 +31,10 @@ export const GET = async ( // Update inventory item export const POST = async ( - req: MedusaRequest, + req: MedusaRequest< + HttpTypes.AdminUpdateInventoryItem, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/inventory-items/route.ts b/packages/medusa/src/api/admin/inventory-items/route.ts index 17d0d13fbc..615531c9f1 100644 --- a/packages/medusa/src/api/admin/inventory-items/route.ts +++ b/packages/medusa/src/api/admin/inventory-items/route.ts @@ -12,7 +12,10 @@ import { refetchInventoryItem } from "./helpers" import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminCreateInventoryItem, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { result } = await createInventoryItemsWorkflow(req.scope).run({ @@ -29,7 +32,7 @@ export const POST = async ( } export const GET = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest, res: MedusaResponse ) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) diff --git a/packages/medusa/src/api/admin/reservations/[id]/route.ts b/packages/medusa/src/api/admin/reservations/[id]/route.ts index 9d8ce655d0..b042579ea0 100644 --- a/packages/medusa/src/api/admin/reservations/[id]/route.ts +++ b/packages/medusa/src/api/admin/reservations/[id]/route.ts @@ -2,10 +2,6 @@ import { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/framework/http" -import { - AdminGetReservationParamsType, - AdminUpdateReservationType, -} from "../validators" import { MedusaError } from "@medusajs/framework/utils" import { deleteReservationsWorkflow, @@ -15,7 +11,9 @@ import { refetchReservation } from "../helpers" import { HttpTypes } from "@medusajs/framework/types" export const GET = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminReservationParams + >, res: MedusaResponse ) => { const { id } = req.params @@ -37,7 +35,10 @@ export const GET = async ( } export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminUpdateReservation, + HttpTypes.AdminReservationParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/reservations/route.ts b/packages/medusa/src/api/admin/reservations/route.ts index f96cb0a34d..0ad78de2fe 100644 --- a/packages/medusa/src/api/admin/reservations/route.ts +++ b/packages/medusa/src/api/admin/reservations/route.ts @@ -37,7 +37,10 @@ export const GET = async ( } export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminCreateReservation, + HttpTypes.AdminGetReservationsParams + >, res: MedusaResponse ) => { const input = [req.validatedBody] diff --git a/packages/medusa/src/api/admin/stock-locations/[id]/fulfillment-providers/route.ts b/packages/medusa/src/api/admin/stock-locations/[id]/fulfillment-providers/route.ts index 8585055f4e..7fc753553e 100644 --- a/packages/medusa/src/api/admin/stock-locations/[id]/fulfillment-providers/route.ts +++ b/packages/medusa/src/api/admin/stock-locations/[id]/fulfillment-providers/route.ts @@ -1,5 +1,5 @@ import { batchLinksWorkflow } from "@medusajs/core-flows" -import { HttpTypes, LinkMethodRequest } from "@medusajs/framework/types" +import { HttpTypes } from "@medusajs/framework/types" import { Modules } from "@medusajs/framework/utils" import { @@ -18,7 +18,10 @@ const buildLinks = (id, fulfillmentProviderIds: string[]) => { } export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminBatchLink, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/stock-locations/[id]/fulfillment-sets/route.ts b/packages/medusa/src/api/admin/stock-locations/[id]/fulfillment-sets/route.ts index 1156122f6e..e712b8ee7c 100644 --- a/packages/medusa/src/api/admin/stock-locations/[id]/fulfillment-sets/route.ts +++ b/packages/medusa/src/api/admin/stock-locations/[id]/fulfillment-sets/route.ts @@ -4,11 +4,13 @@ import { MedusaResponse, } from "@medusajs/framework/http" import { refetchStockLocation } from "../../helpers" -import { AdminCreateStockLocationFulfillmentSetType } from "../../validators" import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminCreateStockLocationFulfillmentSet, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { await createLocationFulfillmentSetWorkflow(req.scope).run({ diff --git a/packages/medusa/src/api/admin/stock-locations/[id]/route.ts b/packages/medusa/src/api/admin/stock-locations/[id]/route.ts index 90e62899aa..df5ccec4d5 100644 --- a/packages/medusa/src/api/admin/stock-locations/[id]/route.ts +++ b/packages/medusa/src/api/admin/stock-locations/[id]/route.ts @@ -11,12 +11,14 @@ import { MedusaError } from "@medusajs/framework/utils" import { refetchStockLocation } from "../helpers" import { AdminGetStockLocationParamsType, - AdminUpdateStockLocationType, } from "../validators" import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminUpdateStockLocation, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/stock-locations/[id]/sales-channels/route.ts b/packages/medusa/src/api/admin/stock-locations/[id]/sales-channels/route.ts index cab1f492e7..7aaa5ea173 100644 --- a/packages/medusa/src/api/admin/stock-locations/[id]/sales-channels/route.ts +++ b/packages/medusa/src/api/admin/stock-locations/[id]/sales-channels/route.ts @@ -4,11 +4,14 @@ import { } from "@medusajs/framework/http" import { linkSalesChannelsToStockLocationWorkflow } from "@medusajs/core-flows" -import { HttpTypes, LinkMethodRequest } from "@medusajs/framework/types" +import { HttpTypes } from "@medusajs/framework/types" import { refetchStockLocation } from "../../helpers" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminBatchLink, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/stock-locations/route.ts b/packages/medusa/src/api/admin/stock-locations/route.ts index dcfc204310..aa03a53c91 100644 --- a/packages/medusa/src/api/admin/stock-locations/route.ts +++ b/packages/medusa/src/api/admin/stock-locations/route.ts @@ -13,7 +13,10 @@ import { HttpTypes } from "@medusajs/framework/types" // Create stock location export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminCreateStockLocation, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { result } = await createStockLocationsWorkflow(req.scope).run({