npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

unnbound-edi-sdk

v1.0.13

Published

An EDI client with structured logging.

Readme

Unnbound EDI Client

A TypeScript EDI client with structured logging and distributed tracing capabilities, built for processing X12 EDI documents with comprehensive error handling and automatic span tracking.

Features

  • X12 EDI Processing: Complete X12 document parsing, validation, and generation
  • Structured Logging: Built-in integration with Unnbound Logger for comprehensive operation tracking
  • Distributed Tracing: Automatic span creation for all EDI operations with detailed payload information
  • Type Safety: Full TypeScript support with comprehensive type definitions
  • Error Handling: Custom error types with detailed error codes and context

Installation

npm install unnbound-edi-sdk
# or
pnpm add unnbound-edi-sdk
# or
yarn add unnbound-edi-sdk

Environment Variables

Required

  • UNNBOUND_EDI_API_KEY - Your API key for authentication

Quick Start

import { UnnboundEdiClient } from 'unnbound-edi-sdk';
import { logger } from 'unnbound-logger-sdk';

// Set your API key
process.env.UNNBOUND_EDI_API_KEY = 'your-api-key';

const edi = new UnnboundEdiClient();

// Parse X12 document to JSON
const x12Interchanges = await edi.fromX12({
  input: 'ISA*00*          *00*          *12*NOTP...',
});

// Validate X12 interchange
const validationResult = await edi.validateX12({
  input: x12Interchanges[0],
});

// Convert JSON back to X12
const x12Document = await edi.toX12({
  input: x12Interchanges[0],
});

// Generate acknowledgment
const acknowledgment = await edi.acknowledgeX12({
  input: x12Interchanges[0],
});

API Reference

Constructor

new UnnboundEdiClient();

Creates a new EDI client instance. Requires UNNBOUND_EDI_API_KEY environment variable to be set.

Methods

fromX12(options: FromX12Options): Promise<X12Interchange[]>

Parses X12 EDI documents into JSON format.

const x12Interchanges = await edi.fromX12({
  input: 'ISA*00*          *00*          *12*NOTP...',
});

Parameters:

  • options.input - The X12 document as a string or File object

Returns: Array of parsed X12 interchange objects

toX12(options: ToX12Options): Promise<unknown>

Converts JSON X12 interchange objects back to X12 format.

const x12Document = await edi.toX12({
  input: x12InterchangeObject,
});

Parameters:

  • options.input - The X12 interchange object to convert

Returns: X12 document as string

validateX12(options: ValidateX12Options): Promise<OperationResult>

Validates X12 interchange objects against EDI standards.

const validationResult = await edi.validateX12({
  input: x12InterchangeObject,
});

Parameters:

  • options.input - The X12 interchange object to validate

Returns: Validation result with operation details

acknowledgeX12(options: AcknolwedgeX12Options): Promise<OperationResult>

Generates acknowledgment for X12 interchange objects.

const acknowledgment = await edi.acknowledgeX12({
  input: x12InterchangeObject,
});

Parameters:

  • options.input - The X12 interchange object to acknowledge

Returns: Acknowledgment result with operation details

Error Handling

The EDI client provides custom error types for different operation failures:

UnnboundEdiClientError

import { UnnboundEdiClientError, isUnnboundEdiClientError } from 'unnbound-edi-sdk';

try {
  await edi.fromX12({ input: invalidX12 });
} catch (error) {
  if (isUnnboundEdiClientError(error)) {
    console.error('EDI Error:', error.code, error.message);
    // Handle specific EDI errors
  }
}

Error Codes

| Code | Description | | ----------------------- | ------------------------------- | | edi_read_error | Error parsing X12 document | | edi_write_error | Error converting JSON to X12 | | edi_validate_error | Error validating X12 document | | edi_acknowledge_error | Error generating acknowledgment | | edi_unknown_error | Unknown error occurred |

Type Definitions

FromX12Options

interface FromX12Options {
  input: unknown; // X12 document as string or File
}

ToX12Options

interface ToX12Options {
  input: X12Interchange; // X12 interchange object
}

ValidateX12Options

interface ValidateX12Options {
  input: X12Interchange; // X12 interchange object
}

AcknolwedgeX12Options

interface AcknolwedgeX12Options {
  input: X12Interchange; // X12 interchange object
}

OperationResult

interface OperationResult {
  LastIndex?: number;
  Details?: Array<OperationDetail> | null;
  Status?: string | null;
}

OperationDetail

interface OperationDetail {
  Index?: number;
  TransactionIndex?: number;
  TransactionRef?: string | null;
  SpecRef?: string | null;
  SegmentId?: string | null;
  DataElementId?: string | null;
  DataElementIndex?: number;
  CompositeIndex?: number;
  RepIndex?: number;
  Value?: string | null;
  Message?: string | null;
  Status?: string | null;
}

Logging and Tracing

The Unnbound EDI Client automatically creates spans for all operations and logs detailed information including:

  • Operation type and timing
  • Input and output data
  • API request/response details
  • Error details (if any)
  • Validation results
  • Acknowledgment status

Example Log Output

{"level":"info","spanId":"556c53e6-3bb8-4118-b3b8-570e41c27654","type":"edi","edi":{"type":"x12","x12":{"input":"ISA*00*...","output":[...]}},"message":"X12 to JSON started."}
{"level":"info","spanId":"556c53e6-3bb8-4118-b3b8-570e41c27654","type":"edi","edi":{"type":"x12","x12":{"input":"ISA*00*...","output":[...]}},"duration":1250,"message":"X12 to JSON completed."}

Complete Example

import { UnnboundEdiClient } from 'unnbound-edi-sdk';
import { logger } from 'unnbound-logger-sdk';

const run = async () => {
  const edi = new UnnboundEdiClient();

  const x12Data = `ISA*00*          *00*          *12*NOTP           *12*NOTP           *080501*1700*U*00401*000001000*0*P*>
GS*PO*NOTP*NOTP*20080501*1700*1000*X*004010
ST*850*000000010
BEG*00*SA*08292243254**20010501*610385388
REF*DP*030
REF*PS*
ITD*14*3*2**45**46
DTM*001*20010510
PKG*F*68***PALLET, SHRINKWRAP 48W X 40D X 45H
PKG*F*66***REGULAR
TD5*A*92*P3**SEE ROUTING GUIDE FOR ROUTING
N1*ST*RETAIL STORE*9*0001234567890
N3*123 ANYWHERE AVENUE
N4*CITY*ST*12345
PO1*1*120*EA*9.25*TE*CB*(12) 0-083628-838*PR*RO*VN*ABA18783
PO1*2*220*EA*13.7 9*TE*CB*(69) 0-093 83 7-991*PR*RO*VN*RUP83112
PO1*3*126*EA*10.9 9*TE*CB*(71) 0-099172-837*PR*RO*VN*CPR19293
PO1*4*76*EA*4.35*TE*CB*(71) 0-012110-737*PR*RO*VN*PIW28173
PO1*5*72*EA*7.5*TE*CB*(71) 0-0848 88-9 75*PR*RO*VN*JBM1938 7
PO1*6*696*EA*9.55*TE*CB*(71) 0-003 922-121*PR*RO*VN*IUI19283
CTT*6
SE*20*000000010
GE*1*1000
IEA*1*000001000`;

  try {
    // Parse X12 to JSON
    const x12Interchanges = await edi.fromX12({ input: x12Data });
    logger.info({ count: x12Interchanges.length }, 'Parsed X12 interchanges');

    // Process each interchange
    for (const interchange of x12Interchanges) {
      // Validate
      const validation = await edi.validateX12({ input: interchange });
      logger.info({ validation }, 'X12 validated');

      // Convert back to X12
      const x12Output = await edi.toX12({ input: interchange });
      logger.info({ x12Output }, 'Converted back to X12');

      // Generate acknowledgment
      const acknowledgment = await edi.acknowledgeX12({ input: interchange });
      logger.info({ acknowledgment }, 'Generated acknowledgment');
    }
  } catch (error) {
    logger.error({ err: error }, 'EDI processing failed');
    throw error;
  }
};

run().catch(console.error);

Requirements

  • Node.js >= 22.0.0
  • TypeScript (for TypeScript projects)
  • Unnbound EDI API key

Dependencies

  • unnbound-logger-sdk: Structured logging and tracing

Support

For support, please open an issue on the GitHub repository.