diff --git a/packages/core/types/src/modules-sdk/index.ts b/packages/core/types/src/modules-sdk/index.ts index d81041da82..3e868e6a2a 100644 --- a/packages/core/types/src/modules-sdk/index.ts +++ b/packages/core/types/src/modules-sdk/index.ts @@ -9,9 +9,10 @@ import { MedusaContainer } from "../common" import { RepositoryService } from "../dal" import { Logger } from "../logger" -export type Constructor = new (...args: any[]) => T +export type Constructor = new (...args: any[]) => T | (new () => T) + export * from "../common/medusa-container" -export * from "./internal-module-service" +export * from "./medusa-internal-service" export * from "./module-provider" export type LogLevel = diff --git a/packages/core/types/src/modules-sdk/internal-module-service.ts b/packages/core/types/src/modules-sdk/medusa-internal-service.ts similarity index 98% rename from packages/core/types/src/modules-sdk/internal-module-service.ts rename to packages/core/types/src/modules-sdk/medusa-internal-service.ts index a16955c388..4434db597e 100644 --- a/packages/core/types/src/modules-sdk/internal-module-service.ts +++ b/packages/core/types/src/modules-sdk/medusa-internal-service.ts @@ -8,7 +8,7 @@ import { UpsertWithReplaceConfig, } from "../dal" -export interface InternalModuleService< +export interface IMedusaInternalService< TEntity extends {}, TContainer extends object = object > { diff --git a/packages/core/utils/src/modules-sdk/__tests__/internal-module-service-factory.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/medusa-internal-service.ts similarity index 93% rename from packages/core/utils/src/modules-sdk/__tests__/internal-module-service-factory.spec.ts rename to packages/core/utils/src/modules-sdk/__tests__/medusa-internal-service.ts index d5633294e3..56436e850e 100644 --- a/packages/core/utils/src/modules-sdk/__tests__/internal-module-service-factory.spec.ts +++ b/packages/core/utils/src/modules-sdk/__tests__/medusa-internal-service.ts @@ -1,4 +1,4 @@ -import { internalModuleServiceFactory } from "../internal-module-service-factory" +import { MedusaInternalService } from "../medusa-internal-service" import { lowerCaseFirst } from "../../common" const defaultContext = { __type: "MedusaContext" } @@ -39,14 +39,14 @@ describe("Internal Module Service Factory", () => { }, } - const internalModuleService = internalModuleServiceFactory(Model) + const IMedusaInternalService = MedusaInternalService(Model) describe("Internal Module Service Methods", () => { let instance beforeEach(() => { jest.clearAllMocks() - instance = new internalModuleService(containerMock) + instance = new IMedusaInternalService(containerMock) }) it("should throw model id undefined error on retrieve if id is not defined", async () => { @@ -62,10 +62,10 @@ describe("Internal Module Service Factory", () => { static meta = { primaryKeys: ["id", "name"] } } - const compositeInternalModuleService = - internalModuleServiceFactory(CompositeModel) + const compositeIMedusaInternalService = + MedusaInternalService(CompositeModel) - const instance = new compositeInternalModuleService(containerMock) + const instance = new compositeIMedusaInternalService(containerMock) const err = await instance.retrieve().catch((e) => e) expect(err.message).toBe("compositeModel - id, name must be defined") @@ -94,10 +94,10 @@ describe("Internal Module Service Factory", () => { static meta = { primaryKeys: ["id", "name"] } } - const compositeInternalModuleService = - internalModuleServiceFactory(CompositeModel) + const compositeIMedusaInternalService = + MedusaInternalService(CompositeModel) - const instance = new compositeInternalModuleService(containerMock) + const instance = new compositeIMedusaInternalService(containerMock) const entity = { id: "1", name: "Item" } containerMock[ diff --git a/packages/core/utils/src/modules-sdk/__tests__/abstract-module-service-factory.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/medusa-service.spec.ts similarity index 90% rename from packages/core/utils/src/modules-sdk/__tests__/abstract-module-service-factory.spec.ts rename to packages/core/utils/src/modules-sdk/__tests__/medusa-service.spec.ts index 140e301a1a..c0a30e1744 100644 --- a/packages/core/utils/src/modules-sdk/__tests__/abstract-module-service-factory.spec.ts +++ b/packages/core/utils/src/modules-sdk/__tests__/medusa-service.spec.ts @@ -1,4 +1,4 @@ -import { abstractModuleServiceFactory } from "../abstract-module-service-factory" +import { MedusaService } from "../medusa-service" const baseRepoMock = { serialize: jest.fn().mockImplementation((item) => item), @@ -41,13 +41,12 @@ describe("Abstract Module Service Factory", () => { }, } - const mainModelMock = class MainModelMock {} - const otherModelMock1 = class OtherModelMock1 {} - const otherModelMock2 = class OtherModelMock2 {} + class MainModelMock {} + class OtherModelMock1 {} + class OtherModelMock2 {} - const abstractModuleService = abstractModuleServiceFactory< - any, - any, + const abstractModuleService = MedusaService< + MainModelMock, { OtherModelMock1: { dto: any @@ -60,22 +59,10 @@ describe("Abstract Module Service Factory", () => { plural: "OtherModelMock2s" } } - >( - mainModelMock, - [ - { - model: otherModelMock1, - plural: "otherModelMock1s", - singular: "otherModelMock1", - }, - { - model: otherModelMock2, - plural: "otherModelMock2s", - singular: "otherModelMock2", - }, - ] - // Add more parameters as needed - ) + >(MainModelMock, { + OtherModelMock1, + OtherModelMock2, + }) describe("Main Model Methods", () => { let instance diff --git a/packages/core/utils/src/modules-sdk/index.ts b/packages/core/utils/src/modules-sdk/index.ts index a8430c6d61..f093862c76 100644 --- a/packages/core/utils/src/modules-sdk/index.ts +++ b/packages/core/utils/src/modules-sdk/index.ts @@ -6,7 +6,7 @@ export * from "./loaders/mikro-orm-connection-loader-factory" export * from "./loaders/container-loader-factory" export * from "./create-pg-connection" export * from "./migration-scripts" -export * from "./internal-module-service-factory" -export * from "./abstract-module-service-factory" +export * from "./medusa-internal-service" +export * from "./medusa-service" export * from "./definition" export * from "./event-builder-factory" diff --git a/packages/core/utils/src/modules-sdk/loaders/container-loader-factory.ts b/packages/core/utils/src/modules-sdk/loaders/container-loader-factory.ts index 6fc93ee105..a3939ba716 100644 --- a/packages/core/utils/src/modules-sdk/loaders/container-loader-factory.ts +++ b/packages/core/utils/src/modules-sdk/loaders/container-loader-factory.ts @@ -8,7 +8,7 @@ import { } from "@medusajs/types" import { asClass } from "awilix" -import { internalModuleServiceFactory } from "../internal-module-service-factory" +import { MedusaInternalService } from "../medusa-internal-service" import { lowerCaseFirst } from "../../common" import { MikroOrmBaseRepository, @@ -100,10 +100,7 @@ export function loadModuleServices({ const finalService = moduleServicesMap.get(mappedServiceName) if (!finalService) { - moduleServicesMap.set( - mappedServiceName, - internalModuleServiceFactory(Model) - ) + moduleServicesMap.set(mappedServiceName, MedusaInternalService(Model)) } }) diff --git a/packages/core/utils/src/modules-sdk/internal-module-service-factory.ts b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts similarity index 98% rename from packages/core/utils/src/modules-sdk/internal-module-service-factory.ts rename to packages/core/utils/src/modules-sdk/medusa-internal-service.ts index 10f871e49e..b859c404cf 100644 --- a/packages/core/utils/src/modules-sdk/internal-module-service-factory.ts +++ b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts @@ -33,20 +33,18 @@ type SelectorAndData = { data: any } -export function internalModuleServiceFactory< - TContainer extends object = object ->( +export function MedusaInternalService( model: any ): { new ( container: TContainer - ): ModulesSdkTypes.InternalModuleService + ): ModulesSdkTypes.IMedusaInternalService } { const injectedRepositoryName = `${lowerCaseFirst(model.name)}Repository` const propertyRepositoryName = `__${injectedRepositoryName}__` class AbstractService_ - implements ModulesSdkTypes.InternalModuleService + implements ModulesSdkTypes.IMedusaInternalService { readonly __container__: TContainer; [key: string]: any @@ -525,5 +523,5 @@ export function internalModuleServiceFactory< return AbstractService_ as unknown as new ( container: TContainer - ) => ModulesSdkTypes.InternalModuleService + ) => ModulesSdkTypes.IMedusaInternalService } diff --git a/packages/core/utils/src/modules-sdk/abstract-module-service-factory.ts b/packages/core/utils/src/modules-sdk/medusa-service.ts similarity index 65% rename from packages/core/utils/src/modules-sdk/abstract-module-service-factory.ts rename to packages/core/utils/src/modules-sdk/medusa-service.ts index 08f1565bfd..112b6721a3 100644 --- a/packages/core/utils/src/modules-sdk/abstract-module-service-factory.ts +++ b/packages/core/utils/src/modules-sdk/medusa-service.ts @@ -12,11 +12,11 @@ import { SoftDeleteReturn, } from "@medusajs/types" import { - MapToConfig, isString, kebabCase, lowerCaseFirst, mapObjectTo, + MapToConfig, pluralize, upperCaseFirst, } from "../common" @@ -25,6 +25,7 @@ import { InjectTransactionManager, MedusaContext, } from "./decorators" +import { ModuleRegistrationName } from "./definition" type BaseMethods = | "retrieve" @@ -49,68 +50,74 @@ const methods: BaseMethods[] = [...readMethods, ...writeMethods] type ModelDTOConfig = { dto: object - create?: object - update?: object -} -type ModelDTOConfigRecord = Record -type ModelNamingConfig = { + create?: any + update?: any + /** + * @internal + */ singular?: string + /** + * @internal + */ plural?: string } -type ModelsConfigTemplate = { - [ModelName: string]: ModelDTOConfig & ModelNamingConfig +type EntitiesConfigTemplate = { [key: string]: ModelDTOConfig } + +type ModelConfigurationToDto = + T extends abstract new (...args: any) => infer R + ? R + : T extends { dto: infer DTO } + ? DTO + : any + +type ModelConfigurationsToConfigTemplate< + T extends Record +> = { + [Key in keyof T as `${Capitalize}`]: { + dto: ModelConfigurationToDto + create: any + update: any + } } -type ExtractSingularName< - T extends Record, - K = keyof T -> = T[K] extends { singular?: string } ? T[K]["singular"] : K - -type CreateMethodName< - TModelDTOConfig extends ModelDTOConfigRecord, - TModelName = keyof TModelDTOConfig -> = TModelDTOConfig[TModelName] extends { create?: object } - ? `create${ExtractPluralName}` - : never - -type UpdateMethodName< - TModelDTOConfig extends ModelDTOConfigRecord, - TModelName = keyof TModelDTOConfig -> = TModelDTOConfig[TModelName] extends { update?: object } - ? `update${ExtractPluralName}` - : never +type ExtractSingularName, K = keyof T> = Capitalize< + T[K] extends { singular?: string } ? T[K]["singular"] & string : K & string +> type ExtractPluralName, K = keyof T> = T[K] extends { plural?: string } - ? T[K]["plural"] + ? T[K]["plural"] & string : Pluralize -type ModelConfiguration = - | Constructor - | { singular?: string; plural?: string; model: Constructor } +// TODO: this will be removed in the follow up pr once the main entity concept will be removed +type ModelConfiguration = Constructor | ModelDTOConfig | any -export interface AbstractModuleServiceBase { - get __container__(): TContainer +type ExtractMutationDtoOrAny = T extends unknown ? any : T + +export interface AbstractModuleServiceBase { + new (container: Record, ...args: any[]): this + + get __container__(): Record retrieve( id: string, config?: FindConfig, sharedContext?: Context - ): Promise + ): Promise list( filters?: any, config?: FindConfig, sharedContext?: Context - ): Promise + ): Promise listAndCount( filters?: any, config?: FindConfig, sharedContext?: Context - ): Promise<[TMainModelDTO[], number]> + ): Promise<[TEntryEntityConfig[], number]> delete( primaryKeyValues: string | object | string[] | object[], @@ -131,56 +138,50 @@ export interface AbstractModuleServiceBase { } export type AbstractModuleService< - TContainer, - TMainModelDTO, - TModelDTOConfig extends ModelsConfigTemplate -> = AbstractModuleServiceBase & { - [TModelName in keyof TModelDTOConfig as `retrieve${ExtractSingularName< - TModelDTOConfig, - TModelName - > & - string}`]: ( + TEntryEntityConfig extends ModelConfiguration, + TEntitiesDtoConfig extends EntitiesConfigTemplate +> = AbstractModuleServiceBase & { + [TEntityName in keyof TEntitiesDtoConfig as `retrieve${ExtractSingularName< + TEntitiesDtoConfig, + TEntityName + >}`]: ( id: string, config?: FindConfig, sharedContext?: Context - ) => Promise + ) => Promise } & { - [TModelName in keyof TModelDTOConfig as `list${ExtractPluralName< - TModelDTOConfig, - TModelName - > & - string}`]: ( + [TEntityName in keyof TEntitiesDtoConfig as `list${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: ( filters?: any, config?: FindConfig, sharedContext?: Context - ) => Promise + ) => Promise } & { - [TModelName in keyof TModelDTOConfig as `listAndCount${ExtractPluralName< - TModelDTOConfig, - TModelName - > & - string}`]: { + [TEntityName in keyof TEntitiesDtoConfig as `listAndCount${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { (filters?: any, config?: FindConfig, sharedContext?: Context): Promise< - [TModelDTOConfig[TModelName & string]["dto"][], number] + [TEntitiesDtoConfig[TEntityName]["dto"][], number] > } } & { - [TModelName in keyof TModelDTOConfig as `delete${ExtractPluralName< - TModelDTOConfig, - TModelName - > & - string}`]: { + [TEntityName in keyof TEntitiesDtoConfig as `delete${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { ( primaryKeyValues: string | object | string[] | object[], sharedContext?: Context ): Promise } } & { - [TModelName in keyof TModelDTOConfig as `softDelete${ExtractPluralName< - TModelDTOConfig, - TModelName - > & - string}`]: { + [TEntityName in keyof TEntitiesDtoConfig as `softDelete${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { ( primaryKeyValues: string | object | string[] | object[], config?: SoftDeleteReturn, @@ -188,11 +189,10 @@ export type AbstractModuleService< ): Promise | void> } } & { - [TModelName in keyof TModelDTOConfig as `restore${ExtractPluralName< - TModelDTOConfig, - TModelName - > & - string}`]: { + [TEntityName in keyof TEntitiesDtoConfig as `restore${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { ( primaryKeyValues: string | object | string[] | object[], config?: RestoreReturn, @@ -200,45 +200,103 @@ export type AbstractModuleService< ): Promise | void> } } & { - [TModelName in keyof TModelDTOConfig as CreateMethodName< - TModelDTOConfig, - TModelName - >]: { - ( - data: TModelDTOConfig[TModelName]["create"][], - sharedContext?: Context - ): Promise + [TEntityName in keyof TEntitiesDtoConfig as `create${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { + (...args: any[]): Promise } } & { - [TModelName in keyof TModelDTOConfig as CreateMethodName< - TModelDTOConfig, - TModelName - >]: { - ( - data: TModelDTOConfig[TModelName]["create"], - sharedContext?: Context - ): Promise + [TEntityName in keyof TEntitiesDtoConfig as `update${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { + (...args: any[]): Promise + } +} + +// TODO: Because of a bug, those methods were not made visible which now cause issues with the fix as our interface are not consistent with the expectations + +// are not consistent accross modules +/* & { + [TEntityName in keyof TEntitiesDtoConfig as `create${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { + (data: any[], sharedContext?: Context): Promise< + TEntitiesDtoConfig[TEntityName]["dto"][] + > } } & { - [TModelName in keyof TModelDTOConfig as UpdateMethodName< - TModelDTOConfig, - TModelName - >]: { - ( - data: TModelDTOConfig[TModelName]["update"][], - sharedContext?: Context - ): Promise + [TEntityName in keyof TEntitiesDtoConfig as `create${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { + (data: any, sharedContext?: Context): Promise< + TEntitiesDtoConfig[TEntityName]["dto"][] + > } } & { - [TModelName in keyof TModelDTOConfig as UpdateMethodName< - TModelDTOConfig, - TModelName - >]: { + [TEntityName in keyof TEntitiesDtoConfig as `update${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { ( - data: TModelDTOConfig[TModelName]["update"], + data: TEntitiesDtoConfig[TEntityName]["update"][], sharedContext?: Context - ): Promise + ): Promise } +} & { + [TEntityName in keyof TEntitiesDtoConfig as `update${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { + ( + data: TEntitiesDtoConfig[TEntityName]["update"], + sharedContext?: Context + ): Promise + } +} & { + [TEntityName in keyof TEntitiesDtoConfig as `update${ExtractPluralName< + TEntitiesDtoConfig, + TEntityName + >}`]: { + ( + idOrdSelector: any, + data: TEntitiesDtoConfig[TEntityName]["update"], + sharedContext?: Context + ): Promise + } +}*/ + +/** + * @internal + */ +function buildMethodNamesFromModel( + model: ModelConfiguration, + suffixed: boolean = true +): Record { + return methods.reduce((acc, method) => { + let modelName: string = "" + + if (method === "retrieve") { + modelName = + "singular" in model && model.singular + ? model.singular + : (model as { name: string }).name + } else { + modelName = + "plural" in model && model.plural + ? model.plural + : pluralize((model as { name: string }).name) + } + + const methodName = suffixed + ? `${method}${upperCaseFirst(modelName)}` + : method + + return { ...acc, [method]: methodName } + }, {}) } /** @@ -246,7 +304,7 @@ export type AbstractModuleService< * * @example * - * const otherModels = new Set([ + * const entities = { * Currency, * Price, * PriceList, @@ -255,12 +313,10 @@ export type AbstractModuleService< * PriceRule, * PriceSetRuleType, * RuleType, - * ]) + * } * - * const AbstractModuleService = ModulesSdkUtils.abstractModuleServiceFactory< - * InjectedDependencies, + * class MyService extends ModulesSdkUtils.MedusaService< * PricingTypes.PriceSetDTO, - * // The configuration of each entity also accept singular/plural properties, if not provided then it is using english pluralization * { * Currency: { dto: PricingTypes.CurrencyDTO } * Price: { dto: PricingTypes.PriceDTO } @@ -269,61 +325,55 @@ export type AbstractModuleService< * PriceList: { dto: PricingTypes.PriceListDTO } * PriceListRule: { dto: PricingTypes.PriceListRuleDTO } * } - * >(PriceSet, [...otherModels], entityNameToLinkableKeysMap) + * >(PriceSet, entities, entityNameToLinkableKeysMap) {} * - * @param mainModel - * @param otherModels + * @example + * + * // Here the DTO's and names will be inferred from the arguments + * + * const entities = { + * Currency, + * Price, + * PriceList, + * PriceListRule, + * PriceListRuleValue, + * PriceRule, + * PriceSetRuleType, + * RuleType, + * } + * + * class MyService extends ModulesSdkUtils.MedusaService(PriceSet, entities, entityNameToLinkableKeysMap) {} + * + * @param entryEntity + * @param entities * @param entityNameToLinkableKeysMap */ -export function abstractModuleServiceFactory< - TContainer, - TMainModelDTO, - ModelsConfig extends ModelsConfigTemplate +export function MedusaService< + TEntryEntityConfig extends ModelConfiguration = ModelConfiguration, + EntitiesConfig extends EntitiesConfigTemplate = { __empty: any }, + TEntities extends Record = Record< + string, + ModelConfiguration + > >( - mainModel: Constructor, - otherModels: ModelConfiguration[], + entryEntity: (TEntryEntityConfig & { name: string }) | Constructor, + entities: TEntities, entityNameToLinkableKeysMap: MapToConfig = {} ): { - new (container: TContainer): AbstractModuleService< - TContainer, - TMainModelDTO, - ModelsConfig + new (...args: any[]): AbstractModuleService< + ModelConfigurationToDto, + EntitiesConfig extends { __empty: any } + ? ModelConfigurationsToConfigTemplate + : EntitiesConfig > } { - const buildMethodNamesFromModel = ( - model: ModelConfiguration, - suffixed: boolean = true - ): Record => { - return methods.reduce((acc, method) => { - let modelName: string = "" - - if (method === "retrieve") { - modelName = - "singular" in model && model.singular - ? model.singular - : (model as Constructor).name - } else { - modelName = - "plural" in model && model.plural - ? model.plural - : pluralize((model as Constructor).name) - } - - const methodName = suffixed - ? `${method}${upperCaseFirst(modelName)}` - : method - - return { ...acc, [method]: methodName } - }, {}) - } - const buildAndAssignMethodImpl = function ( klassPrototype: any, method: string, methodName: string, - model: Constructor + modelName: string ): void { - const serviceRegistrationName = `${lowerCaseFirst(model.name)}Service` + const serviceRegistrationName = `${lowerCaseFirst(modelName)}Service` const applyMethod = function (impl: Function, contextIndex) { klassPrototype[methodName] = impl @@ -465,7 +515,7 @@ export function abstractModuleServiceFactory< await this.eventBusModuleService_?.emit( primaryKeyValues_.map((primaryKeyValue) => ({ - eventName: `${kebabCase(model.name)}.deleted`, + eventName: `${kebabCase(modelName)}.deleted`, data: isString(primaryKeyValue) ? { id: primaryKeyValue } : primaryKeyValue, @@ -500,7 +550,7 @@ export function abstractModuleServiceFactory< await this.eventBusModuleService_?.emit( softDeletedEntities.map(({ id }) => ({ - eventName: `${kebabCase(model.name)}.deleted`, + eventName: `${kebabCase(modelName)}.deleted`, metadata: { source: "", action: "", object: "" }, data: { id }, })) @@ -558,19 +608,19 @@ export function abstractModuleServiceFactory< } class AbstractModuleService_ { - readonly __container__: Record + readonly __container__: Record readonly baseRepository_: RepositoryService readonly eventBusModuleService_: IEventBusModuleService; [key: string]: any - constructor(container: Record) { + constructor(container: Record) { this.__container__ = container this.baseRepository_ = container.baseRepository const hasEventBusModuleService = Object.keys(this.__container__).find( // TODO: Should use ModuleRegistrationName.EVENT_BUS but it would require to move it to the utils package to prevent circular dependencies - (key) => key === "eventBusModuleService" + (key) => key === ModuleRegistrationName.EVENT_BUS ) this.eventBusModuleService_ = hasEventBusModuleService @@ -592,18 +642,18 @@ export function abstractModuleServiceFactory< } } - const mainModelMethods = buildMethodNamesFromModel(mainModel, false) + const entryEntityMethods = buildMethodNamesFromModel(entryEntity, false) /** * Build the main retrieve/list/listAndCount/delete/softDelete/restore methods for the main model */ - for (let [method, methodName] of Object.entries(mainModelMethods)) { + for (let [method, methodName] of Object.entries(entryEntityMethods)) { buildAndAssignMethodImpl( AbstractModuleService_.prototype, method, methodName, - mainModel + entryEntity.name ) } @@ -611,22 +661,26 @@ export function abstractModuleServiceFactory< * Build the retrieve/list/listAndCount/delete/softDelete/restore methods for all the other models */ - const otherModelsMethods: [ModelConfiguration, Record][] = - otherModels.map((model) => [model, buildMethodNamesFromModel(model)]) + const entitiesMethods: [ + string, + ModelConfiguration, + Record + ][] = Object.entries(entities).map(([name, config]) => [ + name, + config, + buildMethodNamesFromModel(config), + ]) - for (let [model, modelsMethods] of otherModelsMethods) { + for (let [modelName, model, modelsMethods] of entitiesMethods) { Object.entries(modelsMethods).forEach(([method, methodName]) => { - model = "model" in model ? model.model : model buildAndAssignMethodImpl( AbstractModuleService_.prototype, method, methodName, - model + modelName ) }) } - return AbstractModuleService_ as unknown as new ( - container: TContainer - ) => AbstractModuleService + return AbstractModuleService_ as any } diff --git a/packages/modules/api-key/src/services/api-key-module-service.ts b/packages/modules/api-key/src/services/api-key-module-service.ts index 2b1e32531a..860ea2ddaf 100644 --- a/packages/modules/api-key/src/services/api-key-module-service.ts +++ b/packages/modules/api-key/src/services/api-key-module-service.ts @@ -1,15 +1,15 @@ import crypto from "crypto" import util from "util" import { + ApiKeyTypes, Context, DAL, - ApiKeyTypes, + FilterableApiKeyProps, + FindConfig, IApiKeyModuleService, - ModulesSdkTypes, InternalModuleDeclaration, ModuleJoinerConfig, - FindConfig, - FilterableApiKeyProps, + ModulesSdkTypes, } from "@medusajs/types" import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" import { ApiKey } from "@models" @@ -23,35 +23,32 @@ import { ApiKeyType, InjectManager, InjectTransactionManager, + isObject, + isString, MedusaContext, MedusaError, ModulesSdkUtils, - isObject, - isString, promiseAll, } from "@medusajs/utils" const scrypt = util.promisify(crypto.scrypt) -const generateMethodForModels = [] - type InjectedDependencies = { baseRepository: DAL.RepositoryService - apiKeyService: ModulesSdkTypes.InternalModuleService + apiKeyService: ModulesSdkTypes.IMedusaInternalService } export default class ApiKeyModuleService - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< ApiKeyTypes.ApiKeyDTO, { ApiKey: { dto: ApiKeyTypes.ApiKeyDTO } } - >(ApiKey, generateMethodForModels, entityNameToLinkableKeysMap) + >(ApiKey, {}, entityNameToLinkableKeysMap) implements IApiKeyModuleService { protected baseRepository_: DAL.RepositoryService - protected readonly apiKeyService_: ModulesSdkTypes.InternalModuleService + protected readonly apiKeyService_: ModulesSdkTypes.IMedusaInternalService constructor( { baseRepository, apiKeyService }: InjectedDependencies, diff --git a/packages/modules/auth/src/services/auth-module.ts b/packages/modules/auth/src/services/auth-module.ts index 39397a69d0..3bee34f61e 100644 --- a/packages/modules/auth/src/services/auth-module.ts +++ b/packages/modules/auth/src/services/auth-module.ts @@ -21,23 +21,21 @@ import { ModulesSdkUtils, } from "@medusajs/utils" import AuthProviderService from "./auth-provider" -import { populate } from "dotenv" type InjectedDependencies = { baseRepository: DAL.RepositoryService - authIdentityService: ModulesSdkTypes.InternalModuleService - providerIdentityService: ModulesSdkTypes.InternalModuleService + authIdentityService: ModulesSdkTypes.IMedusaInternalService + providerIdentityService: ModulesSdkTypes.IMedusaInternalService authProviderService: AuthProviderService } -const generateMethodForModels = [AuthIdentity, ProviderIdentity] +const generateMethodForModels = { AuthIdentity, ProviderIdentity } export default class AuthModuleService< TAuthIdentity extends AuthIdentity = AuthIdentity, TProviderIdentity extends ProviderIdentity = ProviderIdentity > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< AuthTypes.AuthIdentityDTO, { AuthIdentity: { dto: AuthTypes.AuthIdentityDTO } @@ -47,8 +45,8 @@ export default class AuthModuleService< implements AuthTypes.IAuthModuleService { protected baseRepository_: DAL.RepositoryService - protected authIdentityService_: ModulesSdkTypes.InternalModuleService - protected providerIdentityService_: ModulesSdkTypes.InternalModuleService + protected authIdentityService_: ModulesSdkTypes.IMedusaInternalService + protected providerIdentityService_: ModulesSdkTypes.IMedusaInternalService protected readonly authProviderService_: AuthProviderService constructor( diff --git a/packages/modules/cart/src/services/cart-module.ts b/packages/modules/cart/src/services/cart-module.ts index 7dfb559004..adee5a7b3d 100644 --- a/packages/modules/cart/src/services/cart-module.ts +++ b/packages/modules/cart/src/services/cart-module.ts @@ -10,16 +10,16 @@ import { ModulesSdkTypes, } from "@medusajs/types" import { - InjectManager, - InjectTransactionManager, - MedusaContext, - MedusaError, - ModulesSdkUtils, createRawPropertiesFromBigNumber, decorateCartTotals, deduplicate, + InjectManager, + InjectTransactionManager, isObject, isString, + MedusaContext, + MedusaError, + ModulesSdkUtils, } from "@medusajs/utils" import { Address, @@ -43,17 +43,17 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" type InjectedDependencies = { baseRepository: DAL.RepositoryService - cartService: ModulesSdkTypes.InternalModuleService - addressService: ModulesSdkTypes.InternalModuleService - lineItemService: ModulesSdkTypes.InternalModuleService - shippingMethodAdjustmentService: ModulesSdkTypes.InternalModuleService - shippingMethodService: ModulesSdkTypes.InternalModuleService - lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService - lineItemTaxLineService: ModulesSdkTypes.InternalModuleService - shippingMethodTaxLineService: ModulesSdkTypes.InternalModuleService + cartService: ModulesSdkTypes.IMedusaInternalService + addressService: ModulesSdkTypes.IMedusaInternalService + lineItemService: ModulesSdkTypes.IMedusaInternalService + shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService + shippingMethodService: ModulesSdkTypes.IMedusaInternalService + lineItemAdjustmentService: ModulesSdkTypes.IMedusaInternalService + lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService + shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService } -const generateMethodForModels = [ +const generateMethodForModels = { Address, LineItem, LineItemAdjustment, @@ -61,7 +61,7 @@ const generateMethodForModels = [ ShippingMethod, ShippingMethodAdjustment, ShippingMethodTaxLine, -] +} export default class CartModuleService< TCart extends Cart = Cart, @@ -73,8 +73,7 @@ export default class CartModuleService< TShippingMethodTaxLine extends ShippingMethodTaxLine = ShippingMethodTaxLine, TShippingMethod extends ShippingMethod = ShippingMethod > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< CartTypes.CartDTO, { Address: { dto: CartTypes.CartAddressDTO } @@ -89,14 +88,14 @@ export default class CartModuleService< implements ICartModuleService { protected baseRepository_: DAL.RepositoryService - protected cartService_: ModulesSdkTypes.InternalModuleService - protected addressService_: ModulesSdkTypes.InternalModuleService - protected lineItemService_: ModulesSdkTypes.InternalModuleService - protected shippingMethodAdjustmentService_: ModulesSdkTypes.InternalModuleService - protected shippingMethodService_: ModulesSdkTypes.InternalModuleService - protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService - protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService - protected shippingMethodTaxLineService_: ModulesSdkTypes.InternalModuleService + protected cartService_: ModulesSdkTypes.IMedusaInternalService + protected addressService_: ModulesSdkTypes.IMedusaInternalService + protected lineItemService_: ModulesSdkTypes.IMedusaInternalService + protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService + protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService + protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService + protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService + protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService constructor( { @@ -449,6 +448,7 @@ export default class CartModuleService< return await this.lineItemService_.create(data, sharedContext) } + // @ts-ignore updateLineItems( data: CartTypes.UpdateLineItemWithSelectorDTO[] ): Promise @@ -541,6 +541,7 @@ export default class CartModuleService< return await this.lineItemService_.update(toUpdate, sharedContext) } + // @ts-ignore async createAddresses( data: CartTypes.CreateAddressDTO, sharedContext?: Context @@ -577,6 +578,7 @@ export default class CartModuleService< return await this.addressService_.create(data, sharedContext) } + // @ts-ignore async updateAddresses( data: CartTypes.UpdateAddressDTO, sharedContext?: Context diff --git a/packages/modules/currency/src/loaders/initial-data.ts b/packages/modules/currency/src/loaders/initial-data.ts index c4298af3f1..14f05dcf39 100644 --- a/packages/modules/currency/src/loaders/initial-data.ts +++ b/packages/modules/currency/src/loaders/initial-data.ts @@ -14,7 +14,7 @@ export default async ({ const logger = container.resolve(ContainerRegistrationKeys.LOGGER) ?? console const { currencyService_ } = container.resolve<{ - currencyService_: ModulesSdkTypes.InternalModuleService + currencyService_: ModulesSdkTypes.IMedusaInternalService }>(ModuleRegistrationName.CURRENCY) try { diff --git a/packages/modules/currency/src/services/currency-module-service.ts b/packages/modules/currency/src/services/currency-module-service.ts index a66ec983af..985adfedb7 100644 --- a/packages/modules/currency/src/services/currency-module-service.ts +++ b/packages/modules/currency/src/services/currency-module-service.ts @@ -1,30 +1,29 @@ import { + BaseFilterable, + Context, + CurrencyTypes, DAL, + FilterableCurrencyProps, + FindConfig, + ICurrencyModuleService, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, - ICurrencyModuleService, - CurrencyTypes, - Context, - FindConfig, - FilterableCurrencyProps, - BaseFilterable, } from "@medusajs/types" import { ModulesSdkUtils } from "@medusajs/utils" import { Currency } from "@models" import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" -const generateMethodForModels = [] +const generateMethodForModels = {} type InjectedDependencies = { baseRepository: DAL.RepositoryService - currencyService: ModulesSdkTypes.InternalModuleService + currencyService: ModulesSdkTypes.IMedusaInternalService } export default class CurrencyModuleService - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< CurrencyTypes.CurrencyDTO, { Currency: { dto: CurrencyTypes.CurrencyDTO } @@ -33,7 +32,7 @@ export default class CurrencyModuleService implements ICurrencyModuleService { protected baseRepository_: DAL.RepositoryService - protected readonly currencyService_: ModulesSdkTypes.InternalModuleService + protected readonly currencyService_: ModulesSdkTypes.IMedusaInternalService constructor( { baseRepository, currencyService }: InjectedDependencies, diff --git a/packages/modules/customer/src/services/customer-module.ts b/packages/modules/customer/src/services/customer-module.ts index 90d4d01ab7..1934868547 100644 --- a/packages/modules/customer/src/services/customer-module.ts +++ b/packages/modules/customer/src/services/customer-module.ts @@ -27,17 +27,17 @@ import { EntityManager } from "@mikro-orm/core" type InjectedDependencies = { baseRepository: DAL.RepositoryService - customerService: ModulesSdkTypes.InternalModuleService - addressService: ModulesSdkTypes.InternalModuleService - customerGroupService: ModulesSdkTypes.InternalModuleService - customerGroupCustomerService: ModulesSdkTypes.InternalModuleService + customerService: ModulesSdkTypes.IMedusaInternalService + addressService: ModulesSdkTypes.IMedusaInternalService + customerGroupService: ModulesSdkTypes.IMedusaInternalService + customerGroupCustomerService: ModulesSdkTypes.IMedusaInternalService } -const generateMethodForModels = [ - { model: Address, singular: "Address", plural: "Addresses" }, +const generateMethodForModels = { + Address: { singular: "Address", plural: "Addresses" }, CustomerGroup, CustomerGroupCustomer, -] +} export default class CustomerModuleService< TAddress extends Address = Address, @@ -45,8 +45,7 @@ export default class CustomerModuleService< TCustomerGroup extends CustomerGroup = CustomerGroup, TCustomerGroupCustomer extends CustomerGroupCustomer = CustomerGroupCustomer > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< CustomerDTO, { Address: { dto: any } @@ -57,10 +56,10 @@ export default class CustomerModuleService< implements ICustomerModuleService { protected baseRepository_: DAL.RepositoryService - protected customerService_: ModulesSdkTypes.InternalModuleService - protected addressService_: ModulesSdkTypes.InternalModuleService - protected customerGroupService_: ModulesSdkTypes.InternalModuleService - protected customerGroupCustomerService_: ModulesSdkTypes.InternalModuleService + protected customerService_: ModulesSdkTypes.IMedusaInternalService + protected addressService_: ModulesSdkTypes.IMedusaInternalService + protected customerGroupService_: ModulesSdkTypes.IMedusaInternalService + protected customerGroupCustomerService_: ModulesSdkTypes.IMedusaInternalService constructor( { @@ -233,6 +232,7 @@ export default class CustomerModuleService< }) } + // @ts-ignore async updateCustomerGroups( groupId: string, data: CustomerTypes.CustomerGroupUpdatableFields, @@ -372,6 +372,7 @@ export default class CustomerModuleService< ) } + // @ts-ignore async updateAddresses( addressId: string, data: CustomerTypes.UpdateCustomerAddressDTO, diff --git a/packages/modules/fulfillment/src/loaders/providers.ts b/packages/modules/fulfillment/src/loaders/providers.ts index ab0be93881..c844926881 100644 --- a/packages/modules/fulfillment/src/loaders/providers.ts +++ b/packages/modules/fulfillment/src/loaders/providers.ts @@ -66,7 +66,7 @@ async function syncDatabaseProviders({ container }) { container.resolve(FulfillmentIdentifiersRegistrationName) ?? [] ).filter(Boolean) - const providerService: ModulesSdkTypes.InternalModuleService = + const providerService: ModulesSdkTypes.IMedusaInternalService = container.resolve(providerServiceRegistrationKey) const providers = await providerService.list({}) diff --git a/packages/modules/fulfillment/src/services/fulfillment-module-service.ts b/packages/modules/fulfillment/src/services/fulfillment-module-service.ts index 1b4ea6db4a..435919a70b 100644 --- a/packages/modules/fulfillment/src/services/fulfillment-module-service.ts +++ b/packages/modules/fulfillment/src/services/fulfillment-module-service.ts @@ -14,18 +14,18 @@ import { UpdateServiceZoneDTO, } from "@medusajs/types" import { - EmitEvents, - InjectManager, - InjectTransactionManager, - MedusaContext, - MedusaError, - ModulesSdkUtils, arrayDifference, deepEqualObj, + EmitEvents, getSetDifference, + InjectManager, + InjectTransactionManager, isDefined, isPresent, isString, + MedusaContext, + MedusaError, + ModulesSdkUtils, promiseAll, } from "@medusajs/utils" import { @@ -52,7 +52,7 @@ import { UpdateShippingOptionsInput } from "../types/service" import { buildCreatedShippingOptionEvents } from "../utils/events" import FulfillmentProviderService from "./fulfillment-provider" -const generateMethodForModels = [ +const generateMethodForModels = { ServiceZone, ShippingOption, GeoZone, @@ -61,19 +61,19 @@ const generateMethodForModels = [ ShippingOptionType, FulfillmentProvider, // Not adding Fulfillment to not auto generate the methods under the hood and only provide the methods we want to expose8 -] +} type InjectedDependencies = { baseRepository: DAL.RepositoryService - fulfillmentSetService: ModulesSdkTypes.InternalModuleService - serviceZoneService: ModulesSdkTypes.InternalModuleService - geoZoneService: ModulesSdkTypes.InternalModuleService - shippingProfileService: ModulesSdkTypes.InternalModuleService - shippingOptionService: ModulesSdkTypes.InternalModuleService - shippingOptionRuleService: ModulesSdkTypes.InternalModuleService - shippingOptionTypeService: ModulesSdkTypes.InternalModuleService + fulfillmentSetService: ModulesSdkTypes.IMedusaInternalService + serviceZoneService: ModulesSdkTypes.IMedusaInternalService + geoZoneService: ModulesSdkTypes.IMedusaInternalService + shippingProfileService: ModulesSdkTypes.IMedusaInternalService + shippingOptionService: ModulesSdkTypes.IMedusaInternalService + shippingOptionRuleService: ModulesSdkTypes.IMedusaInternalService + shippingOptionTypeService: ModulesSdkTypes.IMedusaInternalService fulfillmentProviderService: FulfillmentProviderService - fulfillmentService: ModulesSdkTypes.InternalModuleService + fulfillmentService: ModulesSdkTypes.IMedusaInternalService } export default class FulfillmentModuleService< @@ -86,8 +86,7 @@ export default class FulfillmentModuleService< TSippingOptionTypeEntity extends ShippingOptionType = ShippingOptionType, TFulfillmentEntity extends Fulfillment = Fulfillment > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< FulfillmentTypes.FulfillmentSetDTO, { FulfillmentSet: { dto: FulfillmentTypes.FulfillmentSetDTO } @@ -103,15 +102,15 @@ export default class FulfillmentModuleService< implements IFulfillmentModuleService { protected baseRepository_: DAL.RepositoryService - protected readonly fulfillmentSetService_: ModulesSdkTypes.InternalModuleService - protected readonly serviceZoneService_: ModulesSdkTypes.InternalModuleService - protected readonly geoZoneService_: ModulesSdkTypes.InternalModuleService - protected readonly shippingProfileService_: ModulesSdkTypes.InternalModuleService - protected readonly shippingOptionService_: ModulesSdkTypes.InternalModuleService - protected readonly shippingOptionRuleService_: ModulesSdkTypes.InternalModuleService - protected readonly shippingOptionTypeService_: ModulesSdkTypes.InternalModuleService + protected readonly fulfillmentSetService_: ModulesSdkTypes.IMedusaInternalService + protected readonly serviceZoneService_: ModulesSdkTypes.IMedusaInternalService + protected readonly geoZoneService_: ModulesSdkTypes.IMedusaInternalService + protected readonly shippingProfileService_: ModulesSdkTypes.IMedusaInternalService + protected readonly shippingOptionService_: ModulesSdkTypes.IMedusaInternalService + protected readonly shippingOptionRuleService_: ModulesSdkTypes.IMedusaInternalService + protected readonly shippingOptionTypeService_: ModulesSdkTypes.IMedusaInternalService protected readonly fulfillmentProviderService_: FulfillmentProviderService - protected readonly fulfillmentService_: ModulesSdkTypes.InternalModuleService + protected readonly fulfillmentService_: ModulesSdkTypes.IMedusaInternalService constructor( { @@ -325,6 +324,7 @@ export default class FulfillmentModuleService< return createdFulfillmentSets } + // @ts-ignore createServiceZones( data: FulfillmentTypes.CreateServiceZoneDTO[], sharedContext?: Context @@ -388,6 +388,7 @@ export default class FulfillmentModuleService< return createdServiceZones } + // @ts-ignore createShippingOptions( data: FulfillmentTypes.CreateShippingOptionDTO[], sharedContext?: Context @@ -448,6 +449,7 @@ export default class FulfillmentModuleService< return createdSO } + // @ts-ignore createShippingProfiles( data: FulfillmentTypes.CreateShippingProfileDTO[], sharedContext?: Context @@ -501,6 +503,7 @@ export default class FulfillmentModuleService< return await this.shippingProfileService_.create(data_, sharedContext) } + // @ts-ignore createGeoZones( data: FulfillmentTypes.CreateGeoZoneDTO[], sharedContext?: Context @@ -537,6 +540,7 @@ export default class FulfillmentModuleService< ) } + // @ts-ignore async createShippingOptionRules( data: FulfillmentTypes.CreateShippingOptionRuleDTO[], sharedContext?: Context @@ -924,6 +928,7 @@ export default class FulfillmentModuleService< : updatedFulfillmentSets[0] } + // @ts-ignore updateServiceZones( id: string, data: FulfillmentTypes.UpdateServiceZoneDTO, @@ -1223,6 +1228,7 @@ export default class FulfillmentModuleService< return [...created, ...updated] } + // @ts-ignore updateShippingOptions( id: string, data: FulfillmentTypes.UpdateShippingOptionDTO, @@ -1540,6 +1546,7 @@ export default class FulfillmentModuleService< return [...created, ...updated] } + // @ts-ignore updateShippingProfiles( selector: FulfillmentTypes.FilterableShippingProfileProps, data: FulfillmentTypes.UpdateShippingProfileDTO, @@ -1643,6 +1650,7 @@ export default class FulfillmentModuleService< return Array.isArray(data) ? allProfiles : allProfiles[0] } + // @ts-ignore updateGeoZones( data: FulfillmentTypes.UpdateGeoZoneDTO[], sharedContext?: Context @@ -1685,6 +1693,7 @@ export default class FulfillmentModuleService< return Array.isArray(data) ? serialized : serialized[0] } + // @ts-ignore updateShippingOptionRules( data: FulfillmentTypes.UpdateShippingOptionRuleDTO[], sharedContext?: Context diff --git a/packages/modules/fulfillment/src/services/fulfillment-provider.ts b/packages/modules/fulfillment/src/services/fulfillment-provider.ts index e617268529..a2b23aa74c 100644 --- a/packages/modules/fulfillment/src/services/fulfillment-provider.ts +++ b/packages/modules/fulfillment/src/services/fulfillment-provider.ts @@ -14,7 +14,7 @@ type InjectedDependencies = { // TODO rework DTO's -export default class FulfillmentProviderService extends ModulesSdkUtils.internalModuleServiceFactory( +export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaInternalService( FulfillmentProvider ) { protected readonly fulfillmentProviderRepository_: DAL.RepositoryService diff --git a/packages/modules/inventory-next/src/services/inventory-level.ts b/packages/modules/inventory-next/src/services/inventory-level.ts index 9a3825a953..c9673f0965 100644 --- a/packages/modules/inventory-next/src/services/inventory-level.ts +++ b/packages/modules/inventory-next/src/services/inventory-level.ts @@ -10,7 +10,7 @@ type InjectedDependencies = { export default class InventoryLevelService< TEntity extends InventoryLevel = InventoryLevel -> extends ModulesSdkUtils.internalModuleServiceFactory( +> extends ModulesSdkUtils.MedusaInternalService( InventoryLevel ) { protected readonly inventoryLevelRepository: InventoryLevelRepository diff --git a/packages/modules/inventory-next/src/services/inventory-module.ts b/packages/modules/inventory-next/src/services/inventory-module.ts index 08a8ab2f7a..5185dff8ed 100644 --- a/packages/modules/inventory-next/src/services/inventory-module.ts +++ b/packages/modules/inventory-next/src/services/inventory-module.ts @@ -30,20 +30,23 @@ import InventoryLevelService from "./inventory-level" type InjectedDependencies = { baseRepository: DAL.RepositoryService - inventoryItemService: ModulesSdkTypes.InternalModuleService + inventoryItemService: ModulesSdkTypes.IMedusaInternalService inventoryLevelService: InventoryLevelService - reservationItemService: ModulesSdkTypes.InternalModuleService + reservationItemService: ModulesSdkTypes.IMedusaInternalService } -const generateMethodForModels = [InventoryItem, InventoryLevel, ReservationItem] +const generateMethodForModels = { + InventoryItem, + InventoryLevel, + ReservationItem, +} export default class InventoryModuleService< TInventoryItem extends InventoryItem = InventoryItem, TInventoryLevel extends InventoryLevel = InventoryLevel, TReservationItem extends ReservationItem = ReservationItem > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< InventoryNext.InventoryItemDTO, { InventoryItem: { @@ -61,8 +64,8 @@ export default class InventoryModuleService< { protected baseRepository_: DAL.RepositoryService - protected readonly inventoryItemService_: ModulesSdkTypes.InternalModuleService - protected readonly reservationItemService_: ModulesSdkTypes.InternalModuleService + protected readonly inventoryItemService_: ModulesSdkTypes.IMedusaInternalService + protected readonly reservationItemService_: ModulesSdkTypes.IMedusaInternalService protected readonly inventoryLevelService_: InventoryLevelService constructor( @@ -209,6 +212,7 @@ export default class InventoryModuleService< await promiseAll(checkLevels) } + // @ts-ignore async createReservationItems( input: InventoryNext.CreateReservationItemInput[], context?: Context @@ -365,6 +369,7 @@ export default class InventoryModuleService< return await this.inventoryItemService_.create(input) } + // @ts-ignore createInventoryLevels( input: InventoryNext.CreateInventoryLevelInput, context?: Context @@ -537,6 +542,7 @@ export default class InventoryModuleService< return await this.inventoryLevelService_.delete(inventoryLevel.id, context) } + // @ts-ignore async updateInventoryLevels( updates: InventoryTypes.BulkUpdateInventoryLevelInput[], context?: Context @@ -623,6 +629,7 @@ export default class InventoryModuleService< * @param context * @return The updated inventory level */ + // @ts-ignore async updateReservationItems( input: InventoryNext.UpdateReservationItemInput[], context?: Context diff --git a/packages/modules/notification/src/loaders/providers.ts b/packages/modules/notification/src/loaders/providers.ts index 9fc659f140..291e046528 100644 --- a/packages/modules/notification/src/loaders/providers.ts +++ b/packages/modules/notification/src/loaders/providers.ts @@ -62,7 +62,7 @@ async function syncDatabaseProviders({ const providerServiceRegistrationKey = lowerCaseFirst( NotificationProviderService.name ) - const providerService: ModulesSdkTypes.InternalModuleService = + const providerService: ModulesSdkTypes.IMedusaInternalService = container.resolve(providerServiceRegistrationKey) const logger = container.resolve(ContainerRegistrationKeys.LOGGER) ?? console diff --git a/packages/modules/notification/src/services/notification-module-service.ts b/packages/modules/notification/src/services/notification-module-service.ts index 32f20674a8..1413d04f09 100644 --- a/packages/modules/notification/src/services/notification-module-service.ts +++ b/packages/modules/notification/src/services/notification-module-service.ts @@ -1,37 +1,36 @@ import { Context, DAL, - NotificationTypes, INotificationModuleService, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, + NotificationTypes, } from "@medusajs/types" import { InjectManager, InjectTransactionManager, MedusaContext, + MedusaError, ModulesSdkUtils, promiseAll, - MedusaError, } from "@medusajs/utils" import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" import NotificationProviderService from "./notification-provider" import { NotificationModel, NotificationProvider } from "@models" -const generateMethodForModels = [NotificationProvider] +const generateMethodForModels = { NotificationProvider } type InjectedDependencies = { baseRepository: DAL.RepositoryService - notificationModelService: ModulesSdkTypes.InternalModuleService + notificationModelService: ModulesSdkTypes.IMedusaInternalService notificationProviderService: NotificationProviderService } export default class NotificationModuleService< TEntity extends NotificationModel = NotificationModel > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< NotificationTypes.NotificationDTO, { NotificationProvider: { dto: NotificationTypes.NotificationProviderDTO } @@ -40,7 +39,7 @@ export default class NotificationModuleService< implements INotificationModuleService { protected baseRepository_: DAL.RepositoryService - protected readonly notificationService_: ModulesSdkTypes.InternalModuleService + protected readonly notificationService_: ModulesSdkTypes.IMedusaInternalService protected readonly notificationProviderService_: NotificationProviderService constructor( diff --git a/packages/modules/notification/src/services/notification-provider.ts b/packages/modules/notification/src/services/notification-provider.ts index d75693e771..c0ebc4a4ec 100644 --- a/packages/modules/notification/src/services/notification-provider.ts +++ b/packages/modules/notification/src/services/notification-provider.ts @@ -1,5 +1,5 @@ -import { Constructor, DAL, NotificationTypes } from "@medusajs/types" -import { ModulesSdkUtils, MedusaError } from "@medusajs/utils" +import { DAL, NotificationTypes } from "@medusajs/types" +import { MedusaError, ModulesSdkUtils } from "@medusajs/utils" import { NotificationProvider } from "@models" import { NotificationProviderRegistrationPrefix } from "@types" @@ -10,7 +10,7 @@ type InjectedDependencies = { ]: NotificationTypes.INotificationProvider } -export default class NotificationProviderService extends ModulesSdkUtils.internalModuleServiceFactory( +export default class NotificationProviderService extends ModulesSdkUtils.MedusaInternalService( NotificationProvider ) { protected readonly notificationProviderRepository_: DAL.RepositoryService diff --git a/packages/modules/order/src/services/order-change-service.ts b/packages/modules/order/src/services/order-change-service.ts index 5a08689c09..205305dd9f 100644 --- a/packages/modules/order/src/services/order-change-service.ts +++ b/packages/modules/order/src/services/order-change-service.ts @@ -6,12 +6,12 @@ import { RepositoryService, } from "@medusajs/types" import { + deduplicate, InjectManager, InjectTransactionManager, MedusaContext, MedusaError, ModulesSdkUtils, - deduplicate, } from "@medusajs/utils" import { OrderChange } from "@models" import { OrderChangeStatus } from "@types" @@ -22,7 +22,7 @@ type InjectedDependencies = { export default class OrderChangeService< TEntity extends OrderChange = OrderChange -> extends ModulesSdkUtils.internalModuleServiceFactory( +> extends ModulesSdkUtils.MedusaInternalService( OrderChange ) { protected readonly orderChangeRepository_: RepositoryService diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index ed8e424812..eac8ea4b7d 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -76,24 +76,24 @@ import OrderService from "./order-service" type InjectedDependencies = { baseRepository: DAL.RepositoryService orderService: OrderService - addressService: ModulesSdkTypes.InternalModuleService - lineItemService: ModulesSdkTypes.InternalModuleService - shippingMethodAdjustmentService: ModulesSdkTypes.InternalModuleService - shippingMethodService: ModulesSdkTypes.InternalModuleService - lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService - lineItemTaxLineService: ModulesSdkTypes.InternalModuleService - shippingMethodTaxLineService: ModulesSdkTypes.InternalModuleService - transactionService: ModulesSdkTypes.InternalModuleService + addressService: ModulesSdkTypes.IMedusaInternalService + lineItemService: ModulesSdkTypes.IMedusaInternalService + shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService + shippingMethodService: ModulesSdkTypes.IMedusaInternalService + lineItemAdjustmentService: ModulesSdkTypes.IMedusaInternalService + lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService + shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService + transactionService: ModulesSdkTypes.IMedusaInternalService orderChangeService: OrderChangeService - orderChangeActionService: ModulesSdkTypes.InternalModuleService - orderItemService: ModulesSdkTypes.InternalModuleService - orderSummaryService: ModulesSdkTypes.InternalModuleService - orderShippingMethodService: ModulesSdkTypes.InternalModuleService - returnReasonService: ModulesSdkTypes.InternalModuleService - returnService: ModulesSdkTypes.InternalModuleService + orderChangeActionService: ModulesSdkTypes.IMedusaInternalService + orderItemService: ModulesSdkTypes.IMedusaInternalService + orderSummaryService: ModulesSdkTypes.IMedusaInternalService + orderShippingMethodService: ModulesSdkTypes.IMedusaInternalService + returnReasonService: ModulesSdkTypes.IMedusaInternalService + returnService: ModulesSdkTypes.IMedusaInternalService } -const generateMethodForModels = [ +const generateMethodForModels = { Address, LineItem, LineItemAdjustment, @@ -109,7 +109,7 @@ const generateMethodForModels = [ OrderShippingMethod, ReturnReason, Return, -] +} export default class OrderModuleService< TOrder extends Order = Order, @@ -129,8 +129,7 @@ export default class OrderModuleService< TReturnReason extends ReturnReason = ReturnReason, TReturn extends Return = Return > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< OrderTypes.OrderDTO, { Address: { dto: OrderTypes.OrderAddressDTO } @@ -156,21 +155,21 @@ export default class OrderModuleService< { protected baseRepository_: DAL.RepositoryService protected orderService_: OrderService - protected addressService_: ModulesSdkTypes.InternalModuleService - protected lineItemService_: ModulesSdkTypes.InternalModuleService - protected shippingMethodAdjustmentService_: ModulesSdkTypes.InternalModuleService - protected shippingMethodService_: ModulesSdkTypes.InternalModuleService - protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService - protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService - protected shippingMethodTaxLineService_: ModulesSdkTypes.InternalModuleService - protected transactionService_: ModulesSdkTypes.InternalModuleService + protected addressService_: ModulesSdkTypes.IMedusaInternalService + protected lineItemService_: ModulesSdkTypes.IMedusaInternalService + protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService + protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService + protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService + protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService + protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService + protected transactionService_: ModulesSdkTypes.IMedusaInternalService protected orderChangeService_: OrderChangeService - protected orderChangeActionService_: ModulesSdkTypes.InternalModuleService - protected orderItemService_: ModulesSdkTypes.InternalModuleService - protected orderSummaryService_: ModulesSdkTypes.InternalModuleService - protected orderShippingMethodService_: ModulesSdkTypes.InternalModuleService - protected returnReasonService_: ModulesSdkTypes.InternalModuleService - protected returnService_: ModulesSdkTypes.InternalModuleService + protected orderChangeActionService_: ModulesSdkTypes.IMedusaInternalService + protected orderItemService_: ModulesSdkTypes.IMedusaInternalService + protected orderSummaryService_: ModulesSdkTypes.IMedusaInternalService + protected orderShippingMethodService_: ModulesSdkTypes.IMedusaInternalService + protected returnReasonService_: ModulesSdkTypes.IMedusaInternalService + protected returnService_: ModulesSdkTypes.IMedusaInternalService constructor( { @@ -553,6 +552,7 @@ export default class OrderModuleService< return result } + // @ts-ignore createLineItems( data: OrderTypes.CreateOrderLineItemForOrderDTO ): Promise @@ -670,6 +670,7 @@ export default class OrderModuleService< return lineItems } + // @ts-ignore updateLineItems( data: OrderTypes.UpdateOrderLineItemWithSelectorDTO[] ): Promise @@ -883,6 +884,7 @@ export default class OrderModuleService< return await this.orderItemService_.update(toUpdate, sharedContext) } + // @ts-ignore async createAddresses( data: OrderTypes.CreateOrderAddressDTO, sharedContext?: Context @@ -919,6 +921,7 @@ export default class OrderModuleService< return await this.addressService_.create(data, sharedContext) } + // @ts-ignore async updateAddresses( data: OrderTypes.UpdateOrderAddressDTO, sharedContext?: Context @@ -955,6 +958,7 @@ export default class OrderModuleService< return await this.addressService_.update(data, sharedContext) } + // @ts-ignore async createShippingMethods( data: OrderTypes.CreateOrderShippingMethodDTO ): Promise @@ -1059,6 +1063,7 @@ export default class OrderModuleService< return sm.map((s) => s.shipping_method) } + // @ts-ignore async createLineItemAdjustments( adjustments: OrderTypes.CreateOrderLineItemAdjustmentDTO[] ): Promise @@ -1228,6 +1233,7 @@ export default class OrderModuleService< }) } + // @ts-ignore async createShippingMethodAdjustments( adjustments: OrderTypes.CreateOrderShippingMethodAdjustmentDTO[] ): Promise @@ -1302,6 +1308,7 @@ export default class OrderModuleService< }) } + // @ts-ignore createLineItemTaxLines( taxLines: OrderTypes.CreateOrderLineItemTaxLineDTO[] ): Promise @@ -1412,6 +1419,7 @@ export default class OrderModuleService< }) } + // @ts-ignore createShippingMethodTaxLines( taxLines: OrderTypes.CreateOrderShippingMethodTaxLineDTO[] ): Promise @@ -2319,6 +2327,7 @@ export default class OrderModuleService< await this.orderSummaryService_.update(summaries, sharedContext) } + // @ts-ignore async createReturnReasons( transactionData: OrderTypes.CreateOrderReturnReasonDTO, sharedContext?: Context @@ -2352,6 +2361,7 @@ export default class OrderModuleService< ) } + // @ts-ignore updateReturnReasons( data: OrderTypes.UpdateOrderReturnReasonWithSelectorDTO[] ): Promise diff --git a/packages/modules/order/src/services/order-service.ts b/packages/modules/order/src/services/order-service.ts index ba8961946b..fec0f7354b 100644 --- a/packages/modules/order/src/services/order-service.ts +++ b/packages/modules/order/src/services/order-service.ts @@ -19,7 +19,7 @@ type InjectedDependencies = { export default class OrderService< TEntity extends Order = Order -> extends ModulesSdkUtils.internalModuleServiceFactory( +> extends ModulesSdkUtils.MedusaInternalService( Order ) { protected readonly orderRepository_: RepositoryService diff --git a/packages/modules/payment/src/services/payment-module.ts b/packages/modules/payment/src/services/payment-module.ts index 1644b5aae4..e4fd5ec0ff 100644 --- a/packages/modules/payment/src/services/payment-module.ts +++ b/packages/modules/payment/src/services/payment-module.ts @@ -52,21 +52,21 @@ import PaymentProviderService from "./payment-provider" type InjectedDependencies = { baseRepository: DAL.RepositoryService - paymentService: ModulesSdkTypes.InternalModuleService - captureService: ModulesSdkTypes.InternalModuleService - refundService: ModulesSdkTypes.InternalModuleService - paymentSessionService: ModulesSdkTypes.InternalModuleService - paymentCollectionService: ModulesSdkTypes.InternalModuleService + paymentService: ModulesSdkTypes.IMedusaInternalService + captureService: ModulesSdkTypes.IMedusaInternalService + refundService: ModulesSdkTypes.IMedusaInternalService + paymentSessionService: ModulesSdkTypes.IMedusaInternalService + paymentCollectionService: ModulesSdkTypes.IMedusaInternalService paymentProviderService: PaymentProviderService } -const generateMethodForModels = [ +const generateMethodForModels = { PaymentCollection, Payment, PaymentSession, Capture, Refund, -] +} export default class PaymentModuleService< TPaymentCollection extends PaymentCollection = PaymentCollection, @@ -75,8 +75,7 @@ export default class PaymentModuleService< TRefund extends Refund = Refund, TPaymentSession extends PaymentSession = PaymentSession > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< PaymentCollectionDTO, { PaymentCollection: { dto: PaymentCollectionDTO } @@ -90,11 +89,11 @@ export default class PaymentModuleService< { protected baseRepository_: DAL.RepositoryService - protected paymentService_: ModulesSdkTypes.InternalModuleService - protected captureService_: ModulesSdkTypes.InternalModuleService - protected refundService_: ModulesSdkTypes.InternalModuleService - protected paymentSessionService_: ModulesSdkTypes.InternalModuleService - protected paymentCollectionService_: ModulesSdkTypes.InternalModuleService + protected paymentService_: ModulesSdkTypes.IMedusaInternalService + protected captureService_: ModulesSdkTypes.IMedusaInternalService + protected refundService_: ModulesSdkTypes.IMedusaInternalService + protected paymentSessionService_: ModulesSdkTypes.IMedusaInternalService + protected paymentCollectionService_: ModulesSdkTypes.IMedusaInternalService protected paymentProviderService_: PaymentProviderService constructor( @@ -126,6 +125,7 @@ export default class PaymentModuleService< return joinerConfig } + // @ts-ignore createPaymentCollections( data: CreatePaymentCollectionDTO, sharedContext?: Context @@ -160,9 +160,10 @@ export default class PaymentModuleService< data: CreatePaymentCollectionDTO[], @MedusaContext() sharedContext?: Context ): Promise { - return this.paymentCollectionService_.create(data, sharedContext) + return await this.paymentCollectionService_.create(data, sharedContext) } + // @ts-ignore updatePaymentCollections( paymentCollectionId: string, data: PaymentCollectionUpdatableFields, diff --git a/packages/modules/pricing/src/services/price-list.ts b/packages/modules/pricing/src/services/price-list.ts index 9810a6a8da..403377d8ef 100644 --- a/packages/modules/pricing/src/services/price-list.ts +++ b/packages/modules/pricing/src/services/price-list.ts @@ -9,7 +9,7 @@ type InjectedDependencies = { export default class PriceListService< TEntity extends PriceList = PriceList -> extends ModulesSdkUtils.internalModuleServiceFactory( +> extends ModulesSdkUtils.MedusaInternalService( PriceList ) { constructor(container: InjectedDependencies) { diff --git a/packages/modules/pricing/src/services/pricing-module.ts b/packages/modules/pricing/src/services/pricing-module.ts index 164e3b657b..467cb8a0fd 100644 --- a/packages/modules/pricing/src/services/pricing-module.ts +++ b/packages/modules/pricing/src/services/pricing-module.ts @@ -48,7 +48,7 @@ import { } from "@models" import { PriceListService, RuleTypeService } from "@services" -import { validatePriceListDates, eventBuilders } from "@utils" +import { eventBuilders, validatePriceListDates } from "@utils" import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" import { PriceListIdPrefix } from "../models/price-list" import { PriceSetIdPrefix } from "../models/price-set" @@ -57,17 +57,17 @@ import { ServiceTypes } from "@types" type InjectedDependencies = { baseRepository: DAL.RepositoryService pricingRepository: PricingRepositoryService - priceSetService: ModulesSdkTypes.InternalModuleService + priceSetService: ModulesSdkTypes.IMedusaInternalService ruleTypeService: RuleTypeService - priceRuleService: ModulesSdkTypes.InternalModuleService - priceSetRuleTypeService: ModulesSdkTypes.InternalModuleService - priceService: ModulesSdkTypes.InternalModuleService + priceRuleService: ModulesSdkTypes.IMedusaInternalService + priceSetRuleTypeService: ModulesSdkTypes.IMedusaInternalService + priceService: ModulesSdkTypes.IMedusaInternalService priceListService: PriceListService - priceListRuleService: ModulesSdkTypes.InternalModuleService - priceListRuleValueService: ModulesSdkTypes.InternalModuleService + priceListRuleService: ModulesSdkTypes.IMedusaInternalService + priceListRuleValueService: ModulesSdkTypes.IMedusaInternalService } -const generateMethodForModels = [ +const generateMethodForModels = { PriceList, PriceListRule, PriceListRuleValue, @@ -75,7 +75,7 @@ const generateMethodForModels = [ Price, PriceSetRuleType, RuleType, -] +} export default class PricingModuleService< TPriceSet extends PriceSet = PriceSet, @@ -87,8 +87,7 @@ export default class PricingModuleService< TPriceListRule extends PriceListRule = PriceListRule, TPriceListRuleValue extends PriceListRuleValue = PriceListRuleValue > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< PricingTypes.PriceSetDTO, { Price: { dto: PricingTypes.PriceDTO } @@ -111,13 +110,13 @@ export default class PricingModuleService< protected baseRepository_: DAL.RepositoryService protected readonly pricingRepository_: PricingRepositoryService protected readonly ruleTypeService_: RuleTypeService - protected readonly priceSetService_: ModulesSdkTypes.InternalModuleService - protected readonly priceRuleService_: ModulesSdkTypes.InternalModuleService - protected readonly priceSetRuleTypeService_: ModulesSdkTypes.InternalModuleService - protected readonly priceService_: ModulesSdkTypes.InternalModuleService + protected readonly priceSetService_: ModulesSdkTypes.IMedusaInternalService + protected readonly priceRuleService_: ModulesSdkTypes.IMedusaInternalService + protected readonly priceSetRuleTypeService_: ModulesSdkTypes.IMedusaInternalService + protected readonly priceService_: ModulesSdkTypes.IMedusaInternalService protected readonly priceListService_: PriceListService - protected readonly priceListRuleService_: ModulesSdkTypes.InternalModuleService - protected readonly priceListRuleValueService_: ModulesSdkTypes.InternalModuleService + protected readonly priceListRuleService_: ModulesSdkTypes.IMedusaInternalService + protected readonly priceListRuleValueService_: ModulesSdkTypes.IMedusaInternalService constructor( { @@ -641,6 +640,7 @@ export default class PricingModuleService< @InjectManager("baseRepository_") @EmitEvents() + // @ts-ignore async createPriceLists( data: PricingTypes.CreatePriceListDTO[], @MedusaContext() sharedContext: Context = {} @@ -653,6 +653,7 @@ export default class PricingModuleService< } @InjectTransactionManager("baseRepository_") + // @ts-ignore async updatePriceLists( data: PricingTypes.UpdatePriceListDTO[], @MedusaContext() sharedContext: Context = {} @@ -1334,7 +1335,7 @@ export default class PricingModuleService< sharedContext ) - ruleTypeMap.set(ruleAttribute, ruleType) + ruleTypeMap.set(ruleAttribute, ruleType!) } const [priceListRule] = await this.priceListRuleService_.create( diff --git a/packages/modules/pricing/src/services/rule-type.ts b/packages/modules/pricing/src/services/rule-type.ts index 52c3b8676c..b7ec25baa3 100644 --- a/packages/modules/pricing/src/services/rule-type.ts +++ b/packages/modules/pricing/src/services/rule-type.ts @@ -13,7 +13,7 @@ type InjectedDependencies = { export default class RuleTypeService< TEntity extends RuleType = RuleType -> extends ModulesSdkUtils.internalModuleServiceFactory( +> extends ModulesSdkUtils.MedusaInternalService( RuleType ) { protected readonly ruleTypeRepository_: DAL.RepositoryService diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index dd6c73ebab..2ac5023be3 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -58,25 +58,25 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "./../joiner-config" type InjectedDependencies = { baseRepository: DAL.RepositoryService productService: ProductService - productVariantService: ModulesSdkTypes.InternalModuleService - productTagService: ModulesSdkTypes.InternalModuleService + productVariantService: ModulesSdkTypes.IMedusaInternalService + productTagService: ModulesSdkTypes.IMedusaInternalService productCategoryService: ProductCategoryService - productCollectionService: ModulesSdkTypes.InternalModuleService - productImageService: ModulesSdkTypes.InternalModuleService - productTypeService: ModulesSdkTypes.InternalModuleService - productOptionService: ModulesSdkTypes.InternalModuleService - productOptionValueService: ModulesSdkTypes.InternalModuleService + productCollectionService: ModulesSdkTypes.IMedusaInternalService + productImageService: ModulesSdkTypes.IMedusaInternalService + productTypeService: ModulesSdkTypes.IMedusaInternalService + productOptionService: ModulesSdkTypes.IMedusaInternalService + productOptionValueService: ModulesSdkTypes.IMedusaInternalService eventBusModuleService?: IEventBusModuleService } -const generateMethodForModels = [ - { model: ProductCategory, singular: "Category", plural: "Categories" }, - { model: ProductCollection, singular: "Collection", plural: "Collections" }, - { model: ProductOption, singular: "Option", plural: "Options" }, - { model: ProductTag, singular: "Tag", plural: "Tags" }, - { model: ProductType, singular: "Type", plural: "Types" }, - { model: ProductVariant, singular: "Variant", plural: "Variants" }, -] +const generateMethodForModels = { + ProductCategory: { singular: "Category", plural: "Categories" }, + ProductCollection: { singular: "Collection", plural: "Collections" }, + ProductOption: { singular: "Option", plural: "Options" }, + ProductTag: { singular: "Tag", plural: "Tags" }, + ProductType: { singular: "Type", plural: "Types" }, + ProductVariant: { singular: "Variant", plural: "Variants" }, +} export default class ProductModuleService< TProduct extends Product = Product, @@ -89,8 +89,7 @@ export default class ProductModuleService< TProductOption extends ProductOption = ProductOption, TProductOptionValue extends ProductOptionValue = ProductOptionValue > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< ProductTypes.ProductDTO, { ProductCategory: { @@ -130,21 +129,21 @@ export default class ProductModuleService< protected baseRepository_: DAL.RepositoryService protected readonly productService_: ProductService // eslint-disable-next-line max-len - protected readonly productVariantService_: ModulesSdkTypes.InternalModuleService + protected readonly productVariantService_: ModulesSdkTypes.IMedusaInternalService // eslint-disable-next-line max-len protected readonly productCategoryService_: ProductCategoryService // eslint-disable-next-line max-len - protected readonly productTagService_: ModulesSdkTypes.InternalModuleService + protected readonly productTagService_: ModulesSdkTypes.IMedusaInternalService // eslint-disable-next-line max-len - protected readonly productCollectionService_: ModulesSdkTypes.InternalModuleService + protected readonly productCollectionService_: ModulesSdkTypes.IMedusaInternalService // eslint-disable-next-line max-len - protected readonly productImageService_: ModulesSdkTypes.InternalModuleService + protected readonly productImageService_: ModulesSdkTypes.IMedusaInternalService // eslint-disable-next-line max-len - protected readonly productTypeService_: ModulesSdkTypes.InternalModuleService + protected readonly productTypeService_: ModulesSdkTypes.IMedusaInternalService // eslint-disable-next-line max-len - protected readonly productOptionService_: ModulesSdkTypes.InternalModuleService + protected readonly productOptionService_: ModulesSdkTypes.IMedusaInternalService // eslint-disable-next-line max-len - protected readonly productOptionValueService_: ModulesSdkTypes.InternalModuleService + protected readonly productOptionValueService_: ModulesSdkTypes.IMedusaInternalService protected readonly eventBusModuleService_?: IEventBusModuleService constructor( @@ -185,6 +184,7 @@ export default class ProductModuleService< } // TODO: Add options validation, among other things + // @ts-ignore createVariants( data: ProductTypes.CreateProductVariantDTO[], sharedContext?: Context @@ -299,6 +299,7 @@ export default class ProductModuleService< return Array.isArray(data) ? allVariants : allVariants[0] } + // @ts-ignore updateVariants( id: string, data: ProductTypes.UpdateProductVariantDTO, @@ -413,6 +414,7 @@ export default class ProductModuleService< return productVariants } + // @ts-ignore createTags( data: ProductTypes.CreateProductTagDTO[], sharedContext?: Context @@ -491,6 +493,7 @@ export default class ProductModuleService< return Array.isArray(data) ? allTags : allTags[0] } + // @ts-ignore updateTags( id: string, data: ProductTypes.UpdateProductTagDTO, @@ -544,6 +547,7 @@ export default class ProductModuleService< return isString(idOrSelector) ? updatedTags[0] : updatedTags } + // @ts-ignore createTypes( data: ProductTypes.CreateProductTypeDTO[], sharedContext?: Context @@ -611,6 +615,7 @@ export default class ProductModuleService< return Array.isArray(data) ? allTypes : allTypes[0] } + // @ts-ignore updateTypes( id: string, data: ProductTypes.UpdateProductTypeDTO, @@ -658,6 +663,7 @@ export default class ProductModuleService< return isString(idOrSelector) ? updatedTypes[0] : updatedTypes } + // @ts-ignore createOptions( data: ProductTypes.CreateProductOptionDTO[], sharedContext?: Context @@ -754,6 +760,7 @@ export default class ProductModuleService< return Array.isArray(data) ? allOptions : allOptions[0] } + // @ts-ignore updateOptions( id: string, data: ProductTypes.UpdateProductOptionDTO, @@ -870,6 +877,7 @@ export default class ProductModuleService< return productOptions } + // @ts-ignore createCollections( data: ProductTypes.CreateProductCollectionDTO[], sharedContext?: Context @@ -989,6 +997,7 @@ export default class ProductModuleService< return Array.isArray(data) ? allCollections : allCollections[0] } + // @ts-ignore updateCollections( id: string, data: ProductTypes.UpdateProductCollectionDTO, @@ -1115,6 +1124,7 @@ export default class ProductModuleService< return collections } + // @ts-ignore createCategories( data: ProductTypes.CreateProductCategoryDTO[], sharedContext?: Context @@ -1218,6 +1228,7 @@ export default class ProductModuleService< return Array.isArray(data) ? result : result[0] } + // @ts-ignore updateCategories( id: string, data: ProductTypes.UpdateProductCategoryDTO, diff --git a/packages/modules/product/src/services/product.ts b/packages/modules/product/src/services/product.ts index 4532be530e..c5f4799a78 100644 --- a/packages/modules/product/src/services/product.ts +++ b/packages/modules/product/src/services/product.ts @@ -1,10 +1,9 @@ import { Context, DAL, + FilterableProductProps, FindConfig, ProductTypes, - BaseFilterable, - FilterableProductProps, } from "@medusajs/types" import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils" import { Product } from "@models" @@ -21,7 +20,7 @@ type NormalizedFilterableProductProps = ProductTypes.FilterableProductProps & { export default class ProductService< TEntity extends Product = Product -> extends ModulesSdkUtils.internalModuleServiceFactory( +> extends ModulesSdkUtils.MedusaInternalService( Product ) { protected readonly productRepository_: DAL.RepositoryService diff --git a/packages/modules/promotion/src/services/promotion-module.ts b/packages/modules/promotion/src/services/promotion-module.ts index 505250cf79..3f2bc7d183 100644 --- a/packages/modules/promotion/src/services/promotion-module.ts +++ b/packages/modules/promotion/src/services/promotion-module.ts @@ -10,20 +10,20 @@ import { import { ApplicationMethodAllocation, ApplicationMethodTargetType, + arrayDifference, CampaignBudgetType, ComputedActions, + deduplicate, InjectManager, InjectTransactionManager, + isDefined, + isPresent, + isString, MathBN, MedusaContext, MedusaError, ModulesSdkUtils, PromotionType, - arrayDifference, - deduplicate, - isDefined, - isPresent, - isString, transformPropertiesToBigNumber, } from "@medusajs/utils" import { @@ -47,9 +47,9 @@ import { UpdatePromotionDTO, } from "@types" import { - ComputeActionUtils, allowedAllocationForQuantity, areRulesValidForContext, + ComputeActionUtils, validateApplicationMethodAttributes, validatePromotionRuleAttributes, } from "@utils" @@ -58,21 +58,21 @@ import { CreatePromotionRuleValueDTO } from "../types/promotion-rule-value" type InjectedDependencies = { baseRepository: DAL.RepositoryService - promotionService: ModulesSdkTypes.InternalModuleService - applicationMethodService: ModulesSdkTypes.InternalModuleService - promotionRuleService: ModulesSdkTypes.InternalModuleService - promotionRuleValueService: ModulesSdkTypes.InternalModuleService - campaignService: ModulesSdkTypes.InternalModuleService - campaignBudgetService: ModulesSdkTypes.InternalModuleService + promotionService: ModulesSdkTypes.IMedusaInternalService + applicationMethodService: ModulesSdkTypes.IMedusaInternalService + promotionRuleService: ModulesSdkTypes.IMedusaInternalService + promotionRuleValueService: ModulesSdkTypes.IMedusaInternalService + campaignService: ModulesSdkTypes.IMedusaInternalService + campaignBudgetService: ModulesSdkTypes.IMedusaInternalService } -const generateMethodForModels = [ +const generateMethodForModels = { ApplicationMethod, Campaign, CampaignBudget, PromotionRule, PromotionRuleValue, -] +} export default class PromotionModuleService< TApplicationMethod extends ApplicationMethod = ApplicationMethod, @@ -82,8 +82,7 @@ export default class PromotionModuleService< TCampaign extends Campaign = Campaign, TCampaignBudget extends CampaignBudget = CampaignBudget > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< PromotionTypes.PromotionDTO, { ApplicationMethod: { dto: PromotionTypes.ApplicationMethodDTO } @@ -96,12 +95,12 @@ export default class PromotionModuleService< implements PromotionTypes.IPromotionModuleService { protected baseRepository_: DAL.RepositoryService - protected promotionService_: ModulesSdkTypes.InternalModuleService - protected applicationMethodService_: ModulesSdkTypes.InternalModuleService - protected promotionRuleService_: ModulesSdkTypes.InternalModuleService - protected promotionRuleValueService_: ModulesSdkTypes.InternalModuleService - protected campaignService_: ModulesSdkTypes.InternalModuleService - protected campaignBudgetService_: ModulesSdkTypes.InternalModuleService + protected promotionService_: ModulesSdkTypes.IMedusaInternalService + protected applicationMethodService_: ModulesSdkTypes.IMedusaInternalService + protected promotionRuleService_: ModulesSdkTypes.IMedusaInternalService + protected promotionRuleValueService_: ModulesSdkTypes.IMedusaInternalService + protected campaignService_: ModulesSdkTypes.IMedusaInternalService + protected campaignBudgetService_: ModulesSdkTypes.IMedusaInternalService constructor( { @@ -839,6 +838,7 @@ export default class PromotionModuleService< } @InjectManager("baseRepository_") + // @ts-ignore async updatePromotionRules( data: PromotionTypes.UpdatePromotionRuleDTO[], @MedusaContext() sharedContext: Context = {} @@ -848,7 +848,7 @@ export default class PromotionModuleService< sharedContext ) - return this.listPromotionRules( + return await this.listPromotionRules( { id: updatedPromotionRules.map((r) => r.id) }, { relations: ["values"] }, sharedContext @@ -1153,6 +1153,7 @@ export default class PromotionModuleService< ) } + // @ts-ignore async createCampaigns( data: PromotionTypes.CreateCampaignDTO, sharedContext?: Context @@ -1262,6 +1263,7 @@ export default class PromotionModuleService< } } + // @ts-ignore async updateCampaigns( data: PromotionTypes.UpdateCampaignDTO, sharedContext?: Context diff --git a/packages/modules/region/src/loaders/defaults.ts b/packages/modules/region/src/loaders/defaults.ts index 44d97521b5..d7b3d60c73 100644 --- a/packages/modules/region/src/loaders/defaults.ts +++ b/packages/modules/region/src/loaders/defaults.ts @@ -6,7 +6,7 @@ export default async ({ container }: LoaderOptions): Promise => { // TODO: Add default logger to the container when running tests const logger = container.resolve(ContainerRegistrationKeys.LOGGER) ?? console - const countryService_: ModulesSdkTypes.InternalModuleService = + const countryService_: ModulesSdkTypes.IMedusaInternalService = container.resolve("countryService") try { diff --git a/packages/modules/region/src/services/region-module.ts b/packages/modules/region/src/services/region-module.ts index 4b7b66e481..1ad48b15a9 100644 --- a/packages/modules/region/src/services/region-module.ts +++ b/packages/modules/region/src/services/region-module.ts @@ -32,18 +32,17 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" type InjectedDependencies = { baseRepository: DAL.RepositoryService - regionService: ModulesSdkTypes.InternalModuleService - countryService: ModulesSdkTypes.InternalModuleService + regionService: ModulesSdkTypes.IMedusaInternalService + countryService: ModulesSdkTypes.IMedusaInternalService } -const generateMethodForModels = [Country] +const generateMethodForModels = { Country } export default class RegionModuleService< TRegion extends Region = Region, TCountry extends Country = Country > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< RegionDTO, { Country: { @@ -54,8 +53,8 @@ export default class RegionModuleService< implements IRegionModuleService { protected baseRepository_: DAL.RepositoryService - protected readonly regionService_: ModulesSdkTypes.InternalModuleService - protected readonly countryService_: ModulesSdkTypes.InternalModuleService + protected readonly regionService_: ModulesSdkTypes.IMedusaInternalService + protected readonly countryService_: ModulesSdkTypes.IMedusaInternalService constructor( { baseRepository, regionService, countryService }: InjectedDependencies, diff --git a/packages/modules/sales-channel/src/services/sales-channel-module.ts b/packages/modules/sales-channel/src/services/sales-channel-module.ts index d44232e447..8fc3def9dc 100644 --- a/packages/modules/sales-channel/src/services/sales-channel-module.ts +++ b/packages/modules/sales-channel/src/services/sales-channel-module.ts @@ -27,21 +27,21 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" type InjectedDependencies = { baseRepository: DAL.RepositoryService - salesChannelService: ModulesSdkTypes.InternalModuleService + salesChannelService: ModulesSdkTypes.IMedusaInternalService } export default class SalesChannelModuleService< TEntity extends SalesChannel = SalesChannel > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, - SalesChannelDTO, - {} - >(SalesChannel, [], entityNameToLinkableKeysMap) + extends ModulesSdkUtils.MedusaService( + SalesChannel, + {}, + entityNameToLinkableKeysMap + ) implements ISalesChannelModuleService { protected baseRepository_: DAL.RepositoryService - protected readonly salesChannelService_: ModulesSdkTypes.InternalModuleService + protected readonly salesChannelService_: ModulesSdkTypes.IMedusaInternalService constructor( { baseRepository, salesChannelService }: InjectedDependencies, diff --git a/packages/modules/stock-location-next/src/services/stock-location-module.ts b/packages/modules/stock-location-next/src/services/stock-location-module.ts index 92de07a8a2..32b2f0f716 100644 --- a/packages/modules/stock-location-next/src/services/stock-location-module.ts +++ b/packages/modules/stock-location-next/src/services/stock-location-module.ts @@ -2,47 +2,45 @@ import { InternalModuleDeclaration } from "@medusajs/modules-sdk" import { Context, CreateStockLocationInput, + DAL, + FilterableStockLocationProps, IEventBusService, + IStockLocationServiceNext, ModuleJoinerConfig, + ModulesSdkTypes, StockLocationAddressInput, StockLocationTypes, - ModulesSdkTypes, - DAL, - IStockLocationServiceNext, - FilterableStockLocationProps, + UpdateStockLocationNextInput, + UpsertStockLocationInput, } from "@medusajs/types" import { InjectManager, InjectTransactionManager, + isString, MedusaContext, ModulesSdkUtils, - isString, + promiseAll, } from "@medusajs/utils" import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" import { StockLocation, StockLocationAddress } from "../models" -import { UpdateStockLocationNextInput } from "@medusajs/types" -import { UpsertStockLocationInput } from "@medusajs/types" -import { promiseAll } from "@medusajs/utils" type InjectedDependencies = { eventBusModuleService: IEventBusService baseRepository: DAL.RepositoryService - stockLocationService: ModulesSdkTypes.InternalModuleService - stockLocationAddressService: ModulesSdkTypes.InternalModuleService + stockLocationService: ModulesSdkTypes.IMedusaInternalService + stockLocationAddressService: ModulesSdkTypes.IMedusaInternalService } -const generateMethodForModels = [StockLocationAddress] +const generateMethodForModels = { StockLocationAddress } /** * Service for managing stock locations. */ - export default class StockLocationModuleService< TEntity extends StockLocation = StockLocation, TStockLocationAddress extends StockLocationAddress = StockLocationAddress > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< StockLocationTypes.StockLocationDTO, { StockLocation: { dto: StockLocationTypes.StockLocationDTO } @@ -53,8 +51,8 @@ export default class StockLocationModuleService< { protected readonly eventBusModuleService_: IEventBusService protected baseRepository_: DAL.RepositoryService - protected readonly stockLocationService_: ModulesSdkTypes.InternalModuleService - protected readonly stockLocationAddressService_: ModulesSdkTypes.InternalModuleService + protected readonly stockLocationService_: ModulesSdkTypes.IMedusaInternalService + protected readonly stockLocationAddressService_: ModulesSdkTypes.IMedusaInternalService constructor( { diff --git a/packages/modules/store/src/services/store-module-service.ts b/packages/modules/store/src/services/store-module-service.ts index 0c8d77e716..42cf6599a3 100644 --- a/packages/modules/store/src/services/store-module-service.ts +++ b/packages/modules/store/src/services/store-module-service.ts @@ -1,19 +1,19 @@ import { + Context, DAL, InternalModuleDeclaration, + IStoreModuleService, ModuleJoinerConfig, ModulesSdkTypes, - IStoreModuleService, StoreTypes, - Context, } from "@medusajs/types" import { InjectManager, InjectTransactionManager, + isString, MedusaContext, MedusaError, ModulesSdkUtils, - isString, promiseAll, removeUndefined, } from "@medusajs/utils" @@ -22,16 +22,15 @@ import { Store } from "@models" import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" import { UpdateStoreInput } from "@types" -const generateMethodForModels = [] +const generateMethodForModels = {} type InjectedDependencies = { baseRepository: DAL.RepositoryService - storeService: ModulesSdkTypes.InternalModuleService + storeService: ModulesSdkTypes.IMedusaInternalService } export default class StoreModuleService - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< StoreTypes.StoreDTO, { Store: { dto: StoreTypes.StoreDTO } @@ -40,7 +39,7 @@ export default class StoreModuleService implements IStoreModuleService { protected baseRepository_: DAL.RepositoryService - protected readonly storeService_: ModulesSdkTypes.InternalModuleService + protected readonly storeService_: ModulesSdkTypes.IMedusaInternalService constructor( { baseRepository, storeService }: InjectedDependencies, diff --git a/packages/modules/tax/src/services/tax-module-service.ts b/packages/modules/tax/src/services/tax-module-service.ts index 24b31f487e..651b9eeccc 100644 --- a/packages/modules/tax/src/services/tax-module-service.ts +++ b/packages/modules/tax/src/services/tax-module-service.ts @@ -1,9 +1,9 @@ import { Context, DAL, + InternalModuleDeclaration, ITaxModuleService, ITaxProvider, - InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, TaxRegionDTO, @@ -12,11 +12,11 @@ import { import { InjectManager, InjectTransactionManager, + isDefined, + isString, MedusaContext, MedusaError, ModulesSdkUtils, - isDefined, - isString, promiseAll, } from "@medusajs/utils" import { TaxProvider, TaxRate, TaxRateRule, TaxRegion } from "@models" @@ -24,14 +24,14 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" type InjectedDependencies = { baseRepository: DAL.RepositoryService - taxRateService: ModulesSdkTypes.InternalModuleService - taxRegionService: ModulesSdkTypes.InternalModuleService - taxRateRuleService: ModulesSdkTypes.InternalModuleService - taxProviderService: ModulesSdkTypes.InternalModuleService + taxRateService: ModulesSdkTypes.IMedusaInternalService + taxRegionService: ModulesSdkTypes.IMedusaInternalService + taxRateRuleService: ModulesSdkTypes.IMedusaInternalService + taxProviderService: ModulesSdkTypes.IMedusaInternalService [key: `tp_${string}`]: ITaxProvider } -const generateForModels = [TaxRegion, TaxRateRule, TaxProvider] +const generateForModels = { TaxRegion, TaxRateRule, TaxProvider } type ItemWithRates = { rates: TaxRate[] @@ -44,8 +44,7 @@ export default class TaxModuleService< TTaxRateRule extends TaxRateRule = TaxRateRule, TTaxProvider extends TaxProvider = TaxProvider > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< TaxTypes.TaxRateDTO, { TaxRegion: { dto: TaxTypes.TaxRegionDTO } @@ -57,10 +56,10 @@ export default class TaxModuleService< { protected readonly container_: InjectedDependencies protected baseRepository_: DAL.RepositoryService - protected taxRateService_: ModulesSdkTypes.InternalModuleService - protected taxRegionService_: ModulesSdkTypes.InternalModuleService - protected taxRateRuleService_: ModulesSdkTypes.InternalModuleService - protected taxProviderService_: ModulesSdkTypes.InternalModuleService + protected taxRateService_: ModulesSdkTypes.IMedusaInternalService + protected taxRegionService_: ModulesSdkTypes.IMedusaInternalService + protected taxRateRuleService_: ModulesSdkTypes.IMedusaInternalService + protected taxProviderService_: ModulesSdkTypes.IMedusaInternalService constructor( { @@ -293,6 +292,7 @@ export default class TaxModuleService< return Array.isArray(data) ? serialized : serialized[0] } + // @ts-ignore createTaxRegions( data: TaxTypes.CreateTaxRegionDTO, sharedContext?: Context @@ -349,6 +349,7 @@ export default class TaxModuleService< ) } + // @ts-ignore createTaxRateRules( data: TaxTypes.CreateTaxRateRuleDTO, sharedContext?: Context diff --git a/packages/modules/user/src/services/invite.ts b/packages/modules/user/src/services/invite.ts index 046fde37cf..52cf0fb437 100644 --- a/packages/modules/user/src/services/invite.ts +++ b/packages/modules/user/src/services/invite.ts @@ -2,10 +2,10 @@ import * as crypto from "crypto" import { Context, DAL } from "@medusajs/types" import { + arrayDifference, InjectTransactionManager, MedusaError, ModulesSdkUtils, - arrayDifference, } from "@medusajs/utils" import jwt, { JwtPayload } from "jsonwebtoken" @@ -21,7 +21,7 @@ const DEFAULT_VALID_INVITE_DURATION = 60 * 60 * 24 * 1000 export default class InviteService< TEntity extends Invite = Invite -> extends ModulesSdkUtils.internalModuleServiceFactory( +> extends ModulesSdkUtils.MedusaInternalService( Invite ) { // eslint-disable-next-line max-len diff --git a/packages/modules/user/src/services/user-module.ts b/packages/modules/user/src/services/user-module.ts index 3abb6532c9..6d243b76ae 100644 --- a/packages/modules/user/src/services/user-module.ts +++ b/packages/modules/user/src/services/user-module.ts @@ -23,19 +23,18 @@ import InviteService from "./invite" type InjectedDependencies = { baseRepository: DAL.RepositoryService - userService: ModulesSdkTypes.InternalModuleService + userService: ModulesSdkTypes.IMedusaInternalService inviteService: InviteService eventBusModuleService: IEventBusModuleService } -const generateMethodForModels = [Invite] +const generateMethodForModels = { Invite } export default class UserModuleService< TUser extends User = User, TInvite extends Invite = Invite > - extends ModulesSdkUtils.abstractModuleServiceFactory< - InjectedDependencies, + extends ModulesSdkUtils.MedusaService< UserTypes.UserDTO, { Invite: { @@ -51,7 +50,7 @@ export default class UserModuleService< protected baseRepository_: DAL.RepositoryService - protected readonly userService_: ModulesSdkTypes.InternalModuleService + protected readonly userService_: ModulesSdkTypes.IMedusaInternalService protected readonly inviteService_: InviteService constructor( @@ -199,6 +198,7 @@ export default class UserModuleService< return Array.isArray(data) ? serializedUsers : serializedUsers[0] } + // @ts-ignore createInvites( data: UserTypes.CreateInviteDTO[], sharedContext?: Context @@ -265,6 +265,7 @@ export default class UserModuleService< return await this.inviteService_.create(toCreate, sharedContext) } + // @ts-ignore updateInvites( data: UserTypes.UpdateInviteDTO[], sharedContext?: Context diff --git a/packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts b/packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts index 29cb6a15c6..77a82257d6 100644 --- a/packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts +++ b/packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts @@ -24,13 +24,13 @@ import { joinerConfig } from "../joiner-config" type InjectedDependencies = { baseRepository: DAL.RepositoryService - workflowExecutionService: ModulesSdkTypes.InternalModuleService + workflowExecutionService: ModulesSdkTypes.IMedusaInternalService workflowOrchestratorService: WorkflowOrchestratorService } export class WorkflowsModuleService implements IWorkflowEngineService { protected baseRepository_: DAL.RepositoryService - protected workflowExecutionService_: ModulesSdkTypes.InternalModuleService + protected workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService protected workflowOrchestratorService_: WorkflowOrchestratorService constructor( diff --git a/packages/modules/workflow-engine-inmemory/src/utils/workflow-orchestrator-storage.ts b/packages/modules/workflow-engine-inmemory/src/utils/workflow-orchestrator-storage.ts index e4a54abc8f..c59433e6ab 100644 --- a/packages/modules/workflow-engine-inmemory/src/utils/workflow-orchestrator-storage.ts +++ b/packages/modules/workflow-engine-inmemory/src/utils/workflow-orchestrator-storage.ts @@ -16,7 +16,7 @@ import { CronExpression, parseExpression } from "cron-parser" export class InMemoryDistributedTransactionStorage implements IDistributedTransactionStorage, IDistributedSchedulerStorage { - private workflowExecutionService_: ModulesSdkTypes.InternalModuleService + private workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService private workflowOrchestratorService_: WorkflowOrchestratorService private storage: Map = new Map() @@ -35,7 +35,7 @@ export class InMemoryDistributedTransactionStorage constructor({ workflowExecutionService, }: { - workflowExecutionService: ModulesSdkTypes.InternalModuleService + workflowExecutionService: ModulesSdkTypes.IMedusaInternalService }) { this.workflowExecutionService_ = workflowExecutionService } diff --git a/packages/modules/workflow-engine-redis/src/services/workflows-module.ts b/packages/modules/workflow-engine-redis/src/services/workflows-module.ts index 092c8563ed..3f6758a95b 100644 --- a/packages/modules/workflow-engine-redis/src/services/workflows-module.ts +++ b/packages/modules/workflow-engine-redis/src/services/workflows-module.ts @@ -24,14 +24,14 @@ import { joinerConfig } from "../joiner-config" type InjectedDependencies = { baseRepository: DAL.RepositoryService - workflowExecutionService: ModulesSdkTypes.InternalModuleService + workflowExecutionService: ModulesSdkTypes.IMedusaInternalService workflowOrchestratorService: WorkflowOrchestratorService redisDisconnectHandler: () => Promise } export class WorkflowsModuleService implements IWorkflowEngineService { protected baseRepository_: DAL.RepositoryService - protected workflowExecutionService_: ModulesSdkTypes.InternalModuleService + protected workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService protected workflowOrchestratorService_: WorkflowOrchestratorService protected redisDisconnectHandler_: () => Promise diff --git a/packages/modules/workflow-engine-redis/src/utils/workflow-orchestrator-storage.ts b/packages/modules/workflow-engine-redis/src/utils/workflow-orchestrator-storage.ts index 72edff2711..c12bb20bc0 100644 --- a/packages/modules/workflow-engine-redis/src/utils/workflow-orchestrator-storage.ts +++ b/packages/modules/workflow-engine-redis/src/utils/workflow-orchestrator-storage.ts @@ -24,7 +24,7 @@ export class RedisDistributedTransactionStorage implements IDistributedTransactionStorage, IDistributedSchedulerStorage { private static TTL_AFTER_COMPLETED = 60 * 15 // 15 minutes - private workflowExecutionService_: ModulesSdkTypes.InternalModuleService + private workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService private workflowOrchestratorService_: WorkflowOrchestratorService private redisClient: Redis @@ -37,7 +37,7 @@ export class RedisDistributedTransactionStorage redisWorkerConnection, redisQueueName, }: { - workflowExecutionService: ModulesSdkTypes.InternalModuleService + workflowExecutionService: ModulesSdkTypes.IMedusaInternalService redisConnection: Redis redisWorkerConnection: Redis redisQueueName: string