diff --git a/packages/core/js-sdk/src/store/index.ts b/packages/core/js-sdk/src/store/index.ts index 2f76e10068..8a32b04053 100644 --- a/packages/core/js-sdk/src/store/index.ts +++ b/packages/core/js-sdk/src/store/index.ts @@ -3,6 +3,7 @@ import { HttpTypes, PaginatedResponse, SelectParams, + DeleteResponse, } from "@medusajs/types" import { Client } from "../client" import { ClientHeaders } from "../types" @@ -47,7 +48,7 @@ export class Store { headers?: ClientHeaders ) => { return this.client.fetch< - PaginatedResponse<{ collections: HttpTypes.StoreCollection }> + PaginatedResponse<{ collections: HttpTypes.StoreCollection[] }> >(`/store/collections`, { query, headers, @@ -74,7 +75,9 @@ export class Store { headers?: ClientHeaders ) => { return this.client.fetch< - PaginatedResponse<{ categories: HttpTypes.StoreProductCategory }> + PaginatedResponse<{ + product_categories: HttpTypes.StoreProductCategory[] + }> >(`/store/product-categories`, { query, headers, @@ -85,13 +88,12 @@ export class Store { query?: SelectParams, headers?: ClientHeaders ) => { - return this.client.fetch<{ category: HttpTypes.StoreProductCategory }>( - `/store/product-categories/${id}`, - { - query, - headers, - } - ) + return this.client.fetch<{ + product_category: HttpTypes.StoreProductCategory + }>(`/store/product-categories/${id}`, { + query, + headers, + }) }, } @@ -101,7 +103,7 @@ export class Store { headers?: ClientHeaders ) => { return this.client.fetch< - PaginatedResponse<{ products: HttpTypes.StoreProduct }> + PaginatedResponse<{ products: HttpTypes.StoreProduct[] }> >(`/store/products`, { query, headers, @@ -122,26 +124,13 @@ export class Store { }, } - public order = { - retrieve: async ( - id: string, - query?: SelectParams, - headers?: ClientHeaders - ) => { - return this.client.fetch(`/store/orders/${id}`, { - query, - headers, - }) - }, - } - public cart = { create: async ( - body: any, + body: HttpTypes.StoreCreateCart, query?: SelectParams, headers?: ClientHeaders ) => { - return this.client.fetch(`/store/carts`, { + return this.client.fetch<{ cart: HttpTypes.StoreCart }>(`/store/carts`, { method: "POST", headers, body, @@ -150,48 +139,57 @@ export class Store { }, update: async ( id: string, - body: any, + body: HttpTypes.StoreUpdateCart, query?: SelectParams, headers?: ClientHeaders ) => { - return this.client.fetch(`/store/carts/${id}`, { - method: "POST", - headers, - body, - query, - }) + return this.client.fetch<{ cart: HttpTypes.StoreCart }>( + `/store/carts/${id}`, + { + method: "POST", + headers, + body, + query, + } + ) }, retrieve: async ( id: string, query?: SelectParams, headers?: ClientHeaders ) => { - return this.client.fetch(`/store/carts/${id}`, { - headers, - query, - }) + return this.client.fetch<{ cart: HttpTypes.StoreCart }>( + `/store/carts/${id}`, + { + headers, + query, + } + ) }, createLineItem: async ( cartId: string, - body: any, + body: HttpTypes.StoreAddCartLineItem, query?: SelectParams, headers?: ClientHeaders ) => { - return this.client.fetch(`/store/carts/${cartId}/line-items`, { - method: "POST", - headers, - body, - query, - }) + return this.client.fetch<{ cart: HttpTypes.StoreCart }>( + `/store/carts/${cartId}/line-items`, + { + method: "POST", + headers, + body, + query, + } + ) }, updateLineItem: async ( cartId: string, lineItemId: string, - body: any, + body: HttpTypes.StoreUpdateCartLineItem, query?: SelectParams, headers?: ClientHeaders ) => { - return this.client.fetch( + return this.client.fetch<{ cart: HttpTypes.StoreCart }>( `/store/carts/${cartId}/line-items/${lineItemId}`, { method: "POST", @@ -206,33 +204,46 @@ export class Store { lineItemId: string, headers?: ClientHeaders ) => { - return this.client.fetch( - `/store/carts/${cartId}/line-items/${lineItemId}`, - { - method: "DELETE", - headers, - } - ) + return this.client.fetch< + DeleteResponse<"line-item", HttpTypes.StoreCart> + >(`/store/carts/${cartId}/line-items/${lineItemId}`, { + method: "DELETE", + headers, + }) }, addShippingMethod: async ( cartId: string, - body: any, + body: HttpTypes.StoreAddCartShippingMethods, query?: SelectParams, headers?: ClientHeaders ) => { - return this.client.fetch(`/store/carts/${cartId}/shipping-methods`, { - method: "POST", - headers, - body, - query, - }) + return this.client.fetch<{ cart: HttpTypes.StoreCart }>( + `/store/carts/${cartId}/shipping-methods`, + { + method: "POST", + headers, + body, + query, + } + ) }, complete: async ( cartId: string, query?: SelectParams, headers?: ClientHeaders ) => { - return this.client.fetch(`/store/carts/${cartId}/complete`, { + return this.client.fetch< + | { type: "order"; order: HttpTypes.StoreOrder } + | { + type: "cart" + cart: HttpTypes.StoreCart + error: { + message: string + name: string + type: string + } + } + >(`/store/carts/${cartId}/complete`, { method: "POST", headers, query, @@ -241,30 +252,33 @@ export class Store { } public fulfillment = { + // TODO: Finalize typings for list options listCartOptions: async ( - query?: Record, + query?: FindParams & { cart_id: string }, headers?: ClientHeaders ) => { return this.client.fetch(`/store/shipping-options`, { - query, headers, + query, }) }, } public payment = { listPaymentProviders: async ( - query?: Record, + query?: FindParams & HttpTypes.StorePaymentProviderFilters, headers?: ClientHeaders ) => { - return this.client.fetch(`/store/payment-providers`, { - query, + return this.client.fetch<{ + payment_providers: HttpTypes.StorePaymentProvider[] + }>(`/store/payment-providers`, { headers, + query, }) }, initiatePaymentSession: async ( - cart: any, + cart: HttpTypes.StoreCart, body: Record, query?: SelectParams, headers?: ClientHeaders @@ -278,7 +292,9 @@ export class Store { amount: cart.total, } paymentCollectionId = ( - await this.client.fetch(`/store/payment-collections`, { + await this.client.fetch<{ + payment_collection: HttpTypes.StorePaymentCollection + }>(`/store/payment-collections`, { method: "POST", headers, body: collectionBody, @@ -286,12 +302,27 @@ export class Store { ).payment_collection.id } - return this.client.fetch( - `/store/payment-collections/${paymentCollectionId}/payment-sessions`, + return this.client.fetch<{ + payment_collection: HttpTypes.StorePaymentCollection + }>(`/store/payment-collections/${paymentCollectionId}/payment-sessions`, { + method: "POST", + headers, + body, + query, + }) + }, + } + + public order = { + retrieve: async ( + id: string, + query?: SelectParams, + headers?: ClientHeaders + ) => { + return this.client.fetch<{ order: HttpTypes.StoreOrder }>( + `/store/orders/${id}`, { - method: "POST", headers, - body, query, } ) diff --git a/packages/core/js-sdk/src/types.ts b/packages/core/js-sdk/src/types.ts index 6428ed118c..4e47683638 100644 --- a/packages/core/js-sdk/src/types.ts +++ b/packages/core/js-sdk/src/types.ts @@ -21,7 +21,9 @@ export type Config = { export type FetchParams = Parameters -export type ClientHeaders = Record +export type ClientHeaders = + // The `tags` header is specifically added for nextJS, as they follow a non-standard header format + Record export type FetchInput = FetchParams[0] diff --git a/packages/core/types/src/cart/common.ts b/packages/core/types/src/cart/common.ts index 52ce29e1f7..d2bfc9f0a9 100644 --- a/packages/core/types/src/cart/common.ts +++ b/packages/core/types/src/cart/common.ts @@ -1260,135 +1260,3 @@ export interface FilterableShippingMethodTaxLineProps */ shipping_method?: FilterableShippingMethodProps } - -/** - * TODO: Remove this in favor of CartDTO, when module is released - * - * @deprecated Use CartDTO instead - */ -export type legacy_CartDTO = { - /** - * The ID of the cart. - */ - id?: string - - /** - * The email of the cart. - */ - email?: string - - /** - * The associated billing address's ID. - */ - billing_address_id?: string - - /** - * The associated shipping address's ID. - */ - shipping_address_id?: string - - /** - * The associated region's ID. - */ - region_id?: string - - /** - * The associated customer's ID. - */ - customer_id?: string - - /** - * The associated payment's ID. - */ - payment_id?: string - - /** - * The associated date. - */ - completed_at?: Date - - /** - * The associated date. - */ - payment_authorized_at?: Date - - /** - * The idempotency key of the cart. - */ - idempotency_key?: string - - /** - * The context of the cart. - */ - context?: Record - - /** - * Holds custom data in key-value pairs. - */ - metadata?: Record - - /** - * The associated sales channel's ID. - */ - sales_channel_id?: string | null - - /** - * The shipping total of the cart. - */ - shipping_total?: number - - /** - * The discount total of the cart. - */ - discount_total?: number - - /** - * The raw discount total of the cart. - */ - raw_discount_total?: number - - /** - * The item tax total of the cart. - */ - item_tax_total?: number | null - - /** - * The shipping tax total of the cart. - */ - shipping_tax_total?: number | null - - /** - * The tax total of the cart. - */ - tax_total?: number | null - - /** - * The refunded total of the cart. - */ - refunded_total?: number - - /** - * The total of the cart. - */ - total?: number - - /** - * The subtotal of the cart. - */ - subtotal?: number - - /** - * The refundable amount of the cart. - */ - refundable_amount?: number - - /** - * The gift card total of the cart. - */ - gift_card_total?: number - - /** - * The gift card tax total of the cart. - */ - gift_card_tax_total?: number -} diff --git a/packages/core/types/src/http/cart/common.ts b/packages/core/types/src/http/cart/common.ts new file mode 100644 index 0000000000..fe29884de8 --- /dev/null +++ b/packages/core/types/src/http/cart/common.ts @@ -0,0 +1,776 @@ +import { BigNumberValue } from "../../totals" + +export interface BaseCart { + /** + * The ID of the cart. + */ + id: string + + /** + * The ID of the region the cart belongs to. + */ + region_id?: string + + /** + * The ID of the associated customer + */ + customer_id?: string + + /** + * The ID of the sales channel the cart belongs to. + */ + sales_channel_id?: string + + /** + * The email of the customer that owns the cart. + */ + email?: string + + /** + * The currency of the cart + */ + currency_code: string + + /** + * The associated shipping address. + * + * @expandable + */ + shipping_address?: BaseCartAddress + + /** + * The associated billing address. + * + * @expandable + */ + billing_address?: BaseCartAddress + + /** + * The associated line items. + * + * @expandable + */ + items?: BaseCartLineItem[] + + /** + * The associated shipping methods + * + * @expandable + */ + shipping_methods?: BaseCartShippingMethod[] + + /** + * Holds custom data in key-value pairs. + */ + metadata?: Record | null + + /** + * When the cart was created. + */ + created_at?: string | Date + + /** + * When the cart was updated. + */ + updated_at?: string | Date + + /** + * The original item total of the cart. + */ + original_item_total: BigNumberValue + + /** + * The original item subtotal of the cart. + */ + original_item_subtotal: BigNumberValue + + /** + * The original item tax total of the cart. + */ + original_item_tax_total: BigNumberValue + + /** + * The item total of the cart. + */ + item_total: BigNumberValue + + /** + * The item subtotal of the cart. + */ + item_subtotal: BigNumberValue + + /** + * The item tax total of the cart. + */ + item_tax_total: BigNumberValue + + /** + * The original total of the cart. + */ + original_total: BigNumberValue + + /** + * The original subtotal of the cart. + */ + original_subtotal: BigNumberValue + + /** + * The original tax total of the cart. + */ + original_tax_total: BigNumberValue + + /** + * The total of the cart. + */ + total: BigNumberValue + + /** + * The subtotal of the cart. (Excluding taxes) + */ + subtotal: BigNumberValue + + /** + * The tax total of the cart. + */ + tax_total: BigNumberValue + + /** + * The discount total of the cart. + */ + discount_total: BigNumberValue + + /** + * The discount tax total of the cart. + */ + discount_tax_total: BigNumberValue + + /** + * The gift card total of the cart. + */ + gift_card_total: BigNumberValue + + /** + * The gift card tax total of the cart. + */ + gift_card_tax_total: BigNumberValue + + /** + * The shipping total of the cart. + */ + shipping_total: BigNumberValue + + /** + * The shipping subtotal of the cart. + */ + shipping_subtotal: BigNumberValue + + /** + * The shipping tax total of the cart. + */ + shipping_tax_total: BigNumberValue + + /** + * The original shipping total of the cart. + */ + original_shipping_total: BigNumberValue + + /** + * The original shipping subtotal of the cart. + */ + original_shipping_subtotal: BigNumberValue + + /** + * The original shipping tax total of the cart. + */ + original_shipping_tax_total: BigNumberValue +} + +export interface BaseCartAddress { + /** + * The ID of the address. + */ + id: string + + /** + * The customer ID of the address. + */ + customer_id?: string + + /** + * 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 | null + + /** + * When the address was created. + */ + created_at: Date | string + + /** + * When the address was updated. + */ + updated_at: Date | string +} + +/** + * The cart shipping method details. + */ +export interface BaseCartShippingMethod { + /** + * The ID of the shipping method. + */ + id: string + + /** + * The ID of the associated cart. + */ + cart_id: string + + /** + * The name of the shipping method. + */ + name: string + + /** + * The description of the shipping method. + */ + description?: string + + /** + * The price of the shipping method. + */ + amount: BigNumberValue + + /** + * Whether the shipping method price is tax inclusive. + */ + is_tax_inclusive: boolean + + /** + * The ID of the shipping option the method was created from. + */ + shipping_option_id?: string + + /** + * Additional data needed for fulfillment. + */ + data?: Record + + /** + * Holds custom data in key-value pairs. + */ + metadata?: Record | null + + /** + * The associated tax lines. + * + * @expandable + */ + tax_lines?: BaseShippingMethodTaxLine[] + + /** + * The associated adjustments. + * + * @expandable + */ + adjustments?: BaseShippingMethodAdjustment[] + + /** + * When the shipping method was created. + */ + created_at: Date | string + + /** + * When the shipping method was updated. + */ + updated_at: Date | string + + /** + * The original total of the cart shipping method. + */ + original_total: BigNumberValue + + /** + * The original subtotal of the cart shipping method. + */ + original_subtotal: BigNumberValue + + /** + * The original tax total of the cart shipping method. + */ + original_tax_total: BigNumberValue + + /** + * The total of the cart shipping method. + */ + total: BigNumberValue + + /** + * The subtotal of the cart shipping method. + */ + subtotal: BigNumberValue + + /** + * The tax total of the cart shipping method. + */ + tax_total: BigNumberValue + + /** + * The discount total of the cart shipping method. + */ + discount_total: BigNumberValue + + /** + * The discount tax total of the cart shipping method. + */ + discount_tax_total: BigNumberValue +} + +/** + * The cart line item details. + */ +export interface BaseCartLineItem extends BaseCartLineItemTotals { + /** + * The ID of the line item. + */ + id: string + + /** + * The title of the line item. + */ + title: string + + /** + * The subtitle of the line item. + */ + subtitle?: string + + /** + * The line item's thumbnail. + */ + thumbnail?: string + + /** + * The line item's quantity in the cart. + */ + quantity: BigNumberValue + + /** + * The ID of the associated product. + */ + product_id?: string + + /** + * The title of the associated product. + */ + product_title?: string + + /** + * The description of the associated product. + */ + product_description?: string + + /** + * The subtitle of the associated product. + */ + product_subtitle?: string + + /** + * The type of the associated product. + */ + product_type?: string + + /** + * The collection of the associated product. + */ + product_collection?: string + + /** + * The handle of the associated product. + */ + product_handle?: string + + /** + * The associated variant's ID of the line item. + */ + variant_id?: string + + /** + * The sku of the associated variant. + */ + variant_sku?: string + + /** + * The barcode of the associated variant. + */ + variant_barcode?: string + + /** + * The title of the associated variant. + */ + variant_title?: string + + /** + * The option values of the associated variant. + */ + variant_option_values?: Record + + /** + * Whether the line item requires shipping. + */ + requires_shipping: boolean + + /** + * Whether the line item is discountable. + */ + is_discountable: boolean + + /** + * Whether the line item price is tax inclusive. + */ + is_tax_inclusive: boolean + + /** + * The calculated price of the line item. + */ + compare_at_unit_price?: BigNumberValue + + /** + * The unit price of the item. + */ + unit_price: BigNumberValue + + /** + * The associated tax lines. + * + * @expandable + */ + tax_lines?: BaseLineItemTaxLine[] + + /** + * The associated adjustments. + * + * @expandable + */ + adjustments?: BaseLineItemAdjustment[] + + /** + * The associated cart. + * + * @expandable + */ + cart: BaseCart + + /** + * The ID of the associated cart. + */ + cart_id: string + + /** + * Holds custom data in key-value pairs. + */ + metadata?: Record | null + + /** + * When the line item was created. + */ + created_at?: Date + + /** + * When the line item was updated. + */ + updated_at?: Date + + /** + * When the line item was deleted. + */ + deleted_at?: Date +} + +/** + * The cart line item totals details. + */ +export interface BaseCartLineItemTotals { + /** + * The original total of the cart line item. + */ + original_total: BigNumberValue + + /** + * The original subtotal of the cart line item. + */ + original_subtotal: BigNumberValue + + /** + * The original tax total of the cart line item. + */ + original_tax_total: BigNumberValue + + /** + * The item total of the cart line item. + */ + item_total: BigNumberValue + + /** + * The item subtotal of the cart line item. + */ + item_subtotal: BigNumberValue + + /** + * The item tax total of the cart line item. + */ + item_tax_total: BigNumberValue + + /** + * The total of the cart line item. + */ + total: BigNumberValue + + /** + * The subtotal of the cart line item. + */ + subtotal: BigNumberValue + + /** + * The tax total of the cart line item. + */ + tax_total: BigNumberValue + + /** + * The discount total of the cart line item. + */ + discount_total: BigNumberValue + + /** + * The discount tax total of the cart line item. + */ + discount_tax_total: BigNumberValue +} + +/** + * The adjustment line details. + */ +export interface BaseAdjustmentLine { + /** + * The ID of the adjustment line + */ + id: string + + /** + * The code of the promotion that lead to + * this adjustment. + */ + code?: string + + /** + * The amount to adjust the original amount with. + */ + amount: BigNumberValue + + /** + * The ID of the associated cart. + */ + cart_id: string + + /** + * The description of the adjustment line. + */ + description?: string + + /** + * The ID of the associated promotion. + */ + promotion_id?: string + + /** + * The ID of the associated provider. + */ + provider_id?: string + + /** + * When the adjustment line was created. + */ + created_at: Date | string + + /** + * When the adjustment line was updated. + */ + updated_at: Date | string +} + +/** + * The shipping method adjustment details. + */ +export interface BaseShippingMethodAdjustment extends BaseAdjustmentLine { + /** + * The associated shipping method. + */ + shipping_method: BaseCartShippingMethod + + /** + * The ID of the associated shipping method. + */ + shipping_method_id: string +} + +/** + * The line item adjustment details. + */ +export interface BaseLineItemAdjustment extends BaseAdjustmentLine { + /** + * The associated line item. + * + * @expandable + */ + item: BaseCartLineItem + + /** + * The ID of the associated line item. + */ + item_id: string +} + +/** + * The tax line details. + */ +export interface BaseTaxLine { + /** + * The ID of the tax line + */ + id: string + + /** + * The description of the tax line + */ + description?: string + + /** + * The ID of the associated tax rate. + */ + tax_rate_id?: string + + /** + * The code of the tax line. + */ + code: string + + /** + * The rate of the tax line. + */ + rate: number + + /** + * The ID of the associated provider. + */ + provider_id?: string + + /** + * When the tax line was created. + */ + created_at: Date | string + + /** + * When the tax line was updated. + */ + updated_at: Date | string +} + +/** + * The shipping method tax line details. + */ +export interface BaseShippingMethodTaxLine extends BaseTaxLine { + /** + * The associated shipping method. + */ + shipping_method: BaseCartShippingMethod + + /** + * The ID of the associated shipping method. + */ + shipping_method_id: string + + /** + * The total tax relative to the shipping method. + */ + total: BigNumberValue + + /** + * The subtotal tax relative to the shipping method. + */ + subtotal: BigNumberValue +} + +/** + * The line item tax line details. + */ +export interface BaseLineItemTaxLine extends BaseTaxLine { + /** + * The associated line item. + */ + item: BaseCartLineItem + + /** + * The ID of the associated line item. + */ + item_id: string + + /** + * The total tax relative to the item. + */ + total: BigNumberValue + + /** + * The subtotal tax relative to the item. + */ + subtotal: BigNumberValue +} diff --git a/packages/core/types/src/http/cart/index.ts b/packages/core/types/src/http/cart/index.ts new file mode 100644 index 0000000000..83c6d56aa5 --- /dev/null +++ b/packages/core/types/src/http/cart/index.ts @@ -0,0 +1 @@ +export * from "./store" diff --git a/packages/core/types/src/http/cart/store.ts b/packages/core/types/src/http/cart/store.ts new file mode 100644 index 0000000000..5ab2c38d12 --- /dev/null +++ b/packages/core/types/src/http/cart/store.ts @@ -0,0 +1,52 @@ +import { + BaseCart, + BaseCartAddress, + BaseCartLineItem, + BaseCartShippingMethod, +} from "./common" + +export interface StoreCart extends BaseCart {} +export interface StoreCartLineItem extends BaseCartLineItem {} +export interface StoreCartAddress extends BaseCartAddress {} +export interface StoreCartShippingMethod extends BaseCartShippingMethod {} + +export interface StoreCreateCart { + region_id?: string + shipping_address?: StoreCartAddress + billing_address?: StoreCartAddress + email?: string + currency_code?: string + items?: StoreCartLineItem[] + sales_channel_id?: string + metadata?: Record +} + +export interface StoreUpdateCart { + region_id?: string + shipping_address?: StoreCartAddress + billing_address?: StoreCartAddress + email?: string + sales_channel_id?: string + metadata?: Record + promo_codes?: string[] +} + +export interface StoreAddCartLineItem { + variant_id: string + quantity: number + metadata?: Record +} + +export interface StoreUpdateCartLineItem { + quantity: number + metadata?: Record +} + +export interface StoreAddCartShippingMethods { + option_id: string + data?: Record +} + +export interface StoreCompleteCart { + idempotency_key?: string +} diff --git a/packages/core/types/src/http/index.ts b/packages/core/types/src/http/index.ts index e975910b1a..bb78bc5018 100644 --- a/packages/core/types/src/http/index.ts +++ b/packages/core/types/src/http/index.ts @@ -14,6 +14,7 @@ export * from "./product-category" export * from "./reservation" export * from "./region" export * from "./product" +export * from "./cart" export * from "./payment" export * from "./collection" export * from "./common" diff --git a/packages/core/types/src/http/order/admin.ts b/packages/core/types/src/http/order/admin.ts new file mode 100644 index 0000000000..58b54a49fe --- /dev/null +++ b/packages/core/types/src/http/order/admin.ts @@ -0,0 +1,3 @@ +import { BaseOrder } from "./common" + +export interface AdminOrder extends BaseOrder {} diff --git a/packages/core/types/src/http/order/admin/index.ts b/packages/core/types/src/http/order/common.ts similarity index 57% rename from packages/core/types/src/http/order/admin/index.ts rename to packages/core/types/src/http/order/common.ts index bde9c301ac..f3ba2d92e7 100644 --- a/packages/core/types/src/http/order/admin/index.ts +++ b/packages/core/types/src/http/order/common.ts @@ -1,7 +1,4 @@ -import { BigNumberRawValue } from "../../../totals" -import { PaginatedResponse } from "../../common" - -interface OrderSummary { +interface BaseOrderSummary { total: number subtotal: number total_tax: number @@ -24,7 +21,7 @@ interface OrderSummary { refunded_total: number } -interface OrderAdjustmentLine { +interface BaseOrderAdjustmentLine { id: string code?: string amount: number @@ -36,17 +33,17 @@ interface OrderAdjustmentLine { updated_at: Date | string } -interface OrderShippingMethodAdjustment extends OrderAdjustmentLine { - shipping_method: OrderShippingMethod +interface BaseOrderShippingMethodAdjustment extends BaseOrderAdjustmentLine { + shipping_method: BaseOrderShippingMethod shipping_method_id: string } -interface OrderLineItemAdjustment extends OrderAdjustmentLine { - item: OrderLineItem +interface BaseOrderLineItemAdjustment extends BaseOrderAdjustmentLine { + item: BaseOrderLineItem item_id: string } -interface OrderTaxLine { +interface BaseOrderTaxLine { id: string description?: string tax_rate_id?: string @@ -57,25 +54,21 @@ interface OrderTaxLine { updated_at: Date | string } -interface OrderShippingMethodTaxLine extends OrderTaxLine { - shipping_method: OrderShippingMethod +interface BaseOrderShippingMethodTaxLine extends BaseOrderTaxLine { + shipping_method: BaseOrderShippingMethod shipping_method_id: string total: number subtotal: number - raw_total?: BigNumberRawValue - raw_subtotal?: BigNumberRawValue } -interface OrderLineItemTaxLine extends OrderTaxLine { - item: OrderLineItem +interface BaseOrderLineItemTaxLine extends BaseOrderTaxLine { + item: BaseOrderLineItem item_id: string total: number subtotal: number - raw_total?: BigNumberRawValue - raw_subtotal?: BigNumberRawValue } -interface OrderAddress { +interface BaseOrderAddress { id: string customer_id?: string first_name?: string @@ -93,24 +86,23 @@ interface OrderAddress { updated_at: Date | string } -interface OrderShippingMethod { +interface BaseOrderShippingMethod { id: string order_id: string name: string description?: string amount: number - raw_amount?: BigNumberRawValue is_tax_inclusive: boolean shipping_option_id: string | null data: Record | null metadata: Record | null - tax_lines?: OrderShippingMethodTaxLine[] - adjustments?: OrderShippingMethodAdjustment[] + tax_lines?: BaseOrderShippingMethodTaxLine[] + adjustments?: BaseOrderShippingMethodAdjustment[] created_at: Date | string updated_at: Date | string } -interface OrderLineItem { +interface BaseOrderLineItem { id: string title: string subtitle: string | null @@ -131,14 +123,11 @@ interface OrderLineItem { is_discountable: boolean is_tax_inclusive: boolean compare_at_unit_price?: number - raw_compare_at_unit_price?: BigNumberRawValue unit_price: number - raw_unit_price?: BigNumberRawValue quantity: number - raw_quantity?: BigNumberRawValue - tax_lines?: OrderLineItemTaxLine[] - adjustments?: OrderLineItemAdjustment[] - detail: OrderItemDetail + tax_lines?: BaseOrderLineItemTaxLine[] + adjustments?: BaseOrderLineItemAdjustment[] + detail: BaseOrderItemDetail created_at: Date updated_at: Date metadata: Record | null @@ -153,23 +142,12 @@ interface OrderLineItem { tax_total: number discount_total: number discount_tax_total: number - raw_original_total?: BigNumberRawValue - raw_original_subtotal?: BigNumberRawValue - raw_original_tax_total?: BigNumberRawValue - raw_item_total?: BigNumberRawValue - raw_item_subtotal?: BigNumberRawValue - raw_item_tax_total?: BigNumberRawValue - raw_total?: BigNumberRawValue - raw_subtotal?: BigNumberRawValue - raw_tax_total?: BigNumberRawValue - raw_discount_total?: BigNumberRawValue - raw_discount_tax_total?: BigNumberRawValue } -interface OrderItemDetail { +interface BaseOrderItemDetail { id: string item_id: string - item: OrderLineItem + item: BaseOrderLineItem quantity: number fulfilled_quantity: number shipped_quantity: number @@ -177,22 +155,15 @@ interface OrderItemDetail { return_received_quantity: number return_dismissed_quantity: number written_off_quantity: number - raw_quantity?: BigNumberRawValue - raw_fulfilled_quantity?: BigNumberRawValue - raw_shipped_quantity?: BigNumberRawValue - raw_return_requested_quantity?: BigNumberRawValue - raw_return_received_quantity?: BigNumberRawValue - raw_return_dismissed_quantity?: BigNumberRawValue - raw_written_off_quantity?: BigNumberRawValue metadata: Record | null created_at: Date updated_at: Date } -interface OrderChange { +interface BaseOrderChange { id: string order_id: string - actions: OrderChangeAction[] + actions: BaseOrderChangeAction[] status: string requested_by: string | null requested_at: Date | string | null @@ -208,10 +179,10 @@ interface OrderChange { updated_at: Date | string } -interface OrderChangeAction { +interface BaseOrderChangeAction { id: string order_change_id: string | null - order_change: OrderChange | null + order_change: BaseOrderChange | null order_id: string | null reference: string reference_id: string @@ -222,11 +193,10 @@ interface OrderChangeAction { updated_at: Date | string } -interface OrderTransaction { +interface BaseOrderTransaction { id: string order_id: string amount: number - raw_amount?: BigNumberRawValue currency_code: string reference: string reference_id: string @@ -235,7 +205,7 @@ interface OrderTransaction { updated_at: Date | string } -export interface OrderResponse { +export interface BaseOrder { id: string version: number region_id: string | null @@ -243,12 +213,13 @@ export interface OrderResponse { sales_channel_id: string | null email: string | null currency_code: string - shipping_address?: OrderAddress - billing_address?: OrderAddress - items: OrderLineItem[] | null - shipping_methods: OrderShippingMethod[] | null - transactions?: OrderTransaction[] - summary: OrderSummary + display_id?: string + shipping_address?: BaseOrderAddress + billing_address?: BaseOrderAddress + items: BaseOrderLineItem[] | null + shipping_methods: BaseOrderShippingMethod[] | null + transactions?: BaseOrderTransaction[] + summary: BaseOrderSummary metadata: Record | null created_at: string | Date updated_at: string | Date @@ -274,34 +245,4 @@ export interface OrderResponse { original_shipping_total: number original_shipping_subtotal: number original_shipping_tax_total: number - raw_original_item_total?: BigNumberRawValue - raw_original_item_subtotal?: BigNumberRawValue - raw_original_item_tax_total?: BigNumberRawValue - raw_item_total?: BigNumberRawValue - raw_item_subtotal?: BigNumberRawValue - raw_item_tax_total?: BigNumberRawValue - raw_original_total?: BigNumberRawValue - raw_original_subtotal?: BigNumberRawValue - raw_original_tax_total?: BigNumberRawValue - raw_total?: BigNumberRawValue - raw_subtotal?: BigNumberRawValue - raw_tax_total?: BigNumberRawValue - raw_discount_total?: BigNumberRawValue - raw_discount_tax_total?: BigNumberRawValue - raw_gift_card_total?: BigNumberRawValue - raw_gift_card_tax_total?: BigNumberRawValue - raw_shipping_total?: BigNumberRawValue - raw_shipping_subtotal?: BigNumberRawValue - raw_shipping_tax_total?: BigNumberRawValue - raw_original_shipping_total?: BigNumberRawValue - raw_original_shipping_subtotal?: BigNumberRawValue - raw_original_shipping_tax_total?: BigNumberRawValue -} - -export type AdminOrderListResponse = PaginatedResponse<{ - orders: OrderResponse[] -}> - -export interface AdminOrderResponse { - order: OrderResponse } diff --git a/packages/core/types/src/http/order/index.ts b/packages/core/types/src/http/order/index.ts index 26b8eb9dad..3bd2bd2cc0 100644 --- a/packages/core/types/src/http/order/index.ts +++ b/packages/core/types/src/http/order/index.ts @@ -1 +1,2 @@ export * from "./admin" +export * from "./store" diff --git a/packages/core/types/src/http/order/store.ts b/packages/core/types/src/http/order/store.ts new file mode 100644 index 0000000000..d3a855293a --- /dev/null +++ b/packages/core/types/src/http/order/store.ts @@ -0,0 +1,3 @@ +import { BaseOrder } from "./common" + +export interface StoreOrder extends BaseOrder {} diff --git a/packages/core/types/src/http/payment/admin.ts b/packages/core/types/src/http/payment/admin.ts index 75c85b2a4d..6151efd25d 100644 --- a/packages/core/types/src/http/payment/admin.ts +++ b/packages/core/types/src/http/payment/admin.ts @@ -1,5 +1,23 @@ -import { BasePaymentProvider } from "./common" +import { + BasePaymentCollection, + BasePaymentCollectionFilters, + BasePaymentProvider, + BasePaymentProviderFilters, + BasePaymentSession, + BasePaymentSessionFilters, +} from "./common" export interface AdminPaymentProvider extends BasePaymentProvider { is_enabled: boolean } + +export interface AdminPaymentCollection extends BasePaymentCollection {} +export interface AdminPaymentSession extends BasePaymentSession {} + +export interface AdminPaymentProviderFilters + extends BasePaymentProviderFilters { + is_enabled?: boolean +} +export interface AdminPaymentCollectionFilters + extends BasePaymentCollectionFilters {} +export interface AdminPaymentSessionFilters extends BasePaymentSessionFilters {} diff --git a/packages/core/types/src/http/payment/common.ts b/packages/core/types/src/http/payment/common.ts index 46a6a2bb32..39474eea05 100644 --- a/packages/core/types/src/http/payment/common.ts +++ b/packages/core/types/src/http/payment/common.ts @@ -1,3 +1,422 @@ +import { BaseFilterable, OperatorMap } from "../../dal" +import { BigNumberValue } from "../../totals" + +/** + * The payment collection's status. + */ +export type BasePaymentCollectionStatus = + | "not_paid" + | "awaiting" + | "authorized" + | "partially_authorized" + | "canceled" + +/** + * + * The status of a payment session. + */ +export type BasePaymentSessionStatus = + | "authorized" + | "pending" + | "requires_more" + | "error" + | "canceled" + export interface BasePaymentProvider { id: string } + +/** + * The payment collection details. + */ +export interface BasePaymentCollection { + /** + * The ID of the payment collection. + */ + id: string + + /** + * The ISO 3 character currency code of the payment sessions and payments associated with payment collection. + */ + currency_code: string + + /** + * The id of the associated region. + */ + region_id: string + + /** + * The total amount to be authorized and captured. + */ + amount: BigNumberValue + + /** + * The amount authorized within the associated payment sessions. + */ + authorized_amount?: BigNumberValue + + /** + * The amount refunded within the associated payments. + */ + refunded_amount?: BigNumberValue + + /** + * When the payment collection was completed. + */ + completed_at?: string | Date + + /** + * When the payment collection was created. + */ + created_at?: string | Date + + /** + * When the payment collection was updated. + */ + updated_at?: string | Date + + /** + * Holds custom data in key-value pairs. + */ + metadata?: Record + + /** + * The status of the payment collection. + */ + status: BasePaymentCollectionStatus + + /** + * The payment provider used to process the associated payment sessions and payments. + * + * @expandable + */ + payment_providers: BasePaymentProvider[] + + /** + * The associated payment sessions. + * + * @expandable + */ + payment_sessions?: BasePaymentSession[] + + /** + * The associated payments. + * + * @expandable + */ + payments?: BasePayment[] +} + +export interface BasePayment { + /** + * The ID of the payment. + */ + id: string + + /** + * The payment's total amount. + */ + amount: BigNumberValue + + /** + * The authorized amount of the payment. + */ + authorized_amount?: BigNumberValue + + /** + * The ISO 3 character currency code of the payment. + */ + currency_code: string + + /** + * The ID of the associated payment provider. + */ + provider_id: string + + /** + * The ID of the associated cart. + */ + cart_id?: string + + /** + * The ID of the associated order. + */ + order_id?: string + + /** + * The ID of the associated order edit. + */ + order_edit_id?: string + + /** + * The ID of the associated customer. + */ + customer_id?: string + + /** + * The data relevant for the payment provider to process the payment. + */ + data?: Record + + /** + * When the payment was created. + */ + created_at?: string | Date + + /** + * When the payment was updated. + */ + updated_at?: string | Date + + /** + * When the payment was captured. + */ + captured_at?: string | Date + + /** + * When the payment was canceled. + */ + canceled_at?: string | Date + + /** + * The sum of the associated captures' amounts. + */ + captured_amount?: BigNumberValue + + /** + * The sum of the associated refunds' amounts. + */ + refunded_amount?: BigNumberValue + + /** + * The associated captures. + * + * @expandable + */ + captures?: BaseCapture[] + + /** + * The associated refunds. + * + * @expandable + */ + refunds?: BaseRefund[] + + /** + * The associated payment collection. + * + * @expandable + */ + payment_collection?: BasePaymentCollection + + /** + * The payment session from which the payment is created. + * + * @expandable + */ + payment_session?: BasePaymentSession +} + +/** + * The capture details. + */ +export interface BaseCapture { + /** + * The ID of the capture. + */ + id: string + + /** + * The captured amount. + */ + amount: BigNumberValue + + /** + * The creation date of the capture. + */ + created_at: Date + + /** + * Who the capture was created by. For example, + * the ID of a user. + */ + created_by?: string + + /** + * The associated payment. + */ + payment: BasePayment +} + +/** + * The refund details. + */ +export interface BaseRefund { + /** + * The ID of the refund + */ + id: string + + /** + * The refunded amount. + */ + amount: BigNumberValue + + /** + * The creation date of the refund. + */ + created_at: Date + + /** + * Who created the refund. For example, + * the user's ID. + */ + created_by?: string + + /** + * The associated payment. + */ + payment: BasePayment +} + +/** + * The payment session details. + */ +export interface BasePaymentSession { + /** + * The ID of the payment session. + */ + id: string + + /** + * The amount to authorize. + */ + amount: BigNumberValue + + /** + * The 3 character currency code of the payment session. + */ + currency_code: string + + /** + * The ID of the associated payment provider. + */ + provider_id: string + + /** + * The data necessary for the payment provider to process the payment session. + */ + data: Record + + /** + * The context necessary for the payment provider. + */ + context?: Record + + /** + * The status of the payment session. + */ + status: BasePaymentSessionStatus + + /** + * When the payment session was authorized. + */ + authorized_at?: Date + + /** + * The payment collection the session is associated with. + * + * @expandable + */ + payment_collection?: BasePaymentCollection + + /** + * The payment created from the session. + * + * @expandable + */ + payment?: BasePayment +} + +/** + * The filters to apply on the retrieved payment collection. + */ +export interface BasePaymentCollectionFilters + extends BaseFilterable { + /** + * The IDs to filter the payment collection by. + */ + id?: string | string[] + + /** + * Filter by associated region's ID. + */ + region_id?: string | string[] | OperatorMap + + /** + * Filter payment collections by created date. + */ + created_at?: OperatorMap + + /** + * Filter payment collections by updated date. + */ + updated_at?: OperatorMap +} + +/** + * The filters to apply on the retrieved payment sessions. + */ +export interface BasePaymentSessionFilters + extends BaseFilterable { + /** + * The IDs to filter the payment sessions by. + */ + id?: string | string[] + + /** + * Filter the payment sessions by their currency code. + */ + currency_code?: string | string[] + + /** + * Filter the payment sessions by their amount. + */ + amount?: BigNumberValue | OperatorMap + + /** + * Filter the payment sessions by the ID of their associated payment provider. + */ + provider_id?: string | string[] + + /** + * Filter the payment sessions by the ID of their associated payment collection. + */ + payment_collection_id?: string | string[] + + /** + * Filter the payment sessions by the ID of their associated region. + */ + region_id?: string | string[] | OperatorMap + + /** + * Filter the payment sessions by their creation date. + */ + created_at?: OperatorMap + + /** + * Filter the payment sessions by their update date. + */ + updated_at?: OperatorMap + + /** + * Filter the payment sessions by their deletion date. + */ + deleted_at?: OperatorMap +} + +export interface BasePaymentProviderFilters + extends BaseFilterable { + id?: string | string[] + region_id?: string | string[] +} diff --git a/packages/core/types/src/http/payment/store.ts b/packages/core/types/src/http/payment/store.ts index 65aeb00886..93cc94ffc2 100644 --- a/packages/core/types/src/http/payment/store.ts +++ b/packages/core/types/src/http/payment/store.ts @@ -1,3 +1,18 @@ -import { BasePaymentProvider } from "./common" +import { + BasePaymentCollection, + BasePaymentCollectionFilters, + BasePaymentProvider, + BasePaymentProviderFilters, + BasePaymentSession, + BasePaymentSessionFilters, +} from "./common" export interface StorePaymentProvider extends BasePaymentProvider {} +export interface StorePaymentCollection extends BasePaymentCollection {} +export interface StorePaymentSession extends BasePaymentSession {} + +export interface StorePaymentProviderFilters + extends BasePaymentProviderFilters {} +export interface StorePaymentCollectionFilters + extends BasePaymentCollectionFilters {} +export interface StorePaymentSessionFilters extends BasePaymentSessionFilters {} diff --git a/packages/core/types/src/http/product/store.ts b/packages/core/types/src/http/product/store.ts index 00dd5f5191..dc08d3e31f 100644 --- a/packages/core/types/src/http/product/store.ts +++ b/packages/core/types/src/http/product/store.ts @@ -24,10 +24,15 @@ export interface StoreProductOption extends BaseProductOption {} export interface StoreProductImage extends BaseProductImage {} export interface StoreProductOptionValue extends BaseProductOptionValue {} -export interface StoreProductFilters extends BaseProductFilters {} export interface StoreProductTagFilters extends BaseProductTagFilters {} export interface StoreProductTypeFilters extends BaseProductTypeFilters {} export interface StoreProductOptionFilters extends BaseProductOptionFilters {} export interface StoreProductVariantFilters extends BaseProductVariantFilters {} +export interface StoreProductFilters extends BaseProductFilters { + // The region ID and currency_code are not filters, but are used for the pricing context. Maybe move to separate type definition. + region_id?: string + currency_code?: string + variants?: StoreProductVariantFilters +} export interface StoreProductCategoryFilters extends BaseProductCategoryFilters {} diff --git a/packages/medusa/src/api-v2/store/carts/[id]/line-items/[line_id]/route.ts b/packages/medusa/src/api-v2/store/carts/[id]/line-items/[line_id]/route.ts index da00fc8754..3244745080 100644 --- a/packages/medusa/src/api-v2/store/carts/[id]/line-items/[line_id]/route.ts +++ b/packages/medusa/src/api-v2/store/carts/[id]/line-items/[line_id]/route.ts @@ -7,6 +7,7 @@ import { MedusaRequest, MedusaResponse } from "../../../../../../types/routing" import { refetchCart } from "../../../helpers" import { StoreUpdateCartLineItemType } from "../../../validators" import { prepareListQuery } from "../../../../../../utils/get-query-config" +import { DeleteResponse } from "@medusajs/types" export const POST = async ( req: MedusaRequest, @@ -62,7 +63,10 @@ export const POST = async ( res.status(200).json({ cart: updatedCart }) } -export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => { +export const DELETE = async ( + req: MedusaRequest, + res: MedusaResponse> +) => { const id = req.params.line_id const { errors } = await deleteLineItemsWorkflow(req.scope).run({ @@ -80,5 +84,10 @@ export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => { req.remoteQueryConfig.fields ) - res.status(200).json({ cart }) + res.status(200).json({ + id: id, + object: "line-item", + deleted: true, + parent: cart, + }) }