@csbeker/medusa-bejerman
v1.0.5
Published
Bejerman Integration for Medusa JS.
Maintainers
Readme
medusa-bejerman
Medusa v2 plugin to integrate a B2B/B2C store with Bejerman ERP via SOAP (XML).
Features
- Products & Prices: ERP → Medusa synchronization (scheduled jobs).
- Customers: Bidirectional synchronization ERP ↔ Medusa.
- Orders: Medusa → ERP submission upon checkout completion.
- Stock: Real-time validation via hooks.
- Admin Dashboard: Panel with logs, manual synchronization buttons, and configuration.
Architecture (Strategy Pattern + DI)
The module uses dependency injection to switch between environments and register internal services:
| Service | Description |
|---|---|
| BejermanModuleService | Main Facade. Delegates based on BEJERMAN_ENV. Exposes getCustomerService(), getMapper(), getLogger(). |
| BejermanSoapService | Real implementation (axios + xml2js). Includes retries + email alerts. |
| BejermanMockService | Mock implementation for development without ERP connection. |
| BejermanCustomerService | Bidirectional customer sync (B2B: ERP→Medusa, B2C: Medusa→ERP). Auto-registered via static IDENTIFIER. |
| BejermanMapperService | Data transformations between Bejerman ERP and Medusa formats. |
| BejermanPriceListService | Price list sync from Bejerman to Medusa PriceLists + CustomerGroups. |
| BejermanLoggerService | Hybrid logger: writes to Medusa Logger + bejerman_log DB table. |
Installation
Add the dependency to the Medusa project:
"medusa-bejerman": "workspace:^"Register the module in
medusa-config.ts.Copy
.env.templateto.envand configure the variables.Run migrations:
npx medusa db:migrate
Structure
src/
├── admin/
│ ├── routes/bejerman/
│ │ └── page.tsx # Dashboard: Config + Sync B2B/B2C + Logs table
│ └── widgets/
│ └── customer-bejerman-info.tsx # Customer detail widget (Bejerman metadata)
│
├── api/admin/bejerman/
│ ├── ping/route.ts # Health-check endpoint
│ ├── logs/route.ts # Paginated log listing
│ └── settings/route.ts # GET/POST settings (retention, B2C code)
│
├── jobs/
│ ├── sync-b2b-customers-from-bejerman.ts # Scheduled B2B customer sync
│ └── cleanup-logs.ts # Log retention cleanup
│
├── subscribers/
│ └── sync-b2c-customers-to-bejerman.ts # customer.created/.updated/.deleted → B2C workflow
│
├── modules/bejerman/ # --- CORE MODULE ---
│ ├── index.ts # Module Definition (BEJERMAN_MODULE)
│ ├── service.ts # Main Facade (DI: CustomerService, Mapper, Logger)
│ ├── models/ # DML Models (Settings, Log)
│ ├── services/ # Internal Services (auto-registered via static IDENTIFIER)
│ │ ├── customer.ts # BejermanCustomerService (B2B/B2C sync logic)
│ │ ├── mapper.ts # BejermanMapperService (ERP ↔ Medusa transforms)
│ │ ├── price-list.ts # BejermanPriceListService
│ │ ├── bejerman-mock.ts # Mock service (development)
│ │ ├── bejerman-soap.ts # Real SOAP service (production)
│ │ ├── bejerman-client.ts # Low-level SOAP client
│ │ └── bejerman-logger.ts # Hybrid logger (console + DB)
│ ├── types/ # Interfaces & Contracts
│ └── utils/ # Helpers (XML parsers, error classes)
│
└── workflows/
├── index.ts # Barrel exports
├── sync-b2b-customers.ts # ERP → Medusa (fetch, filter, upsert)
└── sync-b2c-customer.ts # Medusa → ERP (alta/modificación/baja)