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
This commit is contained in:
Patrick
2023-03-16 04:08:20 -04:00
committed by GitHub
parent da0787bd11
commit 522e306e2e
31 changed files with 448 additions and 52 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/client-types": patch
"@medusajs/medusa": patch
---
feat(oas): declare x-expanded-relations - Store

View File

@@ -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<String>,
"deleted_at": null,
"email": "test@testesen.dk",
"first_name": "test",
"has_account": true,
"id": Any<String>,
"last_name": "testesen",
"metadata": null,
"orders": Array [],
"phone": null,
"updated_at": Any<String>,
}
`;

View File

@@ -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", () => {

View File

@@ -440,7 +440,7 @@ describe("/store/payment-collections", () => {
})
)
expect(response.status).toEqual(207)
expect(response.status).toEqual(200)
})
})
})

View File

@@ -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 })

View File

@@ -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 })

View File

@@ -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:

View File

@@ -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

View File

@@ -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",

View File

@@ -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:

View File

@@ -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<Customer, "password_hash">
}
/**
* @schema StoreCustomersResetPasswordRes
* type: object
* required:
* - customer
* properties:
* customer:
* $ref: "#/components/schemas/Customer"
*/
export type StoreCustomersResetPasswordRes = {
customer: Omit<Customer, "password_hash">
}
/**
* @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

View File

@@ -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":

View File

@@ -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:

View File

@@ -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"

View File

@@ -72,7 +72,7 @@ export default async (req, res) => {
req.request_context
)
res.status(207).json({ payment_collection })
res.status(200).json({ payment_collection })
}
/**

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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 })

View File

@@ -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:

View File

@@ -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,
}

View File

@@ -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:

View File

@@ -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) {

View File

@@ -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:

View File

@@ -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"

View File

@@ -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)

View File

@@ -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":

View File

@@ -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 })
}

View File

@@ -49,6 +49,21 @@ export const defaultStoreSwapFields: FindConfig<Swap>["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:

View File

@@ -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"

View File

@@ -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<ShippingOption> &
ShippingOptionPricing