Skip to main content

Module erp

Module erp 

Source
Expand description

ERP integration traits and reference implementations.

§Role

mako-engine is a protocol processor — it handles EDIFACT parsing, BDEW process rules, AS4 delivery, and regulatory deadlines. All contract data, billing logic, and master data live in the operator’s ERP.

This module defines the stable integration contract between mako-engine and external ERP or backend systems. The payload contract is BO4E, not raw EDIFACT. ERP adapters never see EDIFACT segment codes or format-version identifiers — those are absorbed inside mako-engine.

§Outbound: mako → ERP

Implement ErpAdapter and register it at startup. Every domain event that requires ERP action is delivered as an ErpEvent. The production WebhookErpAdapter (in makod) serialises events as CloudEvents 1.0 structured-mode JSON and POSTs them to the configured ERP endpoint.

POST <erp_webhook_url>
Content-Type: application/cloudevents+json
X-Idempotency-Key: <event.idempotency_key>
X-Mako-Signature: <hmac-sha256-hex>   ← only when secret is configured

{
  "specversion": "1.0",
  "id": "<idempotency_key>",
  "source": "urn:mako:tenant:<tenant_id>",
  "type": "de.mako.aperak.accepted",
  "time": "2026-10-01T10:15:00+02:00",
  "subject": "<process_id>",
  "dataschema": "https://.../Marktlokation.json",
  "datacontenttype": "application/json",
  "makoconvid": "<conversation_id>",
  "makocausationid": "<causation_id>",
  "makopid": 55001,
  "data": { "_typ": "MARKTLOKATION", ... }
}

See ErpEventType::cloud_event_type for the full type → CE type mapping. The BO4E payload is always in the data field; the payload_schema URL maps to the CloudEvents dataschema attribute.

§Inbound: ERP → mako (event-driven)

For ERP systems with a message bus, implement ErpCommandSource to feed BO4E business objects into the engine without a synchronous REST round-trip.

struct MyKafkaSource { consumer: KafkaConsumer }

impl ErpCommandSource for MyKafkaSource {
    async fn next(&self) -> Result<Option<InboundErpCommand>, ErpAdapterError> {
        let msg = self.consumer.poll(Duration::from_millis(100)).await;
        Ok(msg.map(|m| InboundErpCommand {
            idempotency_key: m.offset().to_string(),
            tenant_id: TenantId::new(),
            payload_schema: "…/Marktlokation.json".into(),
            payload: serde_json::from_slice(m.payload()).unwrap(),
        }))
    }

    async fn ack(&self, id: &str) -> Result<(), ErpAdapterError> {
        self.consumer.commit_offset(id.parse().unwrap()).await
            .map_err(ErpAdapterError::transport)
    }

    async fn nack(&self, _id: &str, _reason: &str) -> Result<(), ErpAdapterError> {
        Ok(()) // Kafka auto-redelivers on next poll
    }
}

§Reference implementations

TypeFeatureUse case
[NoopErpAdapter]testingUnit tests, CI
LogErpAdapterStructured log output; starting point for new integrations
[NoopErpCommandSource]testingNo-op inbound source for tests

For the production WebhookErpAdapter and POST /api/v1/commands endpoint, see makod/src/erp_adapter.rs.

Structs§

ErpEvent
A structured process event delivered from mako-engine to the ERP.
InboundErpCommand
A BO4E business object received from the ERP, intended to trigger a mako process.
LogErpAdapter
An ErpAdapter that logs every event at info level without delivering it.

Enums§

ErpAdapterError
Errors produced by ErpAdapter and ErpCommandSource implementations.
ErpEventType
Semantic classification of an outbound ERP process event.

Constants§

BO4E_SCHEMA_ENERGIEMENGE
BO4E JSON Schema URL for Energiemenge.
BO4E_SCHEMA_GESCHAEFTSPARTNER
BO4E JSON Schema URL for Geschaeftspartner.
BO4E_SCHEMA_MARKTLOKATION
BO4E JSON Schema URL for Marktlokation.
BO4E_SCHEMA_MESSLOKATION
BO4E JSON Schema URL for Messlokation.
BO4E_SCHEMA_RECHNUNG
BO4E JSON Schema URL for Rechnung.
BO4E_SCHEMA_VERTRAG
BO4E JSON Schema URL for Vertrag.
BO4E_SCHEMA_ZAEHLER
BO4E JSON Schema URL for Zaehler.
BO4E_V202501_BASE
BO4E schema URL base for v202501.0.0.

Traits§

ErpAdapter
Outbound notification sink — mako-engine calls this when a process event should be reported to the ERP.
ErpCommandSource
Inbound command source — mako-engine polls this for new BO4E objects from the ERP.