diff --git a/integration-tests/modules/__tests__/customer/admin/create-customer-addresses.ts b/integration-tests/modules/__tests__/customer/admin/create-customer-addresses.ts index 2238e3491e93b..0f689c83cc11c 100644 --- a/integration-tests/modules/__tests__/customer/admin/create-customer-addresses.ts +++ b/integration-tests/modules/__tests__/customer/admin/create-customer-addresses.ts @@ -91,7 +91,7 @@ medusaIntegrationTestRunner({ expect(response.status).toEqual(200) - const [address] = await customerModuleService.listAddresses({ + const [address] = await customerModuleService.listCustomerAddresses({ customer_id: customer.id, is_default_shipping: true, }) @@ -126,7 +126,7 @@ medusaIntegrationTestRunner({ expect(response.status).toEqual(200) - const [address] = await customerModuleService.listAddresses({ + const [address] = await customerModuleService.listCustomerAddresses({ customer_id: customer.id, is_default_billing: true, }) diff --git a/integration-tests/modules/__tests__/customer/admin/delete-customer-address.spec.ts b/integration-tests/modules/__tests__/customer/admin/delete-customer-address.spec.ts index 3c8d27b10a916..c45a99a8224bd 100644 --- a/integration-tests/modules/__tests__/customer/admin/delete-customer-address.spec.ts +++ b/integration-tests/modules/__tests__/customer/admin/delete-customer-address.spec.ts @@ -34,7 +34,7 @@ medusaIntegrationTestRunner({ last_name: "Doe", }) - const address = await customerModuleService.createAddresses({ + const address = await customerModuleService.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", diff --git a/integration-tests/modules/__tests__/customer/admin/update-customer-address.spec.ts b/integration-tests/modules/__tests__/customer/admin/update-customer-address.spec.ts index 32bfbaf8fbb24..1b55ce5e2944c 100644 --- a/integration-tests/modules/__tests__/customer/admin/update-customer-address.spec.ts +++ b/integration-tests/modules/__tests__/customer/admin/update-customer-address.spec.ts @@ -34,7 +34,7 @@ medusaIntegrationTestRunner({ last_name: "Doe", }) - const address = await customerModuleService.createAddresses({ + const address = await customerModuleService.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -66,21 +66,23 @@ medusaIntegrationTestRunner({ first_name: "John", last_name: "Doe", }) - const [, address] = await customerModuleService.createAddresses([ - { - customer_id: customer.id, - first_name: "John", - last_name: "Doe", - address_1: "Test street 1", - is_default_shipping: true, - }, - { - customer_id: customer.id, - first_name: "John", - last_name: "Doe", - address_1: "Test street 2", - }, - ]) + const [, address] = await customerModuleService.createCustomerAddresses( + [ + { + customer_id: customer.id, + first_name: "John", + last_name: "Doe", + address_1: "Test street 1", + is_default_shipping: true, + }, + { + customer_id: customer.id, + first_name: "John", + last_name: "Doe", + address_1: "Test street 2", + }, + ] + ) const response = await api.post( `/admin/customers/${customer.id}/addresses/${address.id}`, @@ -93,10 +95,11 @@ medusaIntegrationTestRunner({ expect(response.status).toEqual(200) - const [defaultAddress] = await customerModuleService.listAddresses({ - customer_id: customer.id, - is_default_shipping: true, - }) + const [defaultAddress] = + await customerModuleService.listCustomerAddresses({ + customer_id: customer.id, + is_default_shipping: true, + }) expect(defaultAddress.first_name).toEqual("jane") expect(defaultAddress.address_1).toEqual("Test street 2") @@ -108,21 +111,23 @@ medusaIntegrationTestRunner({ first_name: "John", last_name: "Doe", }) - const [, address] = await customerModuleService.createAddresses([ - { - customer_id: customer.id, - first_name: "John", - last_name: "Doe", - address_1: "Test street 1", - is_default_billing: true, - }, - { - customer_id: customer.id, - first_name: "John", - last_name: "Doe", - address_1: "Test street 2", - }, - ]) + const [, address] = await customerModuleService.createCustomerAddresses( + [ + { + customer_id: customer.id, + first_name: "John", + last_name: "Doe", + address_1: "Test street 1", + is_default_billing: true, + }, + { + customer_id: customer.id, + first_name: "John", + last_name: "Doe", + address_1: "Test street 2", + }, + ] + ) const response = await api.post( `/admin/customers/${customer.id}/addresses/${address.id}`, @@ -135,10 +140,11 @@ medusaIntegrationTestRunner({ expect(response.status).toEqual(200) - const [defaultAddress] = await customerModuleService.listAddresses({ - customer_id: customer.id, - is_default_billing: true, - }) + const [defaultAddress] = + await customerModuleService.listCustomerAddresses({ + customer_id: customer.id, + is_default_billing: true, + }) expect(defaultAddress.first_name).toEqual("jane") expect(defaultAddress.address_1).toEqual("Test street 2") diff --git a/integration-tests/modules/__tests__/customer/store/delete-customer-address.spec.ts b/integration-tests/modules/__tests__/customer/store/delete-customer-address.spec.ts index d80d9c2c08122..fb7734c2a5c0b 100644 --- a/integration-tests/modules/__tests__/customer/store/delete-customer-address.spec.ts +++ b/integration-tests/modules/__tests__/customer/store/delete-customer-address.spec.ts @@ -26,7 +26,7 @@ medusaIntegrationTestRunner({ appContainer ) - const address = await customerModuleService.createAddresses({ + const address = await customerModuleService.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -57,7 +57,7 @@ medusaIntegrationTestRunner({ first_name: "Jane", last_name: "Doe", }) - const address = await customerModuleService.createAddresses({ + const address = await customerModuleService.createCustomerAddresses({ customer_id: otherCustomer.id, first_name: "John", last_name: "Doe", diff --git a/integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts b/integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts index 741d2e12af4e3..6c110f7338156 100644 --- a/integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts +++ b/integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts @@ -26,7 +26,7 @@ medusaIntegrationTestRunner({ appContainer ) - await customerModuleService.createAddresses([ + await customerModuleService.createCustomerAddresses([ { first_name: "Test", last_name: "Test", diff --git a/integration-tests/modules/__tests__/customer/store/update-customer-address.spec.ts b/integration-tests/modules/__tests__/customer/store/update-customer-address.spec.ts index 62e3ade3792cd..b72970a51104e 100644 --- a/integration-tests/modules/__tests__/customer/store/update-customer-address.spec.ts +++ b/integration-tests/modules/__tests__/customer/store/update-customer-address.spec.ts @@ -26,7 +26,7 @@ medusaIntegrationTestRunner({ appContainer ) - const address = await customerModuleService.createAddresses({ + const address = await customerModuleService.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -59,7 +59,7 @@ medusaIntegrationTestRunner({ last_name: "Doe", }) - const address = await customerModuleService.createAddresses({ + const address = await customerModuleService.createCustomerAddresses({ customer_id: otherCustomer.id, first_name: "John", last_name: "Doe", diff --git a/integration-tests/modules/__tests__/link-modules/define-link.spec.ts b/integration-tests/modules/__tests__/link-modules/define-link.spec.ts index 36f8bb2c88741..a42a96c34c303 100644 --- a/integration-tests/modules/__tests__/link-modules/define-link.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/define-link.spec.ts @@ -2,8 +2,8 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils" import CurrencyModule from "@medusajs/currency" import { MedusaModule } from "@medusajs/modules-sdk" -import RegionModule from "@medusajs/region" import ProductModule from "@medusajs/product" +import RegionModule from "@medusajs/region" import { defineLink } from "@medusajs/utils" jest.setTimeout(50000) @@ -43,6 +43,7 @@ medusaIntegrationTestRunner({ relationships: [ { serviceName: "currency", + entity: "Currency", primaryKey: "code", foreignKey: "currency_code", alias: "currency", @@ -53,6 +54,7 @@ medusaIntegrationTestRunner({ }, { serviceName: "region", + entity: "Region", primaryKey: "id", foreignKey: "region_id", alias: "region", @@ -69,6 +71,7 @@ medusaIntegrationTestRunner({ region: { path: "region_link.region", isList: false, + forwardArgumentsOnPath: ["region_link.region"], }, }, relationship: { @@ -85,6 +88,7 @@ medusaIntegrationTestRunner({ currency: { path: "currency_link.currency", isList: false, + forwardArgumentsOnPath: ["currency_link.currency"], }, }, relationship: { @@ -134,6 +138,7 @@ medusaIntegrationTestRunner({ relationships: [ { serviceName: "productService", + entity: "ProductVariant", primaryKey: "id", foreignKey: "product_variant_id", alias: "product_variant", @@ -144,6 +149,7 @@ medusaIntegrationTestRunner({ }, { serviceName: "region", + entity: "Region", primaryKey: "id", foreignKey: "region_id", alias: "region", @@ -160,6 +166,7 @@ medusaIntegrationTestRunner({ region: { path: "region_link.region", isList: false, + forwardArgumentsOnPath: ["region_link.region"], }, }, relationship: { @@ -176,6 +183,9 @@ medusaIntegrationTestRunner({ product_variant: { path: "product_variant_link.product_variant", isList: false, + forwardArgumentsOnPath: [ + "product_variant_link.product_variant", + ], }, }, relationship: { @@ -228,6 +238,7 @@ medusaIntegrationTestRunner({ relationships: [ { serviceName: "currency", + entity: "Currency", primaryKey: "code", foreignKey: "currency_code", alias: "currency", @@ -238,6 +249,7 @@ medusaIntegrationTestRunner({ }, { serviceName: "region", + entity: "Region", primaryKey: "id", foreignKey: "region_id", alias: "region", @@ -254,6 +266,7 @@ medusaIntegrationTestRunner({ region: { path: "region_link.region", isList: false, + forwardArgumentsOnPath: ["region_link.region"], }, }, relationship: { @@ -270,6 +283,7 @@ medusaIntegrationTestRunner({ currency: { path: "currency_link.currency", isList: false, + forwardArgumentsOnPath: ["currency_link.currency"], }, }, relationship: { @@ -318,6 +332,7 @@ medusaIntegrationTestRunner({ relationships: [ { serviceName: "currency", + entity: "Currency", primaryKey: "code", foreignKey: "currency_code", alias: "currency", @@ -328,6 +343,7 @@ medusaIntegrationTestRunner({ }, { serviceName: "region", + entity: "Region", primaryKey: "id", foreignKey: "region_id", alias: "region", @@ -344,6 +360,7 @@ medusaIntegrationTestRunner({ regions: { path: "region_link.region", isList: true, + forwardArgumentsOnPath: ["region_link.region"], }, }, relationship: { @@ -360,6 +377,7 @@ medusaIntegrationTestRunner({ currency: { path: "currency_link.currency", isList: false, + forwardArgumentsOnPath: ["currency_link.currency"], }, }, relationship: { diff --git a/packages/core/core-flows/src/customer/steps/create-addresses.ts b/packages/core/core-flows/src/customer/steps/create-addresses.ts index ef8ebae0604be..ac28b85c8a47f 100644 --- a/packages/core/core-flows/src/customer/steps/create-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/create-addresses.ts @@ -16,7 +16,7 @@ export const createCustomerAddressesStep = createStep( ModuleRegistrationName.CUSTOMER ) - const addresses = await service.createAddresses(data) + const addresses = await service.createCustomerAddresses(data) return new StepResponse( addresses, @@ -32,6 +32,6 @@ export const createCustomerAddressesStep = createStep( ModuleRegistrationName.CUSTOMER ) - await service.deleteAddresses(ids) + await service.deleteCustomerAddresses(ids) } ) diff --git a/packages/core/core-flows/src/customer/steps/delete-addresses.ts b/packages/core/core-flows/src/customer/steps/delete-addresses.ts index 0568ce2effedf..4e64be40b7706 100644 --- a/packages/core/core-flows/src/customer/steps/delete-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/delete-addresses.ts @@ -13,10 +13,10 @@ export const deleteCustomerAddressesStep = createStep( ModuleRegistrationName.CUSTOMER ) - const existing = await service.listAddresses({ + const existing = await service.listCustomerAddresses({ id: ids, }) - await service.deleteAddresses(ids) + await service.deleteCustomerAddresses(ids) return new StepResponse(void 0, existing) }, @@ -29,6 +29,6 @@ export const deleteCustomerAddressesStep = createStep( ModuleRegistrationName.CUSTOMER ) - await service.createAddresses(prevAddresses) + await service.createCustomerAddresses(prevAddresses) } ) diff --git a/packages/core/core-flows/src/customer/steps/maybe-unset-default-billing-addresses.ts b/packages/core/core-flows/src/customer/steps/maybe-unset-default-billing-addresses.ts index d7e20f2829796..55b6b0aa6f884 100644 --- a/packages/core/core-flows/src/customer/steps/maybe-unset-default-billing-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/maybe-unset-default-billing-addresses.ts @@ -55,7 +55,7 @@ export const maybeUnsetDefaultBillingAddressesStep = createStep( ModuleRegistrationName.CUSTOMER ) - await customerModuleService.updateAddresses( + await customerModuleService.updateCustomerAddresses( { id: addressesToSet }, { is_default_billing: true } ) diff --git a/packages/core/core-flows/src/customer/steps/maybe-unset-default-shipping-addresses.ts b/packages/core/core-flows/src/customer/steps/maybe-unset-default-shipping-addresses.ts index 3d967f04cad0f..76722bfec0aef 100644 --- a/packages/core/core-flows/src/customer/steps/maybe-unset-default-shipping-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/maybe-unset-default-shipping-addresses.ts @@ -54,7 +54,7 @@ export const maybeUnsetDefaultShippingAddressesStep = createStep( ModuleRegistrationName.CUSTOMER ) - await customerModuleService.updateAddresses( + await customerModuleService.updateCustomerAddresses( { id: addressesToSet }, { is_default_shipping: true } ) diff --git a/packages/core/core-flows/src/customer/steps/update-addresses.ts b/packages/core/core-flows/src/customer/steps/update-addresses.ts index a89f6efedd538..c6360815dcb83 100644 --- a/packages/core/core-flows/src/customer/steps/update-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/update-addresses.ts @@ -29,12 +29,12 @@ export const updateCustomerAddressesStep = createStep( const { selects, relations } = getSelectsAndRelationsFromObjectArray([ data.update, ]) - const prevCustomers = await service.listAddresses(data.selector, { + const prevCustomers = await service.listCustomerAddresses(data.selector, { select: selects, relations, }) - const customerAddresses = await service.updateAddresses( + const customerAddresses = await service.updateCustomerAddresses( data.selector, data.update ) @@ -51,7 +51,9 @@ export const updateCustomerAddressesStep = createStep( ) await promiseAll( - prevCustomerAddresses.map((c) => service.updateAddresses(c.id, { ...c })) + prevCustomerAddresses.map((c) => + service.updateCustomerAddresses(c.id, { ...c }) + ) ) } ) diff --git a/packages/core/core-flows/src/customer/steps/utils/unset-address-for-create.ts b/packages/core/core-flows/src/customer/steps/utils/unset-address-for-create.ts index 870e67a7a416b..bff27fb1eaec4 100644 --- a/packages/core/core-flows/src/customer/steps/utils/unset-address-for-create.ts +++ b/packages/core/core-flows/src/customer/steps/utils/unset-address-for-create.ts @@ -16,12 +16,12 @@ export const unsetForCreate = async ( return acc }, []) - const customerDefaultAddresses = await customerService.listAddresses({ + const customerDefaultAddresses = await customerService.listCustomerAddresses({ customer_id: customerIds, [field]: true, }) - await customerService.updateAddresses( + await customerService.updateCustomerAddresses( { customer_id: customerIds, [field]: true }, { [field]: false } ) diff --git a/packages/core/core-flows/src/customer/steps/utils/unset-address-for-update.ts b/packages/core/core-flows/src/customer/steps/utils/unset-address-for-update.ts index 3fd072fb98390..e49cdbe6c83b5 100644 --- a/packages/core/core-flows/src/customer/steps/utils/unset-address-for-update.ts +++ b/packages/core/core-flows/src/customer/steps/utils/unset-address-for-update.ts @@ -1,7 +1,7 @@ import { - UpdateCustomerAddressDTO, FilterableCustomerAddressProps, ICustomerModuleService, + UpdateCustomerAddressDTO, } from "@medusajs/types" import { StepResponse } from "@medusajs/workflows-sdk" @@ -17,18 +17,21 @@ export const unsetForUpdate = async ( return new StepResponse(void 0) } - const affectedCustomers = await customerService.listAddresses(data.selector, { - select: ["id", "customer_id"], - }) + const affectedCustomers = await customerService.listCustomerAddresses( + data.selector, + { + select: ["id", "customer_id"], + } + ) const customerIds = affectedCustomers.map((address) => address.customer_id) - const customerDefaultAddresses = await customerService.listAddresses({ + const customerDefaultAddresses = await customerService.listCustomerAddresses({ customer_id: customerIds, [field]: true, }) - await customerService.updateAddresses( + await customerService.updateCustomerAddresses( { customer_id: customerIds, [field]: true }, { [field]: false } ) diff --git a/packages/core/modules-sdk/src/loaders/utils/__fixtures__/module-with-joiner-config/services/module-service.ts b/packages/core/modules-sdk/src/loaders/utils/__fixtures__/module-with-joiner-config/services/module-service.ts index 3cdc974588f08..e56b4d88a64c5 100644 --- a/packages/core/modules-sdk/src/loaders/utils/__fixtures__/module-with-joiner-config/services/module-service.ts +++ b/packages/core/modules-sdk/src/loaders/utils/__fixtures__/module-with-joiner-config/services/module-service.ts @@ -7,9 +7,7 @@ export class ModuleService implements IModuleService { alias: [ { name: ["custom_name"], - args: { - entity: "Custom", - }, + entity: "Custom", }, ], }) diff --git a/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts b/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts index 2648d51c33ba4..70098dc7afd50 100644 --- a/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts +++ b/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts @@ -75,15 +75,15 @@ describe("load internal - load resources", () => { alias: [ { name: ["dml_entity", "dml_entities"], + entity: "DmlEntity", args: { - entity: "DmlEntity", methodSuffix: "DmlEntities", }, }, { name: ["entity_model", "entity_models"], + entity: "EntityModel", args: { - entity: "EntityModel", methodSuffix: "EntityModels", }, }, @@ -156,15 +156,15 @@ describe("load internal - load resources", () => { alias: [ { name: ["entity_model", "entity_models"], + entity: "EntityModel", args: { - entity: "EntityModel", methodSuffix: "EntityModels", }, }, { name: ["dml_entity", "dml_entities"], + entity: "DmlEntity", args: { - entity: "DmlEntity", methodSuffix: "DmlEntities", }, }, @@ -237,15 +237,15 @@ describe("load internal - load resources", () => { alias: [ { name: ["entity2", "entity2s"], + entity: "Entity2", args: { - entity: "Entity2", methodSuffix: "Entity2s", }, }, { name: ["entity_model", "entity_models"], + entity: "EntityModel", args: { - entity: "EntityModel", methodSuffix: "EntityModels", }, }, @@ -310,8 +310,8 @@ describe("load internal - load resources", () => { alias: [ { name: ["custom_name"], + entity: "Custom", args: { - entity: "Custom", methodSuffix: "Customs", }, }, diff --git a/packages/core/orchestration/src/joiner/remote-joiner.ts b/packages/core/orchestration/src/joiner/remote-joiner.ts index 530875b3684b9..faf34a45c6fe1 100644 --- a/packages/core/orchestration/src/joiner/remote-joiner.ts +++ b/packages/core/orchestration/src/joiner/remote-joiner.ts @@ -206,6 +206,7 @@ export class RemoteJoiner { for (const name of alias.name) { service_.alias.push({ name, + entity: alias.entity, args: alias.args, }) } @@ -234,16 +235,13 @@ export class RemoteJoiner { service_.relationships?.set(alias.name as string, { alias: alias.name as string, + entity: alias.entity, foreignKey: alias.name + "_id", primaryKey: "id", serviceName: service_.serviceName!, args, }) - this.cacheServiceConfig( - serviceConfigs, - undefined, - alias.name as string - ) + this.cacheServiceConfig(serviceConfigs, undefined, alias) } this.cacheServiceConfig(serviceConfigs, service_.serviceName) @@ -313,21 +311,23 @@ export class RemoteJoiner { private cacheServiceConfig( serviceConfigs, serviceName?: string, - serviceAlias?: string + serviceAlias?: JoinerServiceConfigAlias ): void { if (serviceAlias) { - const name = `alias_${serviceAlias}` + const name = `alias_${serviceAlias.name}` if (!this.serviceConfigCache.has(name)) { let aliasConfig: JoinerServiceConfigAlias | undefined const config = serviceConfigs.find((conf) => { const aliases = conf.alias as JoinerServiceConfigAlias[] - const hasArgs = aliases?.find((alias) => alias.name === serviceAlias) + const hasArgs = aliases?.find( + (alias) => alias.name === serviceAlias.name + ) aliasConfig = hasArgs return hasArgs }) if (config) { - const serviceConfig = { ...config } + const serviceConfig = { ...config, entity: serviceAlias.entity } if (aliasConfig) { serviceConfig.args = { ...config?.args, ...aliasConfig?.args } } @@ -450,7 +450,7 @@ export class RemoteJoiner { if (notFound.size > 0) { const entityName = - expand.serviceConfig.args?.entity ?? + expand.serviceConfig.entity ?? expand.serviceConfig.args?.methodSuffix ?? expand.serviceConfig.serviceName diff --git a/packages/core/types/src/customer/service.ts b/packages/core/types/src/customer/service.ts index fb87afeb7ff77..b978a6bb7fd58 100644 --- a/packages/core/types/src/customer/service.ts +++ b/packages/core/types/src/customer/service.ts @@ -491,7 +491,7 @@ export interface ICustomerModuleService extends IModuleService { * @returns {Promise} The list of created addresses. * * @example - * const addresses = await customerModuleService.createAddresses([ + * const addresses = await customerModuleService.createCustomerAddresses([ * { * customer_id: "cus_123", * address_name: "Home", @@ -501,7 +501,7 @@ export interface ICustomerModuleService extends IModuleService { * }, * ]) */ - createAddresses( + createCustomerAddresses( addresses: CreateCustomerAddressDTO[], sharedContext?: Context ): Promise @@ -514,7 +514,7 @@ export interface ICustomerModuleService extends IModuleService { * @returns {Promise} The created address. * * @example - * const address = await customerModuleService.createAddresses({ + * const address = await customerModuleService.createCustomerAddresses({ * customer_id: "cus_123", * address_name: "Home", * address_1: "432 Stierlin Rd", @@ -522,7 +522,7 @@ export interface ICustomerModuleService extends IModuleService { * country_code: "us", * }) */ - createAddresses( + createCustomerAddresses( address: CreateCustomerAddressDTO, sharedContext?: Context ): Promise @@ -536,7 +536,7 @@ export interface ICustomerModuleService extends IModuleService { * @returns {Promise} The updated address. * * @example - * const address = await customerModuleService.updateAddresses( + * const address = await customerModuleService.updateCustomerAddresses( * "cuaddr_123", * { * first_name: "John", @@ -544,7 +544,7 @@ export interface ICustomerModuleService extends IModuleService { * } * ) */ - updateAddresses( + updateCustomerAddresses( addressId: string, data: UpdateCustomerAddressDTO, sharedContext?: Context @@ -559,7 +559,7 @@ export interface ICustomerModuleService extends IModuleService { * @returns {Promise} The updated addresses. * * @example - * const addresses = await customerModuleService.updateAddresses( + * const addresses = await customerModuleService.updateCustomerAddresses( * ["cuaddr_123", "cuaddr_321"], * { * first_name: "John", @@ -567,7 +567,7 @@ export interface ICustomerModuleService extends IModuleService { * } * ) */ - updateAddresses( + updateCustomerAddresses( addressIds: string[], data: UpdateCustomerAddressDTO, sharedContext?: Context @@ -582,14 +582,14 @@ export interface ICustomerModuleService extends IModuleService { * @returns {Promise} The updated addresses. * * @example - * const addresses = await customerModuleService.updateAddresses( + * const addresses = await customerModuleService.updateCustomerAddresses( * { first_name: "John" }, * { * last_name: "Smith", * } * ) */ - updateAddresses( + updateCustomerAddresses( selector: FilterableCustomerAddressProps, data: UpdateCustomerAddressDTO, sharedContext?: Context @@ -603,9 +603,12 @@ export interface ICustomerModuleService extends IModuleService { * @returns {Promise} Resolves when the address is deleted successfully. * * @example - * await customerModuleService.deleteAddresses("cuaddr_123") + * await customerModuleService.deleteCustomerAddresses("cuaddr_123") */ - deleteAddresses(addressId: string, sharedContext?: Context): Promise + deleteCustomerAddresses( + addressId: string, + sharedContext?: Context + ): Promise /** * This method deletes addresses by their IDs. @@ -615,12 +618,15 @@ export interface ICustomerModuleService extends IModuleService { * @returns {Promise} Resolves when the addresses are deleted successfully. * * @example - * await customerModuleService.deleteAddresses([ + * await customerModuleService.deleteCustomerAddresses([ * "cuaddr_123", * "cuaddr_321", * ]) */ - deleteAddresses(addressIds: string[], sharedContext?: Context): Promise + deleteCustomerAddresses( + addressIds: string[], + sharedContext?: Context + ): Promise /** * This method deletes addresses matching the specified filters. @@ -630,12 +636,12 @@ export interface ICustomerModuleService extends IModuleService { * @returns {Promise} Resolves when the addresses are deleted successfully. * * @example - * await customerModuleService.deleteAddresses({ + * await customerModuleService.deleteCustomerAddresses({ * first_name: "John", * last_name: "Smith", * }) */ - deleteAddresses( + deleteCustomerAddresses( selector: FilterableCustomerAddressProps, sharedContext?: Context ): Promise @@ -653,7 +659,7 @@ export interface ICustomerModuleService extends IModuleService { * To retrieve a list of addresses using their IDs: * * ```ts - * const addresses = await customerModuleService.listAddresses({ + * const addresses = await customerModuleService.listCustomerAddresses({ * id: ["cuaddr_123", "cuaddr_321"], * }) * ``` @@ -661,7 +667,7 @@ export interface ICustomerModuleService extends IModuleService { * To specify relations that should be retrieved within the addresses: * * ```ts - * const addresses = await customerModuleService.listAddresses( + * const addresses = await customerModuleService.listCustomerAddresses( * { * id: ["cuaddr_123", "cuaddr_321"], * }, @@ -674,7 +680,7 @@ export interface ICustomerModuleService extends IModuleService { * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * const addresses = await customerModuleService.listAddresses( + * const addresses = await customerModuleService.listCustomerAddresses( * { * id: ["cuaddr_123", "cuaddr_321"], * }, @@ -686,7 +692,7 @@ export interface ICustomerModuleService extends IModuleService { * ) * ``` */ - listAddresses( + listCustomerAddresses( filters?: FilterableCustomerAddressProps, config?: FindConfig, sharedContext?: Context @@ -706,7 +712,7 @@ export interface ICustomerModuleService extends IModuleService { * * ```ts * const [addresses, count] = - * await customerModuleService.listAndCountAddresses({ + * await customerModuleService.listAndCountCustomerAddresses({ * id: ["cuaddr_123", "cuaddr_321"], * }) * ``` @@ -715,7 +721,7 @@ export interface ICustomerModuleService extends IModuleService { * * ```ts * const [addresses, count] = - * await customerModuleService.listAndCountAddresses( + * await customerModuleService.listAndCountCustomerAddresses( * { * id: ["cuaddr_123", "cuaddr_321"], * }, @@ -729,7 +735,7 @@ export interface ICustomerModuleService extends IModuleService { * * ```ts * const [addresses, count] = - * await customerModuleService.listAndCountAddresses( + * await customerModuleService.listAndCountCustomerAddresses( * { * id: ["cuaddr_123", "cuaddr_321"], * }, @@ -741,7 +747,7 @@ export interface ICustomerModuleService extends IModuleService { * ) * ``` */ - listAndCountAddresses( + listAndCountCustomerAddresses( filters?: FilterableCustomerAddressProps, config?: FindConfig, sharedContext?: Context diff --git a/packages/core/types/src/joiner/index.ts b/packages/core/types/src/joiner/index.ts index 38bb0e0f2d9e6..17fb19b2d00d3 100644 --- a/packages/core/types/src/joiner/index.ts +++ b/packages/core/types/src/joiner/index.ts @@ -3,6 +3,7 @@ export type JoinerRelationship = { foreignKey: string primaryKey: string serviceName: string + entity?: string /** * In an inverted relationship the foreign key is on the other service and the primary key is on the current service */ @@ -19,6 +20,7 @@ export type JoinerRelationship = { export interface JoinerServiceConfigAlias { name: string | string[] + entity?: string /** * Extra arguments to pass to the remoteFetchData callback */ @@ -96,6 +98,7 @@ export type InternalJoinerServiceConfig = Omit< "relationships" > & { relationships?: Map + entity?: string } export interface RemoteExpandProperty { diff --git a/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts index 9fad50fe16aca..a0cfdd5450ec7 100644 --- a/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts +++ b/packages/core/utils/src/modules-sdk/__tests__/joiner-config-builder.spec.ts @@ -61,57 +61,57 @@ describe("joiner-config-builder", () => { alias: [ { name: ["fulfillment_set", "fulfillment_sets"], + entity: FulfillmentSet.name, args: { - entity: FulfillmentSet.name, methodSuffix: "FulfillmentSets", }, }, { name: ["shipping_option", "shipping_options"], + entity: ShippingOption.name, args: { - entity: ShippingOption.name, methodSuffix: "ShippingOptions", }, }, { name: ["shipping_profile", "shipping_profiles"], + entity: ShippingProfile.name, args: { - entity: ShippingProfile.name, methodSuffix: "ShippingProfiles", }, }, { name: ["fulfillment", "fulfillments"], + entity: Fulfillment.name, args: { - entity: Fulfillment.name, methodSuffix: "Fulfillments", }, }, { name: ["fulfillment_provider", "fulfillment_providers"], + entity: FulfillmentProvider.name, args: { - entity: FulfillmentProvider.name, methodSuffix: "FulfillmentProviders", }, }, { name: ["service_zone", "service_zones"], + entity: ServiceZone.name, args: { - entity: ServiceZone.name, methodSuffix: "ServiceZones", }, }, { name: ["geo_zone", "geo_zones"], + entity: GeoZone.name, args: { - entity: GeoZone.name, methodSuffix: "GeoZones", }, }, { name: ["shipping_option_rule", "shipping_option_rules"], + entity: ShippingOptionRule.name, args: { - entity: ShippingOptionRule.name, methodSuffix: "ShippingOptionRules", }, }, @@ -124,8 +124,8 @@ describe("joiner-config-builder", () => { alias: [ { name: ["custom", "customs"], + entity: "Custom", args: { - entity: "Custom", methodSuffix: "Customs", }, }, @@ -140,8 +140,8 @@ describe("joiner-config-builder", () => { alias: [ { name: ["custom", "customs"], + entity: "Custom", args: { - entity: "Custom", methodSuffix: "Customs", }, }, @@ -164,8 +164,8 @@ describe("joiner-config-builder", () => { alias: [ { name: ["custom", "customs"], + entity: "Custom", args: { - entity: "Custom", methodSuffix: "Customs", }, }, @@ -189,64 +189,64 @@ describe("joiner-config-builder", () => { alias: [ { name: ["custom", "customs"], + entity: "Custom", args: { - entity: "Custom", methodSuffix: "Customs", }, }, { name: ["fulfillment_set", "fulfillment_sets"], + entity: FulfillmentSet.name, args: { - entity: FulfillmentSet.name, methodSuffix: "FulfillmentSets", }, }, { name: ["shipping_option", "shipping_options"], + entity: ShippingOption.name, args: { - entity: ShippingOption.name, methodSuffix: "ShippingOptions", }, }, { name: ["shipping_profile", "shipping_profiles"], + entity: ShippingProfile.name, args: { - entity: ShippingProfile.name, methodSuffix: "ShippingProfiles", }, }, { name: ["fulfillment", "fulfillments"], + entity: Fulfillment.name, args: { - entity: Fulfillment.name, methodSuffix: "Fulfillments", }, }, { name: ["fulfillment_provider", "fulfillment_providers"], + entity: FulfillmentProvider.name, args: { - entity: FulfillmentProvider.name, methodSuffix: "FulfillmentProviders", }, }, { name: ["service_zone", "service_zones"], + entity: ServiceZone.name, args: { - entity: ServiceZone.name, methodSuffix: "ServiceZones", }, }, { name: ["geo_zone", "geo_zones"], + entity: GeoZone.name, args: { - entity: GeoZone.name, methodSuffix: "GeoZones", }, }, { name: ["shipping_option_rule", "shipping_option_rules"], + entity: ShippingOptionRule.name, args: { - entity: ShippingOptionRule.name, methodSuffix: "ShippingOptionRules", }, }, @@ -259,9 +259,8 @@ describe("joiner-config-builder", () => { alias: [ { name: ["custom", "customs"], - args: { - entity: "Custom", - }, + entity: "Custom", + args: {}, }, ], }) @@ -274,8 +273,8 @@ describe("joiner-config-builder", () => { alias: [ { name: ["custom", "customs"], + entity: "Custom", args: { - entity: "Custom", methodSuffix: "Customs", }, }, @@ -283,14 +282,14 @@ describe("joiner-config-builder", () => { }) }) - it("should return a full joiner configuration with custom aliases overriding defaults", () => { + it.only("should return a full joiner configuration with custom aliases overriding defaults", () => { const joinerConfig = defineJoinerConfig(Modules.FULFILLMENT, { models: [FulfillmentSet], alias: [ { name: ["fulfillment_set", "fulfillment_sets"], + entity: "FulfillmentSet", args: { - entity: "FulfillmentSet", methodSuffix: "fulfillmentSetCustom", }, }, @@ -307,8 +306,8 @@ describe("joiner-config-builder", () => { alias: [ { name: ["fulfillment_set", "fulfillment_sets"], + entity: "FulfillmentSet", args: { - entity: "FulfillmentSet", methodSuffix: "fulfillmentSetCustom", }, }, @@ -349,57 +348,57 @@ describe("joiner-config-builder", () => { alias: [ { name: ["fulfillment_set", "fulfillment_sets"], + entity: FulfillmentSet.name, args: { - entity: FulfillmentSet.name, methodSuffix: "FulfillmentSets", }, }, { name: ["shipping_option", "shipping_options"], + entity: ShippingOption.name, args: { - entity: ShippingOption.name, methodSuffix: "ShippingOptions", }, }, { name: ["shipping_profile", "shipping_profiles"], + entity: ShippingProfile.name, args: { - entity: ShippingProfile.name, methodSuffix: "ShippingProfiles", }, }, { name: ["fulfillment", "fulfillments"], + entity: Fulfillment.name, args: { - entity: Fulfillment.name, methodSuffix: "Fulfillments", }, }, { name: ["fulfillment_provider", "fulfillment_providers"], + entity: FulfillmentProvider.name, args: { - entity: FulfillmentProvider.name, methodSuffix: "FulfillmentProviders", }, }, { name: ["service_zone", "service_zones"], + entity: ServiceZone.name, args: { - entity: ServiceZone.name, methodSuffix: "ServiceZones", }, }, { name: ["geo_zone", "geo_zones"], + entity: GeoZone.name, args: { - entity: GeoZone.name, methodSuffix: "GeoZones", }, }, { name: ["shipping_option_rule", "shipping_option_rules"], + entity: ShippingOptionRule.name, args: { - entity: ShippingOptionRule.name, methodSuffix: "ShippingOptionRules", }, }, @@ -518,6 +517,7 @@ describe("joiner-config-builder", () => { car: { id: { field: "car", + entity: "Car", linkable: "car_id", primaryKey: "id", serviceName: "myService", @@ -527,6 +527,7 @@ describe("joiner-config-builder", () => { user: { id: { field: "user", + entity: "User", linkable: "user_id", primaryKey: "id", serviceName: "myService", @@ -537,12 +538,14 @@ describe("joiner-config-builder", () => { expect(linkConfig.car.toJSON()).toEqual({ field: "car", + entity: "Car", linkable: "car_id", primaryKey: "id", serviceName: "myService", }) expect(linkConfig.user.toJSON()).toEqual({ field: "user", + entity: "User", linkable: "user_id", primaryKey: "id", serviceName: "myService", @@ -559,6 +562,7 @@ describe("joiner-config-builder", () => { user: { id: { field: "user", + entity: "User", linkable: "user_id", primaryKey: "id", serviceName: "myService", @@ -568,6 +572,7 @@ describe("joiner-config-builder", () => { currency: { code: { field: "currency", + entity: "Currency", linkable: "currency_code", primaryKey: "code", serviceName: "myService", @@ -578,12 +583,14 @@ describe("joiner-config-builder", () => { expect(linkConfig.user.toJSON()).toEqual({ field: "user", + entity: "User", linkable: "user_id", primaryKey: "id", serviceName: "myService", }) expect(linkConfig.currency.toJSON()).toEqual({ field: "currency", + entity: "Currency", linkable: "currency_code", primaryKey: "code", serviceName: "myService", @@ -645,12 +652,14 @@ describe("joiner-config-builder", () => { expect(linkConfig.user.id).toEqual({ serviceName: "myService", field: "user", + entity: "User", linkable: "user_id", primaryKey: "id", }) expect(linkConfig.car.number_plate).toEqual({ serviceName: "myService", field: "car", + entity: "Car", linkable: "car_number_plate", primaryKey: "number_plate", }) @@ -658,12 +667,14 @@ describe("joiner-config-builder", () => { expect(linkConfig.car.toJSON()).toEqual({ serviceName: "myService", field: "car", + entity: "Car", linkable: "car_number_plate", primaryKey: "number_plate", }) expect(linkConfig.user.toJSON()).toEqual({ serviceName: "myService", field: "user", + entity: "User", linkable: "user_id", primaryKey: "id", }) diff --git a/packages/core/utils/src/modules-sdk/define-link.ts b/packages/core/utils/src/modules-sdk/define-link.ts index 0f62495d9563c..68bb8ad36e64c 100644 --- a/packages/core/utils/src/modules-sdk/define-link.ts +++ b/packages/core/utils/src/modules-sdk/define-link.ts @@ -13,6 +13,8 @@ export interface DefineLinkExport { type InputSource = { serviceName: string field: string + entity?: string + alias?: string linkable: string primaryKey: string } @@ -44,7 +46,9 @@ type DefineLinkInputSource = InputSource | InputOptions | CombinedSource type ModuleLinkableKeyConfig = { module: string + entity?: string key: string + field: string isList?: boolean deleteCascade?: boolean primaryKey: string @@ -74,11 +78,13 @@ function prepareServiceConfig(input: DefineLinkInputSource) { serviceConfig = { key: source.linkable, - alias: camelToSnakeCase(source.field), + alias: source.alias ?? camelToSnakeCase(source.field), + field: source.field, primaryKey: source.primaryKey, isList: false, deleteCascade: false, module: source.serviceName, + entity: source.entity, } } else if (isInputOptions(input)) { const source = isToJSON(input.linkable) @@ -87,11 +93,13 @@ function prepareServiceConfig(input: DefineLinkInputSource) { serviceConfig = { key: source.linkable, - alias: camelToSnakeCase(source.field), + alias: source.alias ?? camelToSnakeCase(source.field), + field: source.field, primaryKey: source.primaryKey, isList: input.isList ?? false, deleteCascade: input.deleteCascade ?? false, module: source.serviceName, + entity: source.entity, } } else { throw new Error( @@ -176,7 +184,7 @@ ${serviceBObj.module}: { let aliasAOptions = serviceAObj.alias ?? serviceAAliases.find((a) => { - return a.args?.entity == serviceAKeyEntity + return a.entity == serviceAKeyEntity })?.name let aliasA = aliasAOptions @@ -190,10 +198,11 @@ ${serviceBObj.module}: { ) } + const serviceAObjEntryPoint = camelToSnakeCase(serviceAObj.field) const serviceAMethodSuffix = serviceAAliases.find((serviceAlias) => { return Array.isArray(serviceAlias.name) - ? serviceAlias.name.includes(aliasA) - : serviceAlias.name === aliasA + ? serviceAlias.name.includes(serviceAObjEntryPoint) + : serviceAlias.name === serviceAObjEntryPoint })?.args?.methodSuffix let serviceBAliases = serviceBInfo.alias ?? [] @@ -204,7 +213,7 @@ ${serviceBObj.module}: { let aliasBOptions = serviceBObj.alias ?? serviceBAliases.find((a) => { - return a.args?.entity == serviceBKeyInfo + return a.entity == serviceBKeyInfo })?.name let aliasB = aliasBOptions @@ -218,10 +227,11 @@ ${serviceBObj.module}: { ) } + const serviceBObjEntryPoint = camelToSnakeCase(serviceBObj.field) const serviceBMethodSuffix = serviceBAliases.find((serviceAlias) => { return Array.isArray(serviceAlias.name) - ? serviceAlias.name.includes(aliasB) - : serviceAlias.name === aliasB + ? serviceAlias.name.includes(serviceBObjEntryPoint) + : serviceAlias.name === serviceBObjEntryPoint })?.args?.methodSuffix const moduleAPrimaryKeys = serviceAInfo.primaryKeys ?? [] @@ -290,6 +300,7 @@ ${serviceBObj.module}: { relationships: [ { serviceName: serviceAObj.module, + entity: serviceAObj.entity, primaryKey: serviceAPrimaryKey, foreignKey: serviceAObj.key, alias: aliasA, @@ -300,6 +311,7 @@ ${serviceBObj.module}: { }, { serviceName: serviceBObj.module, + entity: serviceBObj.entity, primaryKey: serviceBPrimaryKey!, foreignKey: serviceBObj.key, alias: aliasB, @@ -316,6 +328,7 @@ ${serviceBObj.module}: { [serviceBObj.isList ? pluralize(aliasB) : aliasB]: { path: aliasB + "_link." + aliasB, isList: serviceBObj.isList, + forwardArgumentsOnPath: [aliasB + "_link." + aliasB], }, }, relationship: { @@ -332,6 +345,7 @@ ${serviceBObj.module}: { [serviceAObj.isList ? pluralize(aliasA) : aliasA]: { path: aliasA + "_link." + aliasA, isList: serviceAObj.isList, + forwardArgumentsOnPath: [aliasA + "_link." + aliasA], }, }, relationship: { diff --git a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts index 8bbc2df64f6c1..9e1ebaa0dc1c8 100644 --- a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts @@ -193,17 +193,17 @@ export function defineJoinerConfig( alias: [ ...[...(alias ?? ([] as any))].map((alias) => ({ name: alias.name, + entity: alias.entity, args: { - entity: alias.args.entity, methodSuffix: - alias.args.methodSuffix ?? - pluralize(upperCaseFirst(alias.args.entity)), + alias.args?.methodSuffix ?? pluralize(upperCaseFirst(alias.entity)), }, })), ...deduplicatedLoadedModels .filter((model) => { return ( - !alias || !alias.some((alias) => alias.args?.entity === model.name) + !alias || + !alias.some((alias) => alias.entity === upperCaseFirst(model.name)) ) }) .map((entity, i) => ({ @@ -211,8 +211,8 @@ export function defineJoinerConfig( `${camelToSnakeCase(entity.name).toLowerCase()}`, `${pluralize(camelToSnakeCase(entity.name).toLowerCase())}`, ], + entity: upperCaseFirst(entity.name), args: { - entity: upperCaseFirst(entity.name), methodSuffix: pluralize(upperCaseFirst(entity.name)), }, })), @@ -378,6 +378,7 @@ export function buildLinkConfigFromModelObjects< primaryKey: property, serviceName, field: lowerCaseFirst(model.name), + entity: upperCaseFirst(model.name), } } } @@ -412,6 +413,7 @@ export function buildLinkConfigFromLinkableKeys< primaryKey: inferredReferenceProperty, serviceName, field: keyName, + entity: upperCaseFirst(modelName), } linkConfig[keyName] ??= { diff --git a/packages/modules/api-key/integration-tests/__tests__/api-key-module-service.spec.ts b/packages/modules/api-key/integration-tests/__tests__/api-key-module-service.spec.ts index 902cd8d9b1ac6..2f8026de060e3 100644 --- a/packages/modules/api-key/integration-tests/__tests__/api-key-module-service.spec.ts +++ b/packages/modules/api-key/integration-tests/__tests__/api-key-module-service.spec.ts @@ -54,12 +54,14 @@ moduleIntegrationTestRunner({ expect(linkable.apiKey).toEqual({ id: { linkable: "api_key_id", + entity: "ApiKey", primaryKey: "id", serviceName: "apiKey", field: "apiKey", }, publishable_key_id: { field: "apiKey", + entity: "ApiKey", linkable: "publishable_key_id", primaryKey: "publishable_key_id", serviceName: "apiKey", diff --git a/packages/modules/auth/integration-tests/__tests__/auth-module-service/index.spec.ts b/packages/modules/auth/integration-tests/__tests__/auth-module-service/index.spec.ts index a3cd5508139e2..972c73794e536 100644 --- a/packages/modules/auth/integration-tests/__tests__/auth-module-service/index.spec.ts +++ b/packages/modules/auth/integration-tests/__tests__/auth-module-service/index.spec.ts @@ -1,7 +1,7 @@ import { IAuthModuleService } from "@medusajs/types" import { Module, Modules } from "@medusajs/utils" import { AuthModuleService } from "@services" -import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils" +import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils" import { resolve } from "path" let moduleOptions = { @@ -52,6 +52,7 @@ moduleIntegrationTestRunner({ expect(linkable.authIdentity).toEqual({ id: { linkable: "auth_identity_id", + entity: "AuthIdentity", primaryKey: "id", serviceName: "auth", field: "authIdentity", @@ -63,6 +64,7 @@ moduleIntegrationTestRunner({ expect(linkable.providerIdentity).toEqual({ id: { linkable: "provider_identity_id", + entity: "ProviderIdentity", primaryKey: "id", serviceName: "auth", field: "providerIdentity", diff --git a/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts b/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts index 13c407af6441e..ab6397261109e 100644 --- a/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts +++ b/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts @@ -34,6 +34,7 @@ moduleIntegrationTestRunner({ cart: { id: { linkable: "cart_id", + entity: "Cart", primaryKey: "id", serviceName: "cart", field: "cart", @@ -42,6 +43,7 @@ moduleIntegrationTestRunner({ address: { id: { linkable: "address_id", + entity: "Address", primaryKey: "id", serviceName: "cart", field: "address", @@ -50,6 +52,7 @@ moduleIntegrationTestRunner({ lineItem: { id: { linkable: "line_item_id", + entity: "LineItem", primaryKey: "id", serviceName: "cart", field: "lineItem", @@ -58,6 +61,7 @@ moduleIntegrationTestRunner({ lineItemAdjustment: { id: { linkable: "line_item_adjustment_id", + entity: "LineItemAdjustment", primaryKey: "id", serviceName: "cart", field: "lineItemAdjustment", @@ -66,6 +70,7 @@ moduleIntegrationTestRunner({ lineItemTaxLine: { id: { linkable: "line_item_tax_line_id", + entity: "LineItemTaxLine", primaryKey: "id", serviceName: "cart", field: "lineItemTaxLine", @@ -74,6 +79,7 @@ moduleIntegrationTestRunner({ shippingMethod: { id: { linkable: "shipping_method_id", + entity: "ShippingMethod", primaryKey: "id", serviceName: "cart", field: "shippingMethod", @@ -82,6 +88,7 @@ moduleIntegrationTestRunner({ shippingMethodAdjustment: { id: { linkable: "shipping_method_adjustment_id", + entity: "ShippingMethodAdjustment", primaryKey: "id", serviceName: "cart", field: "shippingMethodAdjustment", @@ -90,6 +97,7 @@ moduleIntegrationTestRunner({ shippingMethodTaxLine: { id: { linkable: "shipping_method_tax_line_id", + entity: "ShippingMethodTaxLine", primaryKey: "id", serviceName: "cart", field: "shippingMethodTaxLine", diff --git a/packages/modules/currency/integration-tests/__tests__/currency-module-service.spec.ts b/packages/modules/currency/integration-tests/__tests__/currency-module-service.spec.ts index 758ce506fc6d5..b7a6ca8e19227 100644 --- a/packages/modules/currency/integration-tests/__tests__/currency-module-service.spec.ts +++ b/packages/modules/currency/integration-tests/__tests__/currency-module-service.spec.ts @@ -24,6 +24,7 @@ moduleIntegrationTestRunner({ currency: { code: { linkable: "currency_code", + entity: "Currency", primaryKey: "code", serviceName: "currency", field: "currency", diff --git a/packages/modules/customer/integration-tests/__tests__/services/customer-module/index.spec.ts b/packages/modules/customer/integration-tests/__tests__/services/customer-module/index.spec.ts index df5143b62d579..402c5265ae9b7 100644 --- a/packages/modules/customer/integration-tests/__tests__/services/customer-module/index.spec.ts +++ b/packages/modules/customer/integration-tests/__tests__/services/customer-module/index.spec.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { moduleIntegrationTestRunner } from "medusa-test-utils" import { Module, Modules } from "@medusajs/utils" import { CustomerModuleService } from "@services" +import { moduleIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(30000) @@ -15,7 +15,7 @@ moduleIntegrationTestRunner({ }).linkable expect(Object.keys(linkable)).toEqual([ - "address", + "customerAddress", "customerGroupCustomer", "customerGroup", "customer", @@ -26,17 +26,19 @@ moduleIntegrationTestRunner({ }) expect(linkable).toEqual({ - address: { + customerAddress: { id: { - linkable: "address_id", + linkable: "customer_address_id", + entity: "CustomerAddress", primaryKey: "id", serviceName: "customer", - field: "address", + field: "customerAddress", }, }, customerGroupCustomer: { id: { linkable: "customer_group_customer_id", + entity: "CustomerGroupCustomer", primaryKey: "id", serviceName: "customer", field: "customerGroupCustomer", @@ -45,6 +47,7 @@ moduleIntegrationTestRunner({ customerGroup: { id: { linkable: "customer_group_id", + entity: "CustomerGroup", primaryKey: "id", serviceName: "customer", field: "customerGroup", @@ -53,6 +56,7 @@ moduleIntegrationTestRunner({ customer: { id: { linkable: "customer_id", + entity: "Customer", primaryKey: "id", serviceName: "customer", field: "customer", @@ -196,7 +200,7 @@ moduleIntegrationTestRunner({ } const customer = await service.createCustomers(customerData) - const [address] = await service.listAddresses({ + const [address] = await service.listCustomerAddresses({ customer_id: customer.id, }) @@ -675,7 +679,7 @@ moduleIntegrationTestRunner({ first_name: "John", last_name: "Doe", }) - await service.createAddresses({ + await service.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -684,17 +688,17 @@ moduleIntegrationTestRunner({ }) // verify that the address was added - const customerWithAddress = await service.retrieveCustomer( + const customerWithCustomerAddress = await service.retrieveCustomer( customer.id, { relations: ["addresses"], } ) - expect(customerWithAddress.addresses?.length).toBe(1) + expect(customerWithCustomerAddress.addresses?.length).toBe(1) await service.deleteCustomers(customer.id) - const res = await service.listAddresses({ + const res = await service.listCustomerAddresses({ customer_id: customer.id, }) expect(res.length).toBe(0) @@ -793,25 +797,25 @@ moduleIntegrationTestRunner({ }) }) - describe("addAddresses", () => { + describe("addCustomerAddresses", () => { it("should add a single address to a customer", async () => { const customer = await service.createCustomers({ first_name: "John", last_name: "Doe", }) - const address = await service.createAddresses({ + const address = await service.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", postal_code: "10001", country_code: "US", }) - const [customerWithAddress] = await service.listCustomers( + const [customerWithCustomerAddress] = await service.listCustomers( { id: customer.id }, { relations: ["addresses"] } ) - expect(customerWithAddress.addresses).toEqual([ + expect(customerWithCustomerAddress.addresses).toEqual([ expect.objectContaining({ id: address.id }), ]) }) @@ -821,7 +825,7 @@ moduleIntegrationTestRunner({ first_name: "John", last_name: "Doe", }) - const addresses = await service.createAddresses([ + const addresses = await service.createCustomerAddresses([ { customer_id: customer.id, first_name: "John", @@ -837,12 +841,12 @@ moduleIntegrationTestRunner({ country_code: "US", }, ]) - const [customerWithAddresses] = await service.listCustomers( + const [customerWithCustomerAddresses] = await service.listCustomers( { id: customer.id }, { relations: ["addresses"] } ) - expect(customerWithAddresses.addresses).toEqual( + expect(customerWithCustomerAddresses.addresses).toEqual( expect.arrayContaining([ expect.objectContaining({ id: addresses[0].id }), expect.objectContaining({ id: addresses[1].id }), @@ -855,7 +859,7 @@ moduleIntegrationTestRunner({ first_name: "John", last_name: "Doe", }) - await service.createAddresses({ + await service.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -863,7 +867,7 @@ moduleIntegrationTestRunner({ country_code: "US", is_default_shipping: true, }) - await service.createAddresses({ + await service.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -873,7 +877,7 @@ moduleIntegrationTestRunner({ }) await expect( - service.createAddresses({ + service.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -891,7 +895,7 @@ moduleIntegrationTestRunner({ first_name: "John", last_name: "Doe", }) - await service.createAddresses({ + await service.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -899,7 +903,7 @@ moduleIntegrationTestRunner({ country_code: "US", is_default_billing: true, }) - await service.createAddresses({ + await service.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -909,7 +913,7 @@ moduleIntegrationTestRunner({ }) await expect( - service.createAddresses({ + service.createCustomerAddresses({ customer_id: customer.id, first_name: "John", last_name: "Doe", @@ -923,19 +927,19 @@ moduleIntegrationTestRunner({ }) }) - describe("updateAddresses", () => { + describe("updateCustomerAddresses", () => { it("should update a single address", async () => { const customer = await service.createCustomers({ first_name: "John", last_name: "Doe", }) - const address = await service.createAddresses({ + const address = await service.createCustomerAddresses({ customer_id: customer.id, address_name: "Home", address_1: "123 Main St", }) - await service.updateAddresses(address.id, { + await service.updateCustomerAddresses(address.id, { address_name: "Work", address_1: "456 Main St", }) @@ -959,18 +963,18 @@ moduleIntegrationTestRunner({ first_name: "John", last_name: "Doe", }) - const address1 = await service.createAddresses({ + const address1 = await service.createCustomerAddresses({ customer_id: customer.id, address_name: "Home", address_1: "123 Main St", }) - const address2 = await service.createAddresses({ + const address2 = await service.createCustomerAddresses({ customer_id: customer.id, address_name: "Work", address_1: "456 Main St", }) - await service.updateAddresses( + await service.updateCustomerAddresses( { customer_id: customer.id }, { address_name: "Under Construction", @@ -1001,7 +1005,7 @@ moduleIntegrationTestRunner({ first_name: "John", last_name: "Doe", }) - const [address1, address2] = await service.createAddresses([ + const [address1, address2] = await service.createCustomerAddresses([ { customer_id: customer.id, address_name: "Home", @@ -1014,7 +1018,7 @@ moduleIntegrationTestRunner({ }, ]) - await service.updateAddresses([address1.id, address2.id], { + await service.updateCustomerAddresses([address1.id, address2.id], { address_name: "Under Construction", }) @@ -1049,27 +1053,29 @@ moduleIntegrationTestRunner({ }, ], }) - const address = await service.createAddresses({ + const address = await service.createCustomerAddresses({ customer_id: customer.id, address_name: "Work", address_1: "456 Main St", }) await expect( - service.updateAddresses(address.id, { is_default_shipping: true }) + service.updateCustomerAddresses(address.id, { + is_default_shipping: true, + }) ).rejects.toThrow( /Customer address with customer_id: .*? already exists./ ) }) }) - describe("listAddresses", () => { + describe("listCustomerAddresses", () => { it("should list all addresses for a customer", async () => { const customer = await service.createCustomers({ first_name: "John", last_name: "Doe", }) - const [address1, address2] = await service.createAddresses([ + const [address1, address2] = await service.createCustomerAddresses([ { customer_id: customer.id, address_name: "Home", @@ -1083,7 +1089,7 @@ moduleIntegrationTestRunner({ }, ]) - const addresses = await service.listAddresses({ + const addresses = await service.listCustomerAddresses({ customer_id: customer.id, }) diff --git a/packages/modules/customer/src/joiner-config.ts b/packages/modules/customer/src/joiner-config.ts index 449a6da89b19f..a12ae0a0ea625 100644 --- a/packages/modules/customer/src/joiner-config.ts +++ b/packages/modules/customer/src/joiner-config.ts @@ -1,13 +1,3 @@ import { defineJoinerConfig, Modules } from "@medusajs/utils" -export const joinerConfig = defineJoinerConfig(Modules.CUSTOMER, { - alias: [ - { - name: ["customer_address", "customer_addresses"], - args: { - entity: "Address", - methodSuffix: "Addresses", - }, - }, - ], -}) +export const joinerConfig = defineJoinerConfig(Modules.CUSTOMER) diff --git a/packages/modules/customer/src/models/address.ts b/packages/modules/customer/src/models/address.ts index 15cbac743adc7..c1d31a101f76b 100644 --- a/packages/modules/customer/src/models/address.ts +++ b/packages/modules/customer/src/models/address.ts @@ -39,7 +39,7 @@ const CustomerAddressUniqueCustomerBillingAddress = @Entity({ tableName: "customer_address" }) @CustomerAddressUniqueCustomerShippingAddress.MikroORMIndex() @CustomerAddressUniqueCustomerBillingAddress.MikroORMIndex() -export default class Address { +export default class CustomerAddress { [OptionalProps]: OptionalAddressProps @PrimaryKey({ columnType: "text" }) diff --git a/packages/modules/customer/src/models/customer.ts b/packages/modules/customer/src/models/customer.ts index 3f52712b94a30..dc897b69874e4 100644 --- a/packages/modules/customer/src/models/customer.ts +++ b/packages/modules/customer/src/models/customer.ts @@ -19,7 +19,7 @@ import { Property, Rel, } from "@mikro-orm/core" -import Address from "./address" +import CustomerAddress from "./address" import CustomerGroup from "./customer-group" import CustomerGroupCustomer from "./customer-group-customer" @@ -77,10 +77,10 @@ export default class Customer { }) groups = new Collection>(this) - @OneToMany(() => Address, (address) => address.customer, { + @OneToMany(() => CustomerAddress, (address) => address.customer, { cascade: [Cascade.REMOVE], }) - addresses = new Collection>(this) + addresses = new Collection>(this) @Property({ onCreate: () => new Date(), diff --git a/packages/modules/customer/src/models/index.ts b/packages/modules/customer/src/models/index.ts index 09a25f763e785..196c98f70588a 100644 --- a/packages/modules/customer/src/models/index.ts +++ b/packages/modules/customer/src/models/index.ts @@ -1,5 +1,4 @@ -export { default as Address } from "./address" +export { default as CustomerAddress } from "./address" export { default as Customer } from "./customer" export { default as CustomerGroup } from "./customer-group" export { default as CustomerGroupCustomer } from "./customer-group-customer" - diff --git a/packages/modules/customer/src/services/customer-module.ts b/packages/modules/customer/src/services/customer-module.ts index c815edce82806..3c59071465bbb 100644 --- a/packages/modules/customer/src/services/customer-module.ts +++ b/packages/modules/customer/src/services/customer-module.ts @@ -21,8 +21,8 @@ import { } from "@medusajs/utils" import { EntityManager } from "@mikro-orm/core" import { - Address, Customer, + CustomerAddress, CustomerGroup, CustomerGroupCustomer, } from "@models" @@ -31,23 +31,28 @@ import { joinerConfig } from "../joiner-config" type InjectedDependencies = { baseRepository: DAL.RepositoryService customerService: ModulesSdkTypes.IMedusaInternalService - addressService: ModulesSdkTypes.IMedusaInternalService + customerAddressService: ModulesSdkTypes.IMedusaInternalService customerGroupService: ModulesSdkTypes.IMedusaInternalService customerGroupCustomerService: ModulesSdkTypes.IMedusaInternalService } export default class CustomerModuleService extends MedusaService<{ - Address: { dto: CustomerAddressDTO } + CustomerAddress: { dto: CustomerAddressDTO } Customer: { dto: CustomerDTO } CustomerGroup: { dto: CustomerGroupDTO } CustomerGroupCustomer: { dto: CustomerGroupCustomerDTO } - }>({ Address, Customer, CustomerGroup, CustomerGroupCustomer }) + }>({ + CustomerAddress, + Customer, + CustomerGroup, + CustomerGroupCustomer, + }) implements ICustomerModuleService { protected baseRepository_: DAL.RepositoryService protected customerService_: ModulesSdkTypes.IMedusaInternalService - protected addressService_: ModulesSdkTypes.IMedusaInternalService
+ protected customerAddressService_: ModulesSdkTypes.IMedusaInternalService protected customerGroupService_: ModulesSdkTypes.IMedusaInternalService protected customerGroupCustomerService_: ModulesSdkTypes.IMedusaInternalService @@ -55,7 +60,7 @@ export default class CustomerModuleService { baseRepository, customerService, - addressService, + customerAddressService, customerGroupService, customerGroupCustomerService, }: InjectedDependencies, @@ -66,7 +71,7 @@ export default class CustomerModuleService this.baseRepository_ = baseRepository this.customerService_ = customerService - this.addressService_ = addressService + this.customerAddressService_ = customerAddressService this.customerGroupService_ = customerGroupService this.customerGroupCustomerService_ = customerGroupCustomerService } @@ -128,7 +133,10 @@ export default class CustomerModuleService }) .flat() - await this.createAddresses(addressDataWithCustomerIds, sharedContext) + await this.createCustomerAddresses( + addressDataWithCustomerIds, + sharedContext + ) return customers as unknown as CustomerTypes.CustomerDTO[] } @@ -321,17 +329,17 @@ export default class CustomerModuleService } // @ts-expect-error - async createAddresses( + async createCustomerAddresses( addresses: CustomerTypes.CreateCustomerAddressDTO[], sharedContext?: Context ): Promise - async createAddresses( + async createCustomerAddresses( address: CustomerTypes.CreateCustomerAddressDTO, sharedContext?: Context ): Promise @InjectManager("baseRepository_") - async createAddresses( + async createCustomerAddresses( data: | CustomerTypes.CreateCustomerAddressDTO | CustomerTypes.CreateCustomerAddressDTO[], @@ -339,7 +347,7 @@ export default class CustomerModuleService ): Promise< CustomerTypes.CustomerAddressDTO | CustomerTypes.CustomerAddressDTO[] > { - const addresses = await this.createAddresses_(data, sharedContext) + const addresses = await this.createCustomerAddresses_(data, sharedContext) const serialized = await this.baseRepository_.serialize< CustomerTypes.CustomerAddressDTO[] @@ -353,37 +361,37 @@ export default class CustomerModuleService } @InjectTransactionManager("baseRepository_") - private async createAddresses_( + private async createCustomerAddresses_( data: | CustomerTypes.CreateCustomerAddressDTO | CustomerTypes.CreateCustomerAddressDTO[], @MedusaContext() sharedContext: Context = {} ) { - return await this.addressService_.create( + return await this.customerAddressService_.create( Array.isArray(data) ? data : [data], sharedContext ) } // @ts-expect-error - async updateAddresses( + async updateCustomerAddresses( addressId: string, data: CustomerTypes.UpdateCustomerAddressDTO, sharedContext?: Context ): Promise - async updateAddresses( + async updateCustomerAddresses( addressIds: string[], data: CustomerTypes.UpdateCustomerAddressDTO, sharedContext?: Context ): Promise - async updateAddresses( + async updateCustomerAddresses( selector: CustomerTypes.FilterableCustomerAddressProps, data: CustomerTypes.UpdateCustomerAddressDTO, sharedContext?: Context ): Promise @InjectTransactionManager("baseRepository_") - async updateAddresses( + async updateCustomerAddresses( addressIdOrSelector: | string | string[] @@ -416,7 +424,7 @@ export default class CustomerModuleService } } - const addresses = await this.addressService_.update( + const addresses = await this.customerAddressService_.update( updateData, sharedContext ) diff --git a/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts b/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts index 69b8fb7d3ff95..af6eed0c32db0 100644 --- a/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts +++ b/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts @@ -131,6 +131,7 @@ moduleIntegrationTestRunner({ fulfillmentAddress: { id: { linkable: "fulfillment_address_id", + entity: "FulfillmentAddress", primaryKey: "id", serviceName: "fulfillment", field: "fulfillmentAddress", @@ -139,6 +140,7 @@ moduleIntegrationTestRunner({ fulfillmentItem: { id: { linkable: "fulfillment_item_id", + entity: "FulfillmentItem", primaryKey: "id", serviceName: "fulfillment", field: "fulfillmentItem", @@ -147,6 +149,7 @@ moduleIntegrationTestRunner({ fulfillmentLabel: { id: { linkable: "fulfillment_label_id", + entity: "FulfillmentLabel", primaryKey: "id", serviceName: "fulfillment", field: "fulfillmentLabel", @@ -155,6 +158,7 @@ moduleIntegrationTestRunner({ fulfillmentProvider: { id: { linkable: "fulfillment_provider_id", + entity: "FulfillmentProvider", primaryKey: "id", serviceName: "fulfillment", field: "fulfillmentProvider", @@ -163,6 +167,7 @@ moduleIntegrationTestRunner({ fulfillmentSet: { id: { linkable: "fulfillment_set_id", + entity: "FulfillmentSet", primaryKey: "id", serviceName: "fulfillment", field: "fulfillmentSet", @@ -171,6 +176,7 @@ moduleIntegrationTestRunner({ fulfillment: { id: { linkable: "fulfillment_id", + entity: "Fulfillment", primaryKey: "id", serviceName: "fulfillment", field: "fulfillment", @@ -179,6 +185,7 @@ moduleIntegrationTestRunner({ geoZone: { id: { linkable: "geo_zone_id", + entity: "GeoZone", primaryKey: "id", serviceName: "fulfillment", field: "geoZone", @@ -187,6 +194,7 @@ moduleIntegrationTestRunner({ serviceZone: { id: { linkable: "service_zone_id", + entity: "ServiceZone", primaryKey: "id", serviceName: "fulfillment", field: "serviceZone", @@ -195,6 +203,7 @@ moduleIntegrationTestRunner({ shippingOptionRule: { id: { linkable: "shipping_option_rule_id", + entity: "ShippingOptionRule", primaryKey: "id", serviceName: "fulfillment", field: "shippingOptionRule", @@ -203,6 +212,7 @@ moduleIntegrationTestRunner({ shippingOptionType: { id: { linkable: "shipping_option_type_id", + entity: "ShippingOptionType", primaryKey: "id", serviceName: "fulfillment", field: "shippingOptionType", @@ -211,6 +221,7 @@ moduleIntegrationTestRunner({ shippingOption: { id: { linkable: "shipping_option_id", + entity: "ShippingOption", primaryKey: "id", serviceName: "fulfillment", field: "shippingOption", @@ -219,6 +230,7 @@ moduleIntegrationTestRunner({ shippingProfile: { id: { linkable: "shipping_profile_id", + entity: "ShippingProfile", primaryKey: "id", serviceName: "fulfillment", field: "shippingProfile", diff --git a/packages/modules/inventory-next/integration-tests/__tests__/inventory-module-service.spec.ts b/packages/modules/inventory-next/integration-tests/__tests__/inventory-module-service.spec.ts index d4ab993443eb6..8fdfba19e50a2 100644 --- a/packages/modules/inventory-next/integration-tests/__tests__/inventory-module-service.spec.ts +++ b/packages/modules/inventory-next/integration-tests/__tests__/inventory-module-service.spec.ts @@ -28,6 +28,7 @@ moduleIntegrationTestRunner({ inventoryItem: { id: { field: "inventoryItem", + entity: "InventoryItem", linkable: "inventory_item_id", primaryKey: "id", serviceName: "inventoryService", @@ -36,6 +37,7 @@ moduleIntegrationTestRunner({ inventoryLevel: { id: { field: "inventoryLevel", + entity: "InventoryLevel", linkable: "inventory_level_id", primaryKey: "id", serviceName: "inventoryService", @@ -44,6 +46,7 @@ moduleIntegrationTestRunner({ reservationItem: { id: { field: "reservationItem", + entity: "ReservationItem", linkable: "reservation_item_id", primaryKey: "id", serviceName: "inventoryService", diff --git a/packages/modules/inventory-next/src/joiner-config.ts b/packages/modules/inventory-next/src/joiner-config.ts index 775888d2782d4..68aa91393424d 100644 --- a/packages/modules/inventory-next/src/joiner-config.ts +++ b/packages/modules/inventory-next/src/joiner-config.ts @@ -6,8 +6,8 @@ export const joinerConfig = defineJoinerConfig(Modules.INVENTORY, { alias: [ { name: ["inventory_items", "inventory_item", "inventory"], + entity: "InventoryItem", args: { - entity: "InventoryItem", methodSuffix: "InventoryItems", }, }, @@ -18,8 +18,8 @@ export const joinerConfig = defineJoinerConfig(Modules.INVENTORY, { "reservation_item", "reservation_items", ], + entity: "ReservationItem", args: { - entity: "ReservationItem", methodSuffix: "ReservationItems", }, }, diff --git a/packages/modules/link-modules/src/definitions/cart-payment-collection.ts b/packages/modules/link-modules/src/definitions/cart-payment-collection.ts index 99e4a27337c45..d5cff98945d80 100644 --- a/packages/modules/link-modules/src/definitions/cart-payment-collection.ts +++ b/packages/modules/link-modules/src/definitions/cart-payment-collection.ts @@ -11,15 +11,14 @@ export const CartPaymentCollection: ModuleJoinerConfig = { alias: [ { name: ["cart_payment_collection", "cart_payment_collections"], - args: { - entity: "LinkCartPaymentCollection", - }, + entity: "LinkCartPaymentCollection", }, ], primaryKeys: ["id", "cart_id", "payment_collection_id"], relationships: [ { serviceName: Modules.CART, + entity: "Cart", primaryKey: "id", foreignKey: "cart_id", alias: "cart", @@ -29,6 +28,7 @@ export const CartPaymentCollection: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentCollection", primaryKey: "id", foreignKey: "payment_collection_id", alias: "payment_collection", diff --git a/packages/modules/link-modules/src/definitions/cart-promotion.ts b/packages/modules/link-modules/src/definitions/cart-promotion.ts index 88d26e4606dbf..c655fb3ab412a 100644 --- a/packages/modules/link-modules/src/definitions/cart-promotion.ts +++ b/packages/modules/link-modules/src/definitions/cart-promotion.ts @@ -11,15 +11,14 @@ export const CartPromotion: ModuleJoinerConfig = { alias: [ { name: ["cart_promotion", "cart_promotions"], - args: { - entity: "LinkCartPromotion", - }, + entity: "LinkCartPromotion", }, ], primaryKeys: ["id", "cart_id", "promotion_id"], relationships: [ { serviceName: Modules.CART, + entity: "Cart", primaryKey: "id", foreignKey: "cart_id", alias: "cart", @@ -29,6 +28,7 @@ export const CartPromotion: ModuleJoinerConfig = { }, { serviceName: Modules.PROMOTION, + entity: "Promotion", primaryKey: "id", foreignKey: "promotion_id", alias: "promotions", diff --git a/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts b/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts index 6847cab58318d..2bcb17f85337d 100644 --- a/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts +++ b/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts @@ -11,13 +11,14 @@ export const LocationFulfillmentProvider: ModuleJoinerConfig = { alias: [ { name: ["location_fulfillment_provider", "location_fulfillment_providers"], - args: { entity: "LinkLocationFulfillmentProvider" }, + entity: "LinkLocationFulfillmentProvider", }, ], primaryKeys: ["id", "stock_location_id", "fulfillment_provider_id"], relationships: [ { serviceName: Modules.STOCK_LOCATION, + entity: "StockLocation", primaryKey: "id", foreignKey: "stock_location_id", alias: "location", @@ -25,6 +26,7 @@ export const LocationFulfillmentProvider: ModuleJoinerConfig = { }, { serviceName: Modules.FULFILLMENT, + entity: "FulfillmentProvider", primaryKey: "id", foreignKey: "fulfillment_provider_id", alias: "fulfillment_provider", diff --git a/packages/modules/link-modules/src/definitions/fulfillment-set-location.ts b/packages/modules/link-modules/src/definitions/fulfillment-set-location.ts index dc5a36c4c0b50..c01811eca81ce 100644 --- a/packages/modules/link-modules/src/definitions/fulfillment-set-location.ts +++ b/packages/modules/link-modules/src/definitions/fulfillment-set-location.ts @@ -11,15 +11,14 @@ export const LocationFulfillmentSet: ModuleJoinerConfig = { alias: [ { name: ["location_fulfillment_set", "location_fulfillment_sets"], - args: { - entity: "LinkLocationFulfillmentSet", - }, + entity: "LinkLocationFulfillmentSet", }, ], primaryKeys: ["id", "stock_location_id", "fulfillment_set_id"], relationships: [ { serviceName: Modules.STOCK_LOCATION, + entity: "StockLocation", primaryKey: "id", foreignKey: "stock_location_id", alias: "location", @@ -29,6 +28,7 @@ export const LocationFulfillmentSet: ModuleJoinerConfig = { }, { serviceName: Modules.FULFILLMENT, + entity: "FulfillmentSet", primaryKey: "id", foreignKey: "fulfillment_set_id", alias: "fulfillment_set", diff --git a/packages/modules/link-modules/src/definitions/order-cart.ts b/packages/modules/link-modules/src/definitions/order-cart.ts index 2a017ec9ddd07..7aadad1e4931f 100644 --- a/packages/modules/link-modules/src/definitions/order-cart.ts +++ b/packages/modules/link-modules/src/definitions/order-cart.ts @@ -11,15 +11,14 @@ export const OrderCart: ModuleJoinerConfig = { alias: [ { name: ["order_cart", "order_carts"], - args: { - entity: "LinkOrderCart", - }, + entity: "LinkOrderCart", }, ], primaryKeys: ["id", "order_id", "cart_id"], relationships: [ { serviceName: Modules.ORDER, + entity: "Order", primaryKey: "id", foreignKey: "order_id", alias: "order", @@ -29,6 +28,7 @@ export const OrderCart: ModuleJoinerConfig = { }, { serviceName: Modules.CART, + entity: "Cart", primaryKey: "id", foreignKey: "cart_id", alias: "cart", diff --git a/packages/modules/link-modules/src/definitions/order-claim-payment-collection.ts b/packages/modules/link-modules/src/definitions/order-claim-payment-collection.ts index 33db7942a05dd..e99a80f01f609 100644 --- a/packages/modules/link-modules/src/definitions/order-claim-payment-collection.ts +++ b/packages/modules/link-modules/src/definitions/order-claim-payment-collection.ts @@ -14,15 +14,14 @@ export const OrderClaimPaymentCollection: ModuleJoinerConfig = { "order_claim_payment_collection", "order_claim_payment_collections", ], - args: { - entity: "LinkOrderClaimPaymentCollection", - }, + entity: "LinkOrderClaimPaymentCollection", }, ], primaryKeys: ["id", "claim_id", "payment_collection_id"], relationships: [ { serviceName: Modules.ORDER, + entity: "OrderClaim", primaryKey: "id", foreignKey: "claim_id", alias: "order", @@ -32,6 +31,7 @@ export const OrderClaimPaymentCollection: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentCollection", primaryKey: "id", foreignKey: "payment_collection_id", alias: "payment_collection", diff --git a/packages/modules/link-modules/src/definitions/order-exchange-payment-collection.ts b/packages/modules/link-modules/src/definitions/order-exchange-payment-collection.ts index 19092d0eaec62..aed1b7e51e275 100644 --- a/packages/modules/link-modules/src/definitions/order-exchange-payment-collection.ts +++ b/packages/modules/link-modules/src/definitions/order-exchange-payment-collection.ts @@ -14,15 +14,14 @@ export const OrderExchangePaymentCollection: ModuleJoinerConfig = { "order_exchange_payment_collection", "order_exchange_payment_collections", ], - args: { - entity: "LinkOrderExchangePaymentCollection", - }, + entity: "LinkOrderExchangePaymentCollection", }, ], primaryKeys: ["id", "exchange_id", "payment_collection_id"], relationships: [ { serviceName: Modules.ORDER, + entity: "OrderExchange", primaryKey: "id", foreignKey: "exchange_id", alias: "order", @@ -32,6 +31,7 @@ export const OrderExchangePaymentCollection: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentCollection", primaryKey: "id", foreignKey: "payment_collection_id", alias: "payment_collection", diff --git a/packages/modules/link-modules/src/definitions/order-fulfillment.ts b/packages/modules/link-modules/src/definitions/order-fulfillment.ts index be82c5662ef96..5e1f0bf512a18 100644 --- a/packages/modules/link-modules/src/definitions/order-fulfillment.ts +++ b/packages/modules/link-modules/src/definitions/order-fulfillment.ts @@ -11,15 +11,14 @@ export const OrderFulfillment: ModuleJoinerConfig = { alias: [ { name: ["order_fulfillment", "order_fulfillments"], - args: { - entity: "LinkOrderFulfillment", - }, + entity: "LinkOrderFulfillment", }, ], primaryKeys: ["id", "order_id", "fulfillment_id"], relationships: [ { serviceName: Modules.ORDER, + entity: "Order", primaryKey: "id", foreignKey: "order_id", alias: "order", @@ -29,11 +28,11 @@ export const OrderFulfillment: ModuleJoinerConfig = { }, { serviceName: Modules.FULFILLMENT, + entity: "Fulfillment", primaryKey: "id", foreignKey: "fulfillment_id", alias: "fulfillments", args: { - // TODO: We are not suppose to know the module implementation here, wait for later to think about inferring it methodSuffix: "Fulfillments", }, }, diff --git a/packages/modules/link-modules/src/definitions/order-payment-collection.ts b/packages/modules/link-modules/src/definitions/order-payment-collection.ts index a4e04475fc0fa..b59b2d107baa9 100644 --- a/packages/modules/link-modules/src/definitions/order-payment-collection.ts +++ b/packages/modules/link-modules/src/definitions/order-payment-collection.ts @@ -11,15 +11,14 @@ export const OrderPaymentCollection: ModuleJoinerConfig = { alias: [ { name: ["order_payment_collection", "order_payment_collections"], - args: { - entity: "LinkOrderPaymentCollection", - }, + entity: "LinkOrderPaymentCollection", }, ], primaryKeys: ["id", "order_id", "payment_collection_id"], relationships: [ { serviceName: Modules.ORDER, + entity: "Order", primaryKey: "id", foreignKey: "order_id", alias: "order", @@ -29,6 +28,7 @@ export const OrderPaymentCollection: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentCollection", primaryKey: "id", foreignKey: "payment_collection_id", alias: "payment_collection", diff --git a/packages/modules/link-modules/src/definitions/order-promotion.ts b/packages/modules/link-modules/src/definitions/order-promotion.ts index 3d66d6caeae5e..efb44c2f0215b 100644 --- a/packages/modules/link-modules/src/definitions/order-promotion.ts +++ b/packages/modules/link-modules/src/definitions/order-promotion.ts @@ -11,15 +11,14 @@ export const OrderPromotion: ModuleJoinerConfig = { alias: [ { name: ["order_promotion", "order_promotions"], - args: { - entity: "LinkOrderPromotion", - }, + entity: "LinkOrderPromotion", }, ], primaryKeys: ["id", "order_id", "promotion_id"], relationships: [ { serviceName: Modules.ORDER, + entity: "Order", primaryKey: "id", foreignKey: "order_id", alias: "order", @@ -29,6 +28,7 @@ export const OrderPromotion: ModuleJoinerConfig = { }, { serviceName: Modules.PROMOTION, + entity: "Promotion", primaryKey: "id", foreignKey: "promotion_id", alias: "promotion", diff --git a/packages/modules/link-modules/src/definitions/order-return-fulfillment.ts b/packages/modules/link-modules/src/definitions/order-return-fulfillment.ts index b4f75569a2d0d..3e808291ff03d 100644 --- a/packages/modules/link-modules/src/definitions/order-return-fulfillment.ts +++ b/packages/modules/link-modules/src/definitions/order-return-fulfillment.ts @@ -11,15 +11,14 @@ export const ReturnFulfillment: ModuleJoinerConfig = { alias: [ { name: ["return_fulfillment", "return_fulfillments"], - args: { - entity: "LinkReturnFulfillment", - }, + entity: "LinkReturnFulfillment", }, ], primaryKeys: ["id", "return_id", "fulfillment_id"], relationships: [ { serviceName: Modules.ORDER, + entity: "Order", primaryKey: "id", foreignKey: "return_id", alias: "return", @@ -29,6 +28,7 @@ export const ReturnFulfillment: ModuleJoinerConfig = { }, { serviceName: Modules.FULFILLMENT, + entity: "Fulfillment", primaryKey: "id", foreignKey: "fulfillment_id", alias: "fulfillments", diff --git a/packages/modules/link-modules/src/definitions/product-sales-channel.ts b/packages/modules/link-modules/src/definitions/product-sales-channel.ts index cead75634ac48..2304257ffd466 100644 --- a/packages/modules/link-modules/src/definitions/product-sales-channel.ts +++ b/packages/modules/link-modules/src/definitions/product-sales-channel.ts @@ -20,6 +20,7 @@ export const ProductSalesChannel: ModuleJoinerConfig = { relationships: [ { serviceName: Modules.PRODUCT, + entity: "Product", primaryKey: "id", foreignKey: "product_id", alias: "product", @@ -29,6 +30,7 @@ export const ProductSalesChannel: ModuleJoinerConfig = { }, { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", primaryKey: "id", foreignKey: "sales_channel_id", alias: "sales_channel", diff --git a/packages/modules/link-modules/src/definitions/product-variant-inventory-item.ts b/packages/modules/link-modules/src/definitions/product-variant-inventory-item.ts index bc97b0a783953..93422a9029369 100644 --- a/packages/modules/link-modules/src/definitions/product-variant-inventory-item.ts +++ b/packages/modules/link-modules/src/definitions/product-variant-inventory-item.ts @@ -20,15 +20,14 @@ export const ProductVariantInventoryItem: ModuleJoinerConfig = { "product_variant_inventory_item", "product_variant_inventory_items", ], - args: { - entity: "LinkProductVariantInventoryItem", - }, + entity: "LinkProductVariantInventoryItem", }, ], primaryKeys: ["id", "variant_id", "inventory_item_id"], relationships: [ { serviceName: Modules.PRODUCT, + entity: "ProductVariant", primaryKey: "id", foreignKey: "variant_id", alias: "variant", @@ -38,6 +37,7 @@ export const ProductVariantInventoryItem: ModuleJoinerConfig = { }, { serviceName: Modules.INVENTORY, + entity: "InventoryItem", primaryKey: "id", foreignKey: "inventory_item_id", alias: "inventory", diff --git a/packages/modules/link-modules/src/definitions/product-variant-price-set.ts b/packages/modules/link-modules/src/definitions/product-variant-price-set.ts index 8124afd314935..490827b4ffe14 100644 --- a/packages/modules/link-modules/src/definitions/product-variant-price-set.ts +++ b/packages/modules/link-modules/src/definitions/product-variant-price-set.ts @@ -11,15 +11,14 @@ export const ProductVariantPriceSet: ModuleJoinerConfig = { alias: [ { name: ["product_variant_price_set", "product_variant_price_sets"], - args: { - entity: "LinkProductVariantPriceSet", - }, + entity: "LinkProductVariantPriceSet", }, ], primaryKeys: ["id", "variant_id", "price_set_id"], relationships: [ { serviceName: Modules.PRODUCT, + entity: "ProductVariant", primaryKey: "id", foreignKey: "variant_id", alias: "variant", @@ -29,6 +28,7 @@ export const ProductVariantPriceSet: ModuleJoinerConfig = { }, { serviceName: Modules.PRICING, + entity: "PriceSet", primaryKey: "id", foreignKey: "price_set_id", alias: "price_set", diff --git a/packages/modules/link-modules/src/definitions/publishable-api-key-sales-channel.ts b/packages/modules/link-modules/src/definitions/publishable-api-key-sales-channel.ts index e24447552d538..a78761992e1aa 100644 --- a/packages/modules/link-modules/src/definitions/publishable-api-key-sales-channel.ts +++ b/packages/modules/link-modules/src/definitions/publishable-api-key-sales-channel.ts @@ -20,6 +20,7 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = { relationships: [ { serviceName: Modules.API_KEY, + entity: "ApiKey", primaryKey: "id", foreignKey: "publishable_key_id", alias: "api_key", @@ -29,6 +30,7 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = { }, { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", primaryKey: "id", foreignKey: "sales_channel_id", alias: "sales_channel", diff --git a/packages/modules/link-modules/src/definitions/readonly/cart-customer.ts b/packages/modules/link-modules/src/definitions/readonly/cart-customer.ts index eb93ab73d25bd..3502f5ccddd78 100644 --- a/packages/modules/link-modules/src/definitions/readonly/cart-customer.ts +++ b/packages/modules/link-modules/src/definitions/readonly/cart-customer.ts @@ -9,6 +9,7 @@ export const CartCustomer: ModuleJoinerConfig = { serviceName: Modules.CART, relationship: { serviceName: Modules.CUSTOMER, + entity: "Customer", primaryKey: "id", foreignKey: "customer_id", alias: "customer", @@ -21,6 +22,7 @@ export const CartCustomer: ModuleJoinerConfig = { serviceName: Modules.CUSTOMER, relationship: { serviceName: Modules.CART, + entity: "Cart", primaryKey: "customer_id", foreignKey: "id", alias: "carts", diff --git a/packages/modules/link-modules/src/definitions/readonly/cart-product.ts b/packages/modules/link-modules/src/definitions/readonly/cart-product.ts index af0fc8e7108ee..709d2bea96388 100644 --- a/packages/modules/link-modules/src/definitions/readonly/cart-product.ts +++ b/packages/modules/link-modules/src/definitions/readonly/cart-product.ts @@ -21,6 +21,7 @@ export const CartProduct: ModuleJoinerConfig = { serviceName: Modules.CART, relationship: { serviceName: Modules.PRODUCT, + entity: "ProductVariant", primaryKey: "id", foreignKey: "items.variant_id", alias: "variant", @@ -33,6 +34,7 @@ export const CartProduct: ModuleJoinerConfig = { serviceName: Modules.PRODUCT, relationship: { serviceName: Modules.CART, + entity: "LineItem", primaryKey: "variant_id", foreignKey: "id", alias: "cart_items", diff --git a/packages/modules/link-modules/src/definitions/readonly/cart-region.ts b/packages/modules/link-modules/src/definitions/readonly/cart-region.ts index 5041b2f0a43e7..34fac15f8b9b2 100644 --- a/packages/modules/link-modules/src/definitions/readonly/cart-region.ts +++ b/packages/modules/link-modules/src/definitions/readonly/cart-region.ts @@ -9,6 +9,7 @@ export const CartRegion: ModuleJoinerConfig = { serviceName: Modules.CART, relationship: { serviceName: Modules.REGION, + entity: "Region", primaryKey: "id", foreignKey: "region_id", alias: "region", @@ -21,6 +22,7 @@ export const CartRegion: ModuleJoinerConfig = { serviceName: Modules.REGION, relationship: { serviceName: Modules.CART, + entity: "Cart", primaryKey: "region_id", foreignKey: "id", alias: "carts", diff --git a/packages/modules/link-modules/src/definitions/readonly/cart-sales-channel.ts b/packages/modules/link-modules/src/definitions/readonly/cart-sales-channel.ts index 7d7347efce9b1..b75a5c2651f0d 100644 --- a/packages/modules/link-modules/src/definitions/readonly/cart-sales-channel.ts +++ b/packages/modules/link-modules/src/definitions/readonly/cart-sales-channel.ts @@ -9,6 +9,7 @@ export const CartSalesChannel: ModuleJoinerConfig = { serviceName: Modules.CART, relationship: { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", primaryKey: "id", foreignKey: "sales_channel_id", alias: "sales_channel", @@ -21,6 +22,7 @@ export const CartSalesChannel: ModuleJoinerConfig = { serviceName: Modules.SALES_CHANNEL, relationship: { serviceName: Modules.CART, + entity: "Cart", primaryKey: "sales_channel_id", foreignKey: "id", alias: "carts", diff --git a/packages/modules/link-modules/src/definitions/readonly/inventory-level-stock-location.ts b/packages/modules/link-modules/src/definitions/readonly/inventory-level-stock-location.ts index a47056d5c7492..a8da57f315c13 100644 --- a/packages/modules/link-modules/src/definitions/readonly/inventory-level-stock-location.ts +++ b/packages/modules/link-modules/src/definitions/readonly/inventory-level-stock-location.ts @@ -9,6 +9,7 @@ export const InventoryLevelStockLocation: ModuleJoinerConfig = { serviceName: Modules.INVENTORY, relationship: { serviceName: Modules.STOCK_LOCATION, + entity: "StockLocation", primaryKey: "id", foreignKey: "location_id", alias: "stock_locations", diff --git a/packages/modules/link-modules/src/definitions/readonly/line-item-adjustment-promotion.ts b/packages/modules/link-modules/src/definitions/readonly/line-item-adjustment-promotion.ts index f01166d28f936..5e94ba386ff8c 100644 --- a/packages/modules/link-modules/src/definitions/readonly/line-item-adjustment-promotion.ts +++ b/packages/modules/link-modules/src/definitions/readonly/line-item-adjustment-promotion.ts @@ -9,6 +9,7 @@ export const LineItemAdjustmentPromotion: ModuleJoinerConfig = { serviceName: Modules.CART, relationship: { serviceName: Modules.PROMOTION, + entity: "Promotion", primaryKey: "id", foreignKey: "promotion_id", alias: "promotion", diff --git a/packages/modules/link-modules/src/definitions/readonly/order-customer.ts b/packages/modules/link-modules/src/definitions/readonly/order-customer.ts index 81a77c99c76bb..3440df3e36541 100644 --- a/packages/modules/link-modules/src/definitions/readonly/order-customer.ts +++ b/packages/modules/link-modules/src/definitions/readonly/order-customer.ts @@ -9,6 +9,7 @@ export const OrderCustomer: ModuleJoinerConfig = { serviceName: Modules.ORDER, relationship: { serviceName: Modules.CUSTOMER, + entity: "Customer", primaryKey: "id", foreignKey: "customer_id", alias: "customer", @@ -21,6 +22,7 @@ export const OrderCustomer: ModuleJoinerConfig = { serviceName: Modules.CUSTOMER, relationship: { serviceName: Modules.ORDER, + entity: "Order", primaryKey: "customer_id", foreignKey: "id", alias: "orders", diff --git a/packages/modules/link-modules/src/definitions/readonly/order-product.ts b/packages/modules/link-modules/src/definitions/readonly/order-product.ts index 776eac8f00a8a..67b48ea2d5ec0 100644 --- a/packages/modules/link-modules/src/definitions/readonly/order-product.ts +++ b/packages/modules/link-modules/src/definitions/readonly/order-product.ts @@ -9,6 +9,7 @@ export const OrderProduct: ModuleJoinerConfig = { serviceName: Modules.ORDER, relationship: { serviceName: Modules.PRODUCT, + entity: "Product", primaryKey: "id", foreignKey: "items.product_id", alias: "product", @@ -21,6 +22,7 @@ export const OrderProduct: ModuleJoinerConfig = { serviceName: Modules.ORDER, relationship: { serviceName: Modules.PRODUCT, + entity: "ProductVariant", primaryKey: "id", foreignKey: "items.variant_id", alias: "variant", @@ -33,12 +35,13 @@ export const OrderProduct: ModuleJoinerConfig = { serviceName: Modules.PRODUCT, relationship: { serviceName: Modules.ORDER, + entity: "OrderLineItem", primaryKey: "variant_id", foreignKey: "id", alias: "order_items", isList: true, args: { - methodSuffix: "LineItems", + methodSuffix: "OrderLineItems", }, }, }, diff --git a/packages/modules/link-modules/src/definitions/readonly/order-region.ts b/packages/modules/link-modules/src/definitions/readonly/order-region.ts index 0682b2e2725e1..ae893b9e1a8b9 100644 --- a/packages/modules/link-modules/src/definitions/readonly/order-region.ts +++ b/packages/modules/link-modules/src/definitions/readonly/order-region.ts @@ -9,6 +9,7 @@ export const OrderRegion: ModuleJoinerConfig = { serviceName: Modules.ORDER, relationship: { serviceName: Modules.REGION, + entity: "Region", primaryKey: "id", foreignKey: "region_id", alias: "region", @@ -21,6 +22,7 @@ export const OrderRegion: ModuleJoinerConfig = { serviceName: Modules.REGION, relationship: { serviceName: Modules.ORDER, + entity: "Order", primaryKey: "region_id", foreignKey: "id", alias: "orders", diff --git a/packages/modules/link-modules/src/definitions/readonly/order-sales-channel.ts b/packages/modules/link-modules/src/definitions/readonly/order-sales-channel.ts index b5d6cc3c5c70f..bf89d122004aa 100644 --- a/packages/modules/link-modules/src/definitions/readonly/order-sales-channel.ts +++ b/packages/modules/link-modules/src/definitions/readonly/order-sales-channel.ts @@ -9,6 +9,7 @@ export const OrderSalesChannel: ModuleJoinerConfig = { serviceName: Modules.ORDER, relationship: { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", primaryKey: "id", foreignKey: "sales_channel_id", alias: "sales_channel", @@ -21,6 +22,7 @@ export const OrderSalesChannel: ModuleJoinerConfig = { serviceName: Modules.SALES_CHANNEL, relationship: { serviceName: Modules.ORDER, + entity: "Order", primaryKey: "sales_channel_id", foreignKey: "id", alias: "orders", diff --git a/packages/modules/link-modules/src/definitions/readonly/store-currency.ts b/packages/modules/link-modules/src/definitions/readonly/store-currency.ts index ab04fa274aa21..b929e144a949e 100644 --- a/packages/modules/link-modules/src/definitions/readonly/store-currency.ts +++ b/packages/modules/link-modules/src/definitions/readonly/store-currency.ts @@ -9,6 +9,7 @@ export const StoreCurrencies: ModuleJoinerConfig = { serviceName: Modules.STORE, relationship: { serviceName: Modules.CURRENCY, + entity: "Currency", primaryKey: "code", foreignKey: "supported_currencies.currency_code", alias: "currency", diff --git a/packages/modules/link-modules/src/definitions/region-payment-provider.ts b/packages/modules/link-modules/src/definitions/region-payment-provider.ts index 00c1dfd137df0..5c89ad690a529 100644 --- a/packages/modules/link-modules/src/definitions/region-payment-provider.ts +++ b/packages/modules/link-modules/src/definitions/region-payment-provider.ts @@ -11,15 +11,14 @@ export const RegionPaymentProvider: ModuleJoinerConfig = { alias: [ { name: ["region_payment_provider", "region_payment_providers"], - args: { - entity: "LinkRegionPaymentProvider", - }, + entity: "LinkRegionPaymentProvider", }, ], primaryKeys: ["id", "region_id", "payment_provider_id"], relationships: [ { serviceName: Modules.REGION, + entity: "Region", primaryKey: "id", foreignKey: "region_id", alias: "region", @@ -29,6 +28,7 @@ export const RegionPaymentProvider: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentProvider", primaryKey: "id", foreignKey: "payment_provider_id", alias: "payment_provider", diff --git a/packages/modules/link-modules/src/definitions/sales-channel-location.ts b/packages/modules/link-modules/src/definitions/sales-channel-location.ts index df4863b14abaf..648fddaeae459 100644 --- a/packages/modules/link-modules/src/definitions/sales-channel-location.ts +++ b/packages/modules/link-modules/src/definitions/sales-channel-location.ts @@ -11,15 +11,14 @@ export const SalesChannelLocation: ModuleJoinerConfig = { alias: [ { name: ["sales_channel_location", "sales_channel_locations"], - args: { - entity: "LinkSalesChannelLocation", - }, + entity: "LinkSalesChannelLocation", }, ], primaryKeys: ["id", "sales_channel_id", "stock_location_id"], relationships: [ { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", primaryKey: "id", foreignKey: "sales_channel_id", alias: "sales_channel", @@ -29,6 +28,7 @@ export const SalesChannelLocation: ModuleJoinerConfig = { }, { serviceName: Modules.STOCK_LOCATION, + entity: "StockLocation", primaryKey: "id", foreignKey: "stock_location_id", alias: "location", diff --git a/packages/modules/link-modules/src/definitions/shipping-option-price-set.ts b/packages/modules/link-modules/src/definitions/shipping-option-price-set.ts index cba1ec08f541f..7b29f282652f4 100644 --- a/packages/modules/link-modules/src/definitions/shipping-option-price-set.ts +++ b/packages/modules/link-modules/src/definitions/shipping-option-price-set.ts @@ -11,15 +11,14 @@ export const ShippingOptionPriceSet: ModuleJoinerConfig = { alias: [ { name: ["shipping_option_price_set", "shipping_option_price_sets"], - args: { - entity: "LinkShippingOptionPriceSet", - }, + entity: "LinkShippingOptionPriceSet", }, ], primaryKeys: ["id", "shipping_option_id", "price_set_id"], relationships: [ { serviceName: Modules.FULFILLMENT, + entity: "ShippingOption", primaryKey: "id", foreignKey: "shipping_option_id", alias: "shipping_option", @@ -29,6 +28,7 @@ export const ShippingOptionPriceSet: ModuleJoinerConfig = { }, { serviceName: Modules.PRICING, + entity: "PriceSet", primaryKey: "id", foreignKey: "price_set_id", alias: "price_set", diff --git a/packages/modules/link-modules/src/initialize/index.ts b/packages/modules/link-modules/src/initialize/index.ts index 3e451fc53f09e..ceabcea14f384 100644 --- a/packages/modules/link-modules/src/initialize/index.ts +++ b/packages/modules/link-modules/src/initialize/index.ts @@ -139,7 +139,7 @@ export const initialize = async ( for (const alias of definition.alias) { alias.args ??= {} - alias.args.entity = toPascalCase( + alias.entity = toPascalCase( "Link_" + (definition.databaseConfig?.tableName ?? composeTableName( diff --git a/packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts b/packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts index a52c1ec20007d..9861c851df159 100644 --- a/packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts +++ b/packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts @@ -7,12 +7,12 @@ import { NotificationEvents, NotificationStatus, } from "@medusajs/utils" +import { NotificationModuleService } from "@services" import { MockEventBusService, moduleIntegrationTestRunner, } from "medusa-test-utils" import { resolve } from "path" -import { NotificationModuleService } from "@services" let moduleOptions = { providers: [ @@ -58,6 +58,7 @@ moduleIntegrationTestRunner({ notification: { id: { linkable: "notification_id", + entity: "Notification", primaryKey: "id", serviceName: "notification", field: "notification", diff --git a/packages/modules/order/integration-tests/__tests__/index.spec.ts b/packages/modules/order/integration-tests/__tests__/index.spec.ts index 90b0d94e60e72..660e6ec04bd60 100644 --- a/packages/modules/order/integration-tests/__tests__/index.spec.ts +++ b/packages/modules/order/integration-tests/__tests__/index.spec.ts @@ -33,6 +33,7 @@ moduleIntegrationTestRunner({ order: { id: { linkable: "order_id", + entity: "Order", primaryKey: "id", serviceName: "order", field: "order", @@ -41,6 +42,7 @@ moduleIntegrationTestRunner({ orderAddress: { id: { linkable: "order_address_id", + entity: "OrderAddress", primaryKey: "id", serviceName: "order", field: "orderAddress", @@ -49,6 +51,7 @@ moduleIntegrationTestRunner({ orderChange: { id: { linkable: "order_change_id", + entity: "OrderChange", primaryKey: "id", serviceName: "order", field: "orderChange", @@ -57,12 +60,14 @@ moduleIntegrationTestRunner({ orderClaim: { id: { linkable: "order_claim_id", + entity: "OrderClaim", primaryKey: "id", serviceName: "order", field: "orderClaim", }, claim_id: { linkable: "claim_id", + entity: "OrderClaim", primaryKey: "claim_id", serviceName: "order", field: "orderClaim", @@ -71,12 +76,14 @@ moduleIntegrationTestRunner({ orderExchange: { id: { linkable: "order_exchange_id", + entity: "OrderExchange", primaryKey: "id", serviceName: "order", field: "orderExchange", }, exchange_id: { linkable: "exchange_id", + entity: "OrderExchange", primaryKey: "exchange_id", serviceName: "order", field: "orderExchange", @@ -85,6 +92,7 @@ moduleIntegrationTestRunner({ orderLineItem: { id: { linkable: "order_line_item_id", + entity: "OrderLineItem", primaryKey: "id", serviceName: "order", field: "orderLineItem", @@ -93,6 +101,7 @@ moduleIntegrationTestRunner({ orderShippingMethod: { id: { linkable: "order_shipping_method_id", + entity: "OrderShippingMethod", primaryKey: "id", serviceName: "order", field: "orderShippingMethod", @@ -101,6 +110,7 @@ moduleIntegrationTestRunner({ orderTransaction: { id: { linkable: "order_transaction_id", + entity: "OrderTransaction", primaryKey: "id", serviceName: "order", field: "orderTransaction", @@ -109,6 +119,7 @@ moduleIntegrationTestRunner({ return: { id: { linkable: "return_id", + entity: "Return", primaryKey: "id", serviceName: "order", field: "return", @@ -117,6 +128,7 @@ moduleIntegrationTestRunner({ returnReason: { id: { linkable: "return_reason_id", + entity: "ReturnReason", primaryKey: "id", serviceName: "order", field: "returnReason", diff --git a/packages/modules/payment/integration-tests/__tests__/services/payment-module/index.spec.ts b/packages/modules/payment/integration-tests/__tests__/services/payment-module/index.spec.ts index 552ad4fd1747f..d549df5fface6 100644 --- a/packages/modules/payment/integration-tests/__tests__/services/payment-module/index.spec.ts +++ b/packages/modules/payment/integration-tests/__tests__/services/payment-module/index.spec.ts @@ -35,6 +35,7 @@ moduleIntegrationTestRunner({ payment: { id: { linkable: "payment_id", + entity: "Payment", primaryKey: "id", serviceName: "payment", field: "payment", @@ -43,6 +44,7 @@ moduleIntegrationTestRunner({ paymentCollection: { id: { linkable: "payment_collection_id", + entity: "PaymentCollection", primaryKey: "id", serviceName: "payment", field: "paymentCollection", @@ -51,6 +53,7 @@ moduleIntegrationTestRunner({ paymentProvider: { id: { linkable: "payment_provider_id", + entity: "PaymentProvider", primaryKey: "id", serviceName: "payment", field: "paymentProvider", @@ -59,6 +62,7 @@ moduleIntegrationTestRunner({ paymentSession: { id: { field: "paymentSession", + entity: "PaymentSession", linkable: "payment_session_id", primaryKey: "id", serviceName: "payment", @@ -67,6 +71,7 @@ moduleIntegrationTestRunner({ refundReason: { id: { linkable: "refund_reason_id", + entity: "RefundReason", primaryKey: "id", serviceName: "payment", field: "refundReason", diff --git a/packages/modules/pricing/integration-tests/__tests__/services/pricing-module/index.spec.ts b/packages/modules/pricing/integration-tests/__tests__/services/pricing-module/index.spec.ts index 7ba7d182b5fee..a9c7da41cc8bd 100644 --- a/packages/modules/pricing/integration-tests/__tests__/services/pricing-module/index.spec.ts +++ b/packages/modules/pricing/integration-tests/__tests__/services/pricing-module/index.spec.ts @@ -1,7 +1,7 @@ -import { moduleIntegrationTestRunner } from "medusa-test-utils" import { IPricingModuleService } from "@medusajs/types" import { Module, Modules } from "@medusajs/utils" import { PricingModuleService } from "@services" +import { moduleIntegrationTestRunner } from "medusa-test-utils" moduleIntegrationTestRunner({ moduleName: Modules.PRICING, @@ -27,6 +27,7 @@ moduleIntegrationTestRunner({ priceSet: { id: { linkable: "price_set_id", + entity: "PriceSet", primaryKey: "id", serviceName: "pricingService", field: "priceSet", @@ -35,6 +36,7 @@ moduleIntegrationTestRunner({ priceList: { id: { linkable: "price_list_id", + entity: "PriceList", primaryKey: "id", serviceName: "pricingService", field: "priceList", @@ -43,6 +45,7 @@ moduleIntegrationTestRunner({ price: { id: { linkable: "price_id", + entity: "Price", primaryKey: "id", serviceName: "pricingService", field: "price", @@ -51,6 +54,7 @@ moduleIntegrationTestRunner({ pricePreference: { id: { linkable: "price_preference_id", + entity: "PricePreference", primaryKey: "id", serviceName: "pricingService", field: "pricePreference", diff --git a/packages/modules/product/integration-tests/__tests__/product.ts b/packages/modules/product/integration-tests/__tests__/product.ts index 127feb66d23c6..b74ef8668030f 100644 --- a/packages/modules/product/integration-tests/__tests__/product.ts +++ b/packages/modules/product/integration-tests/__tests__/product.ts @@ -65,6 +65,7 @@ moduleIntegrationTestRunner({ product: { id: { linkable: "product_id", + entity: "Product", primaryKey: "id", serviceName: "productService", field: "product", @@ -73,12 +74,14 @@ moduleIntegrationTestRunner({ productVariant: { id: { linkable: "product_variant_id", + entity: "ProductVariant", primaryKey: "id", serviceName: "productService", field: "productVariant", }, variant_id: { field: "productVariant", + entity: "ProductVariant", linkable: "variant_id", primaryKey: "variant_id", serviceName: "productService", @@ -87,6 +90,7 @@ moduleIntegrationTestRunner({ productOption: { id: { linkable: "product_option_id", + entity: "ProductOption", primaryKey: "id", serviceName: "productService", field: "productOption", @@ -95,6 +99,7 @@ moduleIntegrationTestRunner({ productType: { id: { linkable: "product_type_id", + entity: "ProductType", primaryKey: "id", serviceName: "productService", field: "productType", @@ -103,6 +108,7 @@ moduleIntegrationTestRunner({ productImage: { id: { linkable: "product_image_id", + entity: "ProductImage", primaryKey: "id", serviceName: "productService", field: "productImage", @@ -111,6 +117,7 @@ moduleIntegrationTestRunner({ productTag: { id: { linkable: "product_tag_id", + entity: "ProductTag", primaryKey: "id", serviceName: "productService", field: "productTag", @@ -119,6 +126,7 @@ moduleIntegrationTestRunner({ productCollection: { id: { linkable: "product_collection_id", + entity: "ProductCollection", primaryKey: "id", serviceName: "productService", field: "productCollection", @@ -127,6 +135,7 @@ moduleIntegrationTestRunner({ productCategory: { id: { linkable: "product_category_id", + entity: "ProductCategory", primaryKey: "id", serviceName: "productService", field: "productCategory", diff --git a/packages/modules/product/src/joiner-config.ts b/packages/modules/product/src/joiner-config.ts index 02fc74a1ab224..bfb647c469361 100644 --- a/packages/modules/product/src/joiner-config.ts +++ b/packages/modules/product/src/joiner-config.ts @@ -31,8 +31,9 @@ export const joinerConfig = defineJoinerConfig(Modules.PRODUCT, { alias: [ { name: ["product_variant", "product_variants", "variant", "variants"], + entity: "ProductVariant", args: { - entity: "ProductVariant", + methodSuffix: "ProductVariants", }, }, ], diff --git a/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts b/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts index a7b95776f56cd..70ebcc5ee46d3 100644 --- a/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts +++ b/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/promotion.spec.ts @@ -6,14 +6,14 @@ import { Modules, PromotionType, } from "@medusajs/utils" -import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils" +import { PromotionModuleService } from "@services" +import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils" import { createCampaigns } from "../../../__fixtures__/campaigns" import { createDefaultPromotion, createDefaultPromotions, createPromotions, } from "../../../__fixtures__/promotion" -import { PromotionModuleService } from "@services" jest.setTimeout(30000) @@ -47,6 +47,7 @@ moduleIntegrationTestRunner({ promotion: { id: { linkable: "promotion_id", + entity: "Promotion", primaryKey: "id", serviceName: "promotion", field: "promotion", @@ -55,6 +56,7 @@ moduleIntegrationTestRunner({ campaign: { id: { linkable: "campaign_id", + entity: "Campaign", primaryKey: "id", serviceName: "promotion", field: "campaign", @@ -63,6 +65,7 @@ moduleIntegrationTestRunner({ promotionRule: { id: { linkable: "promotion_rule_id", + entity: "PromotionRule", primaryKey: "id", serviceName: "promotion", field: "promotionRule", diff --git a/packages/modules/region/integration-tests/__tests__/region-module.spec.ts b/packages/modules/region/integration-tests/__tests__/region-module.spec.ts index 4623c5662fb32..99cc5d4e85751 100644 --- a/packages/modules/region/integration-tests/__tests__/region-module.spec.ts +++ b/packages/modules/region/integration-tests/__tests__/region-module.spec.ts @@ -1,7 +1,7 @@ import { IRegionModuleService } from "@medusajs/types" import { Module, Modules } from "@medusajs/utils" -import { moduleIntegrationTestRunner } from "medusa-test-utils" import { RegionModuleService } from "@services" +import { moduleIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(30000) @@ -24,6 +24,7 @@ moduleIntegrationTestRunner({ region: { id: { linkable: "region_id", + entity: "Region", primaryKey: "id", serviceName: "region", field: "region", @@ -32,6 +33,7 @@ moduleIntegrationTestRunner({ country: { iso_2: { linkable: "country_iso_2", + entity: "Country", primaryKey: "iso_2", serviceName: "region", field: "country", diff --git a/packages/modules/sales-channel/integration-tests/__tests__/services/sales-channel-module.spec.ts b/packages/modules/sales-channel/integration-tests/__tests__/services/sales-channel-module.spec.ts index ff8a76c4d11c9..403393272c797 100644 --- a/packages/modules/sales-channel/integration-tests/__tests__/services/sales-channel-module.spec.ts +++ b/packages/modules/sales-channel/integration-tests/__tests__/services/sales-channel-module.spec.ts @@ -1,7 +1,7 @@ import { ISalesChannelModuleService } from "@medusajs/types" -import { moduleIntegrationTestRunner } from "medusa-test-utils" import { Module, Modules } from "@medusajs/utils" import { SalesChannelModuleService } from "@services" +import { moduleIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(30000) @@ -49,6 +49,7 @@ moduleIntegrationTestRunner({ salesChannel: { id: { linkable: "sales_channel_id", + entity: "SalesChannel", primaryKey: "id", serviceName: "salesChannel", field: "salesChannel", diff --git a/packages/modules/stock-location-next/integration-tests/__tests__/stock-location-module-service.spec.ts b/packages/modules/stock-location-next/integration-tests/__tests__/stock-location-module-service.spec.ts index 69a652f0c857c..13e4c3a0cc57a 100644 --- a/packages/modules/stock-location-next/integration-tests/__tests__/stock-location-module-service.spec.ts +++ b/packages/modules/stock-location-next/integration-tests/__tests__/stock-location-module-service.spec.ts @@ -28,6 +28,7 @@ moduleIntegrationTestRunner({ stockLocationAddress: { id: { linkable: "stock_location_address_id", + entity: "StockLocationAddress", primaryKey: "id", serviceName: "stockLocationService", field: "stockLocationAddress", @@ -36,12 +37,14 @@ moduleIntegrationTestRunner({ stockLocation: { id: { field: "stockLocation", + entity: "StockLocation", linkable: "stock_location_id", primaryKey: "id", serviceName: "stockLocationService", }, location_id: { linkable: "location_id", + entity: "StockLocation", primaryKey: "location_id", serviceName: "stockLocationService", field: "stockLocation", diff --git a/packages/modules/store/integration-tests/__tests__/store-module-service.spec.ts b/packages/modules/store/integration-tests/__tests__/store-module-service.spec.ts index 7674c2eda7fb6..6fa61600ae166 100644 --- a/packages/modules/store/integration-tests/__tests__/store-module-service.spec.ts +++ b/packages/modules/store/integration-tests/__tests__/store-module-service.spec.ts @@ -1,8 +1,8 @@ import { IStoreModuleService } from "@medusajs/types" -import { moduleIntegrationTestRunner } from "medusa-test-utils" -import { createStoreFixture } from "../__fixtures__" import { Module, Modules } from "@medusajs/utils" import { StoreModuleService } from "@services" +import { moduleIntegrationTestRunner } from "medusa-test-utils" +import { createStoreFixture } from "../__fixtures__" jest.setTimeout(100000) @@ -25,6 +25,7 @@ moduleIntegrationTestRunner({ store: { id: { linkable: "store_id", + entity: "Store", primaryKey: "id", serviceName: "store", field: "store", @@ -33,6 +34,7 @@ moduleIntegrationTestRunner({ storeCurrency: { id: { linkable: "store_currency_id", + entity: "StoreCurrency", primaryKey: "id", serviceName: "store", field: "storeCurrency", diff --git a/packages/modules/tax/integration-tests/__tests__/index.spec.ts b/packages/modules/tax/integration-tests/__tests__/index.spec.ts index 86a5171542b36..2c6f2e585554a 100644 --- a/packages/modules/tax/integration-tests/__tests__/index.spec.ts +++ b/packages/modules/tax/integration-tests/__tests__/index.spec.ts @@ -30,6 +30,7 @@ moduleIntegrationTestRunner({ taxRate: { id: { linkable: "tax_rate_id", + entity: "TaxRate", primaryKey: "id", serviceName: "tax", field: "taxRate", @@ -38,6 +39,7 @@ moduleIntegrationTestRunner({ taxRegion: { id: { linkable: "tax_region_id", + entity: "TaxRegion", primaryKey: "id", serviceName: "tax", field: "taxRegion", @@ -46,6 +48,7 @@ moduleIntegrationTestRunner({ taxRateRule: { id: { linkable: "tax_rate_rule_id", + entity: "TaxRateRule", primaryKey: "id", serviceName: "tax", field: "taxRateRule", @@ -54,6 +57,7 @@ moduleIntegrationTestRunner({ taxProvider: { id: { linkable: "tax_provider_id", + entity: "TaxProvider", primaryKey: "id", serviceName: "tax", field: "taxProvider", diff --git a/packages/modules/user/integration-tests/__tests__/user.spec.ts b/packages/modules/user/integration-tests/__tests__/user.spec.ts index 0268f3532286b..056279fb60544 100644 --- a/packages/modules/user/integration-tests/__tests__/user.spec.ts +++ b/packages/modules/user/integration-tests/__tests__/user.spec.ts @@ -1,10 +1,10 @@ import { IUserModuleService } from "@medusajs/types" import { Module, Modules, UserEvents } from "@medusajs/utils" +import { UserModuleService } from "@services" import { MockEventBusService, moduleIntegrationTestRunner, } from "medusa-test-utils" -import { UserModuleService } from "@services" jest.setTimeout(30000) @@ -43,6 +43,7 @@ moduleIntegrationTestRunner({ user: { id: { linkable: "user_id", + entity: "User", primaryKey: "id", serviceName: "user", field: "user", @@ -51,6 +52,7 @@ moduleIntegrationTestRunner({ invite: { id: { linkable: "invite_id", + entity: "Invite", primaryKey: "id", serviceName: "user", field: "invite", diff --git a/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts b/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts index faeb0a70d4b59..7edc08ca5cf54 100644 --- a/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts +++ b/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts @@ -5,6 +5,8 @@ import { RemoteQueryFunction, } from "@medusajs/types" import { Module, Modules, TransactionHandlerType } from "@medusajs/utils" +import { WorkflowsModuleService } from "@services" +import { asFunction } from "awilix" import { moduleIntegrationTestRunner } from "medusa-test-utils" import { setTimeout as setTimeoutPromise } from "timers/promises" import "../__fixtures__" @@ -20,8 +22,6 @@ import { workflowEventGroupIdStep2Mock, } from "../__fixtures__/workflow_event_group_id" import { createScheduled } from "../__fixtures__/workflow_scheduled" -import { WorkflowsModuleService } from "@services" -import { asFunction } from "awilix" jest.setTimeout(100000) @@ -51,6 +51,7 @@ moduleIntegrationTestRunner({ workflowExecution: { id: { linkable: "workflow_execution_id", + entity: "WorkflowExecution", primaryKey: "id", serviceName: "workflows", field: "workflowExecution", diff --git a/packages/modules/workflow-engine-redis/integration-tests/__tests__/index.spec.ts b/packages/modules/workflow-engine-redis/integration-tests/__tests__/index.spec.ts index 4e7f51c965e63..cc34d8e2f256a 100644 --- a/packages/modules/workflow-engine-redis/integration-tests/__tests__/index.spec.ts +++ b/packages/modules/workflow-engine-redis/integration-tests/__tests__/index.spec.ts @@ -83,6 +83,7 @@ moduleIntegrationTestRunner({ workflowExecution: { id: { linkable: "workflow_execution_id", + entity: "WorkflowExecution", primaryKey: "id", serviceName: "workflows", field: "workflowExecution",