fix(types, medusa): http types fixes (#9334)

* fix(types, medusa): http types fixes

* fix build error

* remove return fields

* more fixes

* fix cart payload types
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-10-02 10:28:22 +03:00
1 parent 8686ca9d12
commit 7bc7c50eef
22 files changed
+141 -54

No files matched your search

@@ -6,6 +6,10 @@ import {
BaseCartAddress, BaseCartAddress,
BaseCartLineItem, BaseCartLineItem,
BaseCartShippingMethod, BaseCartShippingMethod,
BaseLineItemAdjustment,
BaseLineItemTaxLine,
BaseShippingMethodAdjustment,
BaseShippingMethodTaxLine,
} from "../common" } from "../common"
export interface StoreCart extends Omit<BaseCart, "items"> { export interface StoreCart extends Omit<BaseCart, "items"> {
@@ -20,6 +24,19 @@ export interface StoreCartLineItem extends Omit<BaseCartLineItem, "product" | "v
product?: StoreProduct product?: StoreProduct
variant?: StoreProductVariant variant?: StoreProductVariant
cart: StoreCart cart: StoreCart
tax_lines?: (BaseLineItemTaxLine & {
item: StoreCartLineItem
})[]
adjustments?: (BaseLineItemAdjustment & {
item: StoreCartLineItem
})[]
} }
export interface StoreCartAddress extends BaseCartAddress {} export interface StoreCartAddress extends BaseCartAddress {}
export interface StoreCartShippingMethod extends BaseCartShippingMethod {} export interface StoreCartShippingMethod extends BaseCartShippingMethod {
tax_lines?: (BaseShippingMethodTaxLine & {
shipping_method: StoreCartShippingMethod
})[]
adjustments?: (BaseShippingMethodAdjustment & {
shipping_method: StoreCartShippingMethod
})[]
}
@@ -1,20 +1,18 @@
import { StoreCartAddress, StoreCartLineItem } from "./entities"
export interface StoreCreateCart { export interface StoreCreateCart {
region_id?: string region_id?: string
shipping_address?: StoreCartAddress shipping_address?: StoreAddAddress
billing_address?: StoreCartAddress billing_address?: StoreAddAddress
email?: string email?: string
currency_code?: string currency_code?: string
items?: StoreCartLineItem[] items?: StoreAddCartLineItem[]
sales_channel_id?: string sales_channel_id?: string
metadata?: Record<string, unknown> metadata?: Record<string, unknown>
} }
export interface StoreUpdateCart { export interface StoreUpdateCart {
region_id?: string region_id?: string
shipping_address?: StoreCartAddress shipping_address?: StoreAddAddress | string
billing_address?: StoreCartAddress billing_address?: StoreAddAddress | string
email?: string email?: string
sales_channel_id?: string sales_channel_id?: string
metadata?: Record<string, unknown> metadata?: Record<string, unknown>
@@ -40,3 +38,60 @@ export interface StoreAddCartShippingMethods {
export interface StoreCompleteCart { export interface StoreCompleteCart {
idempotency_key?: string idempotency_key?: string
} }
export interface StoreAddAddress {
/**
* The first name of the address.
*/
first_name?: string
/**
* The last name of the address.
*/
last_name?: string
/**
* The phone number of the address.
*/
phone?: string
/**
* The company of the address.
*/
company?: string
/**
* The first address line of the address.
*/
address_1?: string
/**
* The second address line of the address.
*/
address_2?: string
/**
* The city of the address.
*/
city?: string
/**
* The country code of the address.
*/
country_code?: string
/**
* The province/state of the address.
*/
province?: string
/**
* The postal code of the address.
*/
postal_code?: string
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
}
@@ -1,3 +1,6 @@
import { StoreProduct } from "../../product"
import { BaseCollection } from "../common" import { BaseCollection } from "../common"
export interface StoreCollection extends BaseCollection {} export interface StoreCollection extends Omit<BaseCollection, "products"> {
products?: StoreProduct[]
}
@@ -1,3 +1,6 @@
import { AdminCustomer } from "../../customer/admin"
import { BaseCustomerGroup } from "../common" import { BaseCustomerGroup } from "../common"
export interface AdminCustomerGroup extends BaseCustomerGroup {} export interface AdminCustomerGroup extends BaseCustomerGroup {
customers: AdminCustomer[]
}
@@ -4,5 +4,6 @@ import { BaseCustomer, BaseCustomerAddress } from "../common"
export interface AdminCustomer extends BaseCustomer { export interface AdminCustomer extends BaseCustomer {
has_account: boolean has_account: boolean
groups?: AdminCustomerGroup[] groups?: AdminCustomerGroup[]
addresses: AdminCustomerAddress[]
} }
export interface AdminCustomerAddress extends BaseCustomerAddress {} export interface AdminCustomerAddress extends BaseCustomerAddress {}
@@ -3,5 +3,7 @@ import {
BaseCustomerAddress, BaseCustomerAddress,
} from "../common" } from "../common"
export interface StoreCustomer extends BaseCustomer {} export interface StoreCustomer extends Omit<BaseCustomer, "created_by"> {
addresses: StoreCustomerAddress[]
}
export interface StoreCustomerAddress extends BaseCustomerAddress {} export interface StoreCustomerAddress extends BaseCustomerAddress {}
@@ -22,5 +22,5 @@ export interface AdminDraftOrderResponse {
} }
export type AdminDraftOrderListResponse = PaginatedResponse<{ export type AdminDraftOrderListResponse = PaginatedResponse<{
draft_orders: AdminOrder draft_orders: AdminOrder[]
}> }>
@@ -6,11 +6,17 @@ import {
BaseOrder, BaseOrder,
BaseOrderAddress, BaseOrderAddress,
BaseOrderFulfillment, BaseOrderFulfillment,
BaseOrderItemDetail,
BaseOrderLineItem, BaseOrderLineItem,
BaseOrderLineItemAdjustment,
BaseOrderLineItemTaxLine,
BaseOrderShippingDetail,
BaseOrderShippingMethod, BaseOrderShippingMethod,
BaseOrderShippingMethodAdjustment,
BaseOrderShippingMethodTaxLine,
} from "../common" } from "../common"
export interface StoreOrder extends Omit<BaseOrder, "items"> { export interface StoreOrder extends Omit<BaseOrder, "items" | "version" | "transations"> {
shipping_address?: StoreOrderAddress | null shipping_address?: StoreOrderAddress | null
billing_address?: StoreOrderAddress | null billing_address?: StoreOrderAddress | null
items: StoreOrderLineItem[] | null items: StoreOrderLineItem[] | null
@@ -22,9 +28,28 @@ export interface StoreOrder extends Omit<BaseOrder, "items"> {
export interface StoreOrderLineItem extends Omit<BaseOrderLineItem, "product" | "variant"> { export interface StoreOrderLineItem extends Omit<BaseOrderLineItem, "product" | "variant"> {
variant?: StoreProductVariant variant?: StoreProductVariant
product?: StoreProduct product?: StoreProduct
tax_lines?: (BaseOrderLineItemTaxLine & {
item: StoreOrderLineItem
})[]
adjustments?: (BaseOrderLineItemAdjustment & {
item: StoreOrderLineItem
})[]
detail: BaseOrderItemDetail & {
item: StoreOrderLineItem
}
} }
export interface StoreOrderAddress extends BaseOrderAddress { export interface StoreOrderAddress extends BaseOrderAddress {
country?: StoreRegionCountry country?: StoreRegionCountry
} }
export interface StoreOrderShippingMethod extends BaseOrderShippingMethod {} export interface StoreOrderShippingMethod extends BaseOrderShippingMethod {
tax_lines?: (BaseOrderShippingMethodTaxLine & {
shipping_method: StoreOrderShippingMethod
})[]
adjustments?: (BaseOrderShippingMethodAdjustment & {
shipping_method: StoreOrderShippingMethod
})[]
detail?: BaseOrderShippingDetail & {
shipping_method: StoreOrderShippingMethod
}
}
export interface StoreOrderFulfillment extends BaseOrderFulfillment {} export interface StoreOrderFulfillment extends BaseOrderFulfillment {}
@@ -136,7 +136,11 @@ export interface BaseProductVariantParams
BaseFilterable<BaseProductVariantParams> { BaseFilterable<BaseProductVariantParams> {
q?: string q?: string
id?: string | string[] id?: string | string[]
sku?: string | string[] options?: {
product_id?: string | string[] value: string
options?: Record<string, string> option_id: string
}
created_at?: OperatorMap<string>
updated_at?: OperatorMap<string>
deleted_at?: OperatorMap<string>
} }
@@ -11,7 +11,7 @@ import {
ProductStatus, ProductStatus,
} from "../common" } from "../common"
export interface StoreProduct extends Omit<BaseProduct, "categories" | "sales_channels" | "variants" | "options"> { export interface StoreProduct extends Omit<BaseProduct, "categories" | "sales_channels" | "variants" | "options" | "collection"> {
collection?: StoreCollection | null collection?: StoreCollection | null
categories?: StoreProductCategory[] | null categories?: StoreProductCategory[] | null
variants: StoreProductVariant[] | null variants: StoreProductVariant[] | null
@@ -11,6 +11,6 @@ export interface StoreProductParams extends Omit<BaseProductListParams, "tags" |
// The region ID and currency_code are not params, but are used for the pricing context. Maybe move to separate type definition. // The region ID and currency_code are not params, but are used for the pricing context. Maybe move to separate type definition.
region_id?: string region_id?: string
currency_code?: string currency_code?: string
variants?: StoreProductVariantParams variants?: Pick<StoreProductVariantParams, "options">
province?: string province?: string
} }
@@ -1,6 +1,6 @@
import { BaseReturn, BaseReturnItem } from "../common"; import { BaseReturn, BaseReturnItem } from "../common";
export interface StoreReturn extends BaseReturn { export interface StoreReturn extends Omit<BaseReturn, "no_notification" | "order_version"> {
items: StoreReturnItem[] items: StoreReturnItem[]
} }
export interface StoreReturnItem extends BaseReturnItem {} export interface StoreReturnItem extends BaseReturnItem {}
@@ -40,7 +40,7 @@ export interface AdminCreateShippingOption {
export interface AdminUpdateShippingOptionRule export interface AdminUpdateShippingOptionRule
extends AdminCreateShippingOptionRule { extends AdminCreateShippingOptionRule {
id?: string id: string
} }
export interface AdminUpdateShippingOptionPriceWithCurrency { export interface AdminUpdateShippingOptionPriceWithCurrency {
@@ -5,10 +5,9 @@ import {
MedusaResponse, MedusaResponse,
} from "../../../../../../../types/routing" } from "../../../../../../../types/routing"
import { refetchEntity } from "../../../../../../utils/refetch-entity" import { refetchEntity } from "../../../../../../utils/refetch-entity"
import { AdminMarkOrderFulfillmentDeliveredType } from "../../../../validators"
export const POST = async ( export const POST = async (
req: AuthenticatedMedusaRequest<AdminMarkOrderFulfillmentDeliveredType>, req: AuthenticatedMedusaRequest,
res: MedusaResponse<HttpTypes.AdminOrderResponse> res: MedusaResponse<HttpTypes.AdminOrderResponse>
) => { ) => {
const { id: orderId, fulfillment_id: fulfillmentId } = req.params const { id: orderId, fulfillment_id: fulfillmentId } = req.params
@@ -7,7 +7,7 @@ import { remapKeysForProduct } from "../helpers"
import { exportProductsWorkflow } from "@medusajs/core-flows" import { exportProductsWorkflow } from "@medusajs/core-flows"
export const POST = async ( export const POST = async (
req: AuthenticatedMedusaRequest<HttpTypes.AdminExportProductRequest>, req: AuthenticatedMedusaRequest,
res: MedusaResponse<HttpTypes.AdminExportProductResponse> res: MedusaResponse<HttpTypes.AdminExportProductResponse>
) => { ) => {
const selectFields = remapKeysForProduct(req.remoteQueryConfig.fields ?? []) const selectFields = remapKeysForProduct(req.remoteQueryConfig.fields ?? [])
@@ -4,18 +4,14 @@ import {
MedusaResponse, MedusaResponse,
} from "../../../../../../types/routing" } from "../../../../../../types/routing"
import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types" import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types"
import {
AdminCreatePromotionRuleType,
AdminUpdatePromotionRuleType,
} from "../../../validators"
import { RuleType } from "@medusajs/framework/utils" import { RuleType } from "@medusajs/framework/utils"
import { refetchBatchRules } from "../../../helpers" import { refetchBatchRules } from "../../../helpers"
export const POST = async ( export const POST = async (
req: AuthenticatedMedusaRequest< req: AuthenticatedMedusaRequest<
BatchMethodRequest< BatchMethodRequest<
AdminCreatePromotionRuleType, HttpTypes.AdminCreatePromotionRule,
AdminUpdatePromotionRuleType HttpTypes.AdminUpdatePromotionRule
> >
>, >,
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse> res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
@@ -4,18 +4,14 @@ import {
MedusaResponse, MedusaResponse,
} from "../../../../../../types/routing" } from "../../../../../../types/routing"
import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types" import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types"
import {
AdminCreatePromotionRuleType,
AdminUpdatePromotionRuleType,
} from "../../../validators"
import { RuleType } from "@medusajs/framework/utils" import { RuleType } from "@medusajs/framework/utils"
import { refetchBatchRules } from "../../../helpers" import { refetchBatchRules } from "../../../helpers"
export const POST = async ( export const POST = async (
req: AuthenticatedMedusaRequest< req: AuthenticatedMedusaRequest<
BatchMethodRequest< BatchMethodRequest<
AdminCreatePromotionRuleType, HttpTypes.AdminCreatePromotionRule,
AdminUpdatePromotionRuleType HttpTypes.AdminUpdatePromotionRule
> >
>, >,
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse> res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
@@ -4,18 +4,14 @@ import {
MedusaResponse, MedusaResponse,
} from "../../../../../../types/routing" } from "../../../../../../types/routing"
import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types" import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types"
import {
AdminCreatePromotionRuleType,
AdminUpdatePromotionRuleType,
} from "../../../validators"
import { RuleType } from "@medusajs/framework/utils" import { RuleType } from "@medusajs/framework/utils"
import { refetchBatchRules } from "../../../helpers" import { refetchBatchRules } from "../../../helpers"
export const POST = async ( export const POST = async (
req: AuthenticatedMedusaRequest< req: AuthenticatedMedusaRequest<
BatchMethodRequest< BatchMethodRequest<
AdminCreatePromotionRuleType, HttpTypes.AdminCreatePromotionRule,
AdminUpdatePromotionRuleType HttpTypes.AdminUpdatePromotionRule
> >
>, >,
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse> res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
@@ -3,18 +3,14 @@ import {
MedusaResponse, MedusaResponse,
} from "../../../../../../types/routing" } from "../../../../../../types/routing"
import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types" import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types"
import {
AdminCreateShippingOptionRuleType,
AdminUpdateShippingOptionRuleType,
} from "../../../validators"
import { refetchBatchRules } from "../../../helpers" import { refetchBatchRules } from "../../../helpers"
import { batchShippingOptionRulesWorkflow } from "@medusajs/core-flows" import { batchShippingOptionRulesWorkflow } from "@medusajs/core-flows"
export const POST = async ( export const POST = async (
req: AuthenticatedMedusaRequest< req: AuthenticatedMedusaRequest<
BatchMethodRequest< BatchMethodRequest<
AdminCreateShippingOptionRuleType, HttpTypes.AdminCreateShippingOptionRule,
AdminUpdateShippingOptionRuleType HttpTypes.AdminUpdateShippingOptionRule
> >
>, >,
res: MedusaResponse<HttpTypes.AdminUpdateShippingOptionRulesResponse> res: MedusaResponse<HttpTypes.AdminUpdateShippingOptionRulesResponse>
@@ -7,7 +7,6 @@ const defaultStoreCustomersFields = [
"phone", "phone",
"metadata", "metadata",
"has_account", "has_account",
"created_by",
"deleted_at", "deleted_at",
"created_at", "created_at",
"updated_at", "updated_at",
@@ -3,7 +3,6 @@
export const defaultStoreOrderFields = [ export const defaultStoreOrderFields = [
"id", "id",
"status", "status",
"version",
"summary", "summary",
"display_id", "display_id",
"total", "total",
@@ -16,7 +15,6 @@ export const defaultStoreOrderFields = [
export const defaultStoreRetrieveOrderFields = [ export const defaultStoreRetrieveOrderFields = [
"id", "id",
"status", "status",
"version",
"summary", "summary",
"currency_code", "currency_code",
"display_id", "display_id",
@@ -1,7 +1,6 @@
import { z } from "zod" import { z } from "zod"
import { import {
GetProductsParams, GetProductsParams,
ProductStatusEnum,
transformProductParams, transformProductParams,
} from "../../utils/common-validators" } from "../../utils/common-validators"
import { import {
@@ -32,7 +31,6 @@ export const StoreGetProductVariantsParams = createFindParams({
z.object({ z.object({
q: z.string().optional(), q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(), id: z.union([z.string(), z.array(z.string())]).optional(),
status: ProductStatusEnum.array().optional(),
options: z.object({ value: z.string(), option_id: z.string() }).optional(), options: z.object({ value: z.string(), option_id: z.string() }).optional(),
created_at: createOperatorMap().optional(), created_at: createOperatorMap().optional(),
updated_at: createOperatorMap().optional(), updated_at: createOperatorMap().optional(),
@@ -58,7 +56,6 @@ export const StoreGetProductsParams = createFindParams({
variants: z variants: z
.object({ .object({
status: ProductStatusEnum.array().optional(),
options: z options: z
.object({ value: z.string(), option_id: z.string() }) .object({ value: z.string(), option_id: z.string() })
.optional(), .optional(),