Skip to content

ediflow-lib/core

Repository files navigation

EDIFlow 🌊

Modern EDI Parser, Validator & Builder for TypeScript/JavaScript β€” EDIFACT & X12

NPM Version License: MIT TypeScript Tests Downloads

Clean Architecture β€’ Type-Safe β€’ Business Object Mapping β€’ Schema Export β€’ Battle-Tested


🌊 The Way of Water

"Like water finding its path, EDIFlow seamlessly processes EDI data across any standard, any system, any scale."

Inspired by Taoist philosophy, EDIFlow embodies four principles:

  • πŸ’§ Water finds its way β€” Intelligent parsing that elegantly solves problems
  • 🌊 Water adapts to any form β€” Supports EDIFACT, X12, and more with flexible architecture
  • πŸ’ͺ Water is powerful but gentle β€” Enterprise-grade performance, developer-friendly API
  • πŸ”„ Water connects everything β€” Bridges between systems and standards seamlessly

πŸ’‘ What Makes EDIFlow Different?

Most EDIFACT libraries only parse to generic segments:

// ❌ Other Libraries - No type safety, manual segment parsing
const bgm = message.segments.find(s => s.tag === 'BGM');
const docNumber = bgm?.elements[1]?.value;  // What is element[1]? 🀷

EDIFlow maps to type-safe TypeScript business objects:

// βœ… EDIFlow - IntelliSense, type safety, business logic
const order = mapper.mapToBusinessObject(message);
console.log(order.documentNumber);         // Auto-complete works! πŸŽ‰
console.log(order.parties.buyer.id);
console.log(order.lineItems[0].productId);

🎯 Killer Features

1. Business Object Mapping (EDIFACT ↔️ TypeScript)

// Parse EDIFACT β†’ TypeScript Object
const order = mapper.mapToBusinessObject(parsedMessage);

// Modify with type safety
order.lineItems[0].quantity = 150;
order.lineItems.push({ productId: 'PRODUCT002', quantity: 50 });

// TypeScript Object β†’ EDIFACT
const edifact = mapper.mapFromBusinessObject(order, {...});

2. Schema Export (JSON Schema & TypeScript)

// Generate JSON Schema for validation
const schema = exportSchemaUseCase.execute({
  standard: 'EDIFACT',
  version: 'D20B',
  messageType: 'ORDERS',
  format: 'json-schema'  // or 'typescript'
});

// Validate with Ajv before sending
const ajv = new Ajv();
const validate = ajv.compile(schema);
if (validate(order)) {
  sendToPartner(buildEDI(order));
}

Benefits:

  • βœ… Type Safety - Catch errors at compile time
  • βœ… IntelliSense - Auto-completion for all fields
  • βœ… Validation - Validate with JSON Schema before sending
  • βœ… Testing - Easy to mock business objects
  • βœ… Documentation - Auto-generated TypeScript types

✨ Features

βœ… Type-Safe Business Objects - Map EDIFACT to TypeScript objects
βœ… Schema Export - Generate JSON Schema & TypeScript definitions
βœ… Clean Architecture - SOLID principles, testable, maintainable
βœ… Complete EDIFACT Support - D.96A, D.01B, D.20B, D.12A standards
βœ… X12 Support - 850, 810, 837, 856 and more (v0.3.0)
βœ… 3-Phase Validation - Syntax β†’ Structure β†’ Business Logic
βœ… Envelope Support - UNH/UNT/UNB/UNZ and ISA/GS/GE/IEA
βœ… Well-Tested - 857 tests passing
βœ… Zero Config - Works out of the box


πŸš€ Quick Start

Installation

EDIFlow is published as separate NPM packages (all MIT licensed):

# 1. Install core library (required)
npm install @ediflow/core

# 2. Install EDIFACT standard(s) you need
npm install @ediflow/edifact-d96a   # D.96A (1996) β€” 89 messages
npm install @ediflow/edifact-d01b   # D.01B (2001) β€” 155 messages
npm install @ediflow/edifact-d20b   # D.20B (2020) β€” 178 messages (latest)
npm install @ediflow/edifact-d12a   # D.12A (2012) β€” 196 messages (most complete)
npm install @ediflow/eancom-2002    # EANCOM 2002 β€” 50 GS1 retail messages

# 3. OR: Install X12 (USA market)
npm install @ediflow/x12            # X12 Parser (850, 810, 837, 856, ...)
npm install @ediflow/x12-004010     # X12 004010 β€” 293 transaction sets
npm install @ediflow/x12-006040     # X12 006040 β€” 319 transaction sets (latest 2026)
npm install @ediflow/hipaa-x12-005010  # HIPAA 005010 β€” 14 healthcare transaction sets

Parse EDIFACT Message

import {
  EdifactMessageParser,
  EdifactDelimiterDetector,
  EdifactTokenizer,
  EdifactSegmentParser,
} from '@ediflow/edifact';

const parser  = new EdifactMessageParser(
  new EdifactDelimiterDetector(), new EdifactTokenizer(), new EdifactSegmentParser(),
);
const message = parser.parse(edifactString);

console.log(message.standard);           // 'EDIFACT'
console.log(message.messageType.value);  // 'ORDERS'
console.log(message.segments.length);    // segment count

Validate Message

import { EdifactValidationServiceBuilder } from '@ediflow/edifact';

const validator = EdifactValidationServiceBuilder.forEDIFACT();
const result    = validator.validate(message);

if (result.isValid) {
  console.log('βœ… Message is valid!');
} else {
  result.errors.forEach(e => console.error(`❌ ${e.code}: ${e.message}`));
}

Build EDIFACT Message

import { EdifactMessageBuilder, EdifactEnvelopeBuilder } from '@ediflow/edifact';
import { EDIMessage, Standard, Version, MessageType, EDISegment, EDIElement } from '@ediflow/core';

const msg = new EDIMessage('1', Standard.EDIFACT, new Version(Standard.EDIFACT, 'D.20B'), new MessageType(Standard.EDIFACT, 'ORDERS'));
msg.addSegment(new EDISegment('BGM', [new EDIElement('220'), new EDIElement('PO-001')]));

const envelopeBuilder = new EdifactEnvelopeBuilder();
const wrapped   = envelopeBuilder.wrapMessage(msg, { messageRef: '1', messageType: msg.messageType, version: msg.version });
const builder   = new EdifactMessageBuilder();
const edifactStr = builder.build(wrapped);
console.log(edifactStr); // Ready to send!

πŸ“¦ Package Overview

Package Size Messages License Use Case
@ediflow/core 120 KB - MIT Parser engine, use cases, domain
@ediflow/edifact - - MIT EDIFACT parsers & builders
@ediflow/x12 - - MIT X12 parsers & validators
@ediflow/infrastructure-shared - - MIT Repositories, loaders, cache
@ediflow/cli - - MIT Command-line interface
@ediflow/edifact-d96a 0.32 MB 89 MIT D.96A (1996)
@ediflow/edifact-d01b 0.36 MB 155 MIT D.01B (2001)
@ediflow/edifact-d20b 1.34 MB 178 MIT D.20B (2020) β€” Latest
@ediflow/edifact-d12a 4.44 MB 196 MIT D.12A (2012) β€” Most complete
@ediflow/eancom-2002 - 50 MIT EANCOM 2002 β€” GS1 retail
@ediflow/x12-004010 7.8 MB 293 MIT X12 version 004010
@ediflow/x12-006040 - 319 MIT X12 version 006040 β€” Latest 2026
@ediflow/hipaa-x12-005010 - 14 MIT HIPAA X12 005010 β€” Healthcare

Total (all packages): ~14 MB β€’ 1294+ message types β€’ All MIT licensed

πŸ’‘ Tip: Install only what you need. All packages are free and MIT licensed.



🎯 Features

Core Features

  • Parse β€” EDIFACT / X12 / EANCOM string β†’ structured EDIMessage
  • Validate β€” 3-phase validation (Syntax β†’ Structure β†’ Business)
  • Build β€” EDIMessage β†’ EDI string (EDIFACT, X12)
  • Map β€” Business Object ↔ EDIMessage with 5 key strategies (code, name, camelCase, snake_case, kebab-case)
  • Schema Export β€” JSON Schema & YAML from any message structure
  • Envelopes β€” UNH/UNT/UNB/UNZ and ISA/GS/ST/SE/GE/IEA generation & parsing

Supported Standards

EDIFACT (UN/EDIFACT)

  • D.96A (1996) β€” 89 message types
  • D.01B (2001) β€” 155 message types
  • D.20B (2020) β€” 178 message types
  • D.12A (2012) β€” 196 message types (most complete)

EANCOM 2002 (GS1 retail subset of EDIFACT)

  • EANCOM 2002 β€” 50 message types (DESADV, ORDERS, INVOIC, PRICAT, ...)
  • Uses GLN (Global Location Numbers) & EAN-13 / GTIN product codes

X12 (ANSI ASC X12)

  • 004010 β€” 293 transaction sets (850, 810, 856, 997, ...)
  • 006040 β€” 319 transaction sets β€” Latest 2026 release

HIPAA X12 (Healthcare)

  • 005010 β€” 14 transaction sets (837P, 837I, 835, 270, 271, ...)
  • US-mandated standard for healthcare transactions (HIPAA)

Message Types (1294+ total)

EDIFACT Logistics: DESADV, ORDERS, ORDRSP, RECADV, IFTMIN, IFTSTA, IFCSUM
EDIFACT Financial: INVOIC, REMADV, FINSTA, PAYMUL
EDIFACT Catalog: PRICAT, SLSRPT
EANCOM Retail: DESADV, INVOIC, ORDERS, ORDRSP, PRICAT, SLSRPT, RECADV, ...
X12 Retail/Logistics: 850 PO, 810 Invoice, 856 ASN, 997 Functional ACK
X12 Healthcare: 837P/I Claims, 835 Remittance, 270/271 Eligibility, ...
Plus: 1000+ more across all versions and standards


πŸ’‘ Examples

πŸ“– See complete runnable examples on GitHub: examples/

Folder Examples
examples/edifact/ Build INVOIC, Parse ORDERS, Validate DESADV
examples/eancom/ Parse DESADV (GLN/EAN-13), Validate envelope
examples/x12/ Build 850 PO, Parse 850, Validate 837, Schema Export, Multi-message
examples/hipaa/ Parse 837P, Validate 835
examples/cli/ All CLI commands with input/result files

πŸ—οΈ Architecture

EDIFlow follows Clean Architecture (Uncle Bob) with strict layer separation:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Presentation Layer             β”‚  @ediflow/cli
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Application Layer              β”‚  Use Cases, DTOs
β”‚      @ediflow/core (application/)   β”‚  ParseEDI, ValidateMessage, BuildEDI
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Domain Layer                   β”‚  Entities, Value Objects
β”‚      @ediflow/core (domain/)        β”‚  EDIMessage, ValidationRules
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Infrastructure Layer           β”‚  Format-specific parsers
β”‚  @ediflow/edifact   @ediflow/x12    β”‚  Shared: @ediflow/infrastructure-shared
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Principles:

  • βœ… Dependencies point inward (Domain has zero deps)
  • βœ… Domain Layer is framework-agnostic
  • βœ… Use Cases orchestrate business logic
  • βœ… Dependency Injection via DIContainer
  • βœ… Repository Pattern for standard definitions

Read more: Architecture Documentation


πŸ“š Documentation

Package Documentation


πŸ—ΊοΈ Roadmap

βœ… M1 - EDIFACT Foundation (v0.1.0 / February 2026)

  • EDIFACT parsing, validation, building
  • 4 EDIFACT versions (D.96A, D.01B, D.20B, D.12A)
  • 618 message types total
  • Clean Architecture
  • 599 tests

βœ… M2 - Architecture Refactoring & X12 (v0.2.0 / v0.3.0)

  • Monorepo with format-specific packages
  • X12 Parser with full ISA/GS/ST/SE/GE/IEA envelope support
  • X12 Validation Rules (STRICT/LENIENT)
  • Schema Export for X12 and EDIFACT via CLI
  • EANCOM 2002 and HIPAA X12 005010 data packages
  • Business Object Mapping + unmap (round-trip)
  • 857 tests

πŸš€ M3 - Enhanced Features (Q3 2026)

  • UNG/UNE functional groups
  • More X12 transaction sets
  • Performance optimizations
  • SaaS Platform (EDIFlow Cloud)

🌍 M4 - More Standards (2027)

  • IDOC support (SAP)
  • VDA support (Automotive)
  • Unified API for all standards

πŸ§ͺ Testing

  • EDIFlow is extensively tested with TDD (Test-Driven Development):

  • 857 tests passing (Unit + Integration + E2E)

  • 90%+ coverage for critical paths

  • E2E roundtrip tests across EDIFACT & X12

  • Performance tests (< 200ms parse-build-parse cycle)

npm test                    # Run all tests
npm run test:watch          # Watch mode
npm run test:coverage       # Coverage report

🀝 Contributing

We welcome contributions! EDIFlow is MIT licensed and built by the community.

Ways to contribute:

  • πŸ› Report bugs via GitHub Issues
  • πŸ’‘ Suggest features
  • πŸ“– Improve documentation
  • πŸ”§ Submit pull requests

Getting started:

  1. Read Contributing Guide
  2. Check Developer Guide
  3. Fork, develop, test, submit PR

πŸ’¬ Community


πŸ“Š Stats

Stars Forks Issues PRs


πŸ“„ License

MIT License - see LICENSE for details.

Summary:

  • βœ… Commercial use allowed
  • βœ… Modification allowed
  • βœ… Distribution allowed
  • βœ… Private use allowed
  • ℹ️ License and copyright notice required

πŸ™ Acknowledgments

EDIFlow is built with:

  • TypeScript - Type safety
  • Vitest - Testing framework
  • Clean Architecture - Architecture pattern by Robert C. Martin (Uncle Bob)
  • UN/EDIFACT - Standards by United Nations

Special thanks to the EDI community for feedback and contributions.


Made with ❀️ for the EDI community


πŸ” How Does EDIFlow Compare?

Feature EDIFlow edifact x12-parser
EDIFACT parsing βœ… 4 versions (D.96A–D.20B) ⚠️ generic only ❌
X12 parsing βœ… 2 versions (004010, 006040) ❌ ⚠️ generic only
HIPAA X12 005010 βœ… 14 transaction sets ❌ ❌
EANCOM βœ… 50 GS1 messages ❌ ❌
Validation βœ… Structure + code lists ❌ ❌
Build (JSON β†’ EDI) βœ… Round-trip ❌ ❌
Business Object Mapping βœ… Typed JSON keys ❌ ❌
TypeScript (strict) βœ… ❌ (JS) ❌ (JS)
Message types 1,000+ across all standards ~30 ~20
CLI tool βœ… ❌ ❌
Actively maintained βœ… (2026) ❌ (last update 2020) ❌ (last update 2022)
License MIT MIT MIT

EDIFlow is the only TypeScript library that handles multiple EDI standards with full parse β†’ validate β†’ build round-trip.


Status: πŸš€ Production Ready
Version: 0.3.0
Released: May 2026
Maintained by: EDIFlow Contributors


⭐ Star us on GitHub β€’ πŸ“¦ View on NPM β€’ πŸš€ Quick Start β€’ πŸ› Report Bug