Function: buildTelecomRequest()
buildTelecomRequest(
input):TelecomTransaction
Build a spec-clean NCPDP Telecommunication vD.0 request transaction from a structured model. The conservative (emit) half of Postel's Law: it refuses to construct a message that is invalid by construction: a missing Transaction Code, a missing Segment Identification, a non-2-character field id, an embedded FS/GS/RS control character, or an over-long fixed-header field: throwing a typed NcpdpTelecomBuildError rather than producing malformed wire output a downstream processor would have to reject.
The returned transaction is frozen and ready for
"./serialize".serializeTelecom; the round trip
parseTelecom(serializeTelecom(buildTelecomRequest(input))) re-parses with zero
warnings.
Parameters
input
The header fields and segments to build.
Returns
A frozen, valid-by-construction TelecomTransaction.
Throws
NcpdpTelecomBuildError when the input cannot form a spec-clean message.
Example
import { buildTelecomRequest, serializeTelecom } from "@cosyte/ncpdp/telecom";
const t = buildTelecomRequest({
header: { transactionCode: "B1", binNumber: "999999" },
segments: [{ segmentId: "07", fields: [{ id: "D2", value: "RX0000001" }] }],
});
serializeTelecom(t); // canonical wire string