feat: Fulfillment module basic structure (#6319)
**What** Scafold the fulfillment module basic structure **Bonus** Simplified module scaffolding with new factories and less directories to manage - mikro orm connection loader factory - initialize factory FIXES CORE-1709 FIXES CORE-1710
This commit is contained in:
committed by
GitHub
parent
2104843826
commit
12054f5c01
7
.changeset/chilled-dingos-float.md
Normal file
7
.changeset/chilled-dingos-float.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@medusajs/utils": patch
|
||||
"@medusajs/modules-sdk": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
Feat/shipping method init
|
||||
@@ -30,6 +30,7 @@ packages/*
|
||||
!packages/medusa-react
|
||||
!packages/workflow-engine-redis
|
||||
!packages/workflow-engine-inmemory
|
||||
!packages/fulfillment
|
||||
|
||||
|
||||
**/models/*
|
||||
|
||||
@@ -102,6 +102,7 @@ module.exports = {
|
||||
"./packages/types/tsconfig.json",
|
||||
"./packages/workflow-engine-redis/tsconfig.spec.json",
|
||||
"./packages/workflow-engine-inmemory/tsconfig.spec.json",
|
||||
"./packages/fulfillment/tsconfig.spec.json",
|
||||
],
|
||||
},
|
||||
rules: {
|
||||
|
||||
6
packages/fulfillment/.gitignore
vendored
Normal file
6
packages/fulfillment/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/dist
|
||||
node_modules
|
||||
.DS_store
|
||||
.env*
|
||||
.env
|
||||
*.sql
|
||||
1
packages/fulfillment/README.md
Normal file
1
packages/fulfillment/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# Fulfillment Module
|
||||
@@ -0,0 +1 @@
|
||||
// noop
|
||||
@@ -0,0 +1,5 @@
|
||||
describe("noop", function () {
|
||||
it("should run", function () {
|
||||
expect(true).toBe(true)
|
||||
})
|
||||
})
|
||||
6
packages/fulfillment/integration-tests/setup-env.js
Normal file
6
packages/fulfillment/integration-tests/setup-env.js
Normal file
@@ -0,0 +1,6 @@
|
||||
if (typeof process.env.DB_TEMP_NAME === "undefined") {
|
||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||
process.env.DB_TEMP_NAME = `medusa-fulfillment-integration-${tempName}`
|
||||
}
|
||||
|
||||
process.env.MEDUSA_FULFILLMENT_DB_SCHEMA = "public"
|
||||
3
packages/fulfillment/integration-tests/setup.js
Normal file
3
packages/fulfillment/integration-tests/setup.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import { JestUtils } from "medusa-test-utils"
|
||||
|
||||
JestUtils.afterAllHookDropDatabase()
|
||||
18
packages/fulfillment/integration-tests/utils/database.ts
Normal file
18
packages/fulfillment/integration-tests/utils/database.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { TestDatabaseUtils } from "medusa-test-utils"
|
||||
|
||||
import * as Models from "@models"
|
||||
|
||||
const pathToMigrations = "../../src/migrations"
|
||||
const mikroOrmEntities = Models as unknown as any[]
|
||||
|
||||
export const MikroOrmWrapper = TestDatabaseUtils.getMikroOrmWrapper(
|
||||
mikroOrmEntities,
|
||||
pathToMigrations
|
||||
)
|
||||
|
||||
export const MikroOrmConfig = TestDatabaseUtils.getMikroOrmConfig(
|
||||
mikroOrmEntities,
|
||||
pathToMigrations
|
||||
)
|
||||
|
||||
export const DB_URL = TestDatabaseUtils.getDatabaseURL()
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
|
||||
import { DB_URL } from "./database"
|
||||
|
||||
export function getInitModuleConfig() {
|
||||
const moduleOptions = {
|
||||
defaultAdapterOptions: {
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_FULFILLMENT_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const injectedDependencies = {}
|
||||
|
||||
const modulesConfig_ = {
|
||||
[Modules.FULFILLMENT]: {
|
||||
definition: ModulesDefinition[Modules.FULFILLMENT],
|
||||
options: moduleOptions,
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
injectedDependencies,
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_FULFILLMENT_DB_SCHEMA,
|
||||
},
|
||||
joinerConfig: [],
|
||||
}
|
||||
}
|
||||
1
packages/fulfillment/integration-tests/utils/index.ts
Normal file
1
packages/fulfillment/integration-tests/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./database"
|
||||
22
packages/fulfillment/jest.config.js
Normal file
22
packages/fulfillment/jest.config.js
Normal file
@@ -0,0 +1,22 @@
|
||||
module.exports = {
|
||||
moduleNameMapper: {
|
||||
"^@models": "<rootDir>/src/models",
|
||||
"^@services": "<rootDir>/src/services",
|
||||
"^@repositories": "<rootDir>/src/repositories",
|
||||
"^@types": "<rootDir>/src/types",
|
||||
},
|
||||
transform: {
|
||||
"^.+\\.[jt]s?$": [
|
||||
"ts-jest",
|
||||
{
|
||||
tsConfig: "tsconfig.spec.json",
|
||||
isolatedModules: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
testEnvironment: `node`,
|
||||
moduleFileExtensions: [`js`, `ts`],
|
||||
modulePathIgnorePatterns: ["dist/"],
|
||||
setupFiles: ["<rootDir>/integration-tests/setup-env.js"],
|
||||
setupFilesAfterEnv: ["<rootDir>/integration-tests/setup.js"],
|
||||
}
|
||||
8
packages/fulfillment/mikro-orm.config.dev.ts
Normal file
8
packages/fulfillment/mikro-orm.config.dev.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as entities from "./src/models"
|
||||
|
||||
module.exports = {
|
||||
entities: Object.values(entities),
|
||||
schema: "public",
|
||||
clientUrl: "postgres://postgres@localhost/medusa-fulfillment",
|
||||
type: "postgresql",
|
||||
}
|
||||
61
packages/fulfillment/package.json
Normal file
61
packages/fulfillment/package.json
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "@medusajs/fulfillment",
|
||||
"version": "0.1.0",
|
||||
"description": "Medusa Fulfillment module",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"bin": {
|
||||
"medusa-fulfillment-seed": "dist/scripts/bin/run-seed.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/medusajs/medusa",
|
||||
"directory": "packages/fulfillment"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"watch": "tsc --build --watch",
|
||||
"watch:test": "tsc --build tsconfig.spec.json --watch",
|
||||
"prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
|
||||
"build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
|
||||
"test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
|
||||
"test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.6.3",
|
||||
"medusa-test-utils": "^1.1.40",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-jest": "^29.1.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsc-alias": "^1.8.6",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.4",
|
||||
"@medusajs/types": "^1.11.8",
|
||||
"@medusajs/utils": "^1.11.1",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.1.4",
|
||||
"knex": "2.4.2"
|
||||
}
|
||||
}
|
||||
14
packages/fulfillment/src/index.ts
Normal file
14
packages/fulfillment/src/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { moduleDefinition } from "./module-definition"
|
||||
import { initializeFactory, Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
export * from "./types"
|
||||
export * from "./models"
|
||||
export * from "./services"
|
||||
|
||||
export const initialize = initializeFactory({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
moduleDefinition,
|
||||
})
|
||||
export const runMigrations = moduleDefinition.runMigrations
|
||||
export const revertMigration = moduleDefinition.revertMigration
|
||||
export default moduleDefinition
|
||||
25
packages/fulfillment/src/joiner-config.ts
Normal file
25
packages/fulfillment/src/joiner-config.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { MapToConfig } from "@medusajs/utils"
|
||||
|
||||
// TODO manage the config
|
||||
|
||||
export const LinkableKeys: Record<string, string> = {}
|
||||
|
||||
const entityLinkableKeysMap: MapToConfig = {}
|
||||
Object.entries(LinkableKeys).forEach(([key, value]) => {
|
||||
entityLinkableKeysMap[value] ??= []
|
||||
entityLinkableKeysMap[value].push({
|
||||
mapTo: key,
|
||||
valueFrom: key.split("_").pop()!,
|
||||
})
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
||||
|
||||
export const joinerConfig: ModuleJoinerConfig = {
|
||||
serviceName: Modules.FULFILLMENT,
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: LinkableKeys,
|
||||
alias: [],
|
||||
} as ModuleJoinerConfig
|
||||
56
packages/fulfillment/src/models/fullfilment-set.ts
Normal file
56
packages/fulfillment/src/models/fullfilment-set.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type FulfillmentSetOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class FulfillmentSet {
|
||||
[OptionalProps]?: FulfillmentSetOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_fulfillment_set_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fuset")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fuset")
|
||||
}
|
||||
}
|
||||
1
packages/fulfillment/src/models/index.ts
Normal file
1
packages/fulfillment/src/models/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as FulfillmentSet } from "./fullfilment-set"
|
||||
44
packages/fulfillment/src/module-definition.ts
Normal file
44
packages/fulfillment/src/module-definition.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import * as ModuleServices from "@services"
|
||||
import { FulfillmentModuleService } from "@services"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import * as Models from "@models"
|
||||
import * as ModuleModels from "@models"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import * as ModuleRepositories from "@repositories"
|
||||
|
||||
const migrationScriptOptions = {
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
models: Models,
|
||||
pathToMigrations: __dirname + "/migrations",
|
||||
}
|
||||
|
||||
const runMigrations = ModulesSdkUtils.buildMigrationScript(
|
||||
migrationScriptOptions
|
||||
)
|
||||
|
||||
const revertMigration = ModulesSdkUtils.buildRevertMigrationScript(
|
||||
migrationScriptOptions
|
||||
)
|
||||
|
||||
const containerLoader = ModulesSdkUtils.moduleContainerLoaderFactory({
|
||||
moduleModels: ModuleModels,
|
||||
moduleRepositories: ModuleRepositories,
|
||||
moduleServices: ModuleServices,
|
||||
})
|
||||
|
||||
const connectionLoader = ModulesSdkUtils.mikroOrmConnectionLoaderFactory({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
moduleModels: Object.values(Models),
|
||||
migrationsPath: __dirname + "/migrations",
|
||||
})
|
||||
|
||||
const service = FulfillmentModuleService
|
||||
const loaders = [containerLoader, connectionLoader] as any
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
revertMigration,
|
||||
runMigrations,
|
||||
}
|
||||
1
packages/fulfillment/src/repositories/index.ts
Normal file
1
packages/fulfillment/src/repositories/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils"
|
||||
29
packages/fulfillment/src/scripts/bin/run-seed.ts
Normal file
29
packages/fulfillment/src/scripts/bin/run-seed.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import * as Models from "@models"
|
||||
import { EOL } from "os"
|
||||
|
||||
const args = process.argv
|
||||
const path = args.pop() as string
|
||||
|
||||
export default (async () => {
|
||||
const { config } = await import("dotenv")
|
||||
config()
|
||||
if (!path) {
|
||||
throw new Error(
|
||||
`filePath is required.${EOL}Example: medusa-fulfillment-seed <filePath>`
|
||||
)
|
||||
}
|
||||
|
||||
const run = ModulesSdkUtils.buildSeedScript({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
models: Models,
|
||||
pathToMigrations: __dirname + "/../../migrations",
|
||||
seedHandler: async ({ manager, data }) => {
|
||||
// TODO: Add seed logic
|
||||
},
|
||||
})
|
||||
await run({ path })
|
||||
})()
|
||||
5
packages/fulfillment/src/services/__tests__/noop.ts
Normal file
5
packages/fulfillment/src/services/__tests__/noop.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
describe("noop", function () {
|
||||
it("should run", function () {
|
||||
expect(true).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,91 @@
|
||||
import {
|
||||
Context,
|
||||
DAL,
|
||||
FulfillmentTypes,
|
||||
IFulfillmentModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import { InjectTransactionManager, ModulesSdkUtils } from "@medusajs/utils"
|
||||
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { FulfillmentSet } from "@models"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
fulfillmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
}
|
||||
|
||||
export default class FulfillmentModuleService<
|
||||
TEntity extends FulfillmentSet = FulfillmentSet
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
any, // TODO Create appropriate DTO
|
||||
{}
|
||||
>(FulfillmentSet, [], entityNameToLinkableKeysMap)
|
||||
implements IFulfillmentModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly fulfillmentService_: ModulesSdkTypes.InternalModuleService<TEntity>
|
||||
|
||||
constructor(
|
||||
{ baseRepository, fulfillmentService }: InjectedDependencies,
|
||||
protected readonly moduleDeclaration: InternalModuleDeclaration
|
||||
) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
this.baseRepository_ = baseRepository
|
||||
this.fulfillmentService_ = fulfillmentService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
create(
|
||||
data: any[],
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentTypes.FulfillmentDTO[]>
|
||||
|
||||
create(
|
||||
data: any,
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentTypes.FulfillmentDTO>
|
||||
|
||||
// TODO Implement the methods from the interface and change type
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async create(
|
||||
data: any[] | any,
|
||||
sharedContext?: Context
|
||||
): Promise<
|
||||
FulfillmentTypes.FulfillmentDTO | FulfillmentTypes.FulfillmentDTO[]
|
||||
> {
|
||||
return await Promise.resolve(
|
||||
[] as FulfillmentTypes.FulfillmentDTO[] | FulfillmentTypes.FulfillmentDTO
|
||||
)
|
||||
}
|
||||
|
||||
// TODO Implement the methods from the interface and change type
|
||||
update(
|
||||
data: any[],
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentTypes.FulfillmentDTO[]>
|
||||
update(
|
||||
data: any,
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentTypes.FulfillmentDTO>
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async update(
|
||||
data: any,
|
||||
sharedContext?: Context
|
||||
): Promise<
|
||||
FulfillmentTypes.FulfillmentDTO | FulfillmentTypes.FulfillmentDTO[]
|
||||
> {
|
||||
return await Promise.resolve(
|
||||
[] as FulfillmentTypes.FulfillmentDTO[] | FulfillmentTypes.FulfillmentDTO
|
||||
)
|
||||
}
|
||||
}
|
||||
1
packages/fulfillment/src/services/index.ts
Normal file
1
packages/fulfillment/src/services/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as FulfillmentModuleService } from "./fulfillment-module-service"
|
||||
6
packages/fulfillment/src/types/index.ts
Normal file
6
packages/fulfillment/src/types/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { IEventBusModuleService, Logger } from "@medusajs/types"
|
||||
|
||||
export type InitializeModuleInjectableDependencies = {
|
||||
logger?: Logger
|
||||
eventBusService?: IEventBusModuleService
|
||||
}
|
||||
37
packages/fulfillment/tsconfig.json
Normal file
37
packages/fulfillment/tsconfig.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["es2020"],
|
||||
"target": "es2020",
|
||||
"outDir": "./dist",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"sourceMap": false,
|
||||
"noImplicitReturns": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"noImplicitThis": true,
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"downlevelIteration": true, // to use ES5 specific tooling
|
||||
"baseUrl": ".",
|
||||
"resolveJsonModule": true,
|
||||
"paths": {
|
||||
"@models": ["./src/models"],
|
||||
"@services": ["./src/services"],
|
||||
"@repositories": ["./src/repositories"],
|
||||
"@types": ["./src/types"]
|
||||
}
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": [
|
||||
"dist",
|
||||
"./src/**/__tests__",
|
||||
"./src/**/__mocks__",
|
||||
"./src/**/__fixtures__",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
8
packages/fulfillment/tsconfig.spec.json
Normal file
8
packages/fulfillment/tsconfig.spec.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src", "integration-tests"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"compilerOptions": {
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ export enum Modules {
|
||||
PRODUCT = "productService",
|
||||
PROMOTION = "promotion",
|
||||
SALES_CHANNEL = "salesChannel",
|
||||
FULFILLMENT = "fulfillment",
|
||||
STOCK_LOCATION = "stockLocationService",
|
||||
USER = "user",
|
||||
WORKFLOW_ENGINE = "workflows",
|
||||
@@ -37,6 +38,7 @@ export enum ModuleRegistrationName {
|
||||
PRODUCT = "productModuleService",
|
||||
PROMOTION = "promotionModuleService",
|
||||
SALES_CHANNEL = "salesChannelModuleService",
|
||||
FULFILLMENT = "fulfillmentModuleService",
|
||||
STOCK_LOCATION = "stockLocationService",
|
||||
USER = "userModuleService",
|
||||
WORKFLOW_ENGINE = "workflowsModuleService",
|
||||
@@ -56,6 +58,7 @@ export const MODULE_PACKAGE_NAMES = {
|
||||
[Modules.PRODUCT]: "@medusajs/product",
|
||||
[Modules.PROMOTION]: "@medusajs/promotion",
|
||||
[Modules.SALES_CHANNEL]: "@medusajs/sales-channel",
|
||||
[Modules.FULFILLMENT]: "@medusajs/fulfillment",
|
||||
[Modules.STOCK_LOCATION]: "@medusajs/stock-location",
|
||||
[Modules.USER]: "@medusajs/user",
|
||||
[Modules.WORKFLOW_ENGINE]: "@medusajs/workflow-engine-inmemory",
|
||||
@@ -195,6 +198,19 @@ export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } =
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.FULFILLMENT]: {
|
||||
key: Modules.FULFILLMENT,
|
||||
registrationName: ModuleRegistrationName.FULFILLMENT,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.FULFILLMENT),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger", "eventBusService"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.CART]: {
|
||||
key: Modules.CART,
|
||||
registrationName: ModuleRegistrationName.CART,
|
||||
|
||||
@@ -5,4 +5,4 @@ export * from "./medusa-app"
|
||||
export * from "./medusa-module"
|
||||
export * from "./remote-link"
|
||||
export * from "./remote-query"
|
||||
|
||||
export * from "./utils/initialize-factory"
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./clean-graphql-schema"
|
||||
export * from "./graphql-schema-to-fields"
|
||||
export * from "./initialize-factory"
|
||||
|
||||
44
packages/modules-sdk/src/utils/initialize-factory.ts
Normal file
44
packages/modules-sdk/src/utils/initialize-factory.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
ModuleExports,
|
||||
ModuleServiceInitializeCustomDataLayerOptions,
|
||||
ModuleServiceInitializeOptions,
|
||||
} from "@medusajs/types"
|
||||
import { MODULE_PACKAGE_NAMES } from "../definitions"
|
||||
import { MedusaModule } from "../medusa-module"
|
||||
|
||||
/**
|
||||
* Generate a initialize module factory that is exported by the module to be initialized manually
|
||||
*
|
||||
* @param moduleName
|
||||
* @param moduleDefinition
|
||||
*/
|
||||
export function initializeFactory<T>({
|
||||
moduleName,
|
||||
moduleDefinition,
|
||||
}: {
|
||||
moduleName: string
|
||||
moduleDefinition: ModuleExports
|
||||
}) {
|
||||
return async (
|
||||
options?:
|
||||
| ModuleServiceInitializeOptions
|
||||
| ModuleServiceInitializeCustomDataLayerOptions
|
||||
| ExternalModuleDeclaration
|
||||
| InternalModuleDeclaration,
|
||||
injectedDependencies?: any
|
||||
) => {
|
||||
const loaded = await MedusaModule.bootstrap<T>({
|
||||
moduleKey: moduleName,
|
||||
defaultPath: MODULE_PACKAGE_NAMES[moduleName],
|
||||
declaration: options as
|
||||
| InternalModuleDeclaration
|
||||
| ExternalModuleDeclaration,
|
||||
injectedDependencies,
|
||||
moduleExports: moduleDefinition,
|
||||
})
|
||||
|
||||
return loaded[moduleName] as T
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ export * as CustomerTypes from "./customer"
|
||||
export * as DAL from "./dal"
|
||||
export * as EventBusTypes from "./event-bus"
|
||||
export * as FeatureFlagTypes from "./feature-flag"
|
||||
export * as FulfillmentTypes from "./fulfillment"
|
||||
export * as InventoryTypes from "./inventory"
|
||||
export * as LoggerTypes from "./logger"
|
||||
export * as ModulesSdkTypes from "./modules-sdk"
|
||||
|
||||
4
packages/types/src/fulfillment/common.ts
Normal file
4
packages/types/src/fulfillment/common.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface FulfillmentDTO {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
3
packages/types/src/fulfillment/index.ts
Normal file
3
packages/types/src/fulfillment/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./common"
|
||||
export * from "./mutations"
|
||||
export * from "./service"
|
||||
1
packages/types/src/fulfillment/mutations.ts
Normal file
1
packages/types/src/fulfillment/mutations.ts
Normal file
@@ -0,0 +1 @@
|
||||
export {}
|
||||
58
packages/types/src/fulfillment/service.ts
Normal file
58
packages/types/src/fulfillment/service.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { IModuleService } from "../modules-sdk"
|
||||
import { FulfillmentDTO } from "./common"
|
||||
import { FindConfig } from "../common"
|
||||
import { Context } from "../shared-context"
|
||||
import { RestoreReturn, SoftDeleteReturn } from "../dal"
|
||||
|
||||
export interface IFulfillmentModuleService extends IModuleService {
|
||||
create(
|
||||
data: any[], // TODO Create appropriate DTO
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentDTO[]>
|
||||
create(
|
||||
data: any, // TODO Create appropriate DTO
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentDTO>
|
||||
|
||||
update(
|
||||
data: any[], // TODO Create appropriate DTO
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentDTO[]>
|
||||
update(
|
||||
data: any, // TODO Create appropriate DTO
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentDTO>
|
||||
|
||||
delete(ids: string[], sharedContext?: Context): Promise<void>
|
||||
delete(id: string, sharedContext?: Context): Promise<void>
|
||||
|
||||
retrieve(
|
||||
id: string,
|
||||
config?: FindConfig<FulfillmentDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentDTO>
|
||||
|
||||
list(
|
||||
filters?: any, // TODO Create appropriate filter type
|
||||
config?: FindConfig<FulfillmentDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<FulfillmentDTO[]>
|
||||
|
||||
listAndCount(
|
||||
filters?: any, // TODO Create appropriate filter type
|
||||
config?: FindConfig<FulfillmentDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<[FulfillmentDTO[], number]>
|
||||
|
||||
softDelete<TReturnableLinkableKeys extends string = string>(
|
||||
fulfillmentIds: string[],
|
||||
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
restore<TReturnableLinkableKeys extends string = string>(
|
||||
fulfillmentIds: string[],
|
||||
config?: RestoreReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
}
|
||||
@@ -8,6 +8,7 @@ export * from "./customer"
|
||||
export * from "./dal"
|
||||
export * from "./event-bus"
|
||||
export * from "./feature-flag"
|
||||
export * from "./fulfillment"
|
||||
export * from "./file-service"
|
||||
export * from "./inventory"
|
||||
export * from "./joiner"
|
||||
|
||||
@@ -2,6 +2,7 @@ export * from "./load-module-database-config"
|
||||
export * from "./decorators"
|
||||
export * from "./build-query"
|
||||
export * from "./loaders/mikro-orm-connection-loader"
|
||||
export * from "./loaders/mikro-orm-connection-loader-factory"
|
||||
export * from "./loaders/container-loader-factory"
|
||||
export * from "./create-pg-connection"
|
||||
export * from "./migration-scripts"
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/types"
|
||||
import { mikroOrmConnectionLoader } from "./mikro-orm-connection-loader"
|
||||
|
||||
/**
|
||||
* Factory for creating a MikroORM connection loader for the modules
|
||||
*
|
||||
* @param moduleName
|
||||
* @param moduleModels
|
||||
* @param migrationsPath
|
||||
*/
|
||||
export function mikroOrmConnectionLoaderFactory({
|
||||
moduleName,
|
||||
moduleModels,
|
||||
migrationsPath,
|
||||
}: {
|
||||
moduleName: string
|
||||
moduleModels: any[]
|
||||
migrationsPath?: string
|
||||
}): any {
|
||||
return async (
|
||||
{ options, container, logger }: LoaderOptions,
|
||||
moduleDeclaration?: InternalModuleDeclaration
|
||||
): Promise<void> => {
|
||||
await mikroOrmConnectionLoader({
|
||||
moduleName,
|
||||
entities: moduleModels,
|
||||
container,
|
||||
options,
|
||||
moduleDeclaration,
|
||||
logger,
|
||||
pathToMigrations: migrationsPath ?? "",
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,16 @@ import { ContainerRegistrationKeys, MedusaError } from "../../common"
|
||||
import { mikroOrmCreateConnection } from "../../dal"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
|
||||
/**
|
||||
* Load a MikroORM connection into the container
|
||||
*
|
||||
* @param moduleName
|
||||
* @param container
|
||||
* @param options
|
||||
* @param moduleDeclaration
|
||||
* @param entities
|
||||
* @param pathToMigrations
|
||||
*/
|
||||
export async function mikroOrmConnectionLoader({
|
||||
moduleName,
|
||||
container,
|
||||
|
||||
27
yarn.lock
27
yarn.lock
@@ -8140,6 +8140,33 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@medusajs/fulfillment@workspace:packages/fulfillment":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/fulfillment@workspace:packages/fulfillment"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.4
|
||||
"@medusajs/types": ^1.11.8
|
||||
"@medusajs/utils": ^1.11.1
|
||||
"@mikro-orm/cli": 5.9.7
|
||||
"@mikro-orm/core": 5.9.7
|
||||
"@mikro-orm/migrations": 5.9.7
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
awilix: ^8.0.0
|
||||
cross-env: ^5.2.1
|
||||
dotenv: ^16.1.4
|
||||
jest: ^29.6.3
|
||||
knex: 2.4.2
|
||||
medusa-test-utils: ^1.1.40
|
||||
rimraf: ^3.0.2
|
||||
ts-jest: ^29.1.1
|
||||
ts-node: ^10.9.1
|
||||
tsc-alias: ^1.8.6
|
||||
typescript: ^5.1.6
|
||||
bin:
|
||||
medusa-fulfillment-seed: dist/scripts/bin/run-seed.js
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@medusajs/icons@^1.1.0, @medusajs/icons@^1.2.0, @medusajs/icons@workspace:^, @medusajs/icons@workspace:packages/design-system/icons":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@medusajs/icons@workspace:packages/design-system/icons"
|
||||
|
||||
Reference in New Issue
Block a user