Skip to content

Commit

Permalink
fix(medusa,types,js-sdk): fix request query parameter types for store…
Browse files Browse the repository at this point in the history
… product routes (#10707)

* fix(medusa,types): fix request query parameter types for store product routes

* fix test errors
  • Loading branch information
shahednasser authored Dec 23, 2024
1 parent be9b19e commit 13ddf27
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .changeset/dull-chairs-whisper.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions packages/core/js-sdk/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpTypes.StoreProductListResponse>(
Expand Down Expand Up @@ -451,7 +451,7 @@ export class Store {
*/
retrieve: async (
id: string,
query?: SelectParams,
query?: HttpTypes.StoreProductParams,
headers?: ClientHeaders
) => {
return this.client.fetch<HttpTypes.StoreProductResponse>(
Expand Down
36 changes: 21 additions & 15 deletions packages/core/types/src/http/product/store/queries.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FindParams } from "../../common"
import {
BaseProductListParams,
BaseProductOptionParams,
Expand All @@ -6,29 +7,34 @@ import {

export interface StoreProductOptionParams extends BaseProductOptionParams {}
export interface StoreProductVariantParams extends BaseProductVariantParams {}
export interface StoreProductParams
extends Omit<BaseProductListParams, "tags" | "status" | "categories" | "deleted_at"> {
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<StoreProductVariantParams, "options">
cart_id?: string
}
export interface StoreProductParams extends FindParams, StoreProductPricingContext {}

export interface StoreProductListParams
extends Omit<BaseProductListParams, "tags" | "status" | "categories" | "deleted_at">, 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<StoreProductVariantParams, "options">
}
3 changes: 1 addition & 2 deletions packages/medusa/src/api/store/products/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoreGetProductParamsType>,
req: RequestWithContext<HttpTypes.StoreProductParams>,
res: MedusaResponse<HttpTypes.StoreProductResponse>
) => {
const withInventoryQuantity = req.remoteQueryConfig.fields.some((field) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api/store/products/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RequestWithContext, wrapProductsWithTaxPrices } from "./helpers"
import { HttpTypes } from "@medusajs/framework/types"

export const GET = async (
req: RequestWithContext<HttpTypes.StoreProductParams>,
req: RequestWithContext<HttpTypes.StoreProductListParams>,
res: MedusaResponse<HttpTypes.StoreProductListResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
Expand Down

0 comments on commit 13ddf27

Please sign in to comment.