@ontemper/edi 1.1.0

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.
Files changed (129) hide show
  1. package/README.md +321 -0
  2. package/dist/control-numbers.d.ts +20 -0
  3. package/dist/control-numbers.js +77 -0
  4. package/dist/edination-client/api/edi-model-api.d.ts +268 -0
  5. package/dist/edination-client/api/edi-model-api.js +326 -0
  6. package/dist/edination-client/api/edifact-api.d.ts +453 -0
  7. package/dist/edination-client/api/edifact-api.js +448 -0
  8. package/dist/edination-client/api/hl7-api.d.ts +294 -0
  9. package/dist/edination-client/api/hl7-api.js +315 -0
  10. package/dist/edination-client/api/ncpdp-api.d.ts +278 -0
  11. package/dist/edination-client/api/ncpdp-api.js +305 -0
  12. package/dist/edination-client/api/vda-api.d.ts +262 -0
  13. package/dist/edination-client/api/vda-api.js +295 -0
  14. package/dist/edination-client/api/x12-api.d.ts +437 -0
  15. package/dist/edination-client/api/x12-api.js +438 -0
  16. package/dist/edination-client/api.d.ts +17 -0
  17. package/dist/edination-client/api.js +35 -0
  18. package/dist/edination-client/base.d.ts +66 -0
  19. package/dist/edination-client/base.js +70 -0
  20. package/dist/edination-client/common.d.ts +65 -0
  21. package/dist/edination-client/common.js +142 -0
  22. package/dist/edination-client/configuration.d.ts +91 -0
  23. package/dist/edination-client/configuration.js +104 -0
  24. package/dist/edination-client/index.d.ts +14 -0
  25. package/dist/edination-client/index.js +32 -0
  26. package/dist/edination-client/model/batch-receiving-application.d.ts +36 -0
  27. package/dist/edination-client/model/batch-receiving-application.js +15 -0
  28. package/dist/edination-client/model/batch-receiving-facility.d.ts +36 -0
  29. package/dist/edination-client/model/batch-receiving-facility.js +15 -0
  30. package/dist/edination-client/model/batch-receiving-network-address.d.ts +36 -0
  31. package/dist/edination-client/model/batch-receiving-network-address.js +15 -0
  32. package/dist/edination-client/model/batch-sending-application.d.ts +36 -0
  33. package/dist/edination-client/model/batch-sending-application.js +15 -0
  34. package/dist/edination-client/model/batch-sending-facility.d.ts +36 -0
  35. package/dist/edination-client/model/batch-sending-facility.js +15 -0
  36. package/dist/edination-client/model/batch-sending-network-address.d.ts +36 -0
  37. package/dist/edination-client/model/batch-sending-network-address.js +15 -0
  38. package/dist/edination-client/model/bhs.d.ts +108 -0
  39. package/dist/edination-client/model/bhs.js +15 -0
  40. package/dist/edination-client/model/bts.d.ts +36 -0
  41. package/dist/edination-client/model/bts.js +15 -0
  42. package/dist/edination-client/model/edi-model.d.ts +37 -0
  43. package/dist/edination-client/model/edi-model.js +15 -0
  44. package/dist/edination-client/model/edifact-group.d.ts +38 -0
  45. package/dist/edination-client/model/edifact-group.js +15 -0
  46. package/dist/edination-client/model/edifact-interchange.d.ts +53 -0
  47. package/dist/edination-client/model/edifact-interchange.js +15 -0
  48. package/dist/edination-client/model/error-details.d.ts +30 -0
  49. package/dist/edination-client/model/error-details.js +15 -0
  50. package/dist/edination-client/model/fhs.d.ts +108 -0
  51. package/dist/edination-client/model/fhs.js +15 -0
  52. package/dist/edination-client/model/file-receiving-application.d.ts +36 -0
  53. package/dist/edination-client/model/file-receiving-application.js +15 -0
  54. package/dist/edination-client/model/file-receiving-facility.d.ts +36 -0
  55. package/dist/edination-client/model/file-receiving-facility.js +15 -0
  56. package/dist/edination-client/model/file-receiving-network-address.d.ts +36 -0
  57. package/dist/edination-client/model/file-receiving-network-address.js +15 -0
  58. package/dist/edination-client/model/file-sending-application.d.ts +36 -0
  59. package/dist/edination-client/model/file-sending-application.js +15 -0
  60. package/dist/edination-client/model/file-sending-facility.d.ts +36 -0
  61. package/dist/edination-client/model/file-sending-facility.js +15 -0
  62. package/dist/edination-client/model/file-sending-network-address.d.ts +36 -0
  63. package/dist/edination-client/model/file-sending-network-address.js +15 -0
  64. package/dist/edination-client/model/flat-message.d.ts +37 -0
  65. package/dist/edination-client/model/flat-message.js +15 -0
  66. package/dist/edination-client/model/fts.d.ts +30 -0
  67. package/dist/edination-client/model/fts.js +15 -0
  68. package/dist/edination-client/model/ge.d.ts +30 -0
  69. package/dist/edination-client/model/ge.js +15 -0
  70. package/dist/edination-client/model/gs.d.ts +66 -0
  71. package/dist/edination-client/model/gs.js +15 -0
  72. package/dist/edination-client/model/hl7-group.d.ts +38 -0
  73. package/dist/edination-client/model/hl7-group.js +15 -0
  74. package/dist/edination-client/model/hl7-interchange.d.ts +46 -0
  75. package/dist/edination-client/model/hl7-interchange.js +15 -0
  76. package/dist/edination-client/model/iea.d.ts +30 -0
  77. package/dist/edination-client/model/iea.js +15 -0
  78. package/dist/edination-client/model/index.d.ts +49 -0
  79. package/dist/edination-client/model/index.js +65 -0
  80. package/dist/edination-client/model/isa.d.ts +114 -0
  81. package/dist/edination-client/model/isa.js +15 -0
  82. package/dist/edination-client/model/link.d.ts +36 -0
  83. package/dist/edination-client/model/link.js +15 -0
  84. package/dist/edination-client/model/ncpdp-transmission.d.ts +45 -0
  85. package/dist/edination-client/model/ncpdp-transmission.js +15 -0
  86. package/dist/edination-client/model/operation-detail.d.ts +90 -0
  87. package/dist/edination-client/model/operation-detail.js +15 -0
  88. package/dist/edination-client/model/operation-result.d.ts +37 -0
  89. package/dist/edination-client/model/operation-result.js +15 -0
  90. package/dist/edination-client/model/s001.d.ts +42 -0
  91. package/dist/edination-client/model/s001.js +15 -0
  92. package/dist/edination-client/model/s002.d.ts +42 -0
  93. package/dist/edination-client/model/s002.js +15 -0
  94. package/dist/edination-client/model/s003.d.ts +42 -0
  95. package/dist/edination-client/model/s003.js +15 -0
  96. package/dist/edination-client/model/s004.d.ts +30 -0
  97. package/dist/edination-client/model/s004.js +15 -0
  98. package/dist/edination-client/model/s005.d.ts +30 -0
  99. package/dist/edination-client/model/s005.js +15 -0
  100. package/dist/edination-client/model/s006.d.ts +30 -0
  101. package/dist/edination-client/model/s006.js +15 -0
  102. package/dist/edination-client/model/s007.d.ts +30 -0
  103. package/dist/edination-client/model/s007.js +15 -0
  104. package/dist/edination-client/model/s008.d.ts +36 -0
  105. package/dist/edination-client/model/s008.js +15 -0
  106. package/dist/edination-client/model/ta1.d.ts +48 -0
  107. package/dist/edination-client/model/ta1.js +15 -0
  108. package/dist/edination-client/model/transmission-header.d.ts +66 -0
  109. package/dist/edination-client/model/transmission-header.js +15 -0
  110. package/dist/edination-client/model/transmission-trailer.d.ts +36 -0
  111. package/dist/edination-client/model/transmission-trailer.js +15 -0
  112. package/dist/edination-client/model/una.d.ts +54 -0
  113. package/dist/edination-client/model/una.js +15 -0
  114. package/dist/edination-client/model/unb.d.ts +89 -0
  115. package/dist/edination-client/model/unb.js +15 -0
  116. package/dist/edination-client/model/une.d.ts +30 -0
  117. package/dist/edination-client/model/une.js +15 -0
  118. package/dist/edination-client/model/ung.d.ts +70 -0
  119. package/dist/edination-client/model/ung.js +15 -0
  120. package/dist/edination-client/model/unz.d.ts +30 -0
  121. package/dist/edination-client/model/unz.js +15 -0
  122. package/dist/edination-client/model/x12-group.d.ts +38 -0
  123. package/dist/edination-client/model/x12-group.js +15 -0
  124. package/dist/edination-client/model/x12-interchange.d.ts +65 -0
  125. package/dist/edination-client/model/x12-interchange.js +15 -0
  126. package/dist/index.d.ts +45 -0
  127. package/dist/index.js +197 -0
  128. package/examples/node-edi.ts +58 -0
  129. package/package.json +49 -0
@@ -0,0 +1,70 @@
1
+ /**
2
+ * EdiNation API
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 2
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import type { S004 } from './s004';
13
+ import type { S006 } from './s006';
14
+ import type { S007 } from './s007';
15
+ import type { S008 } from './s008';
16
+ /**
17
+ *
18
+ * @export
19
+ * @interface UNG
20
+ */
21
+ export interface UNG {
22
+ /**
23
+ *
24
+ * @type {string}
25
+ * @memberof UNG
26
+ */
27
+ MessageGroupIdentification_1?: string | null;
28
+ /**
29
+ *
30
+ * @type {S006}
31
+ * @memberof UNG
32
+ */
33
+ APPLICATIONSENDERIDENTIFICATION_2?: S006;
34
+ /**
35
+ *
36
+ * @type {S007}
37
+ * @memberof UNG
38
+ */
39
+ APPLICATIONRECIPIENTIDENTIFICATION_3?: S007;
40
+ /**
41
+ *
42
+ * @type {S004}
43
+ * @memberof UNG
44
+ */
45
+ DATEANDTIMEOFPREPARATION_4?: S004;
46
+ /**
47
+ *
48
+ * @type {string}
49
+ * @memberof UNG
50
+ */
51
+ GroupReferenceNumber_5?: string | null;
52
+ /**
53
+ *
54
+ * @type {string}
55
+ * @memberof UNG
56
+ */
57
+ ControllingAgency_6?: string | null;
58
+ /**
59
+ *
60
+ * @type {S008}
61
+ * @memberof UNG
62
+ */
63
+ MESSAGEVERSION_7?: S008;
64
+ /**
65
+ *
66
+ * @type {string}
67
+ * @memberof UNG
68
+ */
69
+ ApplicationPassword_8?: string | null;
70
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * EdiNation API
6
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+ *
8
+ * The version of the OpenAPI document: 2
9
+ *
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * EdiNation API
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 2
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ /**
13
+ *
14
+ * @export
15
+ * @interface UNZ
16
+ */
17
+ export interface UNZ {
18
+ /**
19
+ *
20
+ * @type {string}
21
+ * @memberof UNZ
22
+ */
23
+ InterchangeControlCount_1?: string | null;
24
+ /**
25
+ *
26
+ * @type {string}
27
+ * @memberof UNZ
28
+ */
29
+ InterchangeControlReference_2?: string | null;
30
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * EdiNation API
6
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+ *
8
+ * The version of the OpenAPI document: 2
9
+ *
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,38 @@
1
+ /**
2
+ * EdiNation API
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 2
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import type { GE } from './ge';
13
+ import type { GS } from './gs';
14
+ /**
15
+ *
16
+ * @export
17
+ * @interface X12Group
18
+ */
19
+ export interface X12Group {
20
+ /**
21
+ *
22
+ * @type {GS}
23
+ * @memberof X12Group
24
+ */
25
+ GS: GS;
26
+ /**
27
+ *
28
+ * @type {Array<any>}
29
+ * @memberof X12Group
30
+ */
31
+ Transactions: Array<any>;
32
+ /**
33
+ *
34
+ * @type {Array<GE>}
35
+ * @memberof X12Group
36
+ */
37
+ GETrailers?: Array<GE> | null;
38
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * EdiNation API
6
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+ *
8
+ * The version of the OpenAPI document: 2
9
+ *
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,65 @@
1
+ /**
2
+ * EdiNation API
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 2
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import type { IEA } from './iea';
13
+ import type { ISA } from './isa';
14
+ import type { OperationResult } from './operation-result';
15
+ import type { TA1 } from './ta1';
16
+ import type { X12Group } from './x12-group';
17
+ /**
18
+ *
19
+ * @export
20
+ * @interface X12Interchange
21
+ */
22
+ export interface X12Interchange {
23
+ /**
24
+ *
25
+ * @type {string}
26
+ * @memberof X12Interchange
27
+ */
28
+ SegmentDelimiter: string;
29
+ /**
30
+ *
31
+ * @type {string}
32
+ * @memberof X12Interchange
33
+ */
34
+ DataElementDelimiter: string;
35
+ /**
36
+ *
37
+ * @type {ISA}
38
+ * @memberof X12Interchange
39
+ */
40
+ ISA: ISA;
41
+ /**
42
+ *
43
+ * @type {TA1}
44
+ * @memberof X12Interchange
45
+ */
46
+ TA1?: TA1;
47
+ /**
48
+ *
49
+ * @type {Array<X12Group>}
50
+ * @memberof X12Interchange
51
+ */
52
+ Groups: Array<X12Group>;
53
+ /**
54
+ *
55
+ * @type {Array<IEA>}
56
+ * @memberof X12Interchange
57
+ */
58
+ IEATrailers?: Array<IEA> | null;
59
+ /**
60
+ *
61
+ * @type {OperationResult}
62
+ * @memberof X12Interchange
63
+ */
64
+ Result?: OperationResult;
65
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * EdiNation API
6
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+ *
8
+ * The version of the OpenAPI document: 2
9
+ *
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,45 @@
1
+ import { type X12Interchange } from './edination-client';
2
+ export * from './edination-client/model';
3
+ export { getNextControlNumber, getCurrentControlNumber, setControlNumber } from './control-numbers';
4
+ interface UnnboundErrorOptions<C extends string = string> extends ErrorOptions {
5
+ message: string;
6
+ code: C;
7
+ }
8
+ declare class UnnboundError<C extends string = string> extends Error {
9
+ code: C;
10
+ constructor({ message, code, ...o }: UnnboundErrorOptions<C>);
11
+ }
12
+ export type UnnboundEdiClientErrorCode = 'edi_read_error' | 'edi_write_error' | 'edi_validate_error' | 'edi_acknowledge_error' | 'edi_unauthorized_error' | 'edi_unknown_error';
13
+ export declare class UnnboundEdiClientError extends UnnboundError<UnnboundEdiClientErrorCode> {
14
+ constructor({ message, code, ...o }: UnnboundErrorOptions<UnnboundEdiClientErrorCode>);
15
+ }
16
+ export declare const isUnnboundEdiClientError: (error: unknown) => error is UnnboundEdiClientError;
17
+ export interface FromX12Options {
18
+ input: unknown;
19
+ }
20
+ export interface ToX12Options {
21
+ input: X12Interchange;
22
+ }
23
+ export interface ValidateX12Options {
24
+ input: X12Interchange;
25
+ }
26
+ export interface AcknolwedgeX12Options {
27
+ input: X12Interchange;
28
+ }
29
+ export declare class UnnboundEdiClient {
30
+ private X12;
31
+ constructor();
32
+ private unwrap;
33
+ private unwrapError;
34
+ fromX12({ input }: FromX12Options): Promise<X12Interchange[]>;
35
+ /**
36
+ * Stamp ISA13/GS06 control numbers on the interchange if not already set.
37
+ * Uses the Restate-backed counter service for atomic, per-trading-partner sequencing.
38
+ * ST02 is always "0001" (one transaction per file per ticket).
39
+ * If a control number is already set, it is left unchanged (opt-out for manual overrides).
40
+ */
41
+ private stampControlNumbers;
42
+ toX12({ input }: ToX12Options): Promise<unknown>;
43
+ validateX12({ input }: ValidateX12Options): Promise<import("./edination-client").OperationResult>;
44
+ acknowledgeX12({ input }: AcknolwedgeX12Options): Promise<X12Interchange[]>;
45
+ }
package/dist/index.js ADDED
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.UnnboundEdiClient = exports.isUnnboundEdiClientError = exports.UnnboundEdiClientError = exports.setControlNumber = exports.getCurrentControlNumber = exports.getNextControlNumber = void 0;
40
+ const axios_1 = __importStar(require("axios"));
41
+ const unnbound_logger_sdk_1 = require("unnbound-logger-sdk");
42
+ const internal_1 = require("unnbound-logger-sdk/dist/internal");
43
+ const edination_client_1 = require("./edination-client");
44
+ __exportStar(require("./edination-client/model"), exports);
45
+ var control_numbers_1 = require("./control-numbers");
46
+ Object.defineProperty(exports, "getNextControlNumber", { enumerable: true, get: function () { return control_numbers_1.getNextControlNumber; } });
47
+ Object.defineProperty(exports, "getCurrentControlNumber", { enumerable: true, get: function () { return control_numbers_1.getCurrentControlNumber; } });
48
+ Object.defineProperty(exports, "setControlNumber", { enumerable: true, get: function () { return control_numbers_1.setControlNumber; } });
49
+ class UnnboundError extends Error {
50
+ code;
51
+ constructor({ message, code, ...o }) {
52
+ super(message, o);
53
+ this.name = 'UnnboundError';
54
+ this.code = code;
55
+ }
56
+ }
57
+ class UnnboundEdiClientError extends UnnboundError {
58
+ constructor({ message, code, ...o }) {
59
+ super({ message, code, ...o });
60
+ this.name = 'UnnboundEdiClientError';
61
+ }
62
+ }
63
+ exports.UnnboundEdiClientError = UnnboundEdiClientError;
64
+ const isUnnboundEdiClientError = (error) => error instanceof UnnboundEdiClientError;
65
+ exports.isUnnboundEdiClientError = isUnnboundEdiClientError;
66
+ const buildEdiPayload = (edi) => ({ type: 'edi', edi });
67
+ const buildEdiX12Payload = (operation, x12) => buildEdiPayload({ operation, type: 'x12', x12 });
68
+ class UnnboundEdiClient {
69
+ X12;
70
+ constructor() {
71
+ const apiKey = process.env.UNNBOUND_EDI_API_KEY;
72
+ // When UNNBOUND_EDI_BASE_URL is set, use self-hosted EdiFabric InHouse API
73
+ // instead of the EDINation cloud API (eliminates 300 calls/min shared rate limit)
74
+ const basePath = process.env.UNNBOUND_EDI_BASE_URL || undefined;
75
+ if (!basePath && !apiKey) {
76
+ throw new Error('EDI service not configured. Set UNNBOUND_EDI_BASE_URL (self-hosted) or UNNBOUND_EDI_API_KEY (EDINation cloud).');
77
+ }
78
+ // Self-hosted service ignores the API key header (ClusterIP, no auth needed),
79
+ // but the OpenAPI client requires a non-empty value — use a placeholder.
80
+ const config = new edination_client_1.Configuration({ apiKey: apiKey ?? 'self-hosted', basePath });
81
+ const client = (0, unnbound_logger_sdk_1.traceAxios)(axios_1.default, { getPayload: internal_1.internal });
82
+ this.X12 = new edination_client_1.X12Api(config, undefined, client);
83
+ }
84
+ unwrap(response) {
85
+ return response.data;
86
+ }
87
+ unwrapError(error, code) {
88
+ if (error instanceof UnnboundEdiClientError)
89
+ throw error;
90
+ if ((0, axios_1.isAxiosError)(error)) {
91
+ if (error.status === 403)
92
+ throw new UnnboundEdiClientError({
93
+ message: 'Unauthorized access to EDI service. Reach out to support.',
94
+ code: 'edi_unauthorized_error',
95
+ });
96
+ throw new UnnboundEdiClientError({ message: error.message, code, cause: error });
97
+ }
98
+ if (error instanceof Error)
99
+ throw new UnnboundEdiClientError({
100
+ message: error.message,
101
+ code: 'edi_unknown_error',
102
+ cause: error,
103
+ });
104
+ throw new UnnboundEdiClientError({
105
+ message: 'Unknown error occured in EDI client.',
106
+ code: 'edi_unknown_error',
107
+ cause: error,
108
+ });
109
+ }
110
+ fromX12({ input }) {
111
+ return (0, unnbound_logger_sdk_1.startSpan)('X12 to JSON', () => {
112
+ return this.X12.x12ReadPost({ body: input })
113
+ .then(this.unwrap.bind(this))
114
+ .catch((error) => this.unwrapError(error, 'edi_read_error'));
115
+ }, (o) => buildEdiX12Payload('fromX12', { input, output: o?.result }));
116
+ }
117
+ /**
118
+ * Stamp ISA13/GS06 control numbers on the interchange if not already set.
119
+ * Uses the Restate-backed counter service for atomic, per-trading-partner sequencing.
120
+ * ST02 is always "0001" (one transaction per file per ticket).
121
+ * If a control number is already set, it is left unchanged (opt-out for manual overrides).
122
+ */
123
+ async stampControlNumbers(input) {
124
+ const { getNextControlNumber } = await Promise.resolve().then(() => __importStar(require('./control-numbers')));
125
+ const isa = input.ISA;
126
+ const senderQual = (isa.SenderIDQualifier_5 || '').trim();
127
+ const senderId = (isa.InterchangeSenderID_6 || '').trim();
128
+ const receiverQual = (isa.ReceiverIDQualifier_7 || '').trim();
129
+ const receiverId = (isa.InterchangeReceiverID_8 || '').trim();
130
+ const senderKey = `${senderQual}:${senderId}`;
131
+ const receiverKey = `${receiverQual}:${receiverId}`;
132
+ // ISA13 — interchange control number (9 digits, zero-padded)
133
+ if (!isa.InterchangeControlNumber_13) {
134
+ const isa13 = await getNextControlNumber('ISA13', senderKey, receiverKey, 9);
135
+ isa.InterchangeControlNumber_13 = isa13;
136
+ // IEA02 must match ISA13
137
+ if (input.IEATrailers?.length) {
138
+ input.IEATrailers[0].InterchangeControlNumber_2 = isa13;
139
+ }
140
+ }
141
+ // GS06 — functional group control number (per group)
142
+ for (const group of input.Groups) {
143
+ if (!group.GS.GroupControlNumber_6) {
144
+ const gs06 = await getNextControlNumber('GS06', senderKey, receiverKey, 9);
145
+ group.GS.GroupControlNumber_6 = gs06;
146
+ // GE02 must match GS06
147
+ if (group.GETrailers?.length) {
148
+ group.GETrailers[0].GroupControlNumber_2 = gs06;
149
+ }
150
+ }
151
+ }
152
+ // ST02 — always "0001" (one transaction per file, no persistence needed)
153
+ for (const group of input.Groups) {
154
+ for (const tx of group.Transactions) {
155
+ if (tx?.ST?.TransactionSetControlNumber_2 === undefined || tx?.ST?.TransactionSetControlNumber_2 === null) {
156
+ if (tx?.ST)
157
+ tx.ST.TransactionSetControlNumber_2 = '0001';
158
+ if (tx?.SE)
159
+ tx.SE.TransactionSetControlNumber_2 = '0001';
160
+ }
161
+ }
162
+ }
163
+ }
164
+ async toX12({ input }) {
165
+ // Auto-stamp control numbers before writing X12
166
+ try {
167
+ await this.stampControlNumbers(input);
168
+ }
169
+ catch (error) {
170
+ // Log but don't fail — workflows can still set control numbers manually
171
+ console.warn('[EDI SDK] Failed to auto-stamp control numbers, proceeding without:', error);
172
+ }
173
+ return (0, unnbound_logger_sdk_1.startSpan)('JSON to X12', () => {
174
+ return this.X12.x12WritePost({ x12Interchange: input })
175
+ .then(this.unwrap.bind(this))
176
+ .catch((error) => this.unwrapError(error, 'edi_write_error'));
177
+ }, (o) => buildEdiX12Payload('toX12', { input, output: o?.result }));
178
+ }
179
+ validateX12({ input }) {
180
+ return (0, unnbound_logger_sdk_1.startSpan)('Validate X12', () => {
181
+ return this.X12.x12ValidatePost({ x12Interchange: input })
182
+ .then(this.unwrap.bind(this))
183
+ .catch((error) => this.unwrapError(error, 'edi_validate_error'));
184
+ }, (o) => ({
185
+ ...buildEdiX12Payload('validateX12', { input, output: o?.result }),
186
+ ...(o?.result?.Status === 'error' && { level: 'warn' }),
187
+ }));
188
+ }
189
+ acknowledgeX12({ input }) {
190
+ return (0, unnbound_logger_sdk_1.startSpan)('Acknolwedge X12', () => {
191
+ return this.X12.x12AckPost({ x12Interchange: input })
192
+ .then(this.unwrap.bind(this))
193
+ .catch((error) => this.unwrapError(error, 'edi_acknowledge_error'));
194
+ }, (o) => buildEdiX12Payload('acknowledgeX12', { input, output: o?.result }));
195
+ }
196
+ }
197
+ exports.UnnboundEdiClient = UnnboundEdiClient;
@@ -0,0 +1,58 @@
1
+ import { logger } from 'unnbound-logger-sdk';
2
+
3
+ import { UnnboundEdiClient } from '../src';
4
+
5
+ const run = async () => {
6
+ const edi = new UnnboundEdiClient();
7
+
8
+ const data = `ISA*00* *00* *12*NOTP *12*NOTP *080501*1700*U*00401*000001000*0*P*>
9
+ GS*PO*NOTP*NOTP*20080501*1700*1000*X*004010
10
+ ST*850*000000010
11
+ BEG*00*SA*08292243254**20010501*610385388
12
+ REF*DP*030
13
+ REF*PS*
14
+ ITD*14*3*2**45**46
15
+ DTM*001*20010510
16
+ PKG*F*68***PALLET, SHRINKWRAP 48W X 40D X 45H
17
+ PKG*F*66***REGULAR
18
+ TD5*A*92*P3**SEE ROUTING GUIDE FOR ROUTING
19
+ N1*ST*RETAIL STORE*9*0001234567890
20
+ N3*123 ANYWHERE AVENUE
21
+ N4*CITY*ST*12345
22
+ PO1*1*120*EA*9.25*TE*CB*(12) 0-083628-838*PR*RO*VN*ABA18783
23
+ PO1*2*220*EA*13.7 9*TE*CB*(69) 0-093 83 7-991*PR*RO*VN*RUP83112
24
+ PO1*3*126*EA*10.9 9*TE*CB*(71) 0-099172-837*PR*RO*VN*CPR19293
25
+ PO1*4*76*EA*4.35*TE*CB*(71) 0-012110-737*PR*RO*VN*PIW28173
26
+ PO1*5*72*EA*7.5*TE*CB*(71) 0-0848 88-9 75*PR*RO*VN*JBM1938 7
27
+ PO1*6*696*EA*9.55*TE*CB*(71) 0-003 922-121*PR*RO*VN*IUI19283
28
+ CTT*6
29
+ SE*20*000000010
30
+ GE*1*1000
31
+ IEA*1*000001000`;
32
+
33
+ const x12Interchanges = await edi.fromX12({ input: data });
34
+
35
+ logger.info({ x12Interchanges: x12Interchanges.length }, 'Input parsed.');
36
+
37
+ await Promise.all(
38
+ x12Interchanges.map(async (x12Interchange) => {
39
+ const validated = await edi.validateX12({ input: x12Interchange });
40
+
41
+ logger.info({ validated }, 'X12 validated.');
42
+
43
+ const x12 = await edi.toX12({ input: x12Interchange });
44
+
45
+ logger.info({ x12 }, 'X12 unparsed.');
46
+
47
+ logger.info({ validated }, 'X12 validated.');
48
+
49
+ const acknowledged = await edi.acknowledgeX12({ input: x12Interchange });
50
+
51
+ logger.info({ acknowledged }, 'X12 acknowledged.');
52
+ }),
53
+ );
54
+ };
55
+
56
+ run()
57
+ .then(() => logger.info('Done'))
58
+ .catch((error) => logger.error({ err: error }, 'Error'));
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@ontemper/edi",
3
+ "description": "An EDI client with structured logging.",
4
+ "version": "1.1.0",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "echo 'No tests'",
10
+ "typecheck": "tsc -noEmit",
11
+ "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
12
+ "lint:fix": "bun run lint --fix",
13
+ "format": "biome format --write .",
14
+ "format:check": "biome format .",
15
+ "prepublishOnly": "bun run build",
16
+ "start:example": "bun --watch examples/node-edi.ts",
17
+ "version:bump": "npm version patch",
18
+ "release": "bun run build && bun publish --access public",
19
+ "codegen": "npx --yes @openapitools/openapi-generator-cli generate -c openapitools.json -o ./src/edination-client"
20
+ },
21
+ "author": "Unnbound Team",
22
+ "license": "MIT",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/unnbounddev/unnbound-sdks.git"
26
+ },
27
+ "homepage": "https://github.com/unnbounddev/unnbound-sdks#readme",
28
+ "bugs": {
29
+ "url": "https://github.com/unnbounddev/unnbound-sdks/issues"
30
+ },
31
+ "dependencies": {
32
+ "axios": "^1.12.2",
33
+ "unnbound-logger-sdk": "3.0.35"
34
+ },
35
+ "devDependencies": {
36
+ "@types/jest": "^29.5.12",
37
+ "@types/node": "^22"
38
+ },
39
+ "files": [
40
+ "examples/*",
41
+ "dist/*",
42
+ "README.md",
43
+ "LICENSE"
44
+ ],
45
+ "engines": {
46
+ "node": ">=22"
47
+ },
48
+ "sideEffects": false
49
+ }