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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@glion/ack

v0.16.0

Published

HL7v2 acknowledgment message builder and typed error classes

Readme

@glion/ack

HL7v2 acknowledgment message builder and typed exception classes.

What it does

@glion/ack builds spec-compliant ACK/NAK response ASTs from a parsed HL7v2 message. The acknowledge() function accepts an original message Root and returns a new Root containing an MSH, MSA, and (when an error is supplied) an ERR segment. Typed exception classes (AckApplicationError, AckApplicationReject, AckCommitError, AckCommitReject) carry the HL7v2 error code and severity that the response needs, so callers throw semantic errors and the builder renders them as the correct MSA-1 code.

Install

npm install @glion/ack

Use

Build a successful acknowledgment (AA):

import { acknowledge } from "@glion/ack";
import { toHl7v2 } from "@glion/to-hl7v2";

const ack = acknowledge(originalTree);
const raw = toHl7v2(ack);
// MSH|^~\&|RecvApp|RecvFac|SendApp|SendFac|20240115023000||ACK^A01|<auto-id>|P|2.5.1
// MSA|AA|MSG001

Build an application error (AE) or reject (AR):

import {
  acknowledge,
  AckApplicationError,
  AckApplicationReject,
} from "@glion/ack";

const error = new AckApplicationError("Validation failed", {
  errorCode: "207",
  severity: "E",
});

const ack = acknowledge(originalTree, { error });
// MSA|AE|MSG001|Validation failed
// ERR|||207|E

The ACK sender (MSH-3/MSH-4) is derived from the original message's MSH-5/MSH-6 by default.

API

acknowledge(origin, options?)

Builds an ACK/NAK Root AST from the original message tree.

| Parameter | Type | Description | | --------------------------- | -------------- | ------------------------------------------------------------------ | | origin | Root | Parsed AST of the original HL7v2 message | | options.id | string | Custom MSH-10 control ID. Auto-generated via uid() when omitted | | options.sending | SendingInfo | MSH-3/MSH-4 of the ACK. Defaults to original message's MSH-5/MSH-6 | | options.processingId | string | MSH-11 processing ID. Defaults to original message's MSH-11 | | options.error | AckException | Sets the MSA-1 code and populates MSA-3 with the error message | | options.includeErrSegment | boolean | Include ERR segment when an error is provided. Defaults to true |

Returns a Root node containing MSH, MSA, and optionally ERR segments.

Exception classes

new AckApplicationError(message, { errorCode, severity?, cause? })
new AckApplicationReject(message, { errorCode, severity?, cause? })
new AckCommitError(message, { errorCode, severity?, cause? })
new AckCommitReject(message, { errorCode, severity?, cause? })

All four extend AckException, which extends Error. Pre-configured convenience subclasses are exported for common cases: ApplicationInternalError (AE, code 207), UnsupportedMessageTypeReject (AR, code 200), CommitInternalError (CE, code 207). The standard cause option supports error chains.

uid(options?)

Generates a unique identifier suitable for MSH-10 control IDs.

| Parameter | Type | Default | Description | | ---------------- | -------- | ------- | -------------------------------- | | options.prefix | string | — | Optional prefix for the ID | | options.size | number | 20 | Total length of the generated ID |

Constants

AckCode, Hl7ErrorCode, and Severity are exported as const objects with the standard HL7v2 enumeration values.

Acknowledgment codes

HL7v2 distinguishes two levels of acknowledgment — application and commit — and each has accept, error, and reject variants. The exception class you throw determines MSA-1 directly.

| Class | MSA-1 | Meaning | | ---------------------- | ----- | ---------------------------------------------------------------------- | | (no error) | AA | Application accept. The receiver processed the message. | | AckApplicationError | AE | Application error. Syntactically valid but rejected by business logic. | | AckApplicationReject | AR | Application reject. The receiver cannot accept the message at all. | | AckCommitError | CE | Commit error (enhanced mode). Persistence or downstream failure. | | AckCommitReject | CR | Commit reject (enhanced mode). Refused at the commit layer. |

When an exception is passed via options.error, its errorCode and severity populate the ERR segment. The error's message populates MSA-3 (text message).

Part of Glion

@glion/ack is part of Glion, the application framework for HL7v2. See the Glion README for the full package catalog and architecture.