vintrace-sdk 0.1.4 → 0.2.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 +6 -1
- package/dist/index.cjs +166 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +247 -8
- package/dist/index.d.ts +247 -8
- package/dist/index.js +166 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -357,10 +357,12 @@ async function batchFetch(ids, fetchFn) {
|
|
|
357
357
|
}
|
|
358
358
|
var ExtIdentifiableEntitySchema = z.object({
|
|
359
359
|
id: z.number().optional(),
|
|
360
|
-
extId: z.string().optional()
|
|
360
|
+
extId: z.string().optional(),
|
|
361
|
+
name: z.string().optional()
|
|
361
362
|
});
|
|
362
363
|
var IdentifiableEntitySchema = z.object({
|
|
363
|
-
id: z.number().optional()
|
|
364
|
+
id: z.number().optional(),
|
|
365
|
+
name: z.string().optional()
|
|
364
366
|
});
|
|
365
367
|
var CodedIdentifiableEntitySchema = z.object({
|
|
366
368
|
id: z.number().optional(),
|
|
@@ -878,15 +880,94 @@ var PaginatedResponseSchema = (itemSchema) => z.object({
|
|
|
878
880
|
last: z.string().nullable().optional(),
|
|
879
881
|
results: z.array(itemSchema).optional()
|
|
880
882
|
});
|
|
883
|
+
var VineyardIdentifiableEntitySchema = IdentifiableEntitySchema.extend({
|
|
884
|
+
name: z.string(),
|
|
885
|
+
grower: ExtIdentifiableEntitySchema
|
|
886
|
+
});
|
|
887
|
+
var GradingSchema = z.object({
|
|
888
|
+
id: z.number().optional(),
|
|
889
|
+
value: z.string().optional(),
|
|
890
|
+
scaleName: z.string().optional(),
|
|
891
|
+
scaleId: z.number().optional()
|
|
892
|
+
});
|
|
893
|
+
var BulkStockSchema = z.object({
|
|
894
|
+
totalVolume: VolumeSchema.optional(),
|
|
895
|
+
equivalentVolume: VolumeSchema.optional(),
|
|
896
|
+
equivalentWeight: VolumeSchema.optional(),
|
|
897
|
+
compWeighting: z.number().optional(),
|
|
898
|
+
percentageOfFruit: z.number().optional(),
|
|
899
|
+
batchId: z.number().optional(),
|
|
900
|
+
batchName: z.string().optional(),
|
|
901
|
+
grading: GradingSchema.nullable().optional()
|
|
902
|
+
});
|
|
903
|
+
var FruitPlacementSchema = z.object({
|
|
904
|
+
vintage: z.string().optional(),
|
|
905
|
+
bulkStocks: z.array(BulkStockSchema).optional()
|
|
906
|
+
});
|
|
881
907
|
var BlockDataSchema = z.object({
|
|
882
908
|
id: z.number(),
|
|
883
909
|
code: z.string().optional(),
|
|
884
|
-
name: z.string()
|
|
885
|
-
description: z.string().optional(),
|
|
910
|
+
name: z.string(),
|
|
886
911
|
extId: z.string().optional(),
|
|
887
|
-
inactive: z.boolean().optional()
|
|
912
|
+
inactive: z.boolean().optional(),
|
|
913
|
+
description: z.string().optional(),
|
|
914
|
+
rowNumbers: z.string().optional(),
|
|
915
|
+
estate: z.boolean().optional(),
|
|
916
|
+
grower: ExtIdentifiableEntitySchema.optional(),
|
|
917
|
+
vineyard: VineyardIdentifiableEntitySchema.optional(),
|
|
918
|
+
region: IdentifiableEntitySchema.optional(),
|
|
919
|
+
subRegion: IdentifiableEntitySchema.optional(),
|
|
920
|
+
variety: IdentifiableEntitySchema.optional(),
|
|
921
|
+
intendedUse: IdentifiableEntitySchema.optional(),
|
|
922
|
+
grading: GradingSchema.nullable().optional(),
|
|
923
|
+
fruitPlacement: FruitPlacementSchema.optional()
|
|
888
924
|
});
|
|
889
925
|
var GetBlocksSuccessResponseSchema = PaginatedResponseSchema(BlockDataSchema);
|
|
926
|
+
var BlockSchema = ExtIdentifiableEntitySchema.extend({
|
|
927
|
+
extId: z.string(),
|
|
928
|
+
name: z.string(),
|
|
929
|
+
estate: z.boolean().optional(),
|
|
930
|
+
vineyard: VineyardIdentifiableEntitySchema,
|
|
931
|
+
variety: IdentifiableEntitySchema,
|
|
932
|
+
countyCode: z.string().optional(),
|
|
933
|
+
inactive: z.boolean().optional(),
|
|
934
|
+
noOfVines: z.number().optional(),
|
|
935
|
+
area: z.number().optional(),
|
|
936
|
+
rootStock: IdentifiableEntitySchema.optional(),
|
|
937
|
+
clone: IdentifiableEntitySchema.optional(),
|
|
938
|
+
vineSpacing: z.string().optional(),
|
|
939
|
+
rowSpacing: z.string().optional(),
|
|
940
|
+
soilProfile: z.string().optional(),
|
|
941
|
+
trellis: IdentifiableEntitySchema.optional(),
|
|
942
|
+
aspect: z.string().optional(),
|
|
943
|
+
plantedTime: z.number().optional(),
|
|
944
|
+
pruningType: z.string().optional(),
|
|
945
|
+
averageGradient: z.number().optional(),
|
|
946
|
+
irrigationType: z.string().optional(),
|
|
947
|
+
frostProtection: z.string().optional(),
|
|
948
|
+
organic: z.boolean().optional(),
|
|
949
|
+
organicCertifiedTime: z.number().optional(),
|
|
950
|
+
township: z.string().optional(),
|
|
951
|
+
range: z.string().optional(),
|
|
952
|
+
section: z.string().optional(),
|
|
953
|
+
emitterRate: z.number().optional(),
|
|
954
|
+
emitterSize: z.string().optional(),
|
|
955
|
+
siteId: z.string().optional(),
|
|
956
|
+
noOfRows: z.number().optional(),
|
|
957
|
+
districtCode: z.string().optional(),
|
|
958
|
+
regionalAdminCode: z.string().optional(),
|
|
959
|
+
comments: z.string().optional(),
|
|
960
|
+
code: z.string().optional(),
|
|
961
|
+
defaultHarvestMethod: z.string().optional(),
|
|
962
|
+
description: z.string().optional(),
|
|
963
|
+
graftedDate: z.number().optional(),
|
|
964
|
+
intendedUse: IdentifiableEntitySchema.optional(),
|
|
965
|
+
rowNumbers: z.string().optional(),
|
|
966
|
+
vineStructure: IdentifiableEntitySchema.optional()
|
|
967
|
+
});
|
|
968
|
+
var BlockResponseSchema = z.object({
|
|
969
|
+
data: BlockSchema
|
|
970
|
+
});
|
|
890
971
|
var V6PaginatedResponseSchema = z.object({
|
|
891
972
|
totalResultCount: z.number().optional(),
|
|
892
973
|
firstResult: z.number().optional(),
|
|
@@ -916,7 +997,7 @@ var WinerySchema = z.object({
|
|
|
916
997
|
name: z.string().optional(),
|
|
917
998
|
businessUnit: z.string().optional()
|
|
918
999
|
});
|
|
919
|
-
var
|
|
1000
|
+
var VesselGradingSchema = z.object({
|
|
920
1001
|
scaleId: z.number().optional(),
|
|
921
1002
|
scaleName: z.string().optional(),
|
|
922
1003
|
valueId: z.number().optional(),
|
|
@@ -933,7 +1014,7 @@ var WineBatchDetailsSchema = z.object({
|
|
|
933
1014
|
program: z.string().optional(),
|
|
934
1015
|
productCategory: CodedIdentifiableEntitySchema.optional(),
|
|
935
1016
|
designatedProduct: CodedIdentifiableEntitySchema.optional(),
|
|
936
|
-
grading:
|
|
1017
|
+
grading: VesselGradingSchema.optional()
|
|
937
1018
|
});
|
|
938
1019
|
var ProductStateSchema = z.object({
|
|
939
1020
|
id: z.number().optional(),
|
|
@@ -1335,6 +1416,46 @@ z.object({
|
|
|
1335
1416
|
status: z.string().optional(),
|
|
1336
1417
|
message: z.string().optional()
|
|
1337
1418
|
});
|
|
1419
|
+
var PurchaseOrderStateEnum = z.enum(["NEW", "APPROVED"]);
|
|
1420
|
+
var FulfillmentEnum = z.enum(["NOT_FULFILLED", "PART_FULFILLED", "FULFILLED", "OVER_FULFILLED"]);
|
|
1421
|
+
var TaxPolicyEnum = z.enum(["TAX_INCLUSIVE", "TAX_EXCLUSIVE", "NO_TAX"]);
|
|
1422
|
+
var PurchaseOrderLineTypeEnum = z.enum(["GENERAL", "ADHOC", "WINE_BATCH", "STOCK"]);
|
|
1423
|
+
var PurchaseOrderLineSchema = z.object({
|
|
1424
|
+
id: z.number(),
|
|
1425
|
+
type: PurchaseOrderLineTypeEnum,
|
|
1426
|
+
lineNumber: z.string().nullable().optional(),
|
|
1427
|
+
itemCode: z.string().nullable().optional(),
|
|
1428
|
+
vendorCode: z.string().nullable().optional(),
|
|
1429
|
+
description: z.string().nullable().optional(),
|
|
1430
|
+
itemName: z.string().optional(),
|
|
1431
|
+
unitPrice: z.number().optional(),
|
|
1432
|
+
totalPrice: z.number().optional(),
|
|
1433
|
+
taxable: z.boolean().optional(),
|
|
1434
|
+
quantityOrdered: MeasurementSchema.optional(),
|
|
1435
|
+
quantityFulfilled: MeasurementSchema.optional()
|
|
1436
|
+
});
|
|
1437
|
+
var PurchaseOrderSchema = z.object({
|
|
1438
|
+
id: z.number(),
|
|
1439
|
+
name: z.string(),
|
|
1440
|
+
state: PurchaseOrderStateEnum.optional(),
|
|
1441
|
+
fulfillment: FulfillmentEnum.optional(),
|
|
1442
|
+
taxPolicy: TaxPolicyEnum.optional(),
|
|
1443
|
+
freightCost: z.number().nullable().optional(),
|
|
1444
|
+
inactive: z.boolean().optional(),
|
|
1445
|
+
vendor: ExtIdentifiableEntitySchema.optional(),
|
|
1446
|
+
vendorReference: z.string().nullable().optional(),
|
|
1447
|
+
deliverBy: z.number().nullable().optional(),
|
|
1448
|
+
notes: z.string().nullable().optional(),
|
|
1449
|
+
winery: z.object({
|
|
1450
|
+
id: z.number().optional(),
|
|
1451
|
+
name: z.string().optional(),
|
|
1452
|
+
businessUnit: z.string().nullable().optional()
|
|
1453
|
+
}).optional(),
|
|
1454
|
+
lines: PurchaseOrderLineSchema.array().optional()
|
|
1455
|
+
});
|
|
1456
|
+
var PurchaseOrderResponseSchema = z.object({
|
|
1457
|
+
data: PurchaseOrderSchema
|
|
1458
|
+
});
|
|
1338
1459
|
|
|
1339
1460
|
// src/client/VintraceClient.ts
|
|
1340
1461
|
var VintraceClient = class {
|
|
@@ -1371,7 +1492,9 @@ var VintraceClient = class {
|
|
|
1371
1492
|
timeout: options?.timeout ?? this.options.timeout,
|
|
1372
1493
|
maxRetries: options?.maxRetries ?? this.options.maxRetries,
|
|
1373
1494
|
validateRequest: options?.validateRequest ?? this.options.validateRequests,
|
|
1374
|
-
validateResponse: options?.validateResponse ?? this.options.validateResponses
|
|
1495
|
+
validateResponse: options?.validateResponse ?? this.options.validateResponses,
|
|
1496
|
+
responseSchema: options?.responseSchema,
|
|
1497
|
+
requestSchema: options?.requestSchema
|
|
1375
1498
|
},
|
|
1376
1499
|
body
|
|
1377
1500
|
);
|
|
@@ -1939,12 +2062,17 @@ var BlocksClient = class {
|
|
|
1939
2062
|
* API consumer can use the include and vintage query params to request including more information in the response.
|
|
1940
2063
|
*/
|
|
1941
2064
|
async getAll(params) {
|
|
1942
|
-
const limit = params?.limit
|
|
2065
|
+
const limit = params?.limit ?? 100;
|
|
2066
|
+
const queryParams = { limit: String(limit), offset: "0" };
|
|
2067
|
+
if (params?.include) queryParams.include = params.include;
|
|
2068
|
+
if (params?.vintage) queryParams.vintage = params.vintage;
|
|
2069
|
+
if (params?.VintraceEntityIds) queryParams.VintraceEntityIds = params.VintraceEntityIds;
|
|
2070
|
+
if (params?.offset) queryParams.offset = String(params.offset);
|
|
1943
2071
|
const firstResponse = await this.client.request(
|
|
1944
2072
|
"v7/harvest/blocks",
|
|
1945
2073
|
"GET",
|
|
1946
2074
|
{ responseSchema: GetBlocksSuccessResponseSchema },
|
|
1947
|
-
|
|
2075
|
+
queryParams
|
|
1948
2076
|
);
|
|
1949
2077
|
if (firstResponse[1]) {
|
|
1950
2078
|
return [null, firstResponse[1]];
|
|
@@ -1964,13 +2092,14 @@ var BlocksClient = class {
|
|
|
1964
2092
|
const batchSize = Math.min(parallelLimit, pagesNeeded - i);
|
|
1965
2093
|
const batchPromises = [];
|
|
1966
2094
|
for (let j = 0; j < batchSize; j++) {
|
|
1967
|
-
const
|
|
2095
|
+
const pageOffset = (i + j) * limit;
|
|
2096
|
+
const pageParams = { ...queryParams, offset: String(pageOffset) };
|
|
1968
2097
|
batchPromises.push(
|
|
1969
2098
|
this.client.request(
|
|
1970
2099
|
"v7/harvest/blocks",
|
|
1971
2100
|
"GET",
|
|
1972
2101
|
{ responseSchema: GetBlocksSuccessResponseSchema },
|
|
1973
|
-
|
|
2102
|
+
pageParams
|
|
1974
2103
|
)
|
|
1975
2104
|
);
|
|
1976
2105
|
}
|
|
@@ -1986,14 +2115,22 @@ var BlocksClient = class {
|
|
|
1986
2115
|
}
|
|
1987
2116
|
return [allResults, null];
|
|
1988
2117
|
}
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
post(data) {
|
|
1996
|
-
|
|
2118
|
+
/**
|
|
2119
|
+
* Upsert block data into system.
|
|
2120
|
+
*
|
|
2121
|
+
* Create or update block data in the system. Provide a Block object in `data`.
|
|
2122
|
+
* Example fields: `extId`, `name`, `estate`, `vineyard`, `variety`, `area`.
|
|
2123
|
+
*/
|
|
2124
|
+
async post(data) {
|
|
2125
|
+
const [response, error] = await this.client.request(
|
|
2126
|
+
"v7/harvest/blocks",
|
|
2127
|
+
"POST",
|
|
2128
|
+
{ responseSchema: BlockResponseSchema },
|
|
2129
|
+
data
|
|
2130
|
+
);
|
|
2131
|
+
if (error) return [null, error];
|
|
2132
|
+
if (!response?.data) return [null, null];
|
|
2133
|
+
return [response.data, null];
|
|
1997
2134
|
}
|
|
1998
2135
|
patch(id, data) {
|
|
1999
2136
|
return this.client.request(`v7/harvest/blocks/${id}`, "PATCH", {}, data);
|
|
@@ -2438,8 +2575,15 @@ var PurchaseOrdersClient = class {
|
|
|
2438
2575
|
/**
|
|
2439
2576
|
* Get purchase order details by id.
|
|
2440
2577
|
*/
|
|
2441
|
-
get(id) {
|
|
2442
|
-
|
|
2578
|
+
async get(id) {
|
|
2579
|
+
const [response, error] = await this.client.request(
|
|
2580
|
+
`v7/account/purchase-orders/${id}`,
|
|
2581
|
+
"GET",
|
|
2582
|
+
{ responseSchema: PurchaseOrderResponseSchema }
|
|
2583
|
+
);
|
|
2584
|
+
if (error) return [null, error];
|
|
2585
|
+
if (!response?.data) return [null, null];
|
|
2586
|
+
return [response.data, null];
|
|
2443
2587
|
}
|
|
2444
2588
|
};
|
|
2445
2589
|
var TransactionsClient = class {
|