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