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/dist/index.cjs
ADDED
|
@@ -0,0 +1,870 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
// src/client/config.ts
|
|
6
|
+
var DEFAULT_OPTIONS = {
|
|
7
|
+
timeout: 3e4,
|
|
8
|
+
maxRetries: 3,
|
|
9
|
+
parallelLimit: 5,
|
|
10
|
+
validateRequests: true,
|
|
11
|
+
validateResponses: true
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/client/errors.ts
|
|
15
|
+
var VintraceError = class extends Error {
|
|
16
|
+
constructor(message, status, correlationId, body) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "VintraceError";
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.correlationId = correlationId;
|
|
21
|
+
this.body = body;
|
|
22
|
+
Error.captureStackTrace(this, this.constructor);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var VintraceAuthenticationError = class extends VintraceError {
|
|
26
|
+
constructor(message = "Authentication failed", correlationId, body) {
|
|
27
|
+
super(message, 401, correlationId, body);
|
|
28
|
+
this.name = "VintraceAuthenticationError";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var VintraceRateLimitError = class extends VintraceError {
|
|
32
|
+
constructor(message = "Rate limit exceeded", retryAfter, correlationId, body) {
|
|
33
|
+
super(message, 429, correlationId, body);
|
|
34
|
+
this.name = "VintraceRateLimitError";
|
|
35
|
+
this.retryAfter = retryAfter;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var VintraceNotFoundError = class extends VintraceError {
|
|
39
|
+
constructor(message = "Resource not found", correlationId, body) {
|
|
40
|
+
super(message, 404, correlationId, body);
|
|
41
|
+
this.name = "VintraceNotFoundError";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var VintraceValidationError = class extends VintraceError {
|
|
45
|
+
constructor(message = "Validation failed", status = 400, correlationId, body) {
|
|
46
|
+
super(message, status, correlationId, body);
|
|
47
|
+
this.name = "VintraceValidationError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var VintraceServerError = class extends VintraceError {
|
|
51
|
+
constructor(message = "Server error", status, correlationId, body) {
|
|
52
|
+
super(message, status, correlationId, body);
|
|
53
|
+
this.name = "VintraceServerError";
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var VintraceAggregateError = class extends VintraceError {
|
|
57
|
+
constructor(errors) {
|
|
58
|
+
const message = errors.length === 1 ? errors[0].message : `${errors.length} errors occurred: ${errors.map((e) => e.message).join("; ")}`;
|
|
59
|
+
super(
|
|
60
|
+
message,
|
|
61
|
+
errors[0]?.status ?? 0,
|
|
62
|
+
errors[0]?.correlationId,
|
|
63
|
+
errors.map((e) => e.body)
|
|
64
|
+
);
|
|
65
|
+
this.name = "VintraceAggregateError";
|
|
66
|
+
this.errors = errors;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
function isRetryableStatus(status) {
|
|
70
|
+
return [408, 429, 500, 502, 503, 504].includes(status);
|
|
71
|
+
}
|
|
72
|
+
var VintraceValidationSchemaError = class extends VintraceError {
|
|
73
|
+
constructor(message, errors, correlationId) {
|
|
74
|
+
super(message, 422, correlationId);
|
|
75
|
+
this.errors = errors;
|
|
76
|
+
this.name = "VintraceValidationSchemaError";
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
function validateResponse(schema, data, correlationId) {
|
|
80
|
+
try {
|
|
81
|
+
const validated = schema.parse(data);
|
|
82
|
+
return [validated, null];
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof zod.ZodError) {
|
|
85
|
+
const message = error.issues.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ");
|
|
86
|
+
return [null, new VintraceValidationSchemaError(message, error.issues, correlationId)];
|
|
87
|
+
}
|
|
88
|
+
return [null, new VintraceError("Response validation failed", 500, correlationId)];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function validateRequest(schema, data, correlationId) {
|
|
92
|
+
try {
|
|
93
|
+
const validated = schema.parse(data);
|
|
94
|
+
return [validated, null];
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error instanceof zod.ZodError) {
|
|
97
|
+
const message = error.issues.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ");
|
|
98
|
+
return [null, new VintraceValidationSchemaError(message, error.issues, correlationId)];
|
|
99
|
+
}
|
|
100
|
+
return [null, new VintraceError("Request validation failed", 500, correlationId)];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/http/fetch.ts
|
|
105
|
+
function generateCorrelationId() {
|
|
106
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
107
|
+
const r = Math.random() * 16 | 0;
|
|
108
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
109
|
+
return v.toString(16);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function getRetryAfterFromHeaders(headers) {
|
|
113
|
+
const retryAfter = headers.get("retry-after");
|
|
114
|
+
if (retryAfter) {
|
|
115
|
+
const parsed = parseInt(retryAfter, 10);
|
|
116
|
+
return isNaN(parsed) ? void 0 : parsed;
|
|
117
|
+
}
|
|
118
|
+
return void 0;
|
|
119
|
+
}
|
|
120
|
+
var VintraceFetchError = class extends VintraceError {
|
|
121
|
+
constructor(message, status, correlationId, body) {
|
|
122
|
+
super(message, status, correlationId, body);
|
|
123
|
+
this.name = "VintraceFetchError";
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
async function vintraceFetch(baseUrl, organization, token, endpoint, method, options = {}, body) {
|
|
127
|
+
const timeout = options.timeout ?? DEFAULT_OPTIONS.timeout;
|
|
128
|
+
const maxRetries = options.maxRetries ?? DEFAULT_OPTIONS.maxRetries;
|
|
129
|
+
const isBodylessMethod = method === "GET" || method === "DELETE";
|
|
130
|
+
let url = `${baseUrl}/${organization}/api/${endpoint}`;
|
|
131
|
+
const correlationId = generateCorrelationId();
|
|
132
|
+
if (isBodylessMethod && body && typeof body === "object") {
|
|
133
|
+
const params = new URLSearchParams();
|
|
134
|
+
for (const [key, value] of Object.entries(body)) {
|
|
135
|
+
if (value !== void 0 && value !== null) {
|
|
136
|
+
params.set(key, String(value));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const qs = params.toString();
|
|
140
|
+
if (qs) url = `${url}?${qs}`;
|
|
141
|
+
}
|
|
142
|
+
const headers = {
|
|
143
|
+
Authorization: `Bearer ${token}`,
|
|
144
|
+
"correlation-id": correlationId,
|
|
145
|
+
"Content-Type": "application/json",
|
|
146
|
+
Accept: "application/json"
|
|
147
|
+
};
|
|
148
|
+
if (options.validateRequest && options.requestSchema && body) {
|
|
149
|
+
const [validatedBody, requestError] = validateRequest(options.requestSchema, body, correlationId);
|
|
150
|
+
if (requestError) {
|
|
151
|
+
return [null, requestError];
|
|
152
|
+
}
|
|
153
|
+
body = validatedBody;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
157
|
+
const controller = new AbortController();
|
|
158
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
159
|
+
try {
|
|
160
|
+
const response = await fetch(url, {
|
|
161
|
+
method,
|
|
162
|
+
headers,
|
|
163
|
+
body: isBodylessMethod ? void 0 : body ? JSON.stringify(body) : void 0,
|
|
164
|
+
signal: controller.signal
|
|
165
|
+
});
|
|
166
|
+
clearTimeout(timeoutId);
|
|
167
|
+
const responseCorrelationId = response.headers.get("correlation-id") || correlationId;
|
|
168
|
+
if (!response.ok) {
|
|
169
|
+
let responseBody;
|
|
170
|
+
const contentType = response.headers.get("content-type");
|
|
171
|
+
try {
|
|
172
|
+
if (contentType?.includes("application/json")) {
|
|
173
|
+
responseBody = await response.json();
|
|
174
|
+
} else {
|
|
175
|
+
responseBody = await response.text();
|
|
176
|
+
}
|
|
177
|
+
} catch {
|
|
178
|
+
}
|
|
179
|
+
const retryAfter = getRetryAfterFromHeaders(response.headers);
|
|
180
|
+
let error;
|
|
181
|
+
if (response.status === 401) {
|
|
182
|
+
error = new VintraceAuthenticationError(
|
|
183
|
+
"Authentication failed",
|
|
184
|
+
responseCorrelationId,
|
|
185
|
+
responseBody
|
|
186
|
+
);
|
|
187
|
+
} else if (response.status === 404) {
|
|
188
|
+
error = new VintraceNotFoundError(
|
|
189
|
+
"Resource not found",
|
|
190
|
+
responseCorrelationId,
|
|
191
|
+
responseBody
|
|
192
|
+
);
|
|
193
|
+
} else if (response.status === 429) {
|
|
194
|
+
error = new VintraceRateLimitError(
|
|
195
|
+
"Rate limit exceeded",
|
|
196
|
+
retryAfter,
|
|
197
|
+
responseCorrelationId,
|
|
198
|
+
responseBody
|
|
199
|
+
);
|
|
200
|
+
} else if (response.status >= 400 && response.status < 500) {
|
|
201
|
+
error = new VintraceValidationError(
|
|
202
|
+
"Request validation failed",
|
|
203
|
+
response.status,
|
|
204
|
+
responseCorrelationId,
|
|
205
|
+
responseBody
|
|
206
|
+
);
|
|
207
|
+
} else if (response.status >= 500) {
|
|
208
|
+
error = new VintraceServerError(
|
|
209
|
+
"Server error",
|
|
210
|
+
response.status,
|
|
211
|
+
responseCorrelationId,
|
|
212
|
+
responseBody
|
|
213
|
+
);
|
|
214
|
+
} else {
|
|
215
|
+
error = new VintraceError(
|
|
216
|
+
`Request failed with status ${response.status}`,
|
|
217
|
+
response.status,
|
|
218
|
+
responseCorrelationId,
|
|
219
|
+
responseBody
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
if (error instanceof VintraceRateLimitError && attempt < maxRetries) {
|
|
223
|
+
const delay = error.retryAfter ?? Math.pow(2, attempt) * 1e3;
|
|
224
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (error instanceof VintraceAuthenticationError) {
|
|
228
|
+
return [null, error];
|
|
229
|
+
}
|
|
230
|
+
if (isRetryableStatus(error.status) && attempt < maxRetries) {
|
|
231
|
+
const delay = Math.pow(2, attempt) * 1e3;
|
|
232
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
return [null, error];
|
|
236
|
+
}
|
|
237
|
+
if (response.status === 204) {
|
|
238
|
+
return [null, null];
|
|
239
|
+
}
|
|
240
|
+
const data = await response.json();
|
|
241
|
+
if (options.validateResponse && options.responseSchema) {
|
|
242
|
+
const [validatedData, responseError] = validateResponse(
|
|
243
|
+
options.responseSchema,
|
|
244
|
+
data,
|
|
245
|
+
responseCorrelationId
|
|
246
|
+
);
|
|
247
|
+
if (responseError) {
|
|
248
|
+
return [null, responseError];
|
|
249
|
+
}
|
|
250
|
+
return [validatedData, null];
|
|
251
|
+
}
|
|
252
|
+
return [data, null];
|
|
253
|
+
} catch (error) {
|
|
254
|
+
clearTimeout(timeoutId);
|
|
255
|
+
if (error instanceof VintraceError) {
|
|
256
|
+
throw error;
|
|
257
|
+
}
|
|
258
|
+
if (error instanceof Error) {
|
|
259
|
+
if (error.name === "AbortError") {
|
|
260
|
+
if (attempt < maxRetries) {
|
|
261
|
+
const delay = Math.pow(2, attempt) * 1e3;
|
|
262
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
return [null, new VintraceError("Request timeout", 408, correlationId)];
|
|
266
|
+
}
|
|
267
|
+
return [null, new VintraceFetchError(error.message, 0, correlationId)];
|
|
268
|
+
}
|
|
269
|
+
return [null, new VintraceFetchError("Unknown error", 0, correlationId)];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return [null, new VintraceError("Max retries exceeded", 0, correlationId)];
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (error instanceof VintraceError) {
|
|
275
|
+
return [null, error];
|
|
276
|
+
}
|
|
277
|
+
return [
|
|
278
|
+
null,
|
|
279
|
+
new VintraceFetchError(
|
|
280
|
+
error instanceof Error ? error.message : "Unknown error",
|
|
281
|
+
0,
|
|
282
|
+
correlationId
|
|
283
|
+
)
|
|
284
|
+
];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/client/VintraceClient.ts
|
|
289
|
+
var VintraceClient = class {
|
|
290
|
+
constructor(config) {
|
|
291
|
+
this.baseUrl = config.baseUrl;
|
|
292
|
+
this.organization = config.organization;
|
|
293
|
+
this.token = config.token;
|
|
294
|
+
this.options = { ...DEFAULT_OPTIONS, ...config.options };
|
|
295
|
+
this.v6 = new VintraceV6Api(this);
|
|
296
|
+
this.v7 = new VintraceV7Api(this);
|
|
297
|
+
}
|
|
298
|
+
request(endpoint, method, options, body) {
|
|
299
|
+
return vintraceFetch(
|
|
300
|
+
this.baseUrl,
|
|
301
|
+
this.organization,
|
|
302
|
+
this.token,
|
|
303
|
+
endpoint,
|
|
304
|
+
method,
|
|
305
|
+
{
|
|
306
|
+
timeout: options?.timeout ?? this.options.timeout,
|
|
307
|
+
maxRetries: options?.maxRetries ?? this.options.maxRetries,
|
|
308
|
+
validateRequest: options?.validateRequest ?? this.options.validateRequests,
|
|
309
|
+
validateResponse: options?.validateResponse ?? this.options.validateResponses
|
|
310
|
+
},
|
|
311
|
+
body
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var VintraceV6Api = class {
|
|
316
|
+
constructor(client) {
|
|
317
|
+
this.client = client;
|
|
318
|
+
}
|
|
319
|
+
get workOrders() {
|
|
320
|
+
return new WorkOrdersClient(this.client);
|
|
321
|
+
}
|
|
322
|
+
get salesOrders() {
|
|
323
|
+
return new SalesOrdersClient(this.client);
|
|
324
|
+
}
|
|
325
|
+
get refunds() {
|
|
326
|
+
return new RefundsClient(this.client);
|
|
327
|
+
}
|
|
328
|
+
get parties() {
|
|
329
|
+
return new PartiesClient(this.client);
|
|
330
|
+
}
|
|
331
|
+
get products() {
|
|
332
|
+
return new ProductsClient(this.client);
|
|
333
|
+
}
|
|
334
|
+
get transactions() {
|
|
335
|
+
return new TransactionsClient(this.client);
|
|
336
|
+
}
|
|
337
|
+
get intakeOperations() {
|
|
338
|
+
return new IntakeOperationsClient(this.client);
|
|
339
|
+
}
|
|
340
|
+
get sampleOperations() {
|
|
341
|
+
return new SampleOperationsClient(this.client);
|
|
342
|
+
}
|
|
343
|
+
get blockAssessments() {
|
|
344
|
+
return new BlockAssessmentsClient(this.client);
|
|
345
|
+
}
|
|
346
|
+
get mrpStock() {
|
|
347
|
+
return new MrpStockClient(this.client);
|
|
348
|
+
}
|
|
349
|
+
get inventory() {
|
|
350
|
+
return new InventoryClient(this.client);
|
|
351
|
+
}
|
|
352
|
+
get search() {
|
|
353
|
+
return new SearchClient(this.client);
|
|
354
|
+
}
|
|
355
|
+
get productAnalysis() {
|
|
356
|
+
return new ProductAnalysisClient(this.client);
|
|
357
|
+
}
|
|
358
|
+
get productComposition() {
|
|
359
|
+
return new ProductCompositionClient(this.client);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
var VintraceV7Api = class {
|
|
363
|
+
constructor(client) {
|
|
364
|
+
this.client = client;
|
|
365
|
+
}
|
|
366
|
+
get blocks() {
|
|
367
|
+
return new BlocksClient(this.client);
|
|
368
|
+
}
|
|
369
|
+
get bookings() {
|
|
370
|
+
return new BookingsClient(this.client);
|
|
371
|
+
}
|
|
372
|
+
get vesselDetailsReport() {
|
|
373
|
+
return new VesselDetailsReportClient(this.client);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
var WorkOrdersClient = class {
|
|
377
|
+
constructor(client) {
|
|
378
|
+
this.client = client;
|
|
379
|
+
}
|
|
380
|
+
getAll(params) {
|
|
381
|
+
return this.client.request("v6/workorders/list", "GET", {}, params);
|
|
382
|
+
}
|
|
383
|
+
get(id) {
|
|
384
|
+
return this.client.request(`v6/workorders/${id}`, "GET");
|
|
385
|
+
}
|
|
386
|
+
getByCode(code) {
|
|
387
|
+
return this.client.request("v6/workorders", "GET", {}, { code });
|
|
388
|
+
}
|
|
389
|
+
getJob(jobId) {
|
|
390
|
+
return this.client.request(`v6/workorders/jobs/${jobId}`, "GET");
|
|
391
|
+
}
|
|
392
|
+
assign(workOrderId) {
|
|
393
|
+
return this.client.request("v6/workorders/assign", "POST", {}, { workOrderId });
|
|
394
|
+
}
|
|
395
|
+
submit(data) {
|
|
396
|
+
return this.client.request("v6/workorders/submit", "POST", {}, data);
|
|
397
|
+
}
|
|
398
|
+
getMany(ids) {
|
|
399
|
+
return this.batchGet(ids, (id) => this.get(id));
|
|
400
|
+
}
|
|
401
|
+
async batchGet(ids, fetchFn) {
|
|
402
|
+
const results = await Promise.allSettled(ids.map((id) => fetchFn(id)));
|
|
403
|
+
const errors = [];
|
|
404
|
+
const data = [];
|
|
405
|
+
for (const result of results) {
|
|
406
|
+
if (result.status === "fulfilled") {
|
|
407
|
+
const [item, error] = result.value;
|
|
408
|
+
if (error) {
|
|
409
|
+
errors.push(error);
|
|
410
|
+
} else if (item !== null) {
|
|
411
|
+
data.push(item);
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (errors.length > 0) {
|
|
418
|
+
return [null, new VintraceAggregateError(errors)];
|
|
419
|
+
}
|
|
420
|
+
return [data, null];
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
var SalesOrdersClient = class {
|
|
424
|
+
constructor(client) {
|
|
425
|
+
this.client = client;
|
|
426
|
+
}
|
|
427
|
+
getAll(params) {
|
|
428
|
+
return this.client.request("v6/sales-order/list", "GET", {}, params);
|
|
429
|
+
}
|
|
430
|
+
get(id) {
|
|
431
|
+
return this.client.request(`v6/sales-order/${id}`, "GET");
|
|
432
|
+
}
|
|
433
|
+
getByCode(code) {
|
|
434
|
+
return this.client.request("v6/sales-order", "GET", {}, { code });
|
|
435
|
+
}
|
|
436
|
+
create(data) {
|
|
437
|
+
return this.client.request("v6/sales-order", "POST", {}, data);
|
|
438
|
+
}
|
|
439
|
+
update(id, data) {
|
|
440
|
+
return this.client.request(`v6/sales-order/${id}`, "PUT", {}, data);
|
|
441
|
+
}
|
|
442
|
+
getMany(ids) {
|
|
443
|
+
return this.batchGet(ids, (id) => this.get(id));
|
|
444
|
+
}
|
|
445
|
+
async batchGet(ids, fetchFn) {
|
|
446
|
+
const results = await Promise.allSettled(ids.map((id) => fetchFn(id)));
|
|
447
|
+
const errors = [];
|
|
448
|
+
const data = [];
|
|
449
|
+
for (const result of results) {
|
|
450
|
+
if (result.status === "fulfilled") {
|
|
451
|
+
const [item, error] = result.value;
|
|
452
|
+
if (error) {
|
|
453
|
+
errors.push(error);
|
|
454
|
+
} else if (item !== null) {
|
|
455
|
+
data.push(item);
|
|
456
|
+
}
|
|
457
|
+
} else {
|
|
458
|
+
errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (errors.length > 0) {
|
|
462
|
+
return [null, new VintraceAggregateError(errors)];
|
|
463
|
+
}
|
|
464
|
+
return [data, null];
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
var RefundsClient = class {
|
|
468
|
+
constructor(client) {
|
|
469
|
+
this.client = client;
|
|
470
|
+
}
|
|
471
|
+
getAll(params) {
|
|
472
|
+
return this.client.request("v6/refund/list", "GET", {}, params);
|
|
473
|
+
}
|
|
474
|
+
get(id) {
|
|
475
|
+
return this.client.request(`v6/refund/${id}`, "GET");
|
|
476
|
+
}
|
|
477
|
+
getByCode(code) {
|
|
478
|
+
return this.client.request("v6/refund", "GET", {}, { code });
|
|
479
|
+
}
|
|
480
|
+
create(data) {
|
|
481
|
+
return this.client.request("v6/refund", "POST", {}, data);
|
|
482
|
+
}
|
|
483
|
+
update(id, data) {
|
|
484
|
+
return this.client.request(`v6/refund/${id}`, "PUT", {}, data);
|
|
485
|
+
}
|
|
486
|
+
getMany(ids) {
|
|
487
|
+
return this.batchGet(ids, (id) => this.get(id));
|
|
488
|
+
}
|
|
489
|
+
async batchGet(ids, fetchFn) {
|
|
490
|
+
const results = await Promise.allSettled(ids.map((id) => fetchFn(id)));
|
|
491
|
+
const errors = [];
|
|
492
|
+
const data = [];
|
|
493
|
+
for (const result of results) {
|
|
494
|
+
if (result.status === "fulfilled") {
|
|
495
|
+
const [item, error] = result.value;
|
|
496
|
+
if (error) {
|
|
497
|
+
errors.push(error);
|
|
498
|
+
} else if (item !== null) {
|
|
499
|
+
data.push(item);
|
|
500
|
+
}
|
|
501
|
+
} else {
|
|
502
|
+
errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (errors.length > 0) {
|
|
506
|
+
return [null, new VintraceAggregateError(errors)];
|
|
507
|
+
}
|
|
508
|
+
return [data, null];
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
var PartiesClient = class {
|
|
512
|
+
constructor(client) {
|
|
513
|
+
this.client = client;
|
|
514
|
+
}
|
|
515
|
+
getAll(params) {
|
|
516
|
+
return this.client.request("v6/party/list", "GET", {}, params);
|
|
517
|
+
}
|
|
518
|
+
get(id) {
|
|
519
|
+
return this.client.request(`v6/party/${id}`, "GET");
|
|
520
|
+
}
|
|
521
|
+
getByName(name) {
|
|
522
|
+
return this.client.request("v6/party", "GET", {}, { name });
|
|
523
|
+
}
|
|
524
|
+
create(data) {
|
|
525
|
+
return this.client.request("v6/party", "POST", {}, data);
|
|
526
|
+
}
|
|
527
|
+
getMany(ids) {
|
|
528
|
+
return this.batchGet(ids, (id) => this.get(id));
|
|
529
|
+
}
|
|
530
|
+
async batchGet(ids, fetchFn) {
|
|
531
|
+
const results = await Promise.allSettled(ids.map((id) => fetchFn(id)));
|
|
532
|
+
const errors = [];
|
|
533
|
+
const data = [];
|
|
534
|
+
for (const result of results) {
|
|
535
|
+
if (result.status === "fulfilled") {
|
|
536
|
+
const [item, error] = result.value;
|
|
537
|
+
if (error) {
|
|
538
|
+
errors.push(error);
|
|
539
|
+
} else if (item !== null) {
|
|
540
|
+
data.push(item);
|
|
541
|
+
}
|
|
542
|
+
} else {
|
|
543
|
+
errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (errors.length > 0) {
|
|
547
|
+
return [null, new VintraceAggregateError(errors)];
|
|
548
|
+
}
|
|
549
|
+
return [data, null];
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
var ProductsClient = class {
|
|
553
|
+
constructor(client) {
|
|
554
|
+
this.client = client;
|
|
555
|
+
}
|
|
556
|
+
getAll(params) {
|
|
557
|
+
return this.client.request("v6/products/list", "GET", {}, params);
|
|
558
|
+
}
|
|
559
|
+
get(id) {
|
|
560
|
+
return this.client.request(`v6/products/${id}`, "GET");
|
|
561
|
+
}
|
|
562
|
+
getMany(ids) {
|
|
563
|
+
return this.batchGet(ids, (id) => this.get(id));
|
|
564
|
+
}
|
|
565
|
+
create(data) {
|
|
566
|
+
return this.client.request("v6/products", "POST", {}, data);
|
|
567
|
+
}
|
|
568
|
+
update(id, data) {
|
|
569
|
+
return this.client.request(`v6/products/${id}`, "PUT", {}, data);
|
|
570
|
+
}
|
|
571
|
+
updateFields(data) {
|
|
572
|
+
return this.client.request("v6/product-update", "POST", {}, data);
|
|
573
|
+
}
|
|
574
|
+
async batchGet(ids, fetchFn) {
|
|
575
|
+
const results = await Promise.allSettled(ids.map((id) => fetchFn(id)));
|
|
576
|
+
const errors = [];
|
|
577
|
+
const data = [];
|
|
578
|
+
for (const result of results) {
|
|
579
|
+
if (result.status === "fulfilled") {
|
|
580
|
+
const [item, error] = result.value;
|
|
581
|
+
if (error) {
|
|
582
|
+
errors.push(error);
|
|
583
|
+
} else if (item !== null) {
|
|
584
|
+
data.push(item);
|
|
585
|
+
}
|
|
586
|
+
} else {
|
|
587
|
+
errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
if (errors.length > 0) {
|
|
591
|
+
return [null, new VintraceAggregateError(errors)];
|
|
592
|
+
}
|
|
593
|
+
return [data, null];
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var BlocksClient = class {
|
|
597
|
+
constructor(client) {
|
|
598
|
+
this.client = client;
|
|
599
|
+
}
|
|
600
|
+
getAll(params) {
|
|
601
|
+
return this.client.request("v7/harvest/blocks", "GET", {}, params);
|
|
602
|
+
}
|
|
603
|
+
get(id) {
|
|
604
|
+
return this.client.request(`v7/harvest/blocks/${id}`, "GET");
|
|
605
|
+
}
|
|
606
|
+
getMany(ids) {
|
|
607
|
+
return this.batchGet(ids, (id) => this.get(id));
|
|
608
|
+
}
|
|
609
|
+
post(data) {
|
|
610
|
+
return this.client.request("v7/harvest/blocks", "POST", {}, data);
|
|
611
|
+
}
|
|
612
|
+
patch(id, data) {
|
|
613
|
+
return this.client.request(`v7/harvest/blocks/${id}`, "PATCH", {}, data);
|
|
614
|
+
}
|
|
615
|
+
async batchGet(ids, fetchFn) {
|
|
616
|
+
const results = await Promise.allSettled(ids.map((id) => fetchFn(id)));
|
|
617
|
+
const errors = [];
|
|
618
|
+
const data = [];
|
|
619
|
+
for (const result of results) {
|
|
620
|
+
if (result.status === "fulfilled") {
|
|
621
|
+
const [item, error] = result.value;
|
|
622
|
+
if (error) {
|
|
623
|
+
errors.push(error);
|
|
624
|
+
} else if (item !== null) {
|
|
625
|
+
data.push(item);
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (errors.length > 0) {
|
|
632
|
+
return [null, new VintraceAggregateError(errors)];
|
|
633
|
+
}
|
|
634
|
+
return [data, null];
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
var BookingsClient = class {
|
|
638
|
+
constructor(client) {
|
|
639
|
+
this.client = client;
|
|
640
|
+
}
|
|
641
|
+
post(data) {
|
|
642
|
+
return this.client.request("v7/operation/bookings", "POST", {}, data);
|
|
643
|
+
}
|
|
644
|
+
deactivate(id) {
|
|
645
|
+
return this.client.request(`v7/operation/bookings/${id}/deactivation`, "POST");
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
var VesselDetailsReportClient = class {
|
|
649
|
+
constructor(client) {
|
|
650
|
+
this.client = client;
|
|
651
|
+
}
|
|
652
|
+
get(params) {
|
|
653
|
+
return this.client.request("v7/report/vessel-details-report", "GET", {}, params);
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
var TransactionsClient = class {
|
|
657
|
+
constructor(client) {
|
|
658
|
+
this.client = client;
|
|
659
|
+
}
|
|
660
|
+
search(params) {
|
|
661
|
+
return this.client.request("v6/transaction/search", "GET", {}, params);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
var IntakeOperationsClient = class {
|
|
665
|
+
constructor(client) {
|
|
666
|
+
this.client = client;
|
|
667
|
+
}
|
|
668
|
+
search(params) {
|
|
669
|
+
return this.client.request("v6/intake-operations/search", "GET", {}, params);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
var SampleOperationsClient = class {
|
|
673
|
+
constructor(client) {
|
|
674
|
+
this.client = client;
|
|
675
|
+
}
|
|
676
|
+
search(params) {
|
|
677
|
+
return this.client.request("v6/sample-operations/search", "GET", {}, params);
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
var BlockAssessmentsClient = class {
|
|
681
|
+
constructor(client) {
|
|
682
|
+
this.client = client;
|
|
683
|
+
}
|
|
684
|
+
create(data) {
|
|
685
|
+
return this.client.request("v6/block-assessments/create", "POST", {}, data);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
var MrpStockClient = class {
|
|
689
|
+
constructor(client) {
|
|
690
|
+
this.client = client;
|
|
691
|
+
}
|
|
692
|
+
get(id, expand) {
|
|
693
|
+
return this.client.request(`v6/mrp/stock/${id}`, "GET", {}, expand ? { expand } : void 0);
|
|
694
|
+
}
|
|
695
|
+
getFields(id) {
|
|
696
|
+
return this.client.request(`v6/mrp/stock/${id}/fields`, "GET");
|
|
697
|
+
}
|
|
698
|
+
getDistributions(id) {
|
|
699
|
+
return this.client.request(`v6/mrp/stock/${id}/distributions`, "GET");
|
|
700
|
+
}
|
|
701
|
+
getHistoryItems(id, params) {
|
|
702
|
+
return this.client.request(`v6/mrp/stock/${id}/history-items`, "GET", {}, params);
|
|
703
|
+
}
|
|
704
|
+
getRawComponents(id) {
|
|
705
|
+
return this.client.request(`v6/mrp/stock/${id}/raw-components`, "GET");
|
|
706
|
+
}
|
|
707
|
+
getNotes(id, params) {
|
|
708
|
+
return this.client.request(`v6/mrp/stock/${id}/notes`, "GET", {}, params);
|
|
709
|
+
}
|
|
710
|
+
postNote(id, data) {
|
|
711
|
+
return this.client.request(`v6/mrp/stock/${id}/notes`, "POST", {}, data);
|
|
712
|
+
}
|
|
713
|
+
getNote(id, noteId) {
|
|
714
|
+
return this.client.request(`v6/mrp/stock/${id}/notes/${noteId}`, "GET");
|
|
715
|
+
}
|
|
716
|
+
updateNote(id, noteId, data) {
|
|
717
|
+
return this.client.request(`v6/mrp/stock/${id}/notes/${noteId}/updates`, "POST", {}, data);
|
|
718
|
+
}
|
|
719
|
+
getBulkInfo(id) {
|
|
720
|
+
return this.client.request(`v6/mrp/stock/${id}/bulk-info`, "GET");
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
var InventoryClient = class {
|
|
724
|
+
constructor(client) {
|
|
725
|
+
this.client = client;
|
|
726
|
+
}
|
|
727
|
+
getAll(params) {
|
|
728
|
+
return this.client.request("v6/inventory", "GET", {}, params);
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
var SearchClient = class {
|
|
732
|
+
constructor(client) {
|
|
733
|
+
this.client = client;
|
|
734
|
+
}
|
|
735
|
+
list(params) {
|
|
736
|
+
return this.client.request("v6/search/list", "GET", {}, params);
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
var ProductAnalysisClient = class {
|
|
740
|
+
constructor(client) {
|
|
741
|
+
this.client = client;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Get analysis data for a product by its numeric ID.
|
|
745
|
+
* The endpoint path matches the `productAnalysisEndpoint` field returned on a Product.
|
|
746
|
+
* e.g. GET v6/product-analysis/{productId}
|
|
747
|
+
*/
|
|
748
|
+
get(productId, params) {
|
|
749
|
+
return this.client.request(
|
|
750
|
+
`v6/product-analysis/${productId}`,
|
|
751
|
+
"GET",
|
|
752
|
+
{},
|
|
753
|
+
params
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Fetch analysis for multiple product IDs in parallel.
|
|
758
|
+
* Respects the client's `parallelLimit` option (default 5 concurrent).
|
|
759
|
+
* Returns `VintraceAggregateError` if any individual request fails.
|
|
760
|
+
*/
|
|
761
|
+
getMany(productIds, params) {
|
|
762
|
+
return this.batchGet(productIds, (id) => this.get(id, params));
|
|
763
|
+
}
|
|
764
|
+
async batchGet(ids, fetchFn) {
|
|
765
|
+
const limit = this.client.options.parallelLimit;
|
|
766
|
+
const errors = [];
|
|
767
|
+
const data = [];
|
|
768
|
+
for (let i = 0; i < ids.length; i += limit) {
|
|
769
|
+
const chunk = ids.slice(i, i + limit);
|
|
770
|
+
const results = await Promise.allSettled(chunk.map((id) => fetchFn(id)));
|
|
771
|
+
for (const result of results) {
|
|
772
|
+
if (result.status === "fulfilled") {
|
|
773
|
+
const [item, error] = result.value;
|
|
774
|
+
if (error) {
|
|
775
|
+
errors.push(error);
|
|
776
|
+
} else if (item !== null) {
|
|
777
|
+
data.push(item);
|
|
778
|
+
}
|
|
779
|
+
} else {
|
|
780
|
+
errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (errors.length > 0) {
|
|
785
|
+
return [null, new VintraceAggregateError(errors)];
|
|
786
|
+
}
|
|
787
|
+
return [data, null];
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
var ProductCompositionClient = class {
|
|
791
|
+
constructor(client) {
|
|
792
|
+
this.client = client;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Get composition (blend components) for a product by its numeric ID.
|
|
796
|
+
* The endpoint path matches the `productCompositionEndpoint` field returned on a Product.
|
|
797
|
+
* e.g. GET v6/product-composition/{productId}
|
|
798
|
+
*/
|
|
799
|
+
get(productId) {
|
|
800
|
+
return this.client.request(
|
|
801
|
+
`v6/product-composition/${productId}`,
|
|
802
|
+
"GET"
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// src/http/pagination.ts
|
|
808
|
+
async function* paginate(fetchFn, options = {}) {
|
|
809
|
+
const limit = options.limit ?? 100;
|
|
810
|
+
let offset = 0;
|
|
811
|
+
let hasMore = true;
|
|
812
|
+
while (hasMore) {
|
|
813
|
+
const [response, error] = await fetchFn(offset, limit);
|
|
814
|
+
if (error) {
|
|
815
|
+
throw error;
|
|
816
|
+
}
|
|
817
|
+
if (response === null) {
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
for (const item of response.results) {
|
|
821
|
+
yield item;
|
|
822
|
+
}
|
|
823
|
+
offset += limit;
|
|
824
|
+
hasMore = response.next !== null;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
async function batchGet(ids, fetchFn, options = {}) {
|
|
828
|
+
const concurrency = options.concurrency ?? 5;
|
|
829
|
+
const errors = [];
|
|
830
|
+
const results = [];
|
|
831
|
+
for (let i = 0; i < ids.length; i += concurrency) {
|
|
832
|
+
const batch = ids.slice(i, i + concurrency);
|
|
833
|
+
const batchResults = await Promise.allSettled(batch.map((id) => fetchFn(id)));
|
|
834
|
+
for (const result of batchResults) {
|
|
835
|
+
if (result.status === "fulfilled") {
|
|
836
|
+
const [data, error] = result.value;
|
|
837
|
+
if (error) {
|
|
838
|
+
errors.push(error);
|
|
839
|
+
} else if (data !== null) {
|
|
840
|
+
results.push(data);
|
|
841
|
+
}
|
|
842
|
+
} else {
|
|
843
|
+
errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (errors.length > 0) {
|
|
848
|
+
return [null, new VintraceAggregateError(errors)];
|
|
849
|
+
}
|
|
850
|
+
return [results, null];
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
|
854
|
+
exports.VintraceAggregateError = VintraceAggregateError;
|
|
855
|
+
exports.VintraceAuthenticationError = VintraceAuthenticationError;
|
|
856
|
+
exports.VintraceClient = VintraceClient;
|
|
857
|
+
exports.VintraceError = VintraceError;
|
|
858
|
+
exports.VintraceFetchError = VintraceFetchError;
|
|
859
|
+
exports.VintraceNotFoundError = VintraceNotFoundError;
|
|
860
|
+
exports.VintraceRateLimitError = VintraceRateLimitError;
|
|
861
|
+
exports.VintraceServerError = VintraceServerError;
|
|
862
|
+
exports.VintraceValidationError = VintraceValidationError;
|
|
863
|
+
exports.VintraceValidationSchemaError = VintraceValidationSchemaError;
|
|
864
|
+
exports.batchGet = batchGet;
|
|
865
|
+
exports.paginate = paginate;
|
|
866
|
+
exports.validateRequest = validateRequest;
|
|
867
|
+
exports.validateResponse = validateResponse;
|
|
868
|
+
exports.vintraceFetch = vintraceFetch;
|
|
869
|
+
//# sourceMappingURL=index.cjs.map
|
|
870
|
+
//# sourceMappingURL=index.cjs.map
|