From 522e306e2e9abf4afce63f30714389eba32bef7f Mon Sep 17 00:00:00 2001 From: Patrick <116003638+patrick-medusajs@users.noreply.github.com> Date: Thu, 16 Mar 2023 04:08:20 -0400 Subject: [PATCH] feat(oas): declare x-expanded-relations - Store (#3482) * feat(oas): declare x-expanded-relations - Store * fixup! feat(oas): declare x-expanded-relations - Store * fixup! feat(oas): declare x-expanded-relations - Store * fixup! feat(oas): declare x-expanded-relations - Store * fixup! feat(oas): declare x-expanded-relations - Store * chore(changeset): patch * fix(tests): update store auth integration test * fix: pr feedback * fix(test): match response code --- .changeset/loud-pillows-report.md | 6 ++ .../store/__snapshots__/auth.js.snap | 18 ---- integration-tests/api/__tests__/store/auth.js | 21 ++-- .../api/__tests__/store/payment-collection.js | 2 +- .../api/routes/store/auth/create-session.ts | 3 +- .../src/api/routes/store/auth/get-session.ts | 3 +- .../medusa/src/api/routes/store/auth/index.ts | 8 ++ .../src/api/routes/store/carts/index.ts | 21 ++-- .../src/api/routes/store/collections/index.ts | 3 +- .../store/collections/list-collections.ts | 9 ++ .../src/api/routes/store/customers/index.ts | 99 +++++++++++++++++++ .../routes/store/customers/reset-password.ts | 2 +- .../src/api/routes/store/order-edits/index.ts | 35 +++++++ .../src/api/routes/store/orders/index.ts | 80 +++++++++++++++ .../authorize-batch-payment-sessions.ts | 2 +- .../routes/store/payment-collections/index.ts | 8 ++ .../routes/store/product-categories/index.ts | 10 ++ .../src/api/routes/store/products/index.ts | 24 +++++ .../api/routes/store/regions/get-region.ts | 3 +- .../src/api/routes/store/regions/index.ts | 12 +++ .../api/routes/store/regions/list-regions.ts | 3 +- .../api/routes/store/return-reasons/index.ts | 10 ++ .../api/routes/store/returns/create-return.ts | 3 +- .../src/api/routes/store/returns/index.ts | 9 ++ .../routes/store/shipping-options/index.ts | 32 +++++- .../store/shipping-options/list-options.ts | 3 +- .../shipping-options/list-shipping-options.ts | 2 +- .../routes/store/swaps/get-swap-by-cart.ts | 6 +- .../src/api/routes/store/swaps/index.ts | 15 +++ .../src/api/routes/store/variants/index.ts | 19 +++- packages/medusa/src/types/pricing.ts | 29 ++++++ 31 files changed, 448 insertions(+), 52 deletions(-) create mode 100644 .changeset/loud-pillows-report.md delete mode 100644 integration-tests/api/__tests__/store/__snapshots__/auth.js.snap diff --git a/.changeset/loud-pillows-report.md b/.changeset/loud-pillows-report.md new file mode 100644 index 0000000000000..d076992908462 --- /dev/null +++ b/.changeset/loud-pillows-report.md @@ -0,0 +1,6 @@ +--- +"@medusajs/client-types": patch +"@medusajs/medusa": patch +--- + +feat(oas): declare x-expanded-relations - Store diff --git a/integration-tests/api/__tests__/store/__snapshots__/auth.js.snap b/integration-tests/api/__tests__/store/__snapshots__/auth.js.snap deleted file mode 100644 index 0cad033c53e98..0000000000000 --- a/integration-tests/api/__tests__/store/__snapshots__/auth.js.snap +++ /dev/null @@ -1,18 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`/store/auth creates store session correctly 1`] = ` -Object { - "billing_address_id": null, - "created_at": Any, - "deleted_at": null, - "email": "test@testesen.dk", - "first_name": "test", - "has_account": true, - "id": Any, - "last_name": "testesen", - "metadata": null, - "orders": Array [], - "phone": null, - "updated_at": Any, -} -`; diff --git a/integration-tests/api/__tests__/store/auth.js b/integration-tests/api/__tests__/store/auth.js index 51427798aac81..bbbad807466a8 100644 --- a/integration-tests/api/__tests__/store/auth.js +++ b/integration-tests/api/__tests__/store/auth.js @@ -49,15 +49,18 @@ describe("/store/auth", () => { expect(response.status).toEqual(200) expect(response.data.customer.password_hash).toEqual(undefined) - expect(response.data.customer).toMatchSnapshot({ - id: expect.any(String), - created_at: expect.any(String), - updated_at: expect.any(String), - first_name: "test", - last_name: "testesen", - phone: null, - email: "test@testesen.dk", - }) + expect(response.data.customer).toEqual( + expect.objectContaining({ + id: expect.any(String), + created_at: expect.any(String), + updated_at: expect.any(String), + first_name: "test", + last_name: "testesen", + phone: null, + email: "test@testesen.dk", + shipping_addresses: expect.arrayContaining([]), + }) + ) }) describe("Store session management", () => { diff --git a/integration-tests/api/__tests__/store/payment-collection.js b/integration-tests/api/__tests__/store/payment-collection.js index 65404e2facba6..f5cbaddce889b 100644 --- a/integration-tests/api/__tests__/store/payment-collection.js +++ b/integration-tests/api/__tests__/store/payment-collection.js @@ -440,7 +440,7 @@ describe("/store/payment-collections", () => { }) ) - expect(response.status).toEqual(207) + expect(response.status).toEqual(200) }) }) }) diff --git a/packages/medusa/src/api/routes/store/auth/create-session.ts b/packages/medusa/src/api/routes/store/auth/create-session.ts index 1358784e33fcb..4e5f06dbd93e8 100644 --- a/packages/medusa/src/api/routes/store/auth/create-session.ts +++ b/packages/medusa/src/api/routes/store/auth/create-session.ts @@ -4,6 +4,7 @@ import { EntityManager } from "typeorm" import AuthService from "../../../../services/auth" import CustomerService from "../../../../services/customer" import { validator } from "../../../../utils/validator" +import { defaultRelations } from "." /** * @oas [post] /store/auth @@ -91,7 +92,7 @@ export default async (req, res) => { const customerService: CustomerService = req.scope.resolve("customerService") const customer = await customerService.retrieve(result.customer?.id || "", { - relations: ["orders", "orders.items"], + relations: defaultRelations, }) res.json({ customer }) diff --git a/packages/medusa/src/api/routes/store/auth/get-session.ts b/packages/medusa/src/api/routes/store/auth/get-session.ts index 3dccbb7370cd0..700d6d7619f2f 100644 --- a/packages/medusa/src/api/routes/store/auth/get-session.ts +++ b/packages/medusa/src/api/routes/store/auth/get-session.ts @@ -1,4 +1,5 @@ import CustomerService from "../../../../services/customer" +import { defaultRelations } from "." /** * @oas [get] /store/auth @@ -52,7 +53,7 @@ export default async (req, res) => { const customerService: CustomerService = req.scope.resolve("customerService") const customer = await customerService.retrieve(req.user.customer_id, { - relations: ["shipping_addresses", "orders", "orders.items"], + relations: defaultRelations, }) res.json({ customer }) diff --git a/packages/medusa/src/api/routes/store/auth/index.ts b/packages/medusa/src/api/routes/store/auth/index.ts index f03a570e059d5..fbf750ce42b41 100644 --- a/packages/medusa/src/api/routes/store/auth/index.ts +++ b/packages/medusa/src/api/routes/store/auth/index.ts @@ -19,9 +19,17 @@ export default (app) => { return app } +export const defaultRelations = ["orders", "orders.items", "shipping_addresses"] + /** * @schema StoreAuthRes * type: object + * x-expanded-relations: + * field: customer + * relations: + * - orders + * - orders.items + * - shipping_addresses * required: * - customer * properties: diff --git a/packages/medusa/src/api/routes/store/carts/index.ts b/packages/medusa/src/api/routes/store/carts/index.ts index e1d534ca18b08..15938dfbe30f7 100644 --- a/packages/medusa/src/api/routes/store/carts/index.ts +++ b/packages/medusa/src/api/routes/store/carts/index.ts @@ -171,15 +171,24 @@ export const defaultStoreCartRelations = [ * - region.payment_providers * - shipping_address * - shipping_methods - * - shipping_methods.shipping_option - * implicit: - * - items.tax_lines - * - items.variant.product + * eager: * - region.fulfillment_providers * - region.payment_providers - * - region.tax_rates * - shipping_methods.shipping_option - * - shipping_methods.tax_lines + * implicit: + * - items + * - items.variant + * - items.variant.product + * - items.tax_lines + * - items.adjustments + * - gift_cards + * - discounts + * - discounts.rule + * - shipping_methods + * - shipping_methods.tax_lines + * - shipping_address + * - region + * - region.tax_rates * totals: * - discount_total * - gift_card_tax_total diff --git a/packages/medusa/src/api/routes/store/collections/index.ts b/packages/medusa/src/api/routes/store/collections/index.ts index e5ec450efbc93..ce549b0d7597b 100644 --- a/packages/medusa/src/api/routes/store/collections/index.ts +++ b/packages/medusa/src/api/routes/store/collections/index.ts @@ -22,11 +22,12 @@ export default (app) => { return app } -export const defaultStoreCollectionRelations = ["products"] +export const defaultStoreCollectionRelations = [] export const allowedFields = [ "id", "title", "handle", + "products", "metadata", "created_at", "updated_at", diff --git a/packages/medusa/src/api/routes/store/collections/list-collections.ts b/packages/medusa/src/api/routes/store/collections/list-collections.ts index 237df4e135659..7e11ceafaa9c1 100644 --- a/packages/medusa/src/api/routes/store/collections/list-collections.ts +++ b/packages/medusa/src/api/routes/store/collections/list-collections.ts @@ -13,6 +13,15 @@ import { Type } from "class-transformer" * - (query) offset=0 {integer} The number of collections to skip before starting to collect the collections set * - (query) limit=10 {integer} The number of collections to return * - in: query + * name: handle + * style: form + * explode: false + * description: Filter by the collection handle + * schema: + * type: array + * items: + * type: string + * - in: query * name: created_at * description: Date comparison for when resulting collections were created. * schema: diff --git a/packages/medusa/src/api/routes/store/customers/index.ts b/packages/medusa/src/api/routes/store/customers/index.ts index df14786dd73ea..ab61aa1f4dcb6 100644 --- a/packages/medusa/src/api/routes/store/customers/index.ts +++ b/packages/medusa/src/api/routes/store/customers/index.ts @@ -114,6 +114,11 @@ export const allowedStoreCustomersFields = [ /** * @schema StoreCustomersRes * type: object + * x-expanded-relations: + * field: customer + * relations: + * - billing_address + * - shipping_addresses * required: * - customer * properties: @@ -124,9 +129,103 @@ export type StoreCustomersRes = { customer: Omit } +/** + * @schema StoreCustomersResetPasswordRes + * type: object + * required: + * - customer + * properties: + * customer: + * $ref: "#/components/schemas/Customer" + */ +export type StoreCustomersResetPasswordRes = { + customer: Omit +} + /** * @schema StoreCustomersListOrdersRes * type: object + * x-expanded-relations: + * field: orders + * relations: + * - customer + * - discounts + * - discounts.rule + * - fulfillments + * - fulfillments.tracking_links + * - items + * - items.variant + * - payments + * - region + * - shipping_address + * - shipping_methods + * eager: + * - region.fulfillment_providers + * - region.payment_providers + * - shipping_methods.shipping_option + * implicit: + * - claims + * - claims.additional_items + * - claims.additional_items.adjustments + * - claims.additional_items.refundable + * - claims.additional_items.tax_lines + * - customer + * - discounts + * - discounts.rule + * - gift_card_transactions + * - gift_card_transactions.gift_card + * - gift_cards + * - items + * - items.adjustments + * - items.refundable + * - items.tax_lines + * - items.variant + * - items.variant.product + * - refunds + * - region + * - shipping_address + * - shipping_methods + * - shipping_methods.tax_lines + * - swaps + * - swaps.additional_items + * - swaps.additional_items.adjustments + * - swaps.additional_items.refundable + * - swaps.additional_items.tax_lines + * totals: + * - discount_total + * - gift_card_tax_total + * - gift_card_total + * - paid_total + * - refundable_amount + * - refunded_total + * - shipping_total + * - subtotal + * - tax_total + * - total + * - claims.additional_items.discount_total + * - claims.additional_items.gift_card_total + * - claims.additional_items.original_tax_total + * - claims.additional_items.original_total + * - claims.additional_items.refundable + * - claims.additional_items.subtotal + * - claims.additional_items.tax_total + * - claims.additional_items.total + * - items.discount_total + * - items.gift_card_total + * - items.original_tax_total + * - items.original_total + * - items.refundable + * - items.subtotal + * - items.tax_total + * - items.total + * - swaps.additional_items.discount_total + * - swaps.additional_items.gift_card_total + * - swaps.additional_items.original_tax_total + * - swaps.additional_items.original_total + * - swaps.additional_items.refundable + * - swaps.additional_items.subtotal + * - swaps.additional_items.tax_total + * - swaps.additional_items.total * required: * - orders * - count diff --git a/packages/medusa/src/api/routes/store/customers/reset-password.ts b/packages/medusa/src/api/routes/store/customers/reset-password.ts index fb1c405ffa891..8607d001f5bf5 100644 --- a/packages/medusa/src/api/routes/store/customers/reset-password.ts +++ b/packages/medusa/src/api/routes/store/customers/reset-password.ts @@ -49,7 +49,7 @@ import { EntityManager } from "typeorm" * content: * application/json: * schema: - * $ref: "#/components/schemas/StoreCustomersRes" + * $ref: "#/components/schemas/StoreCustomersResetPasswordRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/store/order-edits/index.ts b/packages/medusa/src/api/routes/store/order-edits/index.ts index e6e8de1b5d035..f73a10564c24f 100644 --- a/packages/medusa/src/api/routes/store/order-edits/index.ts +++ b/packages/medusa/src/api/routes/store/order-edits/index.ts @@ -44,6 +44,41 @@ export default (app) => { /** * @schema StoreOrderEditsRes * type: object + * x-expanded-relations: + * field: order_edit + * relations: + * - changes + * - changes.line_item + * - changes.line_item.variant + * - changes.original_line_item + * - changes.original_line_item.variant + * - items + * - items.adjustments + * - items.tax_lines + * - items.variant + * - payment_collection + * implicit: + * - items + * - items.tax_lines + * - items.adjustments + * - items.variant + * totals: + * - difference_due + * - discount_total + * - gift_card_tax_total + * - gift_card_total + * - shipping_total + * - subtotal + * - tax_total + * - total + * - items.discount_total + * - items.gift_card_total + * - items.original_tax_total + * - items.original_total + * - items.refundable + * - items.subtotal + * - items.tax_total + * - items.total * required: * - order_edit * properties: diff --git a/packages/medusa/src/api/routes/store/orders/index.ts b/packages/medusa/src/api/routes/store/orders/index.ts index 10f3d85da8e57..679ce0acd9e64 100644 --- a/packages/medusa/src/api/routes/store/orders/index.ts +++ b/packages/medusa/src/api/routes/store/orders/index.ts @@ -131,6 +131,86 @@ export const allowedStoreOrdersFields = [ * type: object * required: * - order + * x-expanded-relations: + * field: order + * relations: + * - customer + * - discounts + * - discounts.rule + * - fulfillments + * - fulfillments.tracking_links + * - items + * - items.variant + * - payments + * - region + * - shipping_address + * - shipping_methods + * eager: + * - fulfillments.items + * - region.fulfillment_providers + * - region.payment_providers + * - shipping_methods.shipping_option + * implicit: + * - claims + * - claims.additional_items + * - claims.additional_items.adjustments + * - claims.additional_items.refundable + * - claims.additional_items.tax_lines + * - discounts + * - discounts.rule + * - gift_card_transactions + * - gift_card_transactions.gift_card + * - gift_cards + * - items + * - items.adjustments + * - items.refundable + * - items.tax_lines + * - items.variant + * - items.variant.product + * - refunds + * - region + * - shipping_methods + * - shipping_methods.tax_lines + * - swaps + * - swaps.additional_items + * - swaps.additional_items.adjustments + * - swaps.additional_items.refundable + * - swaps.additional_items.tax_lines + * totals: + * - discount_total + * - gift_card_tax_total + * - gift_card_total + * - paid_total + * - refundable_amount + * - refunded_total + * - shipping_total + * - subtotal + * - tax_total + * - total + * - claims.additional_items.discount_total + * - claims.additional_items.gift_card_total + * - claims.additional_items.original_tax_total + * - claims.additional_items.original_total + * - claims.additional_items.refundable + * - claims.additional_items.subtotal + * - claims.additional_items.tax_total + * - claims.additional_items.total + * - items.discount_total + * - items.gift_card_total + * - items.original_tax_total + * - items.original_total + * - items.refundable + * - items.subtotal + * - items.tax_total + * - items.total + * - swaps.additional_items.discount_total + * - swaps.additional_items.gift_card_total + * - swaps.additional_items.original_tax_total + * - swaps.additional_items.original_total + * - swaps.additional_items.refundable + * - swaps.additional_items.subtotal + * - swaps.additional_items.tax_total + * - swaps.additional_items.total * properties: * order: * $ref: "#/components/schemas/Order" diff --git a/packages/medusa/src/api/routes/store/payment-collections/authorize-batch-payment-sessions.ts b/packages/medusa/src/api/routes/store/payment-collections/authorize-batch-payment-sessions.ts index c15239201e29c..2bc962542266d 100644 --- a/packages/medusa/src/api/routes/store/payment-collections/authorize-batch-payment-sessions.ts +++ b/packages/medusa/src/api/routes/store/payment-collections/authorize-batch-payment-sessions.ts @@ -72,7 +72,7 @@ export default async (req, res) => { req.request_context ) - res.status(207).json({ payment_collection }) + res.status(200).json({ payment_collection }) } /** diff --git a/packages/medusa/src/api/routes/store/payment-collections/index.ts b/packages/medusa/src/api/routes/store/payment-collections/index.ts index aa0d9d97b97b5..7d10af88c5689 100644 --- a/packages/medusa/src/api/routes/store/payment-collections/index.ts +++ b/packages/medusa/src/api/routes/store/payment-collections/index.ts @@ -74,6 +74,14 @@ export const defaultPaymentCollectionRelations = ["region", "payment_sessions"] /** * @schema StorePaymentCollectionsRes * type: object + * x-expanded-relations: + * field: payment_collection + * relations: + * - payment_sessions + * - region + * eager: + * - region.fulfillment_providers + * - region.payment_providers * required: * - payment_collection * properties: diff --git a/packages/medusa/src/api/routes/store/product-categories/index.ts b/packages/medusa/src/api/routes/store/product-categories/index.ts index 0551c464a0753..3abac1838aa18 100644 --- a/packages/medusa/src/api/routes/store/product-categories/index.ts +++ b/packages/medusa/src/api/routes/store/product-categories/index.ts @@ -74,6 +74,11 @@ export const allowedStoreProductCategoryFields = [ /** * @schema StoreGetProductCategoriesCategoryRes * type: object + * x-expanded-relations: + * field: product_category + * relations: + * - category_children + * - parent_category * required: * - product_category * properties: @@ -87,6 +92,11 @@ export type StoreGetProductCategoriesCategoryRes = { /** * @schema StoreGetProductCategoriesRes * type: object + * x-expanded-relations: + * field: product_categories + * relations: + * - category_children + * - parent_category * required: * - product_categories * - count diff --git a/packages/medusa/src/api/routes/store/products/index.ts b/packages/medusa/src/api/routes/store/products/index.ts index 0f7974f0589ff..7d10aed953570 100644 --- a/packages/medusa/src/api/routes/store/products/index.ts +++ b/packages/medusa/src/api/routes/store/products/index.ts @@ -110,6 +110,18 @@ export * from "./search" /** * @schema StoreProductsRes * type: object + * x-expanded-relations: + * field: product + * relations: + * - collection + * - images + * - options + * - options.values + * - tags + * - type + * - variants + * - variants.options + * - variants.prices * required: * - product * properties: @@ -139,6 +151,18 @@ export type StorePostSearchRes = { /** * @schema StoreProductsListRes * type: object + * x-expanded-relations: + * field: products + * relations: + * - collection + * - images + * - options + * - options.values + * - tags + * - type + * - variants + * - variants.options + * - variants.prices * required: * - products * - count diff --git a/packages/medusa/src/api/routes/store/regions/get-region.ts b/packages/medusa/src/api/routes/store/regions/get-region.ts index d5ce730ec8da9..bc4b9679509f3 100644 --- a/packages/medusa/src/api/routes/store/regions/get-region.ts +++ b/packages/medusa/src/api/routes/store/regions/get-region.ts @@ -1,4 +1,5 @@ import RegionService from "../../../../services/region" +import { defaultRelations } from "." /** * @oas [get] /store/regions/{id} @@ -49,7 +50,7 @@ export default async (req, res) => { const regionService: RegionService = req.scope.resolve("regionService") const region = await regionService.retrieve(region_id, { - relations: ["countries", "payment_providers", "fulfillment_providers"], + relations: defaultRelations, }) res.json({ region }) diff --git a/packages/medusa/src/api/routes/store/regions/index.ts b/packages/medusa/src/api/routes/store/regions/index.ts index 7f7d72ed2c209..76413d966801e 100644 --- a/packages/medusa/src/api/routes/store/regions/index.ts +++ b/packages/medusa/src/api/routes/store/regions/index.ts @@ -13,6 +13,12 @@ export default (app) => { return app } +export const defaultRelations = [ + "countries", + "payment_providers", + "fulfillment_providers", +] + /** * @schema StoreRegionsListRes * type: object @@ -22,6 +28,9 @@ export default (app) => { * - countries * - payment_providers * - fulfillment_providers + * eager: + * - payment_providers + * - fulfillment_providers * required: * - regions * properties: @@ -43,6 +52,9 @@ export type StoreRegionsListRes = { * - countries * - payment_providers * - fulfillment_providers + * eager: + * - payment_providers + * - fulfillment_providers * required: * - region * properties: diff --git a/packages/medusa/src/api/routes/store/regions/list-regions.ts b/packages/medusa/src/api/routes/store/regions/list-regions.ts index c4685c198db77..191f661be3572 100644 --- a/packages/medusa/src/api/routes/store/regions/list-regions.ts +++ b/packages/medusa/src/api/routes/store/regions/list-regions.ts @@ -5,6 +5,7 @@ import RegionService from "../../../../services/region" import { Type } from "class-transformer" import { omit } from "lodash" import { validator } from "../../../../utils/validator" +import { defaultRelations } from "." /** * @oas [get] /store/regions @@ -104,7 +105,7 @@ export default async (req, res) => { const filterableFields = omit(validated, ["limit", "offset"]) const listConfig = { - relations: ["countries", "payment_providers", "fulfillment_providers"], + relations: defaultRelations, skip: offset, take: limit, } diff --git a/packages/medusa/src/api/routes/store/return-reasons/index.ts b/packages/medusa/src/api/routes/store/return-reasons/index.ts index 302111272721d..7e4960dd0a668 100644 --- a/packages/medusa/src/api/routes/store/return-reasons/index.ts +++ b/packages/medusa/src/api/routes/store/return-reasons/index.ts @@ -39,6 +39,11 @@ export const defaultStoreReturnReasonRelations: (keyof ReturnReason)[] = [ /** * @schema StoreReturnReasonsListRes * type: object + * x-expanded-relations: + * field: return_reasons + * relations: + * - parent_return_reason + * - return_reason_children * required: * - return_reasons * properties: @@ -54,6 +59,11 @@ export type StoreReturnReasonsListRes = { /** * @schema StoreReturnReasonsRes * type: object + * x-expanded-relations: + * field: return_reason + * relations: + * - parent_return_reason + * - return_reason_children * required: * - return_reason * properties: diff --git a/packages/medusa/src/api/routes/store/returns/create-return.ts b/packages/medusa/src/api/routes/store/returns/create-return.ts index de855bd8508f5..d4590fe8ddeaa 100644 --- a/packages/medusa/src/api/routes/store/returns/create-return.ts +++ b/packages/medusa/src/api/routes/store/returns/create-return.ts @@ -15,6 +15,7 @@ import EventBusService from "../../../../services/event-bus" import IdempotencyKeyService from "../../../../services/idempotency-key" import ReturnService from "../../../../services/return" import { validator } from "../../../../utils/validator" +import { defaultRelations } from "." /** * @oas [post] /store/returns @@ -172,7 +173,7 @@ export default async (req, res) => { idempotency_key: idempotencyKey.idempotency_key, }, { - relations: ["items", "items.reason"], + relations: defaultRelations, } ) if (!returnOrders.length) { diff --git a/packages/medusa/src/api/routes/store/returns/index.ts b/packages/medusa/src/api/routes/store/returns/index.ts index a3cae206f876d..b1d9000860337 100644 --- a/packages/medusa/src/api/routes/store/returns/index.ts +++ b/packages/medusa/src/api/routes/store/returns/index.ts @@ -12,9 +12,18 @@ export default (app) => { return app } +export const defaultRelations = ["items", "items.reason"] + /** * @schema StoreReturnsRes * type: object + * x-expanded-relations: + * field: return + * relations: + * - items + * - items.reason + * eager: + * - items * required: * - return * properties: diff --git a/packages/medusa/src/api/routes/store/shipping-options/index.ts b/packages/medusa/src/api/routes/store/shipping-options/index.ts index ac151df2ed2b0..305f54efc61d6 100644 --- a/packages/medusa/src/api/routes/store/shipping-options/index.ts +++ b/packages/medusa/src/api/routes/store/shipping-options/index.ts @@ -1,6 +1,6 @@ -import { ShippingOption } from "./../../../../" import { Router } from "express" import middlewares from "../../../middlewares" +import { PricedShippingOption } from "../../../../types/pricing" const route = Router() @@ -16,19 +16,45 @@ export default (app) => { return app } +export const defaultRelations = ["requirements"] + /** * @schema StoreShippingOptionsListRes * type: object + * x-expanded-relations: + * field: shipping_options + * relations: + * - requirements * required: * - shipping_options * properties: * shipping_options: * type: array * items: - * $ref: "#/components/schemas/ShippingOption" + * $ref: "#/components/schemas/PricedShippingOption" */ export type StoreShippingOptionsListRes = { - shipping_options: ShippingOption[] + shipping_options: PricedShippingOption[] +} + +/** + * @schema StoreCartShippingOptionsListRes + * type: object + * x-expanded-relations: + * field: shipping_options + * implicit: + * - profile + * - requirements + * required: + * - shipping_options + * properties: + * shipping_options: + * type: array + * items: + * $ref: "#/components/schemas/PricedShippingOption" + */ +export type StoreCartShippingOptionsListRes = { + shipping_options: PricedShippingOption[] } export * from "./list-options" diff --git a/packages/medusa/src/api/routes/store/shipping-options/list-options.ts b/packages/medusa/src/api/routes/store/shipping-options/list-options.ts index 6e53c859d64c3..d849a7d39e241 100644 --- a/packages/medusa/src/api/routes/store/shipping-options/list-options.ts +++ b/packages/medusa/src/api/routes/store/shipping-options/list-options.ts @@ -2,6 +2,7 @@ import { IsBooleanString, IsOptional, IsString } from "class-validator" import { PricingService, ProductService } from "../../../../services" import ShippingOptionService from "../../../../services/shipping-option" import { validator } from "../../../../utils/validator" +import { defaultRelations } from "." /** * @oas [get] /store/shipping-options @@ -80,7 +81,7 @@ export default async (req, res) => { } const options = await shippingOptionService.list(query, { - relations: ["requirements"], + relations: defaultRelations, }) const data = await pricingService.setShippingOptionPrices(options) diff --git a/packages/medusa/src/api/routes/store/shipping-options/list-shipping-options.ts b/packages/medusa/src/api/routes/store/shipping-options/list-shipping-options.ts index e000a2eb02a8c..094df7a61088b 100644 --- a/packages/medusa/src/api/routes/store/shipping-options/list-shipping-options.ts +++ b/packages/medusa/src/api/routes/store/shipping-options/list-shipping-options.ts @@ -32,7 +32,7 @@ import ShippingProfileService from "../../../../services/shipping-profile" * content: * application/json: * schema: - * $ref: "#/components/schemas/StoreShippingOptionsListRes" + * $ref: "#/components/schemas/StoreCartShippingOptionsListRes" * "400": * $ref: "#/components/responses/400_error" * "404": diff --git a/packages/medusa/src/api/routes/store/swaps/get-swap-by-cart.ts b/packages/medusa/src/api/routes/store/swaps/get-swap-by-cart.ts index f144606e25293..b8398b9b84d4d 100644 --- a/packages/medusa/src/api/routes/store/swaps/get-swap-by-cart.ts +++ b/packages/medusa/src/api/routes/store/swaps/get-swap-by-cart.ts @@ -1,4 +1,5 @@ import SwapService from "../../../../services/swap" +import { defaultStoreSwapRelations } from "." /** * @oas [get] /store/swaps/{cart_id} @@ -48,7 +49,10 @@ export default async (req, res) => { const swapService: SwapService = req.scope.resolve("swapService") - const swap = await swapService.retrieveByCartId(cart_id) + const swap = await swapService.retrieveByCartId( + cart_id, + defaultStoreSwapRelations + ) res.json({ swap }) } diff --git a/packages/medusa/src/api/routes/store/swaps/index.ts b/packages/medusa/src/api/routes/store/swaps/index.ts index 58b68979ec0c1..2215ef2fc3872 100644 --- a/packages/medusa/src/api/routes/store/swaps/index.ts +++ b/packages/medusa/src/api/routes/store/swaps/index.ts @@ -49,6 +49,21 @@ export const defaultStoreSwapFields: FindConfig["select"] = [ /** * @schema StoreSwapsRes * type: object + * x-expanded-relations: + * field: swap + * relations: + * - additional_items + * - additional_items.variant + * - cart + * - fulfillments + * - order + * - payment + * - return_order + * - return_order.shipping_method + * - shipping_address + * - shipping_methods + * eager: + * - fulfillments.items * required: * - swap * properties: diff --git a/packages/medusa/src/api/routes/store/variants/index.ts b/packages/medusa/src/api/routes/store/variants/index.ts index fddfb0ba7872f..be64fd85b4409 100644 --- a/packages/medusa/src/api/routes/store/variants/index.ts +++ b/packages/medusa/src/api/routes/store/variants/index.ts @@ -1,6 +1,5 @@ import { Router } from "express" - -import { ProductVariant } from "../../../../" +import { PricedVariant } from "../../../../types/pricing" import middlewares from "../../../middlewares" import { extendRequestParams } from "../../../middlewares/publishable-api-key/extend-request-params" import { validateSalesChannelParam } from "../../../middlewares/publishable-api-key/validate-sales-channel-param" @@ -24,6 +23,12 @@ export const defaultStoreVariantRelations = ["prices", "options", "product"] /** * @schema StoreVariantsRes * type: object + * x-expanded-relations: + * field: variant + * relations: + * - prices + * - options + * - product * required: * - variant * properties: @@ -31,12 +36,18 @@ export const defaultStoreVariantRelations = ["prices", "options", "product"] * $ref: "#/components/schemas/PricedVariant" */ export type StoreVariantsRes = { - variant: ProductVariant + variant: PricedVariant } /** * @schema StoreVariantsListRes * type: object + * x-expanded-relations: + * field: variants + * relations: + * - prices + * - options + * - product * required: * - variants * properties: @@ -46,7 +57,7 @@ export type StoreVariantsRes = { * $ref: "#/components/schemas/PricedVariant" */ export type StoreVariantsListRes = { - variants: ProductVariant[] + variants: PricedVariant[] } export * from "./list-variants" diff --git a/packages/medusa/src/types/pricing.ts b/packages/medusa/src/types/pricing.ts index 43084f06cb8b5..9faaba175828f 100644 --- a/packages/medusa/src/types/pricing.ts +++ b/packages/medusa/src/types/pricing.ts @@ -31,6 +31,35 @@ export type ShippingOptionPricing = { tax_amount: number } +/** @schema PricedShippingOption + * title: "Priced Shipping Option" + * type: object + * allOf: + * - $ref: "#/components/schemas/ShippingOption" + * - type: object + * properties: + * price_incl_tax: + * type: number + * description: Price including taxes + * tax_rates: + * type: array + * description: An array of applied tax rates + * items: + * type: object + * properties: + * rate: + * type: number + * description: The tax rate value + * name: + * type: string + * description: The name of the tax rate + * code: + * type: string + * description: The code of the tax rate + * tax_amount: + * type: number + * description: The taxes applied. + */ export type PricedShippingOption = Partial & ShippingOptionPricing