diff --git a/.changeset/shy-students-look.md b/.changeset/shy-students-look.md new file mode 100644 index 0000000000000..a95934dfa065f --- /dev/null +++ b/.changeset/shy-students-look.md @@ -0,0 +1,8 @@ +--- +"@medusajs/orchestration": patch +"@medusajs/link-modules": patch +"@medusajs/pricing": patch +"@medusajs/types": patch +--- + +fix(orchestration,link-modules,pricing,types): fix shippingprofile error outside of core + change link alias name diff --git a/packages/link-modules/src/definitions/product-shipping-profile.ts b/packages/link-modules/src/definitions/product-shipping-profile.ts index 706b6b49709e2..dee5273017833 100644 --- a/packages/link-modules/src/definitions/product-shipping-profile.ts +++ b/packages/link-modules/src/definitions/product-shipping-profile.ts @@ -38,7 +38,6 @@ export const ProductShippingProfile: ModuleJoinerConfig = { }, relationship: { serviceName: LINKS.ProductShippingProfile, - isInternalService: true, primaryKey: "product_id", foreignKey: "id", alias: "shipping_profile", diff --git a/packages/link-modules/src/definitions/product-variant-price-set.ts b/packages/link-modules/src/definitions/product-variant-price-set.ts index f64e23f3939ab..d121ae6eafc7a 100644 --- a/packages/link-modules/src/definitions/product-variant-price-set.ts +++ b/packages/link-modules/src/definitions/product-variant-price-set.ts @@ -43,8 +43,7 @@ export const ProductVariantPriceSet: ModuleJoinerConfig = { serviceName: LINKS.ProductVariantPriceSet, primaryKey: "variant_id", foreignKey: "id", - alias: "prices", - isList: false, + alias: "price", }, }, { diff --git a/packages/modules-sdk/src/remote-query.ts b/packages/modules-sdk/src/remote-query.ts index f0eb0680b1a4b..3a80ed26b6e05 100644 --- a/packages/modules-sdk/src/remote-query.ts +++ b/packages/modules-sdk/src/remote-query.ts @@ -157,7 +157,6 @@ export class RemoteQuery { "skip", "take", "limit", - "order", "offset", "cursor", "sort", diff --git a/packages/orchestration/src/joiner/remote-joiner.ts b/packages/orchestration/src/joiner/remote-joiner.ts index fc6b08a6d9dcb..307811692eca1 100644 --- a/packages/orchestration/src/joiner/remote-joiner.ts +++ b/packages/orchestration/src/joiner/remote-joiner.ts @@ -197,6 +197,16 @@ export class RemoteJoiner { { fieldAlias, relationships }, ] of expandedRelationships) { if (!this.serviceConfigCache.has(serviceName)) { + // If true, the relationship is an internal service from the medusa core + // If modules are being used ouside of the core, we should not be throwing + // errors when the core services are not found in cache. + // TODO: Remove when there are no more "internal" services + const isInternalServicePresent = relationships.some( + (rel) => rel.isInternalService === true + ) + + if (isInternalServicePresent) continue + throw new Error(`Service "${serviceName}" was not found`) } diff --git a/packages/pricing/integration-tests/__tests__/services/pricing-module/price-set.spec.ts b/packages/pricing/integration-tests/__tests__/services/pricing-module/price-set.spec.ts index 9295122bac022..0ef870fc35559 100644 --- a/packages/pricing/integration-tests/__tests__/services/pricing-module/price-set.spec.ts +++ b/packages/pricing/integration-tests/__tests__/services/pricing-module/price-set.spec.ts @@ -72,7 +72,7 @@ describe("PricingModule Service - PriceSet", () => { describe("calculatePrices", () => { it("retrieves the calculated prices when no context is set", async () => { const priceSetsResult = await service.calculatePrices( - ["price-set-1", "price-set-2"], + { id: ["price-set-1", "price-set-2"] }, {} ) @@ -96,9 +96,11 @@ describe("PricingModule Service - PriceSet", () => { it("retrieves the calculated prices when a context is set", async () => { const priceSetsResult = await service.calculatePrices( - ["price-set-1", "price-set-2"], + { id: ["price-set-1", "price-set-2"] }, { - currency_code: "USD", + context: { + currency_code: "USD", + }, } ) @@ -122,9 +124,9 @@ describe("PricingModule Service - PriceSet", () => { it("retrieves the calculated prices only when id exists in the database", async () => { const priceSetsResult = await service.calculatePrices( - ["price-set-doesnotexist", "price-set-1"], + { id: ["price-set-doesnotexist", "price-set-1"] }, { - currency_code: "USD", + context: { currency_code: "USD" }, } ) diff --git a/packages/pricing/src/services/pricing-module.ts b/packages/pricing/src/services/pricing-module.ts index 3bf80428cbafa..da4fdd3ceeb83 100644 --- a/packages/pricing/src/services/pricing-module.ts +++ b/packages/pricing/src/services/pricing-module.ts @@ -4,6 +4,8 @@ import { FindConfig, InternalModuleDeclaration, ModuleJoinerConfig, + PricingContext, + PricingFilters, PricingTypes, } from "@medusajs/types" import { Currency, MoneyAmount, PriceSet } from "@models" @@ -25,10 +27,6 @@ type InjectedDependencies = { priceSetService: PriceSetService } -type PricingContext = { - currency_code?: string -} - export default class PricingModuleService< TPriceSet extends PriceSet = PriceSet, TMoneyAmount extends MoneyAmount = MoneyAmount, @@ -61,14 +59,15 @@ export default class PricingModuleService< @InjectManager("baseRepository_") async calculatePrices( - priceSetIds: string[], - pricingContext: PricingContext, + pricingFilters: PricingFilters, + pricingContext: PricingContext = { context: {} }, @MedusaContext() sharedContext: Context = {} ): Promise { // Keeping this whole logic raw in here for now as they will undergo // some changes, will abstract them out once we have a final version + const context = pricingContext.context || {} const priceSetFilters: PricingTypes.FilterablePriceSetProps = { - id: priceSetIds, + id: pricingFilters.id, } const priceSets = await this.list( @@ -95,8 +94,7 @@ export default class PricingModuleService< // When no price is set, return null values for all cases const selectedMoneyAmount = priceSet.money_amounts?.find( (ma) => - pricingContext.currency_code && - ma.currency_code === pricingContext.currency_code + context.currency_code && ma.currency_code === context.currency_code ) return { diff --git a/packages/types/src/joiner/index.ts b/packages/types/src/joiner/index.ts index 479ec690ab978..40f6583d97874 100644 --- a/packages/types/src/joiner/index.ts +++ b/packages/types/src/joiner/index.ts @@ -3,6 +3,11 @@ export type JoinerRelationship = { foreignKey: string primaryKey: string serviceName: string + /** + * If true, the relationship is an internal service from the medusa core + * TODO: Remove when there are no more "internal" services + */ + isInternalService?: boolean /** * In an inverted relationship the foreign key is on the other service and the primary key is on the current service */ diff --git a/packages/types/src/pricing/common/price-set.ts b/packages/types/src/pricing/common/price-set.ts index 71d8f87dc3b62..8195b472a5875 100644 --- a/packages/types/src/pricing/common/price-set.ts +++ b/packages/types/src/pricing/common/price-set.ts @@ -2,8 +2,15 @@ import { BaseFilterable } from "../../dal" import { FilterableMoneyAmountProps, MoneyAmountDTO } from "./money-amount" export interface PricingContext { - currency_code?: string + context?: { + currency_code?: string + } } + +export interface PricingFilters { + id: string[] +} + export interface PriceSetDTO { id: string money_amounts?: MoneyAmountDTO[] diff --git a/packages/types/src/pricing/service.ts b/packages/types/src/pricing/service.ts index edab03a3a7897..0f87e40abc6e5 100644 --- a/packages/types/src/pricing/service.ts +++ b/packages/types/src/pricing/service.ts @@ -13,6 +13,7 @@ import { MoneyAmountDTO, PriceSetDTO, PricingContext, + PricingFilters, UpdateCurrencyDTO, UpdateMoneyAmountDTO, UpdatePriceSetDTO, @@ -22,8 +23,8 @@ export interface IPricingModuleService { __joinerConfig(): ModuleJoinerConfig calculatePrices( - priceSetIds: string[], - pricingContext: PricingContext, + filters: PricingFilters, + context?: PricingContext, sharedContext?: Context ): Promise