vintrace-sdk 0.0.5
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 +241 -0
- package/dist/index.cjs +870 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1239 -0
- package/dist/index.d.ts +1239 -0
- package/dist/index.js +853 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# vintrace-sdk
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for the Vintrace API.
|
|
4
|
+
|
|
5
|
+
> **Disclaimer**: This SDK is not affiliated with or endorsed by Vintrace. It is an independent, third-party project. Use at your own risk. Always refer to the official Vintrace API documentation. Provided as-is without warranties. Test thoroughly before using in production.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Node.js >= 18.0.0
|
|
12
|
+
- pnpm (recommended)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install vintrace-sdk
|
|
18
|
+
# or
|
|
19
|
+
pnpm add vintrace-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { VintraceClient } from 'vintrace-sdk';
|
|
28
|
+
|
|
29
|
+
const client = new VintraceClient({
|
|
30
|
+
baseUrl: 'https://oz50.vintrace.net', // your region (oz50, sandbox, etc.)
|
|
31
|
+
organization: 'wrw', // your customer/organization code
|
|
32
|
+
token: process.env.VINTRACE_TOKEN!,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Get a single record
|
|
36
|
+
const [order, error] = await client.v6.salesOrders.get('123');
|
|
37
|
+
if (error) {
|
|
38
|
+
console.error(error.status, error.message);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
console.log(order.id); // fully typed, never null here
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const client = new VintraceClient({
|
|
50
|
+
baseUrl: 'https://oz50.vintrace.net',
|
|
51
|
+
organization: 'wrw',
|
|
52
|
+
token: 'your-bearer-token',
|
|
53
|
+
options: {
|
|
54
|
+
timeout: 30000, // request timeout in ms (default: 30000)
|
|
55
|
+
maxRetries: 3, // exponential backoff retries (default: 3)
|
|
56
|
+
parallelLimit: 5, // max concurrent requests for batch operations (default: 5)
|
|
57
|
+
validateRequests: true, // Zod validate request payloads (default: true)
|
|
58
|
+
validateResponses: true, // Zod validate API responses (default: true)
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**URL format:** `{baseUrl}/{organization}/api/{version}/{endpoint}`
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Error Handling
|
|
68
|
+
|
|
69
|
+
Every API method returns a Go-style `[data, error]` result tuple — no `try/catch` required.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import {
|
|
73
|
+
VintraceAuthenticationError,
|
|
74
|
+
VintraceRateLimitError,
|
|
75
|
+
VintraceNotFoundError,
|
|
76
|
+
VintraceAggregateError,
|
|
77
|
+
} from 'vintrace-sdk';
|
|
78
|
+
|
|
79
|
+
const [order, error] = await client.v6.salesOrders.get('123');
|
|
80
|
+
if (error) {
|
|
81
|
+
if (error instanceof VintraceAuthenticationError) {
|
|
82
|
+
console.log('Invalid token');
|
|
83
|
+
} else if (error instanceof VintraceRateLimitError) {
|
|
84
|
+
console.log('Rate limited, retry after:', error.retryAfter);
|
|
85
|
+
} else if (error instanceof VintraceNotFoundError) {
|
|
86
|
+
console.log('Entity not found');
|
|
87
|
+
} else if (error instanceof VintraceAggregateError) {
|
|
88
|
+
console.log('Multiple errors:', error.errors.length);
|
|
89
|
+
for (const e of error.errors) console.log(' -', e.message);
|
|
90
|
+
} else {
|
|
91
|
+
console.log('API error:', error.status, error.correlationId);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Error Class Hierarchy
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
VintraceError (base)
|
|
101
|
+
├── VintraceAuthenticationError (401)
|
|
102
|
+
├── VintraceRateLimitError (429) — has .retryAfter
|
|
103
|
+
├── VintraceNotFoundError (404)
|
|
104
|
+
├── VintraceValidationError (400, 422, other 4xx)
|
|
105
|
+
├── VintraceServerError (500+)
|
|
106
|
+
└── VintraceAggregateError (batch operation failures)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
All errors expose: `message`, `status`, `correlationId`, `name`.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## API Patterns
|
|
114
|
+
|
|
115
|
+
### Get by ID
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const [order, error] = await client.v6.salesOrders.get('123');
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Auto-paginated list
|
|
122
|
+
|
|
123
|
+
Automatically fetches all pages — yields one item at a time:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
for await (const order of client.v6.salesOrders.getAll({ status: 'ACTIVE' })) {
|
|
127
|
+
console.log(order.id, order.name);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Batch fetch (parallel)
|
|
132
|
+
|
|
133
|
+
Fetches multiple IDs concurrently (default: 5 at a time):
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const [results, error] = await client.v6.salesOrders.getMany(['id1', 'id2', 'id3']);
|
|
137
|
+
if (error) { /* handle VintraceAggregateError */ }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Create
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const [newOrder, error] = await client.v6.salesOrders.post({ /* payload */ });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Update
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const [updated, error] = await client.v6.salesOrders.update('123', { /* payload */ });
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Result Type
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
type VintraceResult<T> =
|
|
158
|
+
| [data: T, error: null] // success
|
|
159
|
+
| [data: null, error: VintraceError] // error
|
|
160
|
+
| [data: null, error: null]; // 204 No Content
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Retry Logic
|
|
166
|
+
|
|
167
|
+
- **Attempts**: 3 (configurable via `maxRetries`)
|
|
168
|
+
- **Backoff**: 1s → 2s → 4s (exponential)
|
|
169
|
+
- **Retryable codes**: 408, 429, 500, 502, 503, 504
|
|
170
|
+
- **Correlation ID**: Sent as `X-Correlation-ID` header, returned on errors as `error.correlationId`
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## API Coverage
|
|
175
|
+
|
|
176
|
+
### v6 Endpoints
|
|
177
|
+
|
|
178
|
+
| Module | Methods |
|
|
179
|
+
|--------|---------|
|
|
180
|
+
| WorkOrders | `getAll`, `get`, `getMany`, `post`, `update` |
|
|
181
|
+
| SalesOrders | `getAll`, `get`, `getMany`, `post`, `update` |
|
|
182
|
+
| Refunds | `getAll`, `get`, `getMany`, `post` |
|
|
183
|
+
| Parties | `getAll`, `get`, `getMany`, `post` |
|
|
184
|
+
| Products | `getAll`, `get`, `getMany`, `post` |
|
|
185
|
+
| ProductUpdate | `post` |
|
|
186
|
+
| Transactions | `search` |
|
|
187
|
+
| IntakeOperations | `search` |
|
|
188
|
+
| SampleOperations | `search` |
|
|
189
|
+
| BlockAssessments | `post` |
|
|
190
|
+
| MRPStock | `get`, `updateFields`, `getDistributions`, `getHistoryItems`, `getRawComponents`, `getNotes`, `postNote`, `updateNote` |
|
|
191
|
+
| Inventory | `getAll` |
|
|
192
|
+
| Search | `list`, `lookup` |
|
|
193
|
+
|
|
194
|
+
### v7 Endpoints
|
|
195
|
+
|
|
196
|
+
| Module | Methods |
|
|
197
|
+
|--------|---------|
|
|
198
|
+
| Costs | `businessUnitTransactions` |
|
|
199
|
+
| Blocks | `getAll`, `get`, `post`, `update`, `patch`, `getAssessments`, `createAssessment` |
|
|
200
|
+
| Assessments | `getAll` |
|
|
201
|
+
| Vineyards | `post` |
|
|
202
|
+
| MaturitySamples | `post` |
|
|
203
|
+
| Parties | `getAll`, `post` |
|
|
204
|
+
| Shipments | `getAll` |
|
|
205
|
+
| BarrelTreatments | `getAll` |
|
|
206
|
+
| Bookings | `post`, `deactivate` |
|
|
207
|
+
| FruitIntakes | `post`, `updatePricing`, `updateMetrics` |
|
|
208
|
+
| BulkIntakes | `getAll`, `post`, `patch` |
|
|
209
|
+
| TrialBlends | `getAll` |
|
|
210
|
+
| WorkOrders | `getAll` |
|
|
211
|
+
| Tirage | `get`, `patch` |
|
|
212
|
+
| BarrelsMovements | `post` |
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Development
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
pnpm build # Build ESM + CJS bundles
|
|
220
|
+
pnpm dev # Watch mode
|
|
221
|
+
pnpm typecheck # TypeScript type checking
|
|
222
|
+
pnpm lint # ESLint
|
|
223
|
+
pnpm lint:fix # Auto-fix ESLint issues
|
|
224
|
+
pnpm format # Prettier
|
|
225
|
+
pnpm test run # Run tests once
|
|
226
|
+
pnpm generate-types # Regenerate types from OpenAPI YAML
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Output
|
|
230
|
+
|
|
231
|
+
| Format | File |
|
|
232
|
+
|--------|------|
|
|
233
|
+
| ESM | `dist/index.js` |
|
|
234
|
+
| CJS | `dist/index.cjs` |
|
|
235
|
+
| Types | `dist/index.d.ts` |
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## License
|
|
240
|
+
|
|
241
|
+
MIT
|