@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.
- package/README.md +321 -0
- package/dist/control-numbers.d.ts +20 -0
- package/dist/control-numbers.js +77 -0
- package/dist/edination-client/api/edi-model-api.d.ts +268 -0
- package/dist/edination-client/api/edi-model-api.js +326 -0
- package/dist/edination-client/api/edifact-api.d.ts +453 -0
- package/dist/edination-client/api/edifact-api.js +448 -0
- package/dist/edination-client/api/hl7-api.d.ts +294 -0
- package/dist/edination-client/api/hl7-api.js +315 -0
- package/dist/edination-client/api/ncpdp-api.d.ts +278 -0
- package/dist/edination-client/api/ncpdp-api.js +305 -0
- package/dist/edination-client/api/vda-api.d.ts +262 -0
- package/dist/edination-client/api/vda-api.js +295 -0
- package/dist/edination-client/api/x12-api.d.ts +437 -0
- package/dist/edination-client/api/x12-api.js +438 -0
- package/dist/edination-client/api.d.ts +17 -0
- package/dist/edination-client/api.js +35 -0
- package/dist/edination-client/base.d.ts +66 -0
- package/dist/edination-client/base.js +70 -0
- package/dist/edination-client/common.d.ts +65 -0
- package/dist/edination-client/common.js +142 -0
- package/dist/edination-client/configuration.d.ts +91 -0
- package/dist/edination-client/configuration.js +104 -0
- package/dist/edination-client/index.d.ts +14 -0
- package/dist/edination-client/index.js +32 -0
- package/dist/edination-client/model/batch-receiving-application.d.ts +36 -0
- package/dist/edination-client/model/batch-receiving-application.js +15 -0
- package/dist/edination-client/model/batch-receiving-facility.d.ts +36 -0
- package/dist/edination-client/model/batch-receiving-facility.js +15 -0
- package/dist/edination-client/model/batch-receiving-network-address.d.ts +36 -0
- package/dist/edination-client/model/batch-receiving-network-address.js +15 -0
- package/dist/edination-client/model/batch-sending-application.d.ts +36 -0
- package/dist/edination-client/model/batch-sending-application.js +15 -0
- package/dist/edination-client/model/batch-sending-facility.d.ts +36 -0
- package/dist/edination-client/model/batch-sending-facility.js +15 -0
- package/dist/edination-client/model/batch-sending-network-address.d.ts +36 -0
- package/dist/edination-client/model/batch-sending-network-address.js +15 -0
- package/dist/edination-client/model/bhs.d.ts +108 -0
- package/dist/edination-client/model/bhs.js +15 -0
- package/dist/edination-client/model/bts.d.ts +36 -0
- package/dist/edination-client/model/bts.js +15 -0
- package/dist/edination-client/model/edi-model.d.ts +37 -0
- package/dist/edination-client/model/edi-model.js +15 -0
- package/dist/edination-client/model/edifact-group.d.ts +38 -0
- package/dist/edination-client/model/edifact-group.js +15 -0
- package/dist/edination-client/model/edifact-interchange.d.ts +53 -0
- package/dist/edination-client/model/edifact-interchange.js +15 -0
- package/dist/edination-client/model/error-details.d.ts +30 -0
- package/dist/edination-client/model/error-details.js +15 -0
- package/dist/edination-client/model/fhs.d.ts +108 -0
- package/dist/edination-client/model/fhs.js +15 -0
- package/dist/edination-client/model/file-receiving-application.d.ts +36 -0
- package/dist/edination-client/model/file-receiving-application.js +15 -0
- package/dist/edination-client/model/file-receiving-facility.d.ts +36 -0
- package/dist/edination-client/model/file-receiving-facility.js +15 -0
- package/dist/edination-client/model/file-receiving-network-address.d.ts +36 -0
- package/dist/edination-client/model/file-receiving-network-address.js +15 -0
- package/dist/edination-client/model/file-sending-application.d.ts +36 -0
- package/dist/edination-client/model/file-sending-application.js +15 -0
- package/dist/edination-client/model/file-sending-facility.d.ts +36 -0
- package/dist/edination-client/model/file-sending-facility.js +15 -0
- package/dist/edination-client/model/file-sending-network-address.d.ts +36 -0
- package/dist/edination-client/model/file-sending-network-address.js +15 -0
- package/dist/edination-client/model/flat-message.d.ts +37 -0
- package/dist/edination-client/model/flat-message.js +15 -0
- package/dist/edination-client/model/fts.d.ts +30 -0
- package/dist/edination-client/model/fts.js +15 -0
- package/dist/edination-client/model/ge.d.ts +30 -0
- package/dist/edination-client/model/ge.js +15 -0
- package/dist/edination-client/model/gs.d.ts +66 -0
- package/dist/edination-client/model/gs.js +15 -0
- package/dist/edination-client/model/hl7-group.d.ts +38 -0
- package/dist/edination-client/model/hl7-group.js +15 -0
- package/dist/edination-client/model/hl7-interchange.d.ts +46 -0
- package/dist/edination-client/model/hl7-interchange.js +15 -0
- package/dist/edination-client/model/iea.d.ts +30 -0
- package/dist/edination-client/model/iea.js +15 -0
- package/dist/edination-client/model/index.d.ts +49 -0
- package/dist/edination-client/model/index.js +65 -0
- package/dist/edination-client/model/isa.d.ts +114 -0
- package/dist/edination-client/model/isa.js +15 -0
- package/dist/edination-client/model/link.d.ts +36 -0
- package/dist/edination-client/model/link.js +15 -0
- package/dist/edination-client/model/ncpdp-transmission.d.ts +45 -0
- package/dist/edination-client/model/ncpdp-transmission.js +15 -0
- package/dist/edination-client/model/operation-detail.d.ts +90 -0
- package/dist/edination-client/model/operation-detail.js +15 -0
- package/dist/edination-client/model/operation-result.d.ts +37 -0
- package/dist/edination-client/model/operation-result.js +15 -0
- package/dist/edination-client/model/s001.d.ts +42 -0
- package/dist/edination-client/model/s001.js +15 -0
- package/dist/edination-client/model/s002.d.ts +42 -0
- package/dist/edination-client/model/s002.js +15 -0
- package/dist/edination-client/model/s003.d.ts +42 -0
- package/dist/edination-client/model/s003.js +15 -0
- package/dist/edination-client/model/s004.d.ts +30 -0
- package/dist/edination-client/model/s004.js +15 -0
- package/dist/edination-client/model/s005.d.ts +30 -0
- package/dist/edination-client/model/s005.js +15 -0
- package/dist/edination-client/model/s006.d.ts +30 -0
- package/dist/edination-client/model/s006.js +15 -0
- package/dist/edination-client/model/s007.d.ts +30 -0
- package/dist/edination-client/model/s007.js +15 -0
- package/dist/edination-client/model/s008.d.ts +36 -0
- package/dist/edination-client/model/s008.js +15 -0
- package/dist/edination-client/model/ta1.d.ts +48 -0
- package/dist/edination-client/model/ta1.js +15 -0
- package/dist/edination-client/model/transmission-header.d.ts +66 -0
- package/dist/edination-client/model/transmission-header.js +15 -0
- package/dist/edination-client/model/transmission-trailer.d.ts +36 -0
- package/dist/edination-client/model/transmission-trailer.js +15 -0
- package/dist/edination-client/model/una.d.ts +54 -0
- package/dist/edination-client/model/una.js +15 -0
- package/dist/edination-client/model/unb.d.ts +89 -0
- package/dist/edination-client/model/unb.js +15 -0
- package/dist/edination-client/model/une.d.ts +30 -0
- package/dist/edination-client/model/une.js +15 -0
- package/dist/edination-client/model/ung.d.ts +70 -0
- package/dist/edination-client/model/ung.js +15 -0
- package/dist/edination-client/model/unz.d.ts +30 -0
- package/dist/edination-client/model/unz.js +15 -0
- package/dist/edination-client/model/x12-group.d.ts +38 -0
- package/dist/edination-client/model/x12-group.js +15 -0
- package/dist/edination-client/model/x12-interchange.d.ts +65 -0
- package/dist/edination-client/model/x12-interchange.js +15 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +197 -0
- package/examples/node-edi.ts +58 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# Unnbound EDI Client
|
|
2
|
+
|
|
3
|
+
A TypeScript EDI client with structured logging and distributed tracing capabilities, built for processing X12 EDI documents with comprehensive error handling and automatic span tracking.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **X12 EDI Processing**: Complete X12 document parsing, validation, and generation
|
|
8
|
+
- **Structured Logging**: Built-in integration with Unnbound Logger for comprehensive operation tracking
|
|
9
|
+
- **Distributed Tracing**: Automatic span creation for all EDI operations with detailed payload information
|
|
10
|
+
- **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
11
|
+
- **Error Handling**: Custom error types with detailed error codes and context
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install unnbound-edi-sdk
|
|
17
|
+
# or
|
|
18
|
+
bun add unnbound-edi-sdk
|
|
19
|
+
# or
|
|
20
|
+
yarn add unnbound-edi-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Environment Variables
|
|
24
|
+
|
|
25
|
+
### Required
|
|
26
|
+
|
|
27
|
+
- `UNNBOUND_EDI_API_KEY` - Your API key for authentication
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { UnnboundEdiClient } from 'unnbound-edi-sdk';
|
|
33
|
+
import { logger } from 'unnbound-logger-sdk';
|
|
34
|
+
|
|
35
|
+
// Set your API key
|
|
36
|
+
process.env.UNNBOUND_EDI_API_KEY = 'your-api-key';
|
|
37
|
+
|
|
38
|
+
const edi = new UnnboundEdiClient();
|
|
39
|
+
|
|
40
|
+
// Parse X12 document to JSON
|
|
41
|
+
const x12Interchanges = await edi.fromX12({
|
|
42
|
+
input: 'ISA*00* *00* *12*NOTP...',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Validate X12 interchange
|
|
46
|
+
const validationResult = await edi.validateX12({
|
|
47
|
+
input: x12Interchanges[0],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Convert JSON back to X12
|
|
51
|
+
const x12Document = await edi.toX12({
|
|
52
|
+
input: x12Interchanges[0],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Generate acknowledgment
|
|
56
|
+
const acknowledgment = await edi.acknowledgeX12({
|
|
57
|
+
input: x12Interchanges[0],
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API Reference
|
|
62
|
+
|
|
63
|
+
### Constructor
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
new UnnboundEdiClient();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Creates a new EDI client instance. Requires `UNNBOUND_EDI_API_KEY` environment variable to be set.
|
|
70
|
+
|
|
71
|
+
### Methods
|
|
72
|
+
|
|
73
|
+
#### `fromX12(options: FromX12Options): Promise<X12Interchange[]>`
|
|
74
|
+
|
|
75
|
+
Parses X12 EDI documents into JSON format.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const x12Interchanges = await edi.fromX12({
|
|
79
|
+
input: 'ISA*00* *00* *12*NOTP...',
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Parameters:**
|
|
84
|
+
|
|
85
|
+
- `options.input` - The X12 document as a string or File object
|
|
86
|
+
|
|
87
|
+
**Returns:** Array of parsed X12 interchange objects
|
|
88
|
+
|
|
89
|
+
#### `toX12(options: ToX12Options): Promise<unknown>`
|
|
90
|
+
|
|
91
|
+
Converts JSON X12 interchange objects back to X12 format.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const x12Document = await edi.toX12({
|
|
95
|
+
input: x12InterchangeObject,
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Parameters:**
|
|
100
|
+
|
|
101
|
+
- `options.input` - The X12 interchange object to convert
|
|
102
|
+
|
|
103
|
+
**Returns:** X12 document as string
|
|
104
|
+
|
|
105
|
+
#### `validateX12(options: ValidateX12Options): Promise<OperationResult>`
|
|
106
|
+
|
|
107
|
+
Validates X12 interchange objects against EDI standards.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const validationResult = await edi.validateX12({
|
|
111
|
+
input: x12InterchangeObject,
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Parameters:**
|
|
116
|
+
|
|
117
|
+
- `options.input` - The X12 interchange object to validate
|
|
118
|
+
|
|
119
|
+
**Returns:** Validation result with operation details
|
|
120
|
+
|
|
121
|
+
#### `acknowledgeX12(options: AcknolwedgeX12Options): Promise<OperationResult>`
|
|
122
|
+
|
|
123
|
+
Generates acknowledgment for X12 interchange objects.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const acknowledgment = await edi.acknowledgeX12({
|
|
127
|
+
input: x12InterchangeObject,
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Parameters:**
|
|
132
|
+
|
|
133
|
+
- `options.input` - The X12 interchange object to acknowledge
|
|
134
|
+
|
|
135
|
+
**Returns:** Acknowledgment result with operation details
|
|
136
|
+
|
|
137
|
+
## Error Handling
|
|
138
|
+
|
|
139
|
+
The EDI client provides custom error types for different operation failures:
|
|
140
|
+
|
|
141
|
+
### UnnboundEdiClientError
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { UnnboundEdiClientError, isUnnboundEdiClientError } from 'unnbound-edi-sdk';
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
await edi.fromX12({ input: invalidX12 });
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (isUnnboundEdiClientError(error)) {
|
|
150
|
+
console.error('EDI Error:', error.code, error.message);
|
|
151
|
+
// Handle specific EDI errors
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Error Codes
|
|
157
|
+
|
|
158
|
+
| Code | Description |
|
|
159
|
+
| ----------------------- | ------------------------------- |
|
|
160
|
+
| `edi_read_error` | Error parsing X12 document |
|
|
161
|
+
| `edi_write_error` | Error converting JSON to X12 |
|
|
162
|
+
| `edi_validate_error` | Error validating X12 document |
|
|
163
|
+
| `edi_acknowledge_error` | Error generating acknowledgment |
|
|
164
|
+
| `edi_unknown_error` | Unknown error occurred |
|
|
165
|
+
|
|
166
|
+
## Type Definitions
|
|
167
|
+
|
|
168
|
+
### FromX12Options
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
interface FromX12Options {
|
|
172
|
+
input: unknown; // X12 document as string or File
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### ToX12Options
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
interface ToX12Options {
|
|
180
|
+
input: X12Interchange; // X12 interchange object
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### ValidateX12Options
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
interface ValidateX12Options {
|
|
188
|
+
input: X12Interchange; // X12 interchange object
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### AcknolwedgeX12Options
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
interface AcknolwedgeX12Options {
|
|
196
|
+
input: X12Interchange; // X12 interchange object
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### OperationResult
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
interface OperationResult {
|
|
204
|
+
LastIndex?: number;
|
|
205
|
+
Details?: Array<OperationDetail> | null;
|
|
206
|
+
Status?: string | null;
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### OperationDetail
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
interface OperationDetail {
|
|
214
|
+
Index?: number;
|
|
215
|
+
TransactionIndex?: number;
|
|
216
|
+
TransactionRef?: string | null;
|
|
217
|
+
SpecRef?: string | null;
|
|
218
|
+
SegmentId?: string | null;
|
|
219
|
+
DataElementId?: string | null;
|
|
220
|
+
DataElementIndex?: number;
|
|
221
|
+
CompositeIndex?: number;
|
|
222
|
+
RepIndex?: number;
|
|
223
|
+
Value?: string | null;
|
|
224
|
+
Message?: string | null;
|
|
225
|
+
Status?: string | null;
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Logging and Tracing
|
|
230
|
+
|
|
231
|
+
The Unnbound EDI Client automatically creates spans for all operations and logs detailed information including:
|
|
232
|
+
|
|
233
|
+
- Operation type and timing
|
|
234
|
+
- Input and output data
|
|
235
|
+
- API request/response details
|
|
236
|
+
- Error details (if any)
|
|
237
|
+
- Validation results
|
|
238
|
+
- Acknowledgment status
|
|
239
|
+
|
|
240
|
+
### Example Log Output
|
|
241
|
+
|
|
242
|
+
```json
|
|
243
|
+
{"level":"info","spanId":"556c53e6-3bb8-4118-b3b8-570e41c27654","type":"edi","edi":{"type":"x12","x12":{"input":"ISA*00*...","output":[...]}},"message":"X12 to JSON started."}
|
|
244
|
+
{"level":"info","spanId":"556c53e6-3bb8-4118-b3b8-570e41c27654","type":"edi","edi":{"type":"x12","x12":{"input":"ISA*00*...","output":[...]}},"duration":1250,"message":"X12 to JSON completed."}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Complete Example
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { UnnboundEdiClient } from 'unnbound-edi-sdk';
|
|
251
|
+
import { logger } from 'unnbound-logger-sdk';
|
|
252
|
+
|
|
253
|
+
const run = async () => {
|
|
254
|
+
const edi = new UnnboundEdiClient();
|
|
255
|
+
|
|
256
|
+
const x12Data = `ISA*00* *00* *12*NOTP *12*NOTP *080501*1700*U*00401*000001000*0*P*>
|
|
257
|
+
GS*PO*NOTP*NOTP*20080501*1700*1000*X*004010
|
|
258
|
+
ST*850*000000010
|
|
259
|
+
BEG*00*SA*08292243254**20010501*610385388
|
|
260
|
+
REF*DP*030
|
|
261
|
+
REF*PS*
|
|
262
|
+
ITD*14*3*2**45**46
|
|
263
|
+
DTM*001*20010510
|
|
264
|
+
PKG*F*68***PALLET, SHRINKWRAP 48W X 40D X 45H
|
|
265
|
+
PKG*F*66***REGULAR
|
|
266
|
+
TD5*A*92*P3**SEE ROUTING GUIDE FOR ROUTING
|
|
267
|
+
N1*ST*RETAIL STORE*9*0001234567890
|
|
268
|
+
N3*123 ANYWHERE AVENUE
|
|
269
|
+
N4*CITY*ST*12345
|
|
270
|
+
PO1*1*120*EA*9.25*TE*CB*(12) 0-083628-838*PR*RO*VN*ABA18783
|
|
271
|
+
PO1*2*220*EA*13.7 9*TE*CB*(69) 0-093 83 7-991*PR*RO*VN*RUP83112
|
|
272
|
+
PO1*3*126*EA*10.9 9*TE*CB*(71) 0-099172-837*PR*RO*VN*CPR19293
|
|
273
|
+
PO1*4*76*EA*4.35*TE*CB*(71) 0-012110-737*PR*RO*VN*PIW28173
|
|
274
|
+
PO1*5*72*EA*7.5*TE*CB*(71) 0-0848 88-9 75*PR*RO*VN*JBM1938 7
|
|
275
|
+
PO1*6*696*EA*9.55*TE*CB*(71) 0-003 922-121*PR*RO*VN*IUI19283
|
|
276
|
+
CTT*6
|
|
277
|
+
SE*20*000000010
|
|
278
|
+
GE*1*1000
|
|
279
|
+
IEA*1*000001000`;
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
// Parse X12 to JSON
|
|
283
|
+
const x12Interchanges = await edi.fromX12({ input: x12Data });
|
|
284
|
+
logger.info({ count: x12Interchanges.length }, 'Parsed X12 interchanges');
|
|
285
|
+
|
|
286
|
+
// Process each interchange
|
|
287
|
+
for (const interchange of x12Interchanges) {
|
|
288
|
+
// Validate
|
|
289
|
+
const validation = await edi.validateX12({ input: interchange });
|
|
290
|
+
logger.info({ validation }, 'X12 validated');
|
|
291
|
+
|
|
292
|
+
// Convert back to X12
|
|
293
|
+
const x12Output = await edi.toX12({ input: interchange });
|
|
294
|
+
logger.info({ x12Output }, 'Converted back to X12');
|
|
295
|
+
|
|
296
|
+
// Generate acknowledgment
|
|
297
|
+
const acknowledgment = await edi.acknowledgeX12({ input: interchange });
|
|
298
|
+
logger.info({ acknowledgment }, 'Generated acknowledgment');
|
|
299
|
+
}
|
|
300
|
+
} catch (error) {
|
|
301
|
+
logger.error({ err: error }, 'EDI processing failed');
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
run().catch(console.error);
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Requirements
|
|
310
|
+
|
|
311
|
+
- Node.js >= 22.0.0
|
|
312
|
+
- TypeScript (for TypeScript projects)
|
|
313
|
+
- Unnbound EDI API key
|
|
314
|
+
|
|
315
|
+
## Dependencies
|
|
316
|
+
|
|
317
|
+
- `unnbound-logger-sdk`: Structured logging and tracing
|
|
318
|
+
|
|
319
|
+
## Support
|
|
320
|
+
|
|
321
|
+
For support, please open an issue on the [GitHub repository](https://github.com/unnbounddev/unnbound-sdks/issues).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the next control number for an EDI counter.
|
|
3
|
+
*
|
|
4
|
+
* Calls the API-hosted Restate counter object which persists state
|
|
5
|
+
* and handles rollover (999999999 → 1) automatically.
|
|
6
|
+
*
|
|
7
|
+
* @param counterName - Counter type: 'ISA13' or 'GS06'
|
|
8
|
+
* @param senderId - Sender qualifier + ID (e.g. "ZZ:SENDER123")
|
|
9
|
+
* @param receiverId - Receiver qualifier + ID (e.g. "ZZ:RECEIVER456")
|
|
10
|
+
* @param maxDigits - Zero-pad to this width (default: 9 for ISA13)
|
|
11
|
+
*/
|
|
12
|
+
export declare function getNextControlNumber(counterName: string, senderId: string, receiverId: string, maxDigits?: number): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Get the current control number value without incrementing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCurrentControlNumber(counterName: string, senderId: string, receiverId: string, maxDigits?: number): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Set a control number to a specific value (for migration/seeding).
|
|
19
|
+
*/
|
|
20
|
+
export declare function setControlNumber(counterName: string, senderId: string, receiverId: string, value: number, maxDigits?: number): Promise<string>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getNextControlNumber = getNextControlNumber;
|
|
7
|
+
exports.getCurrentControlNumber = getCurrentControlNumber;
|
|
8
|
+
exports.setControlNumber = setControlNumber;
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
let _client = null;
|
|
11
|
+
function getApiClient() {
|
|
12
|
+
if (_client)
|
|
13
|
+
return _client;
|
|
14
|
+
const baseURL = process.env.UNNBOUND_API_URL;
|
|
15
|
+
if (!baseURL) {
|
|
16
|
+
throw new Error('UNNBOUND_API_URL is not set — cannot reach control number service');
|
|
17
|
+
}
|
|
18
|
+
_client = axios_1.default.create({ baseURL });
|
|
19
|
+
// Attach auth: sandbox JWT (preferred) or static service token
|
|
20
|
+
_client.interceptors.request.use(async (config) => {
|
|
21
|
+
const jwt = process.env.UNNBOUND_SANDBOX_JWT;
|
|
22
|
+
if (jwt) {
|
|
23
|
+
config.headers.Authorization = `Bearer ${jwt}`;
|
|
24
|
+
return config;
|
|
25
|
+
}
|
|
26
|
+
// Fallback: static token auth (legacy K8s workflows)
|
|
27
|
+
const serviceToken = process.env.UNNBOUND_SERVICE_TOKEN || process.env.WEBHOOK_API_KEY;
|
|
28
|
+
const orgId = process.env.UNNBOUND_ORGANIZATION_ID;
|
|
29
|
+
if (serviceToken && orgId) {
|
|
30
|
+
config.headers['x-service-token'] = serviceToken;
|
|
31
|
+
config.headers['x-organization-id'] = orgId;
|
|
32
|
+
}
|
|
33
|
+
return config;
|
|
34
|
+
});
|
|
35
|
+
return _client;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the next control number for an EDI counter.
|
|
39
|
+
*
|
|
40
|
+
* Calls the API-hosted Restate counter object which persists state
|
|
41
|
+
* and handles rollover (999999999 → 1) automatically.
|
|
42
|
+
*
|
|
43
|
+
* @param counterName - Counter type: 'ISA13' or 'GS06'
|
|
44
|
+
* @param senderId - Sender qualifier + ID (e.g. "ZZ:SENDER123")
|
|
45
|
+
* @param receiverId - Receiver qualifier + ID (e.g. "ZZ:RECEIVER456")
|
|
46
|
+
* @param maxDigits - Zero-pad to this width (default: 9 for ISA13)
|
|
47
|
+
*/
|
|
48
|
+
async function getNextControlNumber(counterName, senderId, receiverId, maxDigits = 9) {
|
|
49
|
+
const { data } = await getApiClient().post('/api/internal/edi/control-numbers/increment', {
|
|
50
|
+
tradingPartnerKey: `${senderId}:${receiverId}`,
|
|
51
|
+
counterName,
|
|
52
|
+
});
|
|
53
|
+
return String(data.value).padStart(maxDigits, '0');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the current control number value without incrementing.
|
|
57
|
+
*/
|
|
58
|
+
async function getCurrentControlNumber(counterName, senderId, receiverId, maxDigits = 9) {
|
|
59
|
+
const { data } = await getApiClient().get('/api/internal/edi/control-numbers/count', {
|
|
60
|
+
params: {
|
|
61
|
+
tradingPartnerKey: `${senderId}:${receiverId}`,
|
|
62
|
+
counterName,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
return String(data.value).padStart(maxDigits, '0');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set a control number to a specific value (for migration/seeding).
|
|
69
|
+
*/
|
|
70
|
+
async function setControlNumber(counterName, senderId, receiverId, value, maxDigits = 9) {
|
|
71
|
+
const { data } = await getApiClient().post('/api/internal/edi/control-numbers/set', {
|
|
72
|
+
tradingPartnerKey: `${senderId}:${receiverId}`,
|
|
73
|
+
counterName,
|
|
74
|
+
value,
|
|
75
|
+
});
|
|
76
|
+
return String(data.value).padStart(maxDigits, '0');
|
|
77
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
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 { AxiosInstance, AxiosPromise, RawAxiosRequestConfig } from 'axios';
|
|
13
|
+
import { BaseAPI, type RequestArgs } from '../base';
|
|
14
|
+
import type { Configuration } from '../configuration';
|
|
15
|
+
import type { EdiModel } from '../model';
|
|
16
|
+
/**
|
|
17
|
+
* EdiModelApi - axios parameter creator
|
|
18
|
+
* @export
|
|
19
|
+
*/
|
|
20
|
+
export declare const EdiModelApiAxiosParamCreator: (configuration?: Configuration) => {
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @summary Retrieve the names of all EDI models
|
|
24
|
+
* @param {boolean} [system] Whether to retrieve EdiNation\'s or custom uploaded models.
|
|
25
|
+
* @param {*} [options] Override http request option.
|
|
26
|
+
* @throws {RequiredError}
|
|
27
|
+
*/
|
|
28
|
+
modelsGet: (system?: boolean, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @summary Delete an EDI model
|
|
32
|
+
* @param {string} id The model name.
|
|
33
|
+
* @param {*} [options] Override http request option.
|
|
34
|
+
* @throws {RequiredError}
|
|
35
|
+
*/
|
|
36
|
+
modelsIdDelete: (id: string, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @summary Retrieve an EDI model
|
|
40
|
+
* @param {string} id The model name.
|
|
41
|
+
* @param {*} [options] Override http request option.
|
|
42
|
+
* @throws {RequiredError}
|
|
43
|
+
*/
|
|
44
|
+
modelsIdGet: (id: string, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @summary Upload EDI models in either SEF or OpenEDI format
|
|
48
|
+
* @param {File} [body]
|
|
49
|
+
* @param {*} [options] Override http request option.
|
|
50
|
+
* @throws {RequiredError}
|
|
51
|
+
*/
|
|
52
|
+
modelsPost: (body?: File, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* EdiModelApi - functional programming interface
|
|
56
|
+
* @export
|
|
57
|
+
*/
|
|
58
|
+
export declare const EdiModelApiFp: (configuration?: Configuration) => {
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @summary Retrieve the names of all EDI models
|
|
62
|
+
* @param {boolean} [system] Whether to retrieve EdiNation\'s or custom uploaded models.
|
|
63
|
+
* @param {*} [options] Override http request option.
|
|
64
|
+
* @throws {RequiredError}
|
|
65
|
+
*/
|
|
66
|
+
modelsGet(system?: boolean, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<EdiModel>>>;
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @summary Delete an EDI model
|
|
70
|
+
* @param {string} id The model name.
|
|
71
|
+
* @param {*} [options] Override http request option.
|
|
72
|
+
* @throws {RequiredError}
|
|
73
|
+
*/
|
|
74
|
+
modelsIdDelete(id: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @summary Retrieve an EDI model
|
|
78
|
+
* @param {string} id The model name.
|
|
79
|
+
* @param {*} [options] Override http request option.
|
|
80
|
+
* @throws {RequiredError}
|
|
81
|
+
*/
|
|
82
|
+
modelsIdGet(id: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<File>>;
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @summary Upload EDI models in either SEF or OpenEDI format
|
|
86
|
+
* @param {File} [body]
|
|
87
|
+
* @param {*} [options] Override http request option.
|
|
88
|
+
* @throws {RequiredError}
|
|
89
|
+
*/
|
|
90
|
+
modelsPost(body?: File, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* EdiModelApi - factory interface
|
|
94
|
+
* @export
|
|
95
|
+
*/
|
|
96
|
+
export declare const EdiModelApiFactory: (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) => {
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @summary Retrieve the names of all EDI models
|
|
100
|
+
* @param {EdiModelApiModelsGetRequest} requestParameters Request parameters.
|
|
101
|
+
* @param {*} [options] Override http request option.
|
|
102
|
+
* @throws {RequiredError}
|
|
103
|
+
*/
|
|
104
|
+
modelsGet(requestParameters?: EdiModelApiModelsGetRequest, options?: RawAxiosRequestConfig): AxiosPromise<Array<EdiModel>>;
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @summary Delete an EDI model
|
|
108
|
+
* @param {EdiModelApiModelsIdDeleteRequest} requestParameters Request parameters.
|
|
109
|
+
* @param {*} [options] Override http request option.
|
|
110
|
+
* @throws {RequiredError}
|
|
111
|
+
*/
|
|
112
|
+
modelsIdDelete(requestParameters: EdiModelApiModelsIdDeleteRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @summary Retrieve an EDI model
|
|
116
|
+
* @param {EdiModelApiModelsIdGetRequest} requestParameters Request parameters.
|
|
117
|
+
* @param {*} [options] Override http request option.
|
|
118
|
+
* @throws {RequiredError}
|
|
119
|
+
*/
|
|
120
|
+
modelsIdGet(requestParameters: EdiModelApiModelsIdGetRequest, options?: RawAxiosRequestConfig): AxiosPromise<File>;
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* @summary Upload EDI models in either SEF or OpenEDI format
|
|
124
|
+
* @param {EdiModelApiModelsPostRequest} requestParameters Request parameters.
|
|
125
|
+
* @param {*} [options] Override http request option.
|
|
126
|
+
* @throws {RequiredError}
|
|
127
|
+
*/
|
|
128
|
+
modelsPost(requestParameters?: EdiModelApiModelsPostRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* EdiModelApi - interface
|
|
132
|
+
* @export
|
|
133
|
+
* @interface EdiModelApi
|
|
134
|
+
*/
|
|
135
|
+
export interface EdiModelApiInterface {
|
|
136
|
+
/**
|
|
137
|
+
*
|
|
138
|
+
* @summary Retrieve the names of all EDI models
|
|
139
|
+
* @param {EdiModelApiModelsGetRequest} requestParameters Request parameters.
|
|
140
|
+
* @param {*} [options] Override http request option.
|
|
141
|
+
* @throws {RequiredError}
|
|
142
|
+
* @memberof EdiModelApiInterface
|
|
143
|
+
*/
|
|
144
|
+
modelsGet(requestParameters?: EdiModelApiModelsGetRequest, options?: RawAxiosRequestConfig): AxiosPromise<Array<EdiModel>>;
|
|
145
|
+
/**
|
|
146
|
+
*
|
|
147
|
+
* @summary Delete an EDI model
|
|
148
|
+
* @param {EdiModelApiModelsIdDeleteRequest} requestParameters Request parameters.
|
|
149
|
+
* @param {*} [options] Override http request option.
|
|
150
|
+
* @throws {RequiredError}
|
|
151
|
+
* @memberof EdiModelApiInterface
|
|
152
|
+
*/
|
|
153
|
+
modelsIdDelete(requestParameters: EdiModelApiModelsIdDeleteRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
|
|
154
|
+
/**
|
|
155
|
+
*
|
|
156
|
+
* @summary Retrieve an EDI model
|
|
157
|
+
* @param {EdiModelApiModelsIdGetRequest} requestParameters Request parameters.
|
|
158
|
+
* @param {*} [options] Override http request option.
|
|
159
|
+
* @throws {RequiredError}
|
|
160
|
+
* @memberof EdiModelApiInterface
|
|
161
|
+
*/
|
|
162
|
+
modelsIdGet(requestParameters: EdiModelApiModelsIdGetRequest, options?: RawAxiosRequestConfig): AxiosPromise<File>;
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* @summary Upload EDI models in either SEF or OpenEDI format
|
|
166
|
+
* @param {EdiModelApiModelsPostRequest} requestParameters Request parameters.
|
|
167
|
+
* @param {*} [options] Override http request option.
|
|
168
|
+
* @throws {RequiredError}
|
|
169
|
+
* @memberof EdiModelApiInterface
|
|
170
|
+
*/
|
|
171
|
+
modelsPost(requestParameters?: EdiModelApiModelsPostRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Request parameters for modelsGet operation in EdiModelApi.
|
|
175
|
+
* @export
|
|
176
|
+
* @interface EdiModelApiModelsGetRequest
|
|
177
|
+
*/
|
|
178
|
+
export interface EdiModelApiModelsGetRequest {
|
|
179
|
+
/**
|
|
180
|
+
* Whether to retrieve EdiNation\'s or custom uploaded models.
|
|
181
|
+
* @type {boolean}
|
|
182
|
+
* @memberof EdiModelApiModelsGet
|
|
183
|
+
*/
|
|
184
|
+
readonly system?: boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Request parameters for modelsIdDelete operation in EdiModelApi.
|
|
188
|
+
* @export
|
|
189
|
+
* @interface EdiModelApiModelsIdDeleteRequest
|
|
190
|
+
*/
|
|
191
|
+
export interface EdiModelApiModelsIdDeleteRequest {
|
|
192
|
+
/**
|
|
193
|
+
* The model name.
|
|
194
|
+
* @type {string}
|
|
195
|
+
* @memberof EdiModelApiModelsIdDelete
|
|
196
|
+
*/
|
|
197
|
+
readonly id: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Request parameters for modelsIdGet operation in EdiModelApi.
|
|
201
|
+
* @export
|
|
202
|
+
* @interface EdiModelApiModelsIdGetRequest
|
|
203
|
+
*/
|
|
204
|
+
export interface EdiModelApiModelsIdGetRequest {
|
|
205
|
+
/**
|
|
206
|
+
* The model name.
|
|
207
|
+
* @type {string}
|
|
208
|
+
* @memberof EdiModelApiModelsIdGet
|
|
209
|
+
*/
|
|
210
|
+
readonly id: string;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Request parameters for modelsPost operation in EdiModelApi.
|
|
214
|
+
* @export
|
|
215
|
+
* @interface EdiModelApiModelsPostRequest
|
|
216
|
+
*/
|
|
217
|
+
export interface EdiModelApiModelsPostRequest {
|
|
218
|
+
/**
|
|
219
|
+
*
|
|
220
|
+
* @type {File}
|
|
221
|
+
* @memberof EdiModelApiModelsPost
|
|
222
|
+
*/
|
|
223
|
+
readonly body?: File;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* EdiModelApi - object-oriented interface
|
|
227
|
+
* @export
|
|
228
|
+
* @class EdiModelApi
|
|
229
|
+
* @extends {BaseAPI}
|
|
230
|
+
*/
|
|
231
|
+
export declare class EdiModelApi extends BaseAPI implements EdiModelApiInterface {
|
|
232
|
+
/**
|
|
233
|
+
*
|
|
234
|
+
* @summary Retrieve the names of all EDI models
|
|
235
|
+
* @param {EdiModelApiModelsGetRequest} requestParameters Request parameters.
|
|
236
|
+
* @param {*} [options] Override http request option.
|
|
237
|
+
* @throws {RequiredError}
|
|
238
|
+
* @memberof EdiModelApi
|
|
239
|
+
*/
|
|
240
|
+
modelsGet(requestParameters?: EdiModelApiModelsGetRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<EdiModel[], any, {}>>;
|
|
241
|
+
/**
|
|
242
|
+
*
|
|
243
|
+
* @summary Delete an EDI model
|
|
244
|
+
* @param {EdiModelApiModelsIdDeleteRequest} requestParameters Request parameters.
|
|
245
|
+
* @param {*} [options] Override http request option.
|
|
246
|
+
* @throws {RequiredError}
|
|
247
|
+
* @memberof EdiModelApi
|
|
248
|
+
*/
|
|
249
|
+
modelsIdDelete(requestParameters: EdiModelApiModelsIdDeleteRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>;
|
|
250
|
+
/**
|
|
251
|
+
*
|
|
252
|
+
* @summary Retrieve an EDI model
|
|
253
|
+
* @param {EdiModelApiModelsIdGetRequest} requestParameters Request parameters.
|
|
254
|
+
* @param {*} [options] Override http request option.
|
|
255
|
+
* @throws {RequiredError}
|
|
256
|
+
* @memberof EdiModelApi
|
|
257
|
+
*/
|
|
258
|
+
modelsIdGet(requestParameters: EdiModelApiModelsIdGetRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<File, any, {}>>;
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* @summary Upload EDI models in either SEF or OpenEDI format
|
|
262
|
+
* @param {EdiModelApiModelsPostRequest} requestParameters Request parameters.
|
|
263
|
+
* @param {*} [options] Override http request option.
|
|
264
|
+
* @throws {RequiredError}
|
|
265
|
+
* @memberof EdiModelApi
|
|
266
|
+
*/
|
|
267
|
+
modelsPost(requestParameters?: EdiModelApiModelsPostRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>;
|
|
268
|
+
}
|