@cosyte/x12 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1095,7 +1095,10 @@ function splitSegments(text, start, delimiters) {
1095
1095
  return { segments, endIndex: lastEnd };
1096
1096
  }
1097
1097
  function splitElements(segment, delimiters) {
1098
- return Object.freeze(segment.split(delimiters.element));
1098
+ if (delimiters.element === RELEASE_CHAR) {
1099
+ return Object.freeze(segment.split(delimiters.element));
1100
+ }
1101
+ return Object.freeze(splitWithRelease(segment, delimiters.element));
1099
1102
  }
1100
1103
  function el(elements, index) {
1101
1104
  return elements[index] ?? "";
@@ -4567,6 +4570,29 @@ var VERSION_BY_VARIANT = {
4567
4570
  I: "005010X223A3",
4568
4571
  D: "005010X224A2"
4569
4572
  };
4573
+ function resolveVersionRelease(variant, reference, esc) {
4574
+ if (reference === void 0) return VERSION_BY_VARIANT[variant];
4575
+ if (reference === "") {
4576
+ throw new Claim837BuildError(
4577
+ CLAIM_837_BUILD_ERROR_CODES.X12_837_BUILD_INVALID_SPEC,
4578
+ "build837: envelope.implementationConventionReference is empty. ST-03 and GS-08 are required elements and a trailing empty element is not emitted, so an empty reference would remove them rather than send them empty. Omit the field to take the builder's default."
4579
+ );
4580
+ }
4581
+ if (esc(reference) !== reference) {
4582
+ throw new Claim837BuildError(
4583
+ CLAIM_837_BUILD_ERROR_CODES.X12_837_BUILD_INVALID_SPEC,
4584
+ "build837: envelope.implementationConventionReference carries an active delimiter or the release character. Escaping does not make it safe here: the ST and GS segments are read by a splitter that is not release-aware, so a released delimiter still splits the segment and the declaration silently becomes two elements. State a reference that carries neither, or choose different delimiters."
4585
+ );
4586
+ }
4587
+ const named = Object.hasOwn(VARIANT_BY_ICR, reference) ? VARIANT_BY_ICR[reference] : void 0;
4588
+ if (named !== void 0 && named !== variant) {
4589
+ throw new Claim837BuildError(
4590
+ CLAIM_837_BUILD_ERROR_CODES.X12_837_BUILD_INVALID_SPEC,
4591
+ `build837: envelope.implementationConventionReference names an implementation guide this library reads as a DIFFERENT 837 variant, but this is build837${variant}. The emitted file would declare one variant and carry another's service segments, and this library's own reader would then decode none of its service lines. State a reference for the ${variant} 837, or build with the entry point that matches the reference.`
4592
+ );
4593
+ }
4594
+ return reference;
4595
+ }
4570
4596
  var X12_837_FUNCTIONAL_ID = "HC";
4571
4597
  var X12_AGENCY_CODE2 = "X";
4572
4598
  var HL_LEVEL = { BILLING: "20", SUBSCRIBER: "22", PATIENT: "23" };
@@ -4581,7 +4607,6 @@ function build837D(spec) {
4581
4607
  }
4582
4608
  function buildClaim837(variant, spec) {
4583
4609
  const { envelope } = spec;
4584
- const versionRelease = VERSION_BY_VARIANT[variant];
4585
4610
  enforceStructuralSpec2(variant, spec);
4586
4611
  const elementSeparator = envelope.elementSeparator ?? "*";
4587
4612
  const repetitionSeparator = envelope.repetitionSeparator ?? "^";
@@ -4607,6 +4632,11 @@ function buildClaim837(variant, spec) {
4607
4632
  return escaped.slice(0, end).join(componentSeparator);
4608
4633
  };
4609
4634
  const ctx = { seg, esc, comp };
4635
+ const versionRelease = resolveVersionRelease(
4636
+ variant,
4637
+ envelope.implementationConventionReference,
4638
+ esc
4639
+ );
4610
4640
  const senderQualifier = envelope.senderQualifier ?? "ZZ";
4611
4641
  const receiverQualifier = envelope.receiverQualifier ?? "ZZ";
4612
4642
  const usageIndicator = envelope.usageIndicator ?? "P";
@@ -9731,18 +9761,27 @@ function expandYY8(yymmdd) {
9731
9761
  // src/transactions/ack/build-ta1.ts
9732
9762
  function buildTA1(spec, options = {}) {
9733
9763
  enforceAcceptIsClean2(spec);
9734
- const elementSeparator = options.elementSeparator ?? "*";
9764
+ const delimiters = {
9765
+ element: options.elementSeparator ?? "*",
9766
+ repetition: options.repetitionSeparator ?? "^",
9767
+ component: options.componentSeparator ?? ":",
9768
+ segment: options.segmentTerminator ?? "~"
9769
+ };
9770
+ const esc = makeCallerEscaper(delimiters, "buildTA1", refuseSpec9);
9735
9771
  const elements = Object.freeze([
9736
9772
  "TA1",
9737
- spec.interchangeControlNumber,
9738
- spec.interchangeDate,
9739
- spec.interchangeTime,
9740
- spec.ackCode,
9741
- spec.noteCode
9773
+ esc(spec.interchangeControlNumber),
9774
+ esc(spec.interchangeDate),
9775
+ esc(spec.interchangeTime),
9776
+ esc(spec.ackCode),
9777
+ esc(spec.noteCode)
9742
9778
  ]);
9743
- const raw = elements.join(elementSeparator);
9779
+ const raw = elements.join(delimiters.element);
9744
9780
  return Object.freeze({ raw, elements });
9745
9781
  }
9782
+ function refuseSpec9(message) {
9783
+ throw new AckBuildError(ACK_BUILD_ERROR_CODES.X12_ACK_INVALID_SPEC, message);
9784
+ }
9746
9785
  function enforceAcceptIsClean2(spec) {
9747
9786
  if (spec.ackCode === TA1_ACK_CODES.A && spec.noteCode !== "000") {
9748
9787
  throw new AckBuildError(
@@ -9931,7 +9970,7 @@ var X12BuildError = class extends Error {
9931
9970
  };
9932
9971
 
9933
9972
  // src/builder/build-interchange.ts
9934
- function refuseSpec9(message) {
9973
+ function refuseSpec10(message) {
9935
9974
  throw new X12BuildError(X12_BUILD_ERROR_CODES.X12_BUILD_INVALID_SPEC, message);
9936
9975
  }
9937
9976
  function buildInterchange(spec) {
@@ -9945,7 +9984,7 @@ function buildInterchange(spec) {
9945
9984
  component: componentSeparator,
9946
9985
  segment: segmentTerminator
9947
9986
  };
9948
- const esc = makeCallerEscaper(delimiters, "buildInterchange", refuseSpec9);
9987
+ const esc = makeCallerEscaper(delimiters, "buildInterchange", refuseSpec10);
9949
9988
  const senderQualifier = spec.senderQualifier ?? "ZZ";
9950
9989
  const receiverQualifier = spec.receiverQualifier ?? "ZZ";
9951
9990
  const usageIndicator = spec.usageIndicator ?? "P";
@@ -10059,7 +10098,7 @@ function buildTransaction(tx, esc, elementSeparator, segmentTerminator) {
10059
10098
  return st + bodySegments + se;
10060
10099
  }
10061
10100
  function joinSeg2(parts, elementSeparator, segmentTerminator) {
10062
- requireCallerSegment(parts, "buildInterchange", refuseSpec9);
10101
+ requireCallerSegment(parts, "buildInterchange", refuseSpec10);
10063
10102
  return parts.join(elementSeparator) + segmentTerminator;
10064
10103
  }
10065
10104
  function pad9(value, width) {
@@ -10368,7 +10407,7 @@ var profiles = Object.freeze({
10368
10407
  });
10369
10408
 
10370
10409
  // src/index.ts
10371
- var VERSION = "0.0.14";
10410
+ var VERSION = "0.0.15";
10372
10411
 
10373
10412
  export { ACK_BUILD_ERROR_CODES, ALL_WARNING_MESSAGES, AUTH_278_BUILD_ERROR_CODES, AUTH_278_LOOP_2000A, AUTH_278_LOOP_2000B, AUTH_278_LOOP_2000C, AUTH_278_LOOP_2000D, AUTH_278_LOOP_2000E, AUTH_278_LOOP_2000F, AckBuildError, BALANCE_INVARIANTS, BUILD_REFUSAL_VALUE_MAX_LENGTH, BUILD_REFUSAL_VALUE_MAX_RENDERED, CARC, CLAIM_837D_LOOP_2000A, CLAIM_837D_LOOP_2300, CLAIM_837D_LOOP_2400, CLAIM_837I_LOOP_2000A, CLAIM_837I_LOOP_2300, CLAIM_837I_LOOP_2400, CLAIM_837P_LOOP_2000A, CLAIM_837P_LOOP_2300, CLAIM_837P_LOOP_2400, CLAIM_837P_LOOP_2410, CLAIM_837_BUILD_ERROR_CODES, CLAIM_837_LOOP_1000A, CLAIM_837_LOOP_1000B, CLAIM_837_LOOP_2010AA, CLAIM_837_LOOP_2010BA, CLAIM_837_LOOP_2010BB, CLAIM_837_LOOP_2010CA, CLAIM_837_LOOP_2430, CLAIM_ADJUSTMENT_GROUP_CODES, CLAIM_STATUS_277_BUILD_ERROR_CODES, CLAIM_STATUS_CATEGORY_CODES, CLAIM_STATUS_CODES, CLP_STATUS, CONTROL_NUMBER_PAIRS, Claim837BuildError, ClaimStatus277BuildError, DELIMITER_POSITIONS, ELIGIBILITY_271_BUILD_ERROR_CODES, ELIGIBILITY_271_LOOP_2000A, ELIGIBILITY_271_LOOP_2000B, ELIGIBILITY_271_LOOP_2000C, ELIGIBILITY_271_LOOP_2000D, ELIGIBILITY_271_LOOP_2100C, ELIGIBILITY_271_LOOP_2100D, ELIGIBILITY_271_LOOP_2110, ENROLLMENT_834_BUILD_ERROR_CODES, ENROLLMENT_834_LOOP_1000A, ENROLLMENT_834_LOOP_1000B, ENROLLMENT_834_LOOP_2000, ENROLLMENT_834_LOOP_2100A, ENROLLMENT_834_LOOP_2300, ENROLLMENT_834_LOOP_2320, Eligibility271BuildError, Enrollment834BuildError, FATAL_CODES, HI_QUALIFIERS, HL_LEVEL_CODES, IK3_SYNTAX_ERROR_CODES, IK4_SYNTAX_ERROR_CODES, ISA_MIN_LENGTH, LoopSpecDefinitionError, MAINTENANCE_TYPE_CODES, NM1_QUALIFIERS, NON_SPEC_SEGMENT_ID, PREMIUM_820_BUILD_ERROR_CODES, PREMIUM_820_LOOP_1000A, PREMIUM_820_LOOP_1000B, PREMIUM_820_LOOP_2000A, PREMIUM_820_LOOP_2100A, PREMIUM_820_LOOP_2300A, PREMIUM_820_LOOP_2310A, Premium820BuildError, RARC, RELEASE_CHAR, REMIT_835_BUILD_ERROR_CODES, REMIT_835_LOOP_1000A, REMIT_835_LOOP_1000B, REMIT_835_LOOP_2000, REMIT_835_LOOP_2100, REMIT_835_LOOP_2110, REQUIRED_LOOPS, Remit835BuildError, SERVICE_TYPE_CODES, STATUS_277_LOOP_2000A, STATUS_277_LOOP_2000B, STATUS_277_LOOP_2000C, STATUS_277_LOOP_2000D, STATUS_277_LOOP_2000E, STATUS_277_LOOP_2200, STATUS_277_LOOP_2220, ServicesReview278BuildError, TA1_ACK_CODES, TA1_NOTE_CODES, UNEXPECTED_SEGMENT_CONTEXTS, VERSION, WARNING_CODES, X12BuildError, X12Decimal, X12ParseError, X12ProfileError, X12_ACK_DISPOSITION_CODES, X12_BUILD_ERROR_CODES, ambiguous837Variant, amountRowDropped, balanceNotEvaluable, build271, build277, build277CA, build278Request, build278Response, build820, build834, build835, build837D, build837I, build837P, build999, buildInterchange, buildTA1, checkClaimBalance, checkRemitTotalBalance, checkServiceLineBalance, collectElementValues, componentOptional, controlNumberMismatch, danglingReleaseChar, decodeSegment, defineLoopSpec, defineProfile, detectDelimiters, elementDecimal, elementDecimalOrZero, elementOptional, elementValue, entitySegmentDiscardedAfterLx, escapeRelease, get271Eligibility, get277CADisposition, get277Status, get278Request, get278Response, get820Payments, get834Enrollments, get834Header, get835, get837Claims, getAllSegmentValues, getDefaultProfile, getSegmentValue, groupCountMismatch, hlParentLevelInvalid, hlParentMismatch, isAcceptDisposition, isClaimAdjustmentGroupCode, isDiagnosisQualifier, isProcedureQualifier, lookupCarc, lookupClaimStatus, lookupClaimStatusCategory, lookupClpStatus, lookupMaintenanceType, lookupRarc, lookupServiceType, missingGe, missingIea, missingRequiredLoop, missingSe, parse999, parseTA1, parseX12, partitionWarnings, payToAddressRepeated, pre005010, profiles, readElementDecimal, remitBalanceMismatch, renderCallerValue, resolveHiQualifier, segmentCountMismatch, serializeX12, serviceLineDropped, serviceLineNotDecoded, serviceSegmentRepeated, serviceSegmentWithoutLx, setDefaultProfile, statedAmountDiscarded, trailingGarbage, transactionCountMismatch, unescapeRelease, unexpectedSegment, unknown837Variant, unknownCarc, unknownClaimStatus, unknownClaimStatusCategory, unknownHiQualifier, unknownMaintenanceType, unknownRarc, unparseableDecimal };
10374
10413
  //# sourceMappingURL=index.mjs.map