chore: fixes to http and request types for products (#13833)
## Summary
**What** — What changes are introduced in this PR?
This PR is part of a series of PRs to fix HTTP and request type arguments.
This is the last PR in the series. It includes a changeset for the changes made.
**Why** — Why are these changes relevant or necessary?
These types impact the outputted OAS which we show on the API reference. By fixing up the types, we ensure accurate request parameters in the API reference.
**How** — How have these changes been implemented?
Made changes to HTTP types and request type arguments
**Testing** — How have these changes been tested, or how can the reviewer test the feature?
-
---
## Examples
-
---
## Checklist
Please ensure the following before requesting a review:
- [ ] I have added a **changeset** for this PR
- Every non-breaking change should be marked as a **patch**
- To add a changeset, run `yarn changeset` and follow the prompts
- [ ] The changes are covered by relevant **tests**
- [ ] I have verified the code works as intended locally
- [ ] I have linked the related issue(s) if applicable
---
## Additional Context
-
This commit is contained in:
6
.changeset/empty-peaches-crash.md
Normal file
6
.changeset/empty-peaches-crash.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/types": patch
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
chore(types,medusa): clean up HTTP and request type arguments
|
||||
@@ -404,6 +404,11 @@ export interface AdminUpdateProduct {
|
||||
* The product's images.
|
||||
*/
|
||||
images?: {
|
||||
/**
|
||||
* The ID of the image to update
|
||||
* or set for existing images.
|
||||
*/
|
||||
id?: string
|
||||
/**
|
||||
* The image's URL.
|
||||
*/
|
||||
@@ -532,6 +537,12 @@ export interface AdminUpdateProductOption {
|
||||
values?: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @privateRemarks
|
||||
* These types don't match the validators, however, they're used by the admin
|
||||
* dashboard. We should update the admin dashboard to use different types that it
|
||||
* needs instead.
|
||||
*/
|
||||
interface AdminCreateProductVariantInventoryItem {
|
||||
/**
|
||||
* The number of units a single quantity is equivalent to. For example, if a customer orders one quantity of the variant, Medusa checks the availability of the quantity multiplied by the
|
||||
@@ -548,6 +559,12 @@ interface AdminCreateProductVariantInventoryItem {
|
||||
variant_id: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @privateRemarks
|
||||
* These types don't match the validators, however, they're used by the admin
|
||||
* dashboard. We should update the admin dashboard to use different types that it
|
||||
* needs instead.
|
||||
*/
|
||||
interface AdminUpdateProductVariantInventoryItem {
|
||||
/**
|
||||
* The number of units a single quantity is equivalent to. For example, if a customer orders one quantity of the variant, Medusa checks the availability of the quantity multiplied by the
|
||||
|
||||
@@ -60,3 +60,16 @@ export interface AdminProductListParams
|
||||
*/
|
||||
variants?: Omit<AdminProductVariantParams, "q">
|
||||
}
|
||||
|
||||
export interface AdminProductExportParams extends Omit<AdminProductListParams, "tags" | "variants"> {
|
||||
tags?: {
|
||||
id?: string[]
|
||||
}
|
||||
variants?: {
|
||||
options?: {
|
||||
value?: string
|
||||
option_id?: string
|
||||
option?: Record<string, any>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { batchLinkProductsToCollectionWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/framework/types"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -7,7 +7,10 @@ import {
|
||||
import { refetchCollection } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminBatchLink,
|
||||
HttpTypes.AdminCollectionParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
@@ -13,7 +13,7 @@ import { refetchCollection } from "../helpers"
|
||||
import { AdminUpdateCollectionType } from "../validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminCollectionParams>,
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
|
||||
) => {
|
||||
const collection = await refetchCollection(
|
||||
@@ -26,7 +26,10 @@ export const GET = async (
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateCollectionType & AdditionalData>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
AdminUpdateCollectionType & AdditionalData,
|
||||
HttpTypes.AdminCollectionParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
|
||||
) => {
|
||||
const existingCollection = await refetchCollection(req.params.id, req.scope, [
|
||||
|
||||
@@ -37,7 +37,10 @@ export const GET = async (
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateCollectionType & AdditionalData>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
AdminCreateCollectionType & AdditionalData,
|
||||
HttpTypes.AdminCollectionParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
|
||||
) => {
|
||||
const { additional_data, ...rest } = req.validatedBody
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { batchLinkProductsToCategoryWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
AdminProductCategoryResponse,
|
||||
LinkMethodRequest,
|
||||
HttpTypes,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
@@ -10,7 +10,10 @@ import {
|
||||
} from "@medusajs/framework/http"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminBatchLink,
|
||||
HttpTypes.AdminProductCategoryParams
|
||||
>,
|
||||
res: MedusaResponse<AdminProductCategoryResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
@@ -11,14 +11,12 @@ import {
|
||||
MedusaResponse,
|
||||
refetchEntities,
|
||||
} from "@medusajs/framework/http"
|
||||
import {
|
||||
AdminProductCategoryParamsType,
|
||||
AdminUpdateProductCategoryType,
|
||||
} from "../validators"
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminProductCategoryParamsType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminProductCategoryListParams
|
||||
>,
|
||||
res: MedusaResponse<AdminProductCategoryResponse>
|
||||
) => {
|
||||
const {
|
||||
@@ -42,7 +40,10 @@ export const GET = async (
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateProductCategoryType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminUpdateProductCategory,
|
||||
HttpTypes.AdminProductCategoryParams
|
||||
>,
|
||||
res: MedusaResponse<AdminProductCategoryResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
@@ -27,7 +27,10 @@ export const GET = async (
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminCreateProductCategory>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminCreateProductCategory,
|
||||
HttpTypes.AdminProductCategoryParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductCategoryResponse>
|
||||
) => {
|
||||
const { result } = await createProductCategoriesWorkflow(req.scope).run({
|
||||
|
||||
@@ -7,16 +7,13 @@ import {
|
||||
MedusaResponse,
|
||||
refetchEntity,
|
||||
} from "@medusajs/framework/http"
|
||||
|
||||
import {
|
||||
AdminGetProductTagParamsType,
|
||||
AdminUpdateProductTagType,
|
||||
} from "../validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetProductTagParamsType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminProductTagParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductTagResponse>
|
||||
) => {
|
||||
const productTag = await refetchEntity({
|
||||
@@ -30,7 +27,10 @@ export const GET = async (
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateProductTagType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminUpdateProductTag,
|
||||
HttpTypes.AdminProductTagParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductTagResponse>
|
||||
) => {
|
||||
const existingProductTag = await refetchEntity({
|
||||
|
||||
@@ -29,7 +29,10 @@ export const GET = async (
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminCreateProductTag>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminCreateProductTag,
|
||||
HttpTypes.AdminProductTagParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductTagResponse>
|
||||
) => {
|
||||
const input = [req.validatedBody]
|
||||
|
||||
@@ -8,15 +8,13 @@ import {
|
||||
} from "@medusajs/framework/http"
|
||||
|
||||
import { refetchProductType } from "../helpers"
|
||||
import {
|
||||
AdminGetProductTypeParamsType,
|
||||
AdminUpdateProductTypeType,
|
||||
} from "../validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetProductTypeParamsType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminProductTypeParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductTypeResponse>
|
||||
) => {
|
||||
const productType = await refetchProductType(
|
||||
@@ -29,7 +27,10 @@ export const GET = async (
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateProductTypeType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminUpdateProductType,
|
||||
HttpTypes.AdminProductTypeParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductTypeResponse>
|
||||
) => {
|
||||
const existingProductType = await refetchProductType(
|
||||
|
||||
@@ -36,7 +36,10 @@ export const GET = async (
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminCreateProductType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminCreateProductType,
|
||||
HttpTypes.AdminProductTypeParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductTypeResponse>
|
||||
) => {
|
||||
const input = [req.validatedBody]
|
||||
|
||||
@@ -12,7 +12,7 @@ import { remapKeysForProduct, remapProductResponse } from "../../../helpers"
|
||||
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.SelectParams>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductOptionResponse>
|
||||
) => {
|
||||
const productId = req.params.id
|
||||
@@ -29,7 +29,8 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminUpdateProductOption & AdditionalData
|
||||
HttpTypes.AdminUpdateProductOption & AdditionalData,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductResponse>
|
||||
) => {
|
||||
@@ -56,7 +57,7 @@ export const POST = async (
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<{}, HttpTypes.SelectParams>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductOptionDeleteResponse>
|
||||
) => {
|
||||
const productId = req.params.id
|
||||
|
||||
@@ -32,7 +32,8 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminCreateProductOption & AdditionalData
|
||||
HttpTypes.AdminCreateProductOption & AdditionalData,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductResponse>
|
||||
) => {
|
||||
|
||||
@@ -12,7 +12,7 @@ import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
||||
import { refetchEntity } from "@medusajs/framework/http"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.SelectParams>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductResponse>
|
||||
) => {
|
||||
const selectFields = remapKeysForProduct(req.queryConfig.fields ?? [])
|
||||
@@ -32,7 +32,8 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminUpdateProduct & AdditionalData
|
||||
HttpTypes.AdminUpdateProduct & AdditionalData,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductResponse>
|
||||
) => {
|
||||
|
||||
@@ -9,7 +9,10 @@ import { AdminUpdateVariantInventoryItemType } from "../../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateVariantInventoryItemType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
AdminUpdateVariantInventoryItemType,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantResponse>
|
||||
) => {
|
||||
const variantId = req.params.variant_id
|
||||
@@ -35,7 +38,7 @@ export const POST = async (
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<{}, HttpTypes.SelectParams>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantInventoryLinkDeleteResponse>
|
||||
) => {
|
||||
const variantId = req.params.variant_id
|
||||
|
||||
@@ -9,7 +9,10 @@ import { AdminCreateVariantInventoryItemType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateVariantInventoryItemType>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
AdminCreateVariantInventoryItemType,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantResponse>
|
||||
) => {
|
||||
const variantId = req.params.variant_id
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "../../../helpers"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.SelectParams>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantResponse>
|
||||
) => {
|
||||
const productId = req.params.id
|
||||
@@ -36,7 +36,8 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminUpdateProductVariant & AdditionalData
|
||||
HttpTypes.AdminUpdateProductVariant & AdditionalData,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductResponse>
|
||||
) => {
|
||||
@@ -63,7 +64,7 @@ export const POST = async (
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<{}, HttpTypes.SelectParams>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductVariantDeleteResponse>
|
||||
) => {
|
||||
const productId = req.params.id
|
||||
|
||||
@@ -7,7 +7,10 @@ import { refetchBatchVariants, remapVariantResponse } from "../../../helpers"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminBatchProductVariantRequest>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminBatchProductVariantRequest,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminBatchProductVariantResponse>
|
||||
) => {
|
||||
const productId = req.params.id
|
||||
|
||||
@@ -51,7 +51,8 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminCreateProductVariant & AdditionalData
|
||||
HttpTypes.AdminCreateProductVariant & AdditionalData,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductResponse>
|
||||
) => {
|
||||
|
||||
@@ -7,7 +7,10 @@ import { refetchBatchProducts, remapProductResponse } from "../helpers"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminBatchProductRequest>,
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminBatchProductRequest,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminBatchProductResponse>
|
||||
) => {
|
||||
const { result } = await batchProductsWorkflow(req.scope).run({
|
||||
|
||||
@@ -7,7 +7,7 @@ import { remapKeysForProduct } from "../helpers"
|
||||
import { exportProductsWorkflow } from "@medusajs/core-flows"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<{}, HttpTypes.AdminProductExportParams>,
|
||||
res: MedusaResponse<HttpTypes.AdminExportProductResponse>
|
||||
) => {
|
||||
const selectFields = remapKeysForProduct(req.queryConfig.fields ?? [])
|
||||
|
||||
@@ -93,7 +93,8 @@ async function getProductsWithIndexEngine(
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
HttpTypes.AdminCreateProduct & AdditionalData
|
||||
HttpTypes.AdminCreateProduct & AdditionalData,
|
||||
HttpTypes.SelectParams
|
||||
>,
|
||||
res: MedusaResponse<HttpTypes.AdminProductResponse>
|
||||
) => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
import { refetchCollection } from "../helpers"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.SelectParams>,
|
||||
res: MedusaResponse<HttpTypes.StoreCollectionResponse>
|
||||
) => {
|
||||
const collection = await refetchCollection(
|
||||
|
||||
Reference in New Issue
Block a user