From 13ddf27c68fc2831b3661940bc5f27bab23ce8c0 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 23 Dec 2024 18:10:08 +0200 Subject: [PATCH] fix(medusa,types,js-sdk): fix request query parameter types for store product routes (#10707) * fix(medusa,types): fix request query parameter types for store product routes * fix test errors --- .changeset/dull-chairs-whisper.md | 7 ++++ packages/core/js-sdk/src/store/index.ts | 4 +-- .../types/src/http/product/store/queries.ts | 36 +++++++++++-------- .../src/api/store/products/[id]/route.ts | 3 +- .../medusa/src/api/store/products/route.ts | 2 +- 5 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 .changeset/dull-chairs-whisper.md diff --git a/.changeset/dull-chairs-whisper.md b/.changeset/dull-chairs-whisper.md new file mode 100644 index 0000000000000..d1cbe7bcd3f2f --- /dev/null +++ b/.changeset/dull-chairs-whisper.md @@ -0,0 +1,7 @@ +--- +"@medusajs/types": patch +"@medusajs/medusa": patch +"@medusajs/js-sdk": patch +--- + +fix(medusa,types,js-sdk): fix request query parameter types for store product routes diff --git a/packages/core/js-sdk/src/store/index.ts b/packages/core/js-sdk/src/store/index.ts index c08786f11de57..0be8540f386c0 100644 --- a/packages/core/js-sdk/src/store/index.ts +++ b/packages/core/js-sdk/src/store/index.ts @@ -401,7 +401,7 @@ export class Store { * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations). */ list: async ( - query?: HttpTypes.StoreProductParams, + query?: HttpTypes.StoreProductListParams, headers?: ClientHeaders ) => { return this.client.fetch( @@ -451,7 +451,7 @@ export class Store { */ retrieve: async ( id: string, - query?: SelectParams, + query?: HttpTypes.StoreProductParams, headers?: ClientHeaders ) => { return this.client.fetch( diff --git a/packages/core/types/src/http/product/store/queries.ts b/packages/core/types/src/http/product/store/queries.ts index e7b71fbedd413..7862ae3c9b02e 100644 --- a/packages/core/types/src/http/product/store/queries.ts +++ b/packages/core/types/src/http/product/store/queries.ts @@ -1,3 +1,4 @@ +import { FindParams } from "../../common" import { BaseProductListParams, BaseProductOptionParams, @@ -6,29 +7,34 @@ import { export interface StoreProductOptionParams extends BaseProductOptionParams {} export interface StoreProductVariantParams extends BaseProductVariantParams {} -export interface StoreProductParams - extends Omit { +export interface StoreProductPricingContext { /** - * Filter by the product's tag(s). + * The ID of the customer's region. This parameter must be included if you want to apply taxes on the product variant's price. */ - tag_id?: string | string[] + region_id?: string /** - * The ID of the region the products are being viewed from. This is required if you're retrieving product variant prices with taxes. - * - * @privateRemarks - * The region ID and currency_code are not params, but are used for the pricing context. Maybe move to separate type definition. + * The customer's country code. This parameter must be included if you want to apply taxes on the product variant's price. */ - region_id?: string + country_code?: string /** - * The currency code to retrieve prices in. + * The province, which can be taken from a customer's address. This parameter helps further narrowing down the taxes applied on a the product variant's prices. */ - currency_code?: string + province?: string /** - * Filter by the product's variants. + * The ID of the customer's cart, if available. If set, the cart's region and shipping address's country code and province are used instead of the `region_id`, `country_code`, and `province` parameters. */ - variants?: Pick + cart_id?: string +} +export interface StoreProductParams extends FindParams, StoreProductPricingContext {} + +export interface StoreProductListParams + extends Omit, StoreProductPricingContext { /** - * The province the products are being viewed from. This is useful to narrow down the tax context when calculating product variant prices with taxes. + * Filter by the product's tag(s). */ - province?: string + tag_id?: string | string[] + /** + * Filter by the product's variants. + */ + variants?: Pick } diff --git a/packages/medusa/src/api/store/products/[id]/route.ts b/packages/medusa/src/api/store/products/[id]/route.ts index 6c96a075e1b54..88c24d614c69a 100644 --- a/packages/medusa/src/api/store/products/[id]/route.ts +++ b/packages/medusa/src/api/store/products/[id]/route.ts @@ -6,11 +6,10 @@ import { RequestWithContext, wrapProductsWithTaxPrices, } from "../helpers" -import { StoreGetProductParamsType } from "../validators" import { HttpTypes } from "@medusajs/framework/types" export const GET = async ( - req: RequestWithContext, + req: RequestWithContext, res: MedusaResponse ) => { const withInventoryQuantity = req.remoteQueryConfig.fields.some((field) => diff --git a/packages/medusa/src/api/store/products/route.ts b/packages/medusa/src/api/store/products/route.ts index 4fbc50419bf5a..a9741fe8e2fa4 100644 --- a/packages/medusa/src/api/store/products/route.ts +++ b/packages/medusa/src/api/store/products/route.ts @@ -9,7 +9,7 @@ import { RequestWithContext, wrapProductsWithTaxPrices } from "./helpers" import { HttpTypes } from "@medusajs/framework/types" export const GET = async ( - req: RequestWithContext, + req: RequestWithContext, res: MedusaResponse ) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)