Skip to main content
Version: v0.0.2

Function: buildTA1()

buildTA1(spec, options?): Ta1Segment

buildTA1 - assemble a TA1 Interchange Acknowledgment segment from the supplied spec. The returned Ta1Segment carries the 1-indexed 5-element value array (elements[0] = "TA1", elements[1] = TA1-01, …, elements[5] = TA1-05) plus the verbatim wire text on raw (no segment terminator appended - that's the envelope's job).

Safety guards (refused via AckBuildError):

  • ackCode === "A" paired with noteCode !== "000" → "./errors.js".ACK_BUILD_ERROR_CODES.X12_TA1_ACCEPT_WITH_NOTE. Accept must mean accept. Use E (accept with errors) when the inbound had structural defects you elected to ignore.

Parameters

spec

BuildTA1Spec

The TA1 fields. interchangeControlNumber echoes the inbound ISA-13; interchangeDate / interchangeTime echo the inbound ISA-09 / ISA-10; ackCode is the disposition; noteCode is the note (000 for no-error pairings).

options?

BuildTA1Options = {}

Optional delimiter overrides for callers building TA1 segments embedded in non-default envelopes. The defaults match the cosyte parser archetype (* element, ~ segment) - override when wrapping a TA1 in an ISA envelope whose declared delimiters differ.

Returns

Ta1Segment

Example

import { buildTA1 } from "@cosyte/x12";

// Accept (canonical "no error" pairing).
const ok = buildTA1({
interchangeControlNumber: "000000001",
interchangeDate: "250101",
interchangeTime: "1200",
ackCode: "A",
noteCode: "000",
});
ok.raw; // 'TA1*000000001*250101*1200*A*000'

// Reject (control number mismatch).
const reject = buildTA1({
interchangeControlNumber: "000000007",
interchangeDate: "250101",
interchangeTime: "1200",
ackCode: "R",
noteCode: "001",
});