chore: Migrate modules to use the Module util (#7964)
**What** Apply the `Module` util to each module to handle the export and provide the linkable configuration object. - Most joiner config that does not have any special config are removed/cleaned up in favor of the autogenerated one or simpler one - linkable are now available in all modules - cleaned up the dependencies of the modules FIXES CORE-2410
This commit is contained in:
committed by
GitHub
parent
eafa3560ae
commit
b368251ca3
@@ -32,7 +32,7 @@ import { accessSync } from "fs"
|
||||
* then it will be inferred from the entity name of the alias args.
|
||||
*
|
||||
* @param serviceName
|
||||
* @param alias
|
||||
* @param alias custom aliases will be merged with the computed aliases from the provided models. Though, if a custom alias correspond to a computed alias for the same model then the custom alias will take place. Also, note that the methodSuffix will be inferred from the entity name if not provided as part of the args.
|
||||
* @param schema
|
||||
* @param models
|
||||
* @param linkableKeys
|
||||
@@ -72,11 +72,19 @@ export function defineJoinerConfig(
|
||||
|
||||
while (true) {
|
||||
++index
|
||||
const fullPath = getCallerFilePath(index)
|
||||
let fullPath = getCallerFilePath(index)
|
||||
if (!fullPath) {
|
||||
break
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle integration-tests/__tests__ path based on conventional naming
|
||||
*/
|
||||
if (fullPath.includes("integration-tests/__tests__")) {
|
||||
const sourcePath = fullPath.split("integration-tests/__tests__")[0]
|
||||
fullPath = path.join(sourcePath, "src")
|
||||
}
|
||||
|
||||
const srcDir = fullPath.includes("dist") ? "dist" : "src"
|
||||
const splitPath = fullPath.split(srcDir)
|
||||
|
||||
@@ -297,10 +305,10 @@ export function buildLinkableKeysFromMikroOrmObjects(
|
||||
* // {
|
||||
* // user: {
|
||||
* // id: {
|
||||
* // serviceName: 'userService',
|
||||
* // field: 'user',
|
||||
* // linkable: 'user_id',
|
||||
* // primaryKey: 'id'
|
||||
* // serviceName: 'userService', // The name of the module service it originate from
|
||||
* // field: 'user', // The field name of the entity, the query field is inferred from it as kebab cased singular/plural
|
||||
* // linkable: 'user_id', // The linkable key
|
||||
* // primaryKey: 'id' // The primary key if refers to in the original object representation, it will be used to be passed to the filters of the corresponding public service method
|
||||
* // },
|
||||
* // toJSON() { ... }
|
||||
* // },
|
||||
|
||||
@@ -53,7 +53,7 @@ export function Module<
|
||||
} else {
|
||||
linkable = buildLinkConfigFromLinkableKeys(
|
||||
serviceName,
|
||||
defaultJoinerConfig.linkableKeys
|
||||
service.prototype.__joinerConfig().linkableKeys
|
||||
) as Linkable
|
||||
}
|
||||
}
|
||||
|
||||
+21
-1
@@ -1,11 +1,12 @@
|
||||
import { IApiKeyModuleService } from "@medusajs/types"
|
||||
import { ApiKeyType, Modules } from "@medusajs/utils"
|
||||
import { ApiKeyType, Module, Modules } from "@medusajs/utils"
|
||||
import crypto from "crypto"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
createPublishableKeyFixture,
|
||||
createSecretKeyFixture,
|
||||
} from "../__fixtures__"
|
||||
import { ApiKeyModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -39,6 +40,25 @@ moduleIntegrationTestRunner<IApiKeyModuleService>({
|
||||
jest.restoreAllMocks()
|
||||
})
|
||||
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.API_KEY, {
|
||||
service: ApiKeyModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["apiKey"])
|
||||
|
||||
linkable.apiKey.toJSON = undefined
|
||||
|
||||
expect(linkable.apiKey).toEqual({
|
||||
id: {
|
||||
linkable: "api_key_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "apiKey",
|
||||
field: "apiKey",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("API Key Module Service", () => {
|
||||
describe("creating a publishable API key", () => {
|
||||
it("should create it successfully", async function () {
|
||||
|
||||
@@ -45,13 +45,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { ApiKeyModuleService } from "@services"
|
||||
|
||||
const moduleDefinition: ModuleExports = { service: ApiKeyModuleService }
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.API_KEY, {
|
||||
service: ApiKeyModuleService,
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.API_KEY)
|
||||
@@ -8,10 +8,8 @@ import {
|
||||
FindConfig,
|
||||
IApiKeyModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { ApiKey } from "@models"
|
||||
import {
|
||||
CreateApiKeyDTO,
|
||||
@@ -38,7 +36,7 @@ type InjectedDependencies = {
|
||||
apiKeyService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
export default class ApiKeyModuleService
|
||||
export class ApiKeyModuleService
|
||||
extends MedusaService<{
|
||||
ApiKey: { dto: ApiKeyTypes.ApiKeyDTO }
|
||||
}>({ ApiKey })
|
||||
@@ -57,9 +55,6 @@ export default class ApiKeyModuleService
|
||||
this.apiKeyService_ = apiKeyService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
//@ts-expect-error
|
||||
createApiKeys(
|
||||
data: ApiKeyTypes.CreateApiKeyDTO[],
|
||||
|
||||
@@ -1 +1 @@
|
||||
export { default as ApiKeyModuleService } from "./api-key-module-service"
|
||||
export { ApiKeyModuleService } from "./api-key-module-service"
|
||||
|
||||
+21
-1
@@ -1,7 +1,8 @@
|
||||
import { IAuthModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { resolve } from "path"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { AuthModuleService } from "@services"
|
||||
|
||||
let moduleOptions = {
|
||||
providers: [
|
||||
@@ -36,6 +37,25 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
})
|
||||
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.AUTH, {
|
||||
service: AuthModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["authIdentity"])
|
||||
|
||||
linkable.authIdentity.toJSON = undefined
|
||||
|
||||
expect(linkable.authIdentity).toEqual({
|
||||
id: {
|
||||
linkable: "auth_identity_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "auth",
|
||||
field: "authIdentity",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("it fails if the provider does not exist", async () => {
|
||||
const err = await service
|
||||
.authenticate("facebook", {
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.14",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
@@ -45,15 +46,12 @@
|
||||
"dependencies": {
|
||||
"@medusajs/auth-emailpass": "0.0.1",
|
||||
"@medusajs/modules-sdk": "^1.12.9",
|
||||
"@medusajs/types": "^1.11.14",
|
||||
"@medusajs/utils": "^1.11.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"knex": "2.4.2",
|
||||
"scrypt-kdf": "^2.0.1",
|
||||
"simple-oauth2": "^5.0.0"
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { AuthModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.AUTH, {
|
||||
service: AuthModuleService,
|
||||
loaders: [loadProviders] as any,
|
||||
}
|
||||
export default moduleDefinition
|
||||
loaders: [loadProviders],
|
||||
})
|
||||
|
||||
+108
-1
@@ -1,7 +1,8 @@
|
||||
import { ICartModuleService } from "@medusajs/types"
|
||||
import { BigNumber, Modules } from "@medusajs/utils"
|
||||
import { BigNumber, Module, Modules } from "@medusajs/utils"
|
||||
import { CheckConstraintViolationException } from "@mikro-orm/core"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { CartModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -9,6 +10,112 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
moduleName: Modules.CART,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Cart Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.CART, {
|
||||
service: CartModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"address",
|
||||
"adjustmentLine",
|
||||
"cart",
|
||||
"lineItemAdjustment",
|
||||
"lineItemTaxLine",
|
||||
"lineItem",
|
||||
"shippingMethodAdjustment",
|
||||
"shippingMethodTaxLine",
|
||||
"shippingMethod",
|
||||
"taxLine",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
address: {
|
||||
id: {
|
||||
linkable: "address_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "address",
|
||||
},
|
||||
},
|
||||
adjustmentLine: {
|
||||
id: {
|
||||
linkable: "adjustment_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "adjustmentLine",
|
||||
},
|
||||
},
|
||||
cart: {
|
||||
id: {
|
||||
linkable: "cart_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "cart",
|
||||
},
|
||||
},
|
||||
lineItemAdjustment: {
|
||||
id: {
|
||||
linkable: "line_item_adjustment_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "lineItemAdjustment",
|
||||
},
|
||||
},
|
||||
lineItemTaxLine: {
|
||||
id: {
|
||||
linkable: "line_item_tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "lineItemTaxLine",
|
||||
},
|
||||
},
|
||||
lineItem: {
|
||||
id: {
|
||||
linkable: "line_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "lineItem",
|
||||
},
|
||||
},
|
||||
shippingMethodAdjustment: {
|
||||
id: {
|
||||
linkable: "shipping_method_adjustment_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "shippingMethodAdjustment",
|
||||
},
|
||||
},
|
||||
shippingMethodTaxLine: {
|
||||
id: {
|
||||
linkable: "shipping_method_tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "shippingMethodTaxLine",
|
||||
},
|
||||
},
|
||||
shippingMethod: {
|
||||
id: {
|
||||
linkable: "shipping_method_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "shippingMethod",
|
||||
},
|
||||
},
|
||||
taxLine: {
|
||||
id: {
|
||||
linkable: "tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "taxLine",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should throw an error when required params are not passed", async () => {
|
||||
const error = await service
|
||||
|
||||
@@ -45,13 +45,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { CartModuleService } from "./services"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const service = CartModuleService
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.CART, {
|
||||
service: CartModuleService,
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CART)
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
FindConfig,
|
||||
ICartModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
@@ -39,7 +38,6 @@ import {
|
||||
UpdateLineItemDTO,
|
||||
UpdateShippingMethodTaxLineDTO,
|
||||
} from "@types"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -115,10 +113,6 @@ export default class CartModuleService
|
||||
this.lineItemTaxLineService_ = lineItemTaxLineService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
private shouldIncludeTotals(config: FindConfig<any>): boolean {
|
||||
const totalFields = [
|
||||
"total",
|
||||
|
||||
+25
-1
@@ -1,6 +1,7 @@
|
||||
import { ICurrencyModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { CurrencyModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -8,6 +9,29 @@ moduleIntegrationTestRunner<ICurrencyModuleService>({
|
||||
moduleName: Modules.CURRENCY,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Currency Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.CURRENCY, {
|
||||
service: CurrencyModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["currency"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
currency: {
|
||||
code: {
|
||||
linkable: "currency_code",
|
||||
primaryKey: "code",
|
||||
serviceName: "currency",
|
||||
field: "currency",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("list", () => {
|
||||
it("list currencies", async () => {
|
||||
const currenciesResult = await service.listCurrencies(
|
||||
|
||||
@@ -45,13 +45,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CURRENCY, {
|
||||
primaryKeys: ["code"],
|
||||
linkableKeys: {
|
||||
currency_code: "currency",
|
||||
},
|
||||
})
|
||||
@@ -7,13 +7,11 @@ import {
|
||||
FindConfig,
|
||||
ICurrencyModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { MedusaService } from "@medusajs/utils"
|
||||
import { Currency } from "@models"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -41,10 +39,6 @@ export default class CurrencyModuleService
|
||||
this.currencyService_ = currencyService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
async retrieveCurrency(
|
||||
code: string,
|
||||
|
||||
+54
-1
@@ -1,6 +1,7 @@
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { CustomerModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -8,6 +9,58 @@ moduleIntegrationTestRunner<ICustomerModuleService>({
|
||||
moduleName: Modules.CUSTOMER,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Customer Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.CUSTOMER, {
|
||||
service: CustomerModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"address",
|
||||
"customerGroupCustomer",
|
||||
"customerGroup",
|
||||
"customer",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
address: {
|
||||
id: {
|
||||
linkable: "address_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "customer",
|
||||
field: "address",
|
||||
},
|
||||
},
|
||||
customerGroupCustomer: {
|
||||
id: {
|
||||
linkable: "customer_group_customer_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "customer",
|
||||
field: "customerGroupCustomer",
|
||||
},
|
||||
},
|
||||
customerGroup: {
|
||||
id: {
|
||||
linkable: "customer_group_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "customer",
|
||||
field: "customerGroup",
|
||||
},
|
||||
},
|
||||
customer: {
|
||||
id: {
|
||||
linkable: "customer_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "customer",
|
||||
field: "customer",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should create a single customer", async () => {
|
||||
const customerData = {
|
||||
|
||||
@@ -50,8 +50,6 @@
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { CustomerModuleService } from "@services"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.CUSTOMER, {
|
||||
service: CustomerModuleService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
@@ -2,7 +2,8 @@ import { resolve } from "path"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { Entity, PrimaryKey } from "@mikro-orm/core"
|
||||
import { IFileModuleService } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { FileModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -31,6 +32,20 @@ moduleIntegrationTestRunner<IFileModuleService>({
|
||||
moduleModels: [DummyEntity],
|
||||
testSuite: ({ service }) => {
|
||||
describe("File Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.FILE, {
|
||||
service: FileModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({})
|
||||
})
|
||||
|
||||
it("creates and gets a file", async () => {
|
||||
const res = await service.createFiles({
|
||||
filename: "test.jpg",
|
||||
|
||||
@@ -47,14 +47,11 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.10",
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.8",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2",
|
||||
"lodash": "^4.17.21"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { FileModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const loaders = [loadProviders] as any
|
||||
|
||||
const service = FileModuleService
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.FILE, {
|
||||
service: FileModuleService,
|
||||
loaders: [loadProviders],
|
||||
})
|
||||
|
||||
+55
-3
@@ -1,11 +1,11 @@
|
||||
import { ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
import { FulfillmentSetDTO, IFulfillmentModuleService } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { FulfillmentProviderService } from "@services"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { FulfillmentModuleService, FulfillmentProviderService } from "@services"
|
||||
import {
|
||||
SuiteOptions,
|
||||
initModules,
|
||||
moduleIntegrationTestRunner,
|
||||
SuiteOptions,
|
||||
} from "medusa-test-utils"
|
||||
import { resolve } from "path"
|
||||
import { createFullDataStructure } from "../../__fixtures__"
|
||||
@@ -103,6 +103,58 @@ moduleIntegrationTestRunner({
|
||||
service,
|
||||
}: SuiteOptions<IFulfillmentModuleService>) =>
|
||||
describe("Fulfillment Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.FULFILLMENT, {
|
||||
service: FulfillmentModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"fulfillment",
|
||||
"fulfillmentSet",
|
||||
"shippingOption",
|
||||
"shippingOptionRule",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
fulfillment: {
|
||||
id: {
|
||||
linkable: "fulfillment_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "fulfillment",
|
||||
field: "fulfillment",
|
||||
},
|
||||
},
|
||||
fulfillmentSet: {
|
||||
id: {
|
||||
linkable: "fulfillment_set_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "fulfillment",
|
||||
field: "fulfillmentSet",
|
||||
},
|
||||
},
|
||||
shippingOption: {
|
||||
id: {
|
||||
linkable: "shipping_option_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "fulfillment",
|
||||
field: "shippingOption",
|
||||
},
|
||||
},
|
||||
shippingOptionRule: {
|
||||
id: {
|
||||
linkable: "shipping_option_rule_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "fulfillment",
|
||||
field: "shippingOptionRule",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("should load and save all the providers on bootstrap with the correct is_enabled value", async () => {
|
||||
const databaseConfig = {
|
||||
schema: "public",
|
||||
|
||||
@@ -51,8 +51,6 @@
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { FulfillmentModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const service = FulfillmentModuleService
|
||||
const loaders = [loadProviders]
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
}
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.FULFILLMENT, {
|
||||
service: FulfillmentModuleService,
|
||||
loaders: [loadProviders],
|
||||
})
|
||||
|
||||
// Module options types
|
||||
export { FulfillmentModuleOptions } from "./types"
|
||||
|
||||
+45
-1
@@ -1,6 +1,7 @@
|
||||
import { IInventoryService, InventoryItemDTO } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { InventoryModuleService } from "../../src/services"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -8,6 +9,49 @@ moduleIntegrationTestRunner<IInventoryService>({
|
||||
moduleName: Modules.INVENTORY,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Inventory Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.INVENTORY, {
|
||||
service: InventoryModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"inventoryItem",
|
||||
"inventoryLevel",
|
||||
"reservationItem",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
inventoryItem: {
|
||||
id: {
|
||||
field: "inventoryItem",
|
||||
linkable: "inventory_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "inventoryService",
|
||||
},
|
||||
},
|
||||
inventoryLevel: {
|
||||
id: {
|
||||
field: "inventoryLevel",
|
||||
linkable: "inventory_level_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "inventoryService",
|
||||
},
|
||||
},
|
||||
reservationItem: {
|
||||
id: {
|
||||
field: "reservationItem",
|
||||
linkable: "reservation_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "inventoryService",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should create an inventory item", async () => {
|
||||
const data = { sku: "test-sku", origin_country: "test-country" }
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
module.exports = {
|
||||
moduleNameMapper: {
|
||||
"^@models": "<rootDir>/src/models",
|
||||
"^@services": "<rootDir>/src/services",
|
||||
"^@repositories": "<rootDir>/src/repositories",
|
||||
"^@types": "<rootDir>/src/types",
|
||||
},
|
||||
transform: {
|
||||
"^.+\\.[jt]s$": [
|
||||
"@swc/jest",
|
||||
|
||||
@@ -36,9 +36,7 @@
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "tsc --build --watch",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import InventoryService from "./services/inventory-module"
|
||||
import InventoryModuleService from "./services/inventory-module"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
service: InventoryService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.INVENTORY, {
|
||||
service: InventoryModuleService,
|
||||
})
|
||||
|
||||
@@ -9,13 +9,6 @@ export const joinerConfig = defineJoinerConfig(Modules.INVENTORY, {
|
||||
methodSuffix: "InventoryItems",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["inventory_level", "inventory_levels"],
|
||||
args: {
|
||||
entity: "InventoryLevel",
|
||||
methodSuffix: "InventoryLevels",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: [
|
||||
"reservation",
|
||||
|
||||
+25
-1
@@ -1,7 +1,8 @@
|
||||
import { INotificationModuleService } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { resolve } from "path"
|
||||
import { NotificationModuleService } from "@services"
|
||||
|
||||
let moduleOptions = {
|
||||
providers: [
|
||||
@@ -26,6 +27,29 @@ moduleIntegrationTestRunner({
|
||||
moduleOptions,
|
||||
testSuite: ({ service }: SuiteOptions<INotificationModuleService>) =>
|
||||
describe("Notification Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.NOTIFICATION, {
|
||||
service: NotificationModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["notification"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
notification: {
|
||||
id: {
|
||||
linkable: "notification_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "notification",
|
||||
field: "notification",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("sends a notification and stores it in the database", async () => {
|
||||
const notification = {
|
||||
to: "admin@medusa.com",
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
@@ -45,13 +46,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { NotificationModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.NOTIFICATION, {
|
||||
service: NotificationModuleService,
|
||||
loaders: [loadProviders],
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.NOTIFICATION, {
|
||||
models: [{ name: "Notification" }],
|
||||
})
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
InferEntityType,
|
||||
INotificationModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
NotificationTypes,
|
||||
} from "@medusajs/types"
|
||||
@@ -17,7 +16,6 @@ import {
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { Notification } from "@models"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import NotificationProviderService from "./notification-provider"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -55,10 +53,6 @@ export default class NotificationModuleService
|
||||
this.notificationProviderService_ = notificationProviderService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
createNotifications(
|
||||
data: NotificationTypes.CreateNotificationDTO[],
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { IOrderModuleService } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { OrderModuleService } from "@services"
|
||||
|
||||
moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
moduleName: Modules.ORDER,
|
||||
testSuite: () => {
|
||||
describe("Order Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.ORDER, {
|
||||
service: OrderModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"address",
|
||||
"adjustmentLine",
|
||||
"claimItemImage",
|
||||
"orderClaimItem",
|
||||
"orderClaim",
|
||||
"orderExchangeItem",
|
||||
"orderExchange",
|
||||
"lineItemAdjustment",
|
||||
"lineItemTaxLine",
|
||||
"lineItem",
|
||||
"orderChangeAction",
|
||||
"orderChange",
|
||||
"orderItem",
|
||||
"orderShippingMethod",
|
||||
"orderSummary",
|
||||
"order",
|
||||
"returnItem",
|
||||
"returnReason",
|
||||
"return",
|
||||
"shippingMethodAdjustment",
|
||||
"shippingMethodTaxLine",
|
||||
"shippingMethod",
|
||||
"taxLine",
|
||||
"transaction",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
address: {
|
||||
id: {
|
||||
linkable: "address_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "address",
|
||||
},
|
||||
},
|
||||
adjustmentLine: {
|
||||
id: {
|
||||
linkable: "adjustment_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "adjustmentLine",
|
||||
},
|
||||
},
|
||||
claimItemImage: {
|
||||
id: {
|
||||
linkable: "claim_item_image_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "claimItemImage",
|
||||
},
|
||||
},
|
||||
orderClaimItem: {
|
||||
id: {
|
||||
linkable: "order_claim_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderClaimItem",
|
||||
},
|
||||
},
|
||||
orderClaim: {
|
||||
id: {
|
||||
linkable: "order_claim_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderClaim",
|
||||
},
|
||||
},
|
||||
orderExchangeItem: {
|
||||
id: {
|
||||
linkable: "order_exchange_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderExchangeItem",
|
||||
},
|
||||
},
|
||||
orderExchange: {
|
||||
id: {
|
||||
linkable: "order_exchange_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderExchange",
|
||||
},
|
||||
},
|
||||
lineItemAdjustment: {
|
||||
id: {
|
||||
linkable: "line_item_adjustment_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "lineItemAdjustment",
|
||||
},
|
||||
},
|
||||
lineItemTaxLine: {
|
||||
id: {
|
||||
linkable: "line_item_tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "lineItemTaxLine",
|
||||
},
|
||||
},
|
||||
lineItem: {
|
||||
id: {
|
||||
linkable: "line_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "lineItem",
|
||||
},
|
||||
},
|
||||
orderChangeAction: {
|
||||
id: {
|
||||
linkable: "order_change_action_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderChangeAction",
|
||||
},
|
||||
},
|
||||
orderChange: {
|
||||
id: {
|
||||
linkable: "order_change_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderChange",
|
||||
},
|
||||
},
|
||||
orderItem: {
|
||||
id: {
|
||||
linkable: "order_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderItem",
|
||||
},
|
||||
},
|
||||
orderShippingMethod: {
|
||||
id: {
|
||||
linkable: "order_shipping_method_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderShippingMethod",
|
||||
},
|
||||
},
|
||||
orderSummary: {
|
||||
id: {
|
||||
linkable: "order_summary_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "orderSummary",
|
||||
},
|
||||
},
|
||||
order: {
|
||||
id: {
|
||||
linkable: "order_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "order",
|
||||
},
|
||||
},
|
||||
returnItem: {
|
||||
id: {
|
||||
linkable: "return_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "returnItem",
|
||||
},
|
||||
},
|
||||
returnReason: {
|
||||
id: {
|
||||
linkable: "return_reason_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "returnReason",
|
||||
},
|
||||
},
|
||||
return: {
|
||||
id: {
|
||||
linkable: "return_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "return",
|
||||
},
|
||||
},
|
||||
shippingMethodAdjustment: {
|
||||
id: {
|
||||
linkable: "shipping_method_adjustment_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "shippingMethodAdjustment",
|
||||
},
|
||||
},
|
||||
shippingMethodTaxLine: {
|
||||
id: {
|
||||
linkable: "shipping_method_tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "shippingMethodTaxLine",
|
||||
},
|
||||
},
|
||||
shippingMethod: {
|
||||
id: {
|
||||
linkable: "shipping_method_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "shippingMethod",
|
||||
},
|
||||
},
|
||||
taxLine: {
|
||||
id: {
|
||||
linkable: "tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "taxLine",
|
||||
},
|
||||
},
|
||||
transaction: {
|
||||
id: {
|
||||
linkable: "transaction_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "order",
|
||||
field: "transaction",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -50,8 +50,6 @@
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { OrderModuleService } from "@services"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const service = OrderModuleService
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
}
|
||||
|
||||
export * from "./models"
|
||||
export * from "./services"
|
||||
export * from "./types"
|
||||
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.ORDER, {
|
||||
service: OrderModuleService,
|
||||
})
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
// TODO: review configuration
|
||||
export const joinerConfig = defineJoinerConfig(Modules.ORDER)
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
FindConfig,
|
||||
InternalModuleDeclaration,
|
||||
IOrderModuleService,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
OrderDTO,
|
||||
OrderTypes,
|
||||
@@ -65,7 +64,6 @@ import {
|
||||
UpdateOrderLineItemTaxLineDTO,
|
||||
UpdateOrderShippingMethodTaxLineDTO,
|
||||
} from "@types"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import {
|
||||
applyChangesToOrder,
|
||||
ApplyOrderChangeDTO,
|
||||
@@ -239,10 +237,6 @@ export default class OrderModuleService<
|
||||
this.orderExchangeService_ = orderExchangeService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
private shouldIncludeTotals(config: FindConfig<any>): boolean {
|
||||
const totalFields = [
|
||||
"total",
|
||||
|
||||
+46
-2
@@ -1,11 +1,12 @@
|
||||
import { IPaymentModuleService } from "@medusajs/types"
|
||||
import { Modules, promiseAll } from "@medusajs/utils"
|
||||
import { Module, Modules, promiseAll } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
createPaymentCollections,
|
||||
createPaymentSessions,
|
||||
createPayments,
|
||||
createPaymentSessions,
|
||||
} from "../../../__fixtures__"
|
||||
import { PaymentModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -13,6 +14,49 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
moduleName: Modules.PAYMENT,
|
||||
testSuite: ({ MikroOrmWrapper, service }) => {
|
||||
describe("Payment Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.PAYMENT, {
|
||||
service: PaymentModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"payment",
|
||||
"paymentCollection",
|
||||
"paymentProvider",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
payment: {
|
||||
id: {
|
||||
linkable: "payment_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "payment",
|
||||
field: "payment",
|
||||
},
|
||||
},
|
||||
paymentCollection: {
|
||||
id: {
|
||||
linkable: "payment_collection_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "payment",
|
||||
field: "paymentCollection",
|
||||
},
|
||||
},
|
||||
paymentProvider: {
|
||||
id: {
|
||||
linkable: "payment_provider_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "payment",
|
||||
field: "paymentProvider",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("Payment Flow", () => {
|
||||
it("complete payment flow successfully", async () => {
|
||||
let paymentCollection = await service.createPaymentCollections({
|
||||
|
||||
@@ -52,8 +52,6 @@
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"bignumber.js": "^9.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
|
||||
import { PaymentModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.PAYMENT, {
|
||||
service: PaymentModuleService,
|
||||
loaders: [loadProviders],
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
export { PaymentModuleOptions } from "./types"
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { PricingModuleService } from "@services"
|
||||
|
||||
moduleIntegrationTestRunner<IPricingModuleService>({
|
||||
moduleName: Modules.PRICING,
|
||||
testSuite: () => {
|
||||
describe("PricingModule Service - Calculate Price", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.PRICING, {
|
||||
service: PricingModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"priceSet",
|
||||
"priceList",
|
||||
"price",
|
||||
"pricePreference",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
priceSet: {
|
||||
id: {
|
||||
linkable: "price_set_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "pricingService",
|
||||
field: "priceSet",
|
||||
},
|
||||
},
|
||||
priceList: {
|
||||
id: {
|
||||
linkable: "price_list_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "pricingService",
|
||||
field: "priceList",
|
||||
},
|
||||
},
|
||||
price: {
|
||||
id: {
|
||||
linkable: "price_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "pricingService",
|
||||
field: "price",
|
||||
},
|
||||
},
|
||||
pricePreference: {
|
||||
id: {
|
||||
linkable: "price_preference_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "pricingService",
|
||||
field: "pricePreference",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -34,6 +34,7 @@
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
@@ -45,14 +46,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { PricingModuleService } from "@services"
|
||||
|
||||
const service = PricingModuleService
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.PRICING, {
|
||||
service: PricingModuleService,
|
||||
})
|
||||
|
||||
export * from "./types"
|
||||
|
||||
@@ -3,10 +3,4 @@ import { Price, PriceList, PricePreference, PriceSet } from "@models"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.PRICING, {
|
||||
models: [PriceSet, PriceList, Price, PricePreference],
|
||||
linkableKeys: {
|
||||
price_set_id: PriceSet.name,
|
||||
price_list_id: PriceList.name,
|
||||
price_id: Price.name,
|
||||
price_preference_id: PricePreference.name,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -9,9 +9,13 @@ import {
|
||||
} from "../__fixtures__/product"
|
||||
|
||||
import { IProductModuleService, ProductDTO } from "@medusajs/types"
|
||||
import { kebabCase, Modules, ProductStatus } from "@medusajs/utils"
|
||||
import { kebabCase, Module, Modules, ProductStatus } from "@medusajs/utils"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { ProductCategoryService, ProductService } from "@services"
|
||||
import {
|
||||
ProductCategoryService,
|
||||
ProductModuleService,
|
||||
ProductService,
|
||||
} from "@services"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
categoriesData,
|
||||
@@ -37,6 +41,94 @@ moduleIntegrationTestRunner<Service>({
|
||||
categoryService = moduleService.productCategoryService_
|
||||
})
|
||||
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.PRODUCT, {
|
||||
service: ProductModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"product",
|
||||
"productVariant",
|
||||
"productOption",
|
||||
"productType",
|
||||
"productImage",
|
||||
"productTag",
|
||||
"productCollection",
|
||||
"productCategory",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
product: {
|
||||
id: {
|
||||
linkable: "product_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "productService",
|
||||
field: "product",
|
||||
},
|
||||
},
|
||||
productVariant: {
|
||||
id: {
|
||||
linkable: "product_variant_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "productService",
|
||||
field: "productVariant",
|
||||
},
|
||||
},
|
||||
productOption: {
|
||||
id: {
|
||||
linkable: "product_option_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "productService",
|
||||
field: "productOption",
|
||||
},
|
||||
},
|
||||
productType: {
|
||||
id: {
|
||||
linkable: "product_type_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "productService",
|
||||
field: "productType",
|
||||
},
|
||||
},
|
||||
productImage: {
|
||||
id: {
|
||||
linkable: "product_image_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "productService",
|
||||
field: "productImage",
|
||||
},
|
||||
},
|
||||
productTag: {
|
||||
id: {
|
||||
linkable: "product_tag_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "productService",
|
||||
field: "productTag",
|
||||
},
|
||||
},
|
||||
productCollection: {
|
||||
id: {
|
||||
linkable: "product_collection_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "productService",
|
||||
field: "productCollection",
|
||||
},
|
||||
},
|
||||
productCategory: {
|
||||
id: {
|
||||
linkable: "product_category_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "productService",
|
||||
field: "productCategory",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("Product Service", () => {
|
||||
let testManager: SqlEntityManager
|
||||
let products!: Product[]
|
||||
|
||||
@@ -47,14 +47,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2",
|
||||
"lodash": "^4.17.21"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { ProductModuleService } from "@services"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.PRODUCT, {
|
||||
service: ProductModuleService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
@@ -1,56 +1,33 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
import {
|
||||
Product,
|
||||
ProductCategory,
|
||||
ProductCollection,
|
||||
ProductOption,
|
||||
ProductTag,
|
||||
ProductType,
|
||||
ProductVariant,
|
||||
} from "@models"
|
||||
import ProductImage from "./models/product-image"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.PRODUCT, {
|
||||
models: [
|
||||
Product,
|
||||
ProductVariant,
|
||||
ProductOption,
|
||||
ProductType,
|
||||
ProductImage,
|
||||
ProductTag,
|
||||
ProductCollection,
|
||||
ProductCategory,
|
||||
],
|
||||
primaryKeys: ["id", "handle"],
|
||||
// This module provides more alias than the default config builder
|
||||
alias: [
|
||||
{
|
||||
name: ["product", "products"],
|
||||
args: {
|
||||
entity: "Product",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["product_variant", "product_variants", "variant", "variants"],
|
||||
args: {
|
||||
entity: "ProductVariant",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["product_option", "product_options"],
|
||||
args: {
|
||||
entity: "ProductOption",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["product_type", "product_types"],
|
||||
args: {
|
||||
entity: "ProductType",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["product_image", "product_images"],
|
||||
args: {
|
||||
entity: "ProductImage",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["product_tag", "product_tags"],
|
||||
args: {
|
||||
entity: "ProductTag",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["product_collection", "product_collections"],
|
||||
args: {
|
||||
entity: "ProductCollection",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["product_category", "product_categories"],
|
||||
args: {
|
||||
entity: "ProductCategory",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
+45
@@ -2,6 +2,7 @@ import { IPromotionModuleService } from "@medusajs/types"
|
||||
import {
|
||||
ApplicationMethodType,
|
||||
CampaignBudgetType,
|
||||
Module,
|
||||
Modules,
|
||||
PromotionType,
|
||||
} from "@medusajs/utils"
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
createDefaultPromotions,
|
||||
createPromotions,
|
||||
} from "../../../__fixtures__/promotion"
|
||||
import { PromotionModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -26,6 +28,49 @@ moduleIntegrationTestRunner({
|
||||
await createCampaigns(MikroOrmWrapper.forkManager())
|
||||
})
|
||||
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.PROMOTION, {
|
||||
service: PromotionModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"promotion",
|
||||
"campaign",
|
||||
"promotionRule",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
promotion: {
|
||||
id: {
|
||||
linkable: "promotion_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "promotion",
|
||||
field: "promotion",
|
||||
},
|
||||
},
|
||||
campaign: {
|
||||
id: {
|
||||
linkable: "campaign_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "promotion",
|
||||
field: "campaign",
|
||||
},
|
||||
},
|
||||
promotionRule: {
|
||||
id: {
|
||||
linkable: "promotion_rule_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "promotion",
|
||||
field: "promotionRule",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should throw an error when required params are not passed", async () => {
|
||||
const error = await createDefaultPromotion(service, {
|
||||
|
||||
@@ -46,13 +46,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { PromotionModuleService } from "@services"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.PROMOTION, {
|
||||
service: PromotionModuleService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
@@ -3,9 +3,4 @@ import { Campaign, Promotion, PromotionRule } from "@models"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.PROMOTION, {
|
||||
models: [Promotion, Campaign, PromotionRule],
|
||||
linkableKeys: {
|
||||
promotion_id: Promotion.name,
|
||||
campaign_id: Campaign.name,
|
||||
promotion_rule_id: PromotionRule.name,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { IRegionModuleService } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { RegionModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -8,6 +9,37 @@ moduleIntegrationTestRunner<IRegionModuleService>({
|
||||
moduleName: Modules.REGION,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Region Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.REGION, {
|
||||
service: RegionModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["region", "country"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
region: {
|
||||
id: {
|
||||
linkable: "region_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "region",
|
||||
field: "region",
|
||||
},
|
||||
},
|
||||
country: {
|
||||
iso_2: {
|
||||
linkable: "country_iso_2",
|
||||
primaryKey: "iso_2",
|
||||
serviceName: "region",
|
||||
field: "country",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("should create countries on application start", async () => {
|
||||
const countries = await service.listCountries({}, { take: null })
|
||||
expect(countries.length).toEqual(250)
|
||||
|
||||
@@ -45,13 +45,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.REGION)
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
InferEntityType,
|
||||
InternalModuleDeclaration,
|
||||
IRegionModuleService,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
RegionCountryDTO,
|
||||
RegionDTO,
|
||||
@@ -28,7 +27,6 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { Country, Region } from "@models"
|
||||
import { UpdateRegionInput } from "@types"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -68,10 +66,6 @@ export default class RegionModuleService
|
||||
this.countryService_ = countryService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
async createRegions(
|
||||
data: CreateRegionDTO[],
|
||||
|
||||
+25
-1
@@ -1,6 +1,7 @@
|
||||
import { ISalesChannelModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { SalesChannelModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -33,6 +34,29 @@ moduleIntegrationTestRunner<ISalesChannelModuleService>({
|
||||
await service.createSalesChannels(salesChannelData)
|
||||
})
|
||||
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.SALES_CHANNEL, {
|
||||
service: SalesChannelModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["salesChannel"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
salesChannel: {
|
||||
id: {
|
||||
linkable: "sales_channel_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "salesChannel",
|
||||
field: "salesChannel",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should create a SalesChannel successfully", async () => {
|
||||
const [created] = await service.createSalesChannels([
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.14",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
@@ -44,14 +45,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.9",
|
||||
"@medusajs/types": "^1.11.14",
|
||||
"@medusajs/utils": "^1.11.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { SalesChannelModuleService } from "@services"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.SALES_CHANNEL, {
|
||||
service: SalesChannelModuleService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.SALES_CHANNEL)
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
FilterableSalesChannelProps,
|
||||
InternalModuleDeclaration,
|
||||
ISalesChannelModuleService,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
SalesChannelDTO,
|
||||
UpdateSalesChannelDTO,
|
||||
@@ -22,7 +21,6 @@ import {
|
||||
|
||||
import { SalesChannel } from "@models"
|
||||
import { UpdateSalesChanneInput } from "@types"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -48,10 +46,6 @@ export default class SalesChannelModuleService
|
||||
this.salesChannelService_ = salesChannelService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
async createSalesChannels(
|
||||
data: CreateSalesChannelDTO[],
|
||||
|
||||
+25
-1
@@ -1,7 +1,8 @@
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
import { IStockLocationService } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { StockLocationModuleService } from "../../src/services"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -9,6 +10,29 @@ moduleIntegrationTestRunner<IStockLocationService>({
|
||||
moduleName: Modules.STOCK_LOCATION,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Stock Location Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.STOCK_LOCATION, {
|
||||
service: StockLocationModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["stockLocation"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
stockLocation: {
|
||||
location_id: {
|
||||
linkable: "location_id",
|
||||
primaryKey: "location_id",
|
||||
serviceName: "stockLocationService",
|
||||
field: "stockLocation",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should create a stock location", async () => {
|
||||
const data = { name: "location" }
|
||||
|
||||
@@ -36,9 +36,7 @@
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "tsc --build --watch",
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { IStoreModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createStoreFixture } from "../__fixtures__"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { StoreModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -9,6 +10,37 @@ moduleIntegrationTestRunner<IStoreModuleService>({
|
||||
moduleName: Modules.STORE,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Store Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.STORE, {
|
||||
service: StoreModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["storeCurrency", "store"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
storeCurrency: {
|
||||
id: {
|
||||
linkable: "store_currency_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "store",
|
||||
field: "storeCurrency",
|
||||
},
|
||||
},
|
||||
store: {
|
||||
id: {
|
||||
linkable: "store_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "store",
|
||||
field: "store",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("creating a store", () => {
|
||||
it("should get created successfully", async function () {
|
||||
const store = await service.createStores(createStoreFixture)
|
||||
|
||||
@@ -45,13 +45,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { StoreModuleService } from "@services"
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.STORE, {
|
||||
service: StoreModuleService,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.STORE)
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
DAL,
|
||||
InternalModuleDeclaration,
|
||||
IStoreModuleService,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
StoreTypes,
|
||||
} from "@medusajs/types"
|
||||
@@ -20,7 +19,6 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import { Store, StoreCurrency } from "@models"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { UpdateStoreInput } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -48,10 +46,6 @@ export default class StoreModuleService
|
||||
this.storeService_ = storeService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
async createStores(
|
||||
data: StoreTypes.CreateStoreDTO[],
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { ITaxModuleService } from "@medusajs/types"
|
||||
import { setupTaxStructure } from "../utils/setup-tax-structure"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { TaxModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -9,6 +10,58 @@ moduleIntegrationTestRunner<ITaxModuleService>({
|
||||
moduleName: Modules.TAX,
|
||||
testSuite: ({ service }) => {
|
||||
describe("TaxModuleService", function () {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.TAX, {
|
||||
service: TaxModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"taxProvider",
|
||||
"taxRateRule",
|
||||
"taxRate",
|
||||
"taxRegion",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
taxProvider: {
|
||||
id: {
|
||||
linkable: "tax_provider_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "tax",
|
||||
field: "taxProvider",
|
||||
},
|
||||
},
|
||||
taxRateRule: {
|
||||
id: {
|
||||
linkable: "tax_rate_rule_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "tax",
|
||||
field: "taxRateRule",
|
||||
},
|
||||
},
|
||||
taxRate: {
|
||||
id: {
|
||||
linkable: "tax_rate_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "tax",
|
||||
field: "taxRate",
|
||||
},
|
||||
},
|
||||
taxRegion: {
|
||||
id: {
|
||||
linkable: "tax_region_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "tax",
|
||||
field: "taxRegion",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("should create tax rates and update them", async () => {
|
||||
const region = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.14",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
@@ -45,13 +46,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.9",
|
||||
"@medusajs/types": "^1.11.14",
|
||||
"@medusajs/utils": "^1.11.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { TaxModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const service = TaxModuleService
|
||||
const loaders = [loadProviders]
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.TAX, {
|
||||
service: TaxModuleService,
|
||||
loaders: [loadProviders],
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.TAX)
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
InternalModuleDeclaration,
|
||||
ITaxModuleService,
|
||||
ITaxProvider,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
TaxRegionDTO,
|
||||
TaxTypes,
|
||||
@@ -20,7 +19,6 @@ import {
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { TaxProvider, TaxRate, TaxRateRule, TaxRegion } from "@models"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -75,10 +73,6 @@ export default class TaxModuleService
|
||||
this.taxProviderService_ = taxProviderService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
async createTaxRates(
|
||||
data: TaxTypes.CreateTaxRateDTO[],
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
import { Modules, UserEvents } from "@medusajs/utils"
|
||||
import { Module, Modules, UserEvents } from "@medusajs/utils"
|
||||
import {
|
||||
MockEventBusService,
|
||||
moduleIntegrationTestRunner,
|
||||
} from "medusa-test-utils"
|
||||
import { UserModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -27,6 +28,37 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
eventBusModuleService: new MockEventBusService(),
|
||||
},
|
||||
testSuite: ({ service }) => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.USER, {
|
||||
service: UserModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["invite", "user"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
invite: {
|
||||
id: {
|
||||
linkable: "invite_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "user",
|
||||
field: "invite",
|
||||
},
|
||||
},
|
||||
user: {
|
||||
id: {
|
||||
linkable: "user_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "user",
|
||||
field: "user",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("UserModuleService - User", () => {
|
||||
afterEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
|
||||
@@ -47,14 +47,11 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.10",
|
||||
"@medusajs/utils": "^1.11.8",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"knex": "2.4.2"
|
||||
"jsonwebtoken": "^9.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { UserModuleService } from "@services"
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.USER, {
|
||||
service: UserModuleService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.USER)
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
DAL,
|
||||
IEventBusModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
UserTypes,
|
||||
} from "@medusajs/types"
|
||||
@@ -19,7 +18,6 @@ import {
|
||||
UserEvents,
|
||||
} from "@medusajs/utils"
|
||||
import jwt, { JwtPayload } from "jsonwebtoken"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import crypto from "node:crypto"
|
||||
|
||||
import { Invite, User } from "@models"
|
||||
@@ -44,10 +42,6 @@ export default class UserModuleService
|
||||
}>({ User, Invite })
|
||||
implements UserTypes.IUserModuleService
|
||||
{
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
protected readonly userService_: ModulesSdkTypes.IMedusaInternalService<User>
|
||||
|
||||
+25
-1
@@ -4,7 +4,7 @@ import {
|
||||
IWorkflowEngineService,
|
||||
RemoteQueryFunction,
|
||||
} from "@medusajs/types"
|
||||
import { Modules, TransactionHandlerType } from "@medusajs/utils"
|
||||
import { Module, Modules, TransactionHandlerType } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { setTimeout as setTimeoutPromise } from "timers/promises"
|
||||
import "../__fixtures__"
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
workflowEventGroupIdStep2Mock,
|
||||
} from "../__fixtures__/workflow_event_group_id"
|
||||
import { createScheduled } from "../__fixtures__/workflow_scheduled"
|
||||
import { WorkflowsModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -34,6 +35,29 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
query = medusaApp.query
|
||||
})
|
||||
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.WORKFLOW_ENGINE, {
|
||||
service: WorkflowsModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["workflowExecution"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
workflowExecution: {
|
||||
id: {
|
||||
linkable: "workflow_execution_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "workflows",
|
||||
field: "workflowExecution",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("should execute an async workflow keeping track of the event group id provided in the context", async () => {
|
||||
const eventGroupId = "event-group-id"
|
||||
|
||||
|
||||
@@ -45,15 +45,12 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@medusajs/workflows-sdk": "^0.1.6",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"cron-parser": "^4.9.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"cron-parser": "^4.9.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { moduleDefinition } from "./module-definition"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { WorkflowsModuleService } from "@services"
|
||||
import { loadUtils } from "./loaders"
|
||||
|
||||
export default moduleDefinition
|
||||
|
||||
export * from "./loaders"
|
||||
export * from "./models"
|
||||
export default Module(Modules.WORKFLOW_ENGINE, {
|
||||
service: WorkflowsModuleService,
|
||||
loaders: [loadUtils],
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.WORKFLOW_ENGINE)
|
||||
@@ -1 +1 @@
|
||||
export * from "./utils"
|
||||
export { default as loadUtils } from "./utils"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { WorkflowsModuleService } from "@services"
|
||||
import loadUtils from "./loaders/utils"
|
||||
|
||||
const service = WorkflowsModuleService
|
||||
const loaders = [loadUtils]
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import {
|
||||
Context,
|
||||
DAL,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
WorkflowsSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
@@ -17,7 +16,6 @@ import type {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { WorkflowExecution } from "@models"
|
||||
import { WorkflowOrchestratorService } from "@services"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -50,10 +48,6 @@ export class WorkflowsModuleService<
|
||||
this.workflowOrchestratorService_ = workflowOrchestratorService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
@InjectSharedContext()
|
||||
async run<TWorkflow extends string | ReturnWorkflow<any, any, any>>(
|
||||
workflowIdOrWorkflow: TWorkflow,
|
||||
|
||||
@@ -11,9 +11,11 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
createMedusaContainer,
|
||||
Module,
|
||||
Modules,
|
||||
TransactionHandlerType,
|
||||
TransactionStepState,
|
||||
createMedusaContainer,
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import { knex } from "knex"
|
||||
@@ -21,6 +23,7 @@ import { setTimeout } from "timers/promises"
|
||||
import "../__fixtures__"
|
||||
import { createScheduled } from "../__fixtures__/workflow_scheduled"
|
||||
import { DB_URL, TestDatabase } from "../utils"
|
||||
import { WorkflowsModuleService } from "@medusajs/workflow-engine-inmemory/dist/services"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -78,6 +81,29 @@ describe("Workflow Orchestrator module", function () {
|
||||
workflowOrcModule = modules.workflows as unknown as IWorkflowEngineService
|
||||
})
|
||||
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.WORKFLOW_ENGINE, {
|
||||
service: WorkflowsModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["workflowExecution"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
workflowExecution: {
|
||||
id: {
|
||||
linkable: "workflow_execution_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "workflows",
|
||||
field: "workflowExecution",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("Testing basic workflow", function () {
|
||||
afterEach(afterEach_)
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { moduleDefinition } from "./module-definition"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { WorkflowsModuleService } from "@services"
|
||||
import { loadUtils, redisConnection } from "./loaders"
|
||||
|
||||
export default moduleDefinition
|
||||
|
||||
export * from "./loaders"
|
||||
export * from "./models"
|
||||
export default Module(Modules.WORKFLOW_ENGINE, {
|
||||
service: WorkflowsModuleService,
|
||||
loaders: [loadUtils, redisConnection] as any[],
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.WORKFLOW_ENGINE)
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from "./redis"
|
||||
export * from "./utils"
|
||||
export { default as redisConnection } from "./redis"
|
||||
export { default as loadUtils } from "./utils"
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { WorkflowsModuleService } from "@services"
|
||||
import redisConnection from "./loaders/redis"
|
||||
import loadUtils from "./loaders/utils"
|
||||
|
||||
const service = WorkflowsModuleService
|
||||
const loaders = [loadUtils, redisConnection] as any
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import {
|
||||
Context,
|
||||
DAL,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
WorkflowsSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
@@ -17,7 +16,6 @@ import type {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { WorkflowExecution } from "@models"
|
||||
import { WorkflowOrchestratorService } from "@services"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -54,10 +52,6 @@ export class WorkflowsModuleService<
|
||||
this.redisDisconnectHandler_ = redisDisconnectHandler
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
__hooks = {
|
||||
onApplicationShutdown: async () => {
|
||||
await this.workflowOrchestratorService_.onApplicationShutdown()
|
||||
|
||||
@@ -4226,7 +4226,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/api-key@workspace:packages/modules/api-key"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.16
|
||||
"@medusajs/utils": ^1.11.9
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -4235,9 +4234,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -4289,10 +4286,8 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
jsonwebtoken: ^9.0.2
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.42
|
||||
rimraf: ^3.0.2
|
||||
scrypt-kdf: ^2.0.1
|
||||
@@ -4336,7 +4331,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/cart@workspace:packages/modules/cart"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": "workspace:^"
|
||||
"@medusajs/utils": ^1.11.9
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -4345,9 +4339,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -4380,7 +4372,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/currency@workspace:packages/modules/currency"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.16
|
||||
"@medusajs/utils": ^1.11.9
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -4389,9 +4380,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: "workspace:^"
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -4413,9 +4402,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -4544,7 +4531,7 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/file@workspace:packages/modules/file"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.10
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.15
|
||||
"@medusajs/utils": ^1.11.8
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -4553,11 +4540,8 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
faker: ^5.5.3
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
lodash: ^4.17.21
|
||||
medusa-test-utils: ^1.1.43
|
||||
pg-god: ^1.0.12
|
||||
rimraf: ^3.0.2
|
||||
@@ -4595,9 +4579,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -4653,9 +4635,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.43
|
||||
rimraf: ^5.0.1
|
||||
ts-node: ^10.9.1
|
||||
@@ -4905,9 +4885,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -4953,9 +4931,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -4998,9 +4974,7 @@ __metadata:
|
||||
awilix: ^8.0.0
|
||||
bignumber.js: ^9.1.2
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-jest: ^29.1.1
|
||||
@@ -5014,7 +4988,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/pricing@workspace:packages/modules/pricing"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.16
|
||||
"@medusajs/utils": ^1.11.9
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -5023,9 +4996,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-jest: ^29.1.1
|
||||
@@ -5039,7 +5010,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/product@workspace:packages/modules/product"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.16
|
||||
"@medusajs/utils": ^1.11.9
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -5048,11 +5018,8 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
faker: ^5.5.3
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
lodash: ^4.17.21
|
||||
medusa-test-utils: ^1.1.44
|
||||
pg-god: ^1.0.12
|
||||
rimraf: ^3.0.2
|
||||
@@ -5066,7 +5033,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/promotion@workspace:packages/modules/promotion"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.16
|
||||
"@medusajs/utils": 1.11.9
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -5075,9 +5041,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-jest: ^29.1.1
|
||||
@@ -5091,7 +5055,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/region@workspace:packages/modules/region"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.16
|
||||
"@medusajs/utils": ^1.11.9
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -5100,9 +5063,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: "workspace:^"
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -5115,7 +5076,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/sales-channel@workspace:packages/modules/sales-channel"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.9
|
||||
"@medusajs/types": ^1.11.14
|
||||
"@medusajs/utils": ^1.11.7
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -5124,9 +5084,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.42
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -5148,9 +5106,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^5.0.1
|
||||
ts-node: ^10.9.1
|
||||
@@ -5163,7 +5119,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/store@workspace:packages/modules/store"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.16
|
||||
"@medusajs/utils": ^1.11.9
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -5172,9 +5127,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: "workspace:^"
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -5196,9 +5149,7 @@ __metadata:
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.42
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -5343,7 +5294,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/user@workspace:packages/modules/user"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.10
|
||||
"@medusajs/types": ^1.11.15
|
||||
"@medusajs/utils": ^1.11.8
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
@@ -5354,10 +5304,8 @@ __metadata:
|
||||
"@swc/jest": ^0.2.36
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
jsonwebtoken: ^9.0.2
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.43
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
@@ -5395,7 +5343,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/workflow-engine-inmemory@workspace:packages/modules/workflow-engine-inmemory"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.11
|
||||
"@medusajs/types": ^1.11.16
|
||||
"@medusajs/utils": ^1.11.9
|
||||
"@medusajs/workflows-sdk": ^0.1.6
|
||||
@@ -5406,9 +5353,7 @@ __metadata:
|
||||
awilix: ^8.0.0
|
||||
cron-parser: ^4.9.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.4.5
|
||||
jest: ^29.7.0
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.44
|
||||
rimraf: ^3.0.2
|
||||
ts-node: ^10.9.1
|
||||
|
||||
Reference in New Issue
Block a user