vintrace-sdk 0.0.7 → 0.0.9

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/dist/index.cjs CHANGED
@@ -146,7 +146,11 @@ async function vintraceFetch(baseUrl, organization, token, endpoint, method, opt
146
146
  Accept: "application/json"
147
147
  };
148
148
  if (options.validateRequest && options.requestSchema && body) {
149
- const [validatedBody, requestError] = validateRequest(options.requestSchema, body, correlationId);
149
+ const [validatedBody, requestError] = validateRequest(
150
+ options.requestSchema,
151
+ body,
152
+ correlationId
153
+ );
150
154
  if (requestError) {
151
155
  return [null, requestError];
152
156
  }
@@ -285,8 +289,723 @@ async function vintraceFetch(baseUrl, organization, token, endpoint, method, opt
285
289
  }
286
290
  }
287
291
 
292
+ // src/client/utils.ts
293
+ async function batchFetch(ids, fetchFn) {
294
+ const results = await Promise.allSettled(ids.map((id) => fetchFn(id)));
295
+ const errors = [];
296
+ const data = [];
297
+ for (const result of results) {
298
+ if (result.status === "fulfilled") {
299
+ const [item, error] = result.value;
300
+ if (error) {
301
+ errors.push(error);
302
+ } else if (item !== null) {
303
+ data.push(item);
304
+ }
305
+ } else {
306
+ errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
307
+ }
308
+ }
309
+ if (errors.length > 0) {
310
+ return [null, new VintraceAggregateError(errors)];
311
+ }
312
+ return [data, null];
313
+ }
314
+ var ExtIdentifiableEntitySchema = zod.z.object({
315
+ id: zod.z.number().optional(),
316
+ extId: zod.z.string().optional()
317
+ });
318
+ var IdentifiableEntitySchema = zod.z.object({
319
+ id: zod.z.number().optional()
320
+ });
321
+ var CodedIdentifiableEntitySchema = zod.z.object({
322
+ id: zod.z.number().optional(),
323
+ code: zod.z.string().optional()
324
+ });
325
+ var ResourceLinkSchema = zod.z.object({
326
+ rel: zod.z.string().optional(),
327
+ href: zod.z.string().optional()
328
+ });
329
+ var FieldValuePairSchema = zod.z.object({
330
+ fieldName: zod.z.string().optional(),
331
+ value: zod.z.unknown().optional()
332
+ });
333
+ var WorkOrderJobSchema = zod.z.object({
334
+ id: zod.z.number().optional(),
335
+ type: zod.z.enum(["WINERY", "MRP"]).optional(),
336
+ jobNumber: zod.z.number().optional(),
337
+ status: zod.z.enum([
338
+ "INCOMPLETE",
339
+ "ASSIGNED",
340
+ "COMPLETED",
341
+ "ROLLBACK_REPLAY",
342
+ "IN_PROGRESS",
343
+ "PENDING_APPROVAL"
344
+ ]).optional(),
345
+ scheduledTime: zod.z.number().optional(),
346
+ finishedTime: zod.z.number().optional(),
347
+ link: ResourceLinkSchema.optional()
348
+ });
349
+ var WineryWorkOrderJobSchema = WorkOrderJobSchema.extend({
350
+ operationType: zod.z.string().optional()
351
+ });
352
+ var WorkOrderSchema = zod.z.object({
353
+ id: zod.z.number().optional(),
354
+ name: zod.z.string().optional(),
355
+ assignedTo: ExtIdentifiableEntitySchema.optional(),
356
+ issuedBy: ExtIdentifiableEntitySchema.optional(),
357
+ status: zod.z.enum(["DRAFT", "READY", "IN_PROGRESS", "SUBMITTED", "COMPLETED", "CANCELLED", "REPLAY"]).optional(),
358
+ scheduledTime: zod.z.number().optional(),
359
+ summary: zod.z.string().optional(),
360
+ jobs: WineryWorkOrderJobSchema.array().optional()
361
+ });
362
+ zod.z.object({
363
+ totalResults: zod.z.number().optional(),
364
+ offset: zod.z.number().optional(),
365
+ limit: zod.z.number().optional(),
366
+ first: zod.z.string().optional(),
367
+ previous: zod.z.string().optional(),
368
+ next: zod.z.string().optional(),
369
+ last: zod.z.string().optional(),
370
+ results: WorkOrderSchema.array().optional()
371
+ });
372
+ var ProductLiveMetricMeasurementSchema = zod.z.object({
373
+ name: zod.z.string().optional(),
374
+ value: zod.z.number().optional(),
375
+ unit: zod.z.string().optional(),
376
+ maxVal: zod.z.number().optional()
377
+ });
378
+ var ProductLiveMetricSchema = zod.z.object({
379
+ name: zod.z.string().optional(),
380
+ description: zod.z.string().optional(),
381
+ measurements: ProductLiveMetricMeasurementSchema.array().optional()
382
+ });
383
+ var VolumeSchema = zod.z.object({
384
+ value: zod.z.number().optional(),
385
+ unit: zod.z.string().optional()
386
+ });
387
+ var BeverageTypePropertiesSchema = zod.z.record(zod.z.string(), zod.z.unknown());
388
+ var ProductSchema = zod.z.object({
389
+ id: zod.z.number().optional(),
390
+ batchCode: zod.z.string().optional(),
391
+ vesselId: zod.z.number().optional(),
392
+ description: zod.z.string().optional(),
393
+ descriptionCanEdit: zod.z.boolean().optional(),
394
+ volume: VolumeSchema.optional(),
395
+ vesselCode: zod.z.string().optional(),
396
+ hasDipTable: zod.z.boolean().optional(),
397
+ dipTableEndpoint: zod.z.string().optional(),
398
+ colour: zod.z.string().optional(),
399
+ physicalProductState: zod.z.string().optional(),
400
+ vesselType: zod.z.string().optional(),
401
+ productStatus: zod.z.string().optional(),
402
+ productAnalysisEndpoint: zod.z.string().optional(),
403
+ productCompositionEndpoint: zod.z.string().optional(),
404
+ productEndpoint: zod.z.string().optional(),
405
+ liveMetrics: ProductLiveMetricSchema.array().optional(),
406
+ fieldValuePairs: FieldValuePairSchema.array().optional(),
407
+ canAccessNotes: zod.z.boolean().optional(),
408
+ notesCount: zod.z.number().optional(),
409
+ notesEndpoint: zod.z.string().optional(),
410
+ beverageTypeProperties: BeverageTypePropertiesSchema.optional()
411
+ });
412
+ var ProductVesselDetailsSchema = zod.z.object({
413
+ vesselId: zod.z.number().optional(),
414
+ containerType: zod.z.enum(["Tank", "Barrel", "Barrel group", "Bin group", "Press", "Bin", "Tanker"]).optional()
415
+ });
416
+ var ProductResponseSchema = zod.z.object({
417
+ status: zod.z.string().optional(),
418
+ product: ProductSchema.optional(),
419
+ vessel: ProductVesselDetailsSchema.optional()
420
+ });
421
+ var ProductListResponseSchema = zod.z.object({
422
+ status: zod.z.string().optional(),
423
+ products: ProductSchema.array().optional(),
424
+ totalResultCount: zod.z.number().optional(),
425
+ firstResult: zod.z.number().optional(),
426
+ maxResult: zod.z.number().optional(),
427
+ nextURLPath: zod.z.string().nullable().optional(),
428
+ prevURLPath: zod.z.string().nullable().optional()
429
+ });
430
+ var ProductUpdateFieldSchema = zod.z.object({
431
+ propertyType: zod.z.string().optional(),
432
+ propertyValue: zod.z.string().optional(),
433
+ propertyId: zod.z.number().optional()
434
+ });
435
+ var ProductUpdateDataSchema = zod.z.object({
436
+ productId: zod.z.number().optional(),
437
+ updateFields: ProductUpdateFieldSchema.array().optional()
438
+ });
439
+ var ProductUpdateResponseSchema = zod.z.object({
440
+ status: zod.z.string().optional(),
441
+ product: ProductSchema.optional()
442
+ });
443
+ var AddressSchema = zod.z.object({
444
+ street1: zod.z.string().nullable(),
445
+ street2: zod.z.string().nullable(),
446
+ city: zod.z.string().nullable(),
447
+ state: zod.z.string().nullable(),
448
+ postalCode: zod.z.string().nullable(),
449
+ country: zod.z.string().nullable()
450
+ });
451
+ var SendToAddressSchema = zod.z.object({
452
+ name: zod.z.string().nullable(),
453
+ phone: zod.z.string().nullable(),
454
+ address: AddressSchema.nullable()
455
+ });
456
+ var TaxBreakdownSchema = zod.z.object({
457
+ name: zod.z.string(),
458
+ amount: zod.z.number(),
459
+ ratePct: zod.z.number(),
460
+ inclusive: zod.z.boolean()
461
+ });
462
+ var SalesOrderItemSchema = zod.z.object({
463
+ id: zod.z.number().optional(),
464
+ itemId: zod.z.number().optional(),
465
+ itemName: zod.z.string().optional(),
466
+ unitPrice: zod.z.number().optional(),
467
+ quantity: zod.z.number().optional(),
468
+ unitOfMeasure: zod.z.string().nullable(),
469
+ discountPct: zod.z.number().nullable(),
470
+ adjustment: zod.z.number().nullable(),
471
+ taxAmount: zod.z.number().optional(),
472
+ lineTotal: zod.z.number().optional(),
473
+ accountId: zod.z.number().optional(),
474
+ accountCode: zod.z.string().optional(),
475
+ taxRateId: zod.z.number().optional(),
476
+ taxRateName: zod.z.string().nullable()
477
+ });
478
+ var PriceDetailsSchema = zod.z.object({
479
+ countryCurrencyCode: zod.z.string().optional(),
480
+ taxPolicy: zod.z.string().optional()
481
+ });
482
+ var SalesOrderSchema = zod.z.object({
483
+ id: zod.z.number().optional(),
484
+ invoiceDate: zod.z.number().nullable(),
485
+ invoiceDateAsText: zod.z.string(),
486
+ customerId: zod.z.number().optional(),
487
+ customerName: zod.z.string().optional(),
488
+ sendTo: SendToAddressSchema.optional(),
489
+ salesType: zod.z.string().optional(),
490
+ salesPriceListId: zod.z.number().nullable(),
491
+ salesPriceListName: zod.z.string().nullable(),
492
+ priceDetails: PriceDetailsSchema.optional(),
493
+ salesOrderStatus: zod.z.string().optional(),
494
+ salesOrderItems: SalesOrderItemSchema.array().optional(),
495
+ code: zod.z.string().optional(),
496
+ description: zod.z.string().nullable(),
497
+ reference: zod.z.string().nullable(),
498
+ orderDate: zod.z.number().optional(),
499
+ orderDateAsText: zod.z.string(),
500
+ wineryId: zod.z.number().nullable(),
501
+ wineryName: zod.z.string().nullable(),
502
+ fulfillment: zod.z.string().optional(),
503
+ fulfillmentDate: zod.z.number().nullable(),
504
+ fulfillmentDateAsText: zod.z.string(),
505
+ salesRegionId: zod.z.number().nullable(),
506
+ salesRegionCode: zod.z.string().nullable(),
507
+ notes: zod.z.string().nullable(),
508
+ customerPickup: zod.z.boolean().optional(),
509
+ disableAccountsSync: zod.z.boolean().optional(),
510
+ subTotal: zod.z.number().optional(),
511
+ taxBreakdown: TaxBreakdownSchema.array().optional(),
512
+ total: zod.z.number().optional(),
513
+ acctReference: zod.z.string().nullable(),
514
+ posSaleReference: zod.z.string().nullable(),
515
+ ignoreStockError: zod.z.boolean().optional()
516
+ });
517
+ var SalesOrderResponseSchema = zod.z.object({
518
+ status: zod.z.string(),
519
+ message: zod.z.string().nullable(),
520
+ salesOrders: SalesOrderSchema.array(),
521
+ totalResultCount: zod.z.number().optional(),
522
+ firstResult: zod.z.number().optional(),
523
+ maxResult: zod.z.number().optional(),
524
+ nextURLPath: zod.z.string().nullable().optional(),
525
+ prevURLPath: zod.z.string().nullable().optional()
526
+ });
527
+ var SalesOrderUpdateResponseSchema = zod.z.object({
528
+ status: zod.z.string(),
529
+ message: zod.z.string().nullable(),
530
+ salesOrder: SalesOrderSchema.optional()
531
+ });
532
+ var RefundLineItemSchema = zod.z.object({
533
+ id: zod.z.number().optional(),
534
+ itemId: zod.z.number().optional(),
535
+ itemName: zod.z.string().optional(),
536
+ unitPrice: zod.z.number().optional(),
537
+ returnQuantity: zod.z.number().optional(),
538
+ returnTotal: zod.z.number().optional(),
539
+ taxAmount: zod.z.number().optional()
540
+ });
541
+ var RefundSchema = zod.z.object({
542
+ id: zod.z.number().optional(),
543
+ name: zod.z.string().optional(),
544
+ refundDate: zod.z.number().optional(),
545
+ refundDateAsText: zod.z.string(),
546
+ reference: zod.z.string().nullable(),
547
+ stockReturned: zod.z.boolean().optional(),
548
+ storageAreaId: zod.z.number().nullable(),
549
+ storageAreaName: zod.z.string().nullable(),
550
+ customerId: zod.z.number().optional(),
551
+ customerName: zod.z.string().optional(),
552
+ refundStatus: zod.z.string().optional(),
553
+ notes: zod.z.string().nullable(),
554
+ salesOrderId: zod.z.number().optional(),
555
+ salesOrderName: zod.z.string().optional(),
556
+ subTotal: zod.z.number().optional(),
557
+ total: zod.z.number().optional(),
558
+ taxBreakdown: TaxBreakdownSchema.array().optional(),
559
+ refundLineItems: RefundLineItemSchema.array().optional(),
560
+ posSaleReference: zod.z.string().nullable(),
561
+ disableAccountsSync: zod.z.boolean().optional(),
562
+ acctReference: zod.z.string().nullable()
563
+ });
564
+ var RefundResponseSchema = zod.z.object({
565
+ status: zod.z.string(),
566
+ message: zod.z.string().nullable(),
567
+ refunds: RefundSchema.array(),
568
+ totalResultCount: zod.z.number().optional(),
569
+ firstResult: zod.z.number().optional(),
570
+ maxResult: zod.z.number().optional(),
571
+ nextURLPath: zod.z.string().nullable().optional(),
572
+ prevURLPath: zod.z.string().nullable().optional()
573
+ });
574
+ var RefundUpdateResponseSchema = zod.z.object({
575
+ status: zod.z.string(),
576
+ message: zod.z.string().nullable(),
577
+ refund: RefundSchema.optional()
578
+ });
579
+ var PartySchema = zod.z.object({
580
+ id: zod.z.number().optional(),
581
+ primeName: zod.z.string().optional(),
582
+ givenName: zod.z.string().nullable(),
583
+ phone: zod.z.string().nullable(),
584
+ email: zod.z.string().nullable(),
585
+ address: AddressSchema.optional(),
586
+ isOrganization: zod.z.boolean().optional()
587
+ });
588
+ var PartyResponseSchema = zod.z.object({
589
+ status: zod.z.string(),
590
+ message: zod.z.string().nullable(),
591
+ parties: PartySchema.array(),
592
+ totalResultCount: zod.z.number().optional(),
593
+ firstResult: zod.z.number().optional(),
594
+ maxResult: zod.z.number().optional(),
595
+ nextURLPath: zod.z.string().nullable().optional(),
596
+ prevURLPath: zod.z.string().nullable().optional()
597
+ });
598
+ var WorkOrderJobDetailSchema = zod.z.object({
599
+ id: zod.z.number().optional(),
600
+ code: zod.z.string().optional(),
601
+ scheduledDate: zod.z.number().nullable(),
602
+ finishedDate: zod.z.number().nullable(),
603
+ scheduledDateAsText: zod.z.string(),
604
+ finishedDateAsText: zod.z.string(),
605
+ status: zod.z.string().optional(),
606
+ assignedBy: zod.z.string().optional(),
607
+ assignedTo: zod.z.string().optional(),
608
+ summaryText: zod.z.string().optional(),
609
+ miniSummaryText: zod.z.string().optional(),
610
+ jobColour: zod.z.string().optional(),
611
+ jobNumber: zod.z.number().optional(),
612
+ stepText: zod.z.string().nullable(),
613
+ steps: zod.z.array(zod.z.unknown()).optional(),
614
+ endpointURL: zod.z.string().optional(),
615
+ jobVersion: zod.z.number().optional(),
616
+ workOrderId: zod.z.number().optional()
617
+ });
618
+ var WorkOrderDetailSchema = zod.z.object({
619
+ id: zod.z.number().optional(),
620
+ code: zod.z.string().optional(),
621
+ jobCount: zod.z.number().optional(),
622
+ jobCountText: zod.z.string().optional(),
623
+ status: zod.z.string().optional(),
624
+ assignedTo: zod.z.string().optional(),
625
+ assignedBy: zod.z.string().optional(),
626
+ assignedDate: zod.z.number().optional(),
627
+ scheduledDate: zod.z.number().nullable(),
628
+ assignedDateAsText: zod.z.string(),
629
+ scheduledDateAsText: zod.z.string(),
630
+ canAssign: zod.z.boolean().optional(),
631
+ summary: zod.z.string().optional(),
632
+ indicators: zod.z.array(zod.z.string()).optional(),
633
+ bond: zod.z.string().nullable(),
634
+ winery: zod.z.string().nullable(),
635
+ jobs: WorkOrderJobDetailSchema.array().optional(),
636
+ colourCode: zod.z.string().optional(),
637
+ endpointURL: zod.z.string().optional()
638
+ });
639
+ var WorkOrderSearchResponseSchema = zod.z.object({
640
+ firstResult: zod.z.number().optional(),
641
+ maxResult: zod.z.number().optional(),
642
+ totalResultCount: zod.z.number().optional(),
643
+ nextURLPath: zod.z.string().nullable(),
644
+ prevURLPath: zod.z.string().nullable(),
645
+ listText: zod.z.string().optional(),
646
+ workOrders: WorkOrderDetailSchema.array().optional()
647
+ });
648
+ var AssignWorkDataSchema = zod.z.object({
649
+ workOrderId: zod.z.number().optional()
650
+ });
651
+ var AssignWorkResponseSchema = zod.z.object({
652
+ status: zod.z.string(),
653
+ message: zod.z.string().nullable(),
654
+ jobEndpointURL: zod.z.string().nullable(),
655
+ workOrderEndpointURL: zod.z.string().optional()
656
+ });
657
+ var SubmitJobFieldSchema = zod.z.object({
658
+ fieldId: zod.z.string(),
659
+ value: zod.z.string().optional()
660
+ });
661
+ var SubmitJobRequestSchema = zod.z.object({
662
+ jobId: zod.z.number().optional(),
663
+ submitType: zod.z.string().optional(),
664
+ fields: SubmitJobFieldSchema.array().optional()
665
+ });
666
+ var SubmitWorkOrderStepsResponseSchema = zod.z.object({
667
+ status: zod.z.string(),
668
+ message: zod.z.string().optional()
669
+ });
670
+ var PartyUpdateResponseSchema = zod.z.object({
671
+ status: zod.z.string(),
672
+ message: zod.z.string().nullable(),
673
+ party: PartySchema.optional()
674
+ });
675
+ var SalesOrderWriteSchema = SalesOrderSchema.partial();
676
+ var RefundWriteSchema = RefundSchema.partial();
677
+ var PartyWriteSchema = PartySchema.partial();
678
+ zod.z.object({
679
+ dateFrom: zod.z.string().optional(),
680
+ dateTo: zod.z.string().optional(),
681
+ ownerName: zod.z.string().optional(),
682
+ batchName: zod.z.string().optional(),
683
+ wineryName: zod.z.string().optional(),
684
+ maxResults: zod.z.number().optional(),
685
+ firstResult: zod.z.number().optional()
686
+ });
687
+ zod.z.object({
688
+ modifiedSince: zod.z.string().optional(),
689
+ operationId: zod.z.number().optional(),
690
+ processId: zod.z.number().optional(),
691
+ deliveryDocket: zod.z.string().optional(),
692
+ intakeDocket: zod.z.string().optional(),
693
+ externalWeighTag: zod.z.string().optional(),
694
+ externalSystemBlocksOnly: zod.z.boolean().optional(),
695
+ externalBlockId: zod.z.string().optional(),
696
+ blockId: zod.z.number().optional(),
697
+ blockName: zod.z.string().optional(),
698
+ vineyardId: zod.z.number().optional(),
699
+ vineyardName: zod.z.string().optional(),
700
+ wineryId: zod.z.number().optional(),
701
+ wineryName: zod.z.string().optional(),
702
+ growerType: zod.z.string().optional(),
703
+ growerId: zod.z.number().optional(),
704
+ growerName: zod.z.string().optional(),
705
+ ownerId: zod.z.number().optional(),
706
+ ownerName: zod.z.string().optional(),
707
+ vintage: zod.z.string().optional(),
708
+ recordedAfter: zod.z.string().optional(),
709
+ recordedBefore: zod.z.string().optional(),
710
+ customAdapter: zod.z.string().optional(),
711
+ maxResults: zod.z.number().optional(),
712
+ firstResult: zod.z.number().optional()
713
+ });
714
+ zod.z.object({
715
+ modifiedSince: zod.z.string().optional(),
716
+ operationId: zod.z.number().optional(),
717
+ processId: zod.z.number().optional(),
718
+ externalSystemBlocksOnly: zod.z.boolean().optional(),
719
+ externalBlockId: zod.z.string().optional(),
720
+ blockId: zod.z.number().optional(),
721
+ blockName: zod.z.string().optional(),
722
+ vineyardId: zod.z.number().optional(),
723
+ vineyardName: zod.z.string().optional(),
724
+ growerId: zod.z.number().optional(),
725
+ growerName: zod.z.string().optional(),
726
+ ownerId: zod.z.number().optional(),
727
+ ownerName: zod.z.string().optional(),
728
+ vintage: zod.z.string().optional(),
729
+ recordedAfter: zod.z.string().optional(),
730
+ recordedBefore: zod.z.string().optional(),
731
+ customAdapter: zod.z.string().optional(),
732
+ maxResults: zod.z.number().optional(),
733
+ firstResult: zod.z.number().optional()
734
+ });
735
+ zod.z.object({
736
+ max: zod.z.string().optional(),
737
+ first: zod.z.string().optional(),
738
+ date: zod.z.string().optional(),
739
+ stockType: zod.z.string().optional(),
740
+ ownerName: zod.z.string().optional(),
741
+ showEquivalentType: zod.z.string().optional(),
742
+ breakoutCosting: zod.z.boolean().optional(),
743
+ disableCommitHeaders: zod.z.boolean().optional()
744
+ });
745
+ zod.z.object({
746
+ type: zod.z.string(),
747
+ first: zod.z.string().optional(),
748
+ startsWith: zod.z.string().optional(),
749
+ exactMatch: zod.z.boolean().optional(),
750
+ max: zod.z.string().optional()
751
+ });
752
+ zod.z.object({
753
+ firstResult: zod.z.number(),
754
+ maxResult: zod.z.number()
755
+ });
756
+ zod.z.object({
757
+ firstResult: zod.z.number().optional(),
758
+ maxResult: zod.z.number().optional()
759
+ });
760
+ var RateOfChangeSchema = zod.z.object({
761
+ value: zod.z.number().nullable(),
762
+ sign: zod.z.string().nullable(),
763
+ absValue: zod.z.number().nullable(),
764
+ unit: zod.z.string().nullable(),
765
+ description: zod.z.string().nullable()
766
+ });
767
+ var AnalysisMeasurementSchema = zod.z.object({
768
+ value: zod.z.string(),
769
+ rateOfChange: RateOfChangeSchema.nullable(),
770
+ measurementDateText: zod.z.string(),
771
+ measurementDate: zod.z.number(),
772
+ resultId: zod.z.number(),
773
+ processId: zod.z.number(),
774
+ canDelete: zod.z.boolean(),
775
+ canEdit: zod.z.boolean(),
776
+ canReverse: zod.z.boolean(),
777
+ measurementValidity: zod.z.string()
778
+ });
779
+ var AnalysisMetricDataSchema = zod.z.object({
780
+ id: zod.z.number(),
781
+ name: zod.z.string(),
782
+ unit: zod.z.string(),
783
+ dataType: zod.z.string(),
784
+ dataTypeValues: zod.z.unknown().nullable(),
785
+ minVal: zod.z.number().nullable(),
786
+ maxVal: zod.z.number().nullable(),
787
+ grouping: zod.z.unknown().nullable(),
788
+ canAddValue: zod.z.boolean(),
789
+ measurements: AnalysisMeasurementSchema.array(),
790
+ result: zod.z.unknown().nullable()
791
+ });
792
+ var ProductMetricDataSchema = zod.z.object({
793
+ id: zod.z.number(),
794
+ name: zod.z.string(),
795
+ nextURL: zod.z.string().nullable(),
796
+ metricDataList: AnalysisMetricDataSchema.array()
797
+ });
798
+ var ProductAnalysisResponseSchema = zod.z.object({
799
+ productId: zod.z.number(),
800
+ batchCode: zod.z.string(),
801
+ description: zod.z.string(),
802
+ canAddResult: zod.z.boolean(),
803
+ productMetricDataList: ProductMetricDataSchema.array()
804
+ });
805
+ zod.z.object({
806
+ startDate: zod.z.string().optional(),
807
+ endDate: zod.z.string().optional(),
808
+ metricId: zod.z.number().optional(),
809
+ weighting: zod.z.number().optional()
810
+ });
811
+ var CompositionComponentSchema = zod.z.object({
812
+ productId: zod.z.number().optional(),
813
+ batchCode: zod.z.string().optional(),
814
+ description: zod.z.string().optional(),
815
+ vintage: zod.z.string().nullable().optional(),
816
+ variety: zod.z.string().nullable().optional(),
817
+ region: zod.z.string().nullable().optional(),
818
+ percentage: zod.z.number().optional(),
819
+ volume: VolumeSchema.optional()
820
+ });
821
+ var ProductCompositionResponseSchema = zod.z.object({
822
+ productId: zod.z.number().optional(),
823
+ batchCode: zod.z.string().optional(),
824
+ description: zod.z.string().optional(),
825
+ components: CompositionComponentSchema.array().optional()
826
+ });
827
+ var PaginatedResponseSchema = (itemSchema) => zod.z.object({
828
+ totalResults: zod.z.number().optional(),
829
+ offset: zod.z.number().optional(),
830
+ limit: zod.z.number().optional(),
831
+ first: zod.z.string().nullable().optional(),
832
+ previous: zod.z.string().nullable().optional(),
833
+ next: zod.z.string().nullable().optional(),
834
+ last: zod.z.string().nullable().optional(),
835
+ results: zod.z.array(itemSchema).optional()
836
+ });
837
+ var BlockDataSchema = zod.z.object({
838
+ id: zod.z.number(),
839
+ code: zod.z.string().optional(),
840
+ name: zod.z.string().optional(),
841
+ description: zod.z.string().optional(),
842
+ extId: zod.z.string().optional(),
843
+ inactive: zod.z.boolean().optional()
844
+ });
845
+ var GetBlocksSuccessResponseSchema = PaginatedResponseSchema(BlockDataSchema);
846
+ var V6PaginatedResponseSchema = zod.z.object({
847
+ totalResultCount: zod.z.number().optional(),
848
+ firstResult: zod.z.number().optional(),
849
+ maxResult: zod.z.number().optional(),
850
+ nextURLPath: zod.z.string().nullable().optional(),
851
+ prevURLPath: zod.z.string().nullable().optional(),
852
+ results: zod.z.array(zod.z.unknown()).optional()
853
+ });
854
+ var InventoryResponseSchema = V6PaginatedResponseSchema;
855
+ var TransactionSearchResponseSchema = V6PaginatedResponseSchema;
856
+ var IntakeOperationSearchResponseSchema = V6PaginatedResponseSchema;
857
+ var SampleOperationSearchResponseSchema = V6PaginatedResponseSchema;
858
+ var SearchListResponseSchema = V6PaginatedResponseSchema;
859
+ var MeasurementSchema = zod.z.object({
860
+ value: zod.z.number().optional(),
861
+ unit: zod.z.string().optional()
862
+ });
863
+ var WinerySchema = zod.z.object({
864
+ id: zod.z.number().optional(),
865
+ name: zod.z.string().optional(),
866
+ businessUnit: zod.z.string().optional()
867
+ });
868
+ var GradingSchema = zod.z.object({
869
+ scaleId: zod.z.number().optional(),
870
+ scaleName: zod.z.string().optional(),
871
+ valueId: zod.z.number().optional(),
872
+ valueName: zod.z.string().optional()
873
+ });
874
+ var WineBatchDetailsSchema = zod.z.object({
875
+ id: zod.z.number().optional(),
876
+ name: zod.z.string().optional(),
877
+ description: zod.z.string().optional(),
878
+ vintage: zod.z.string().optional(),
879
+ designatedRegion: CodedIdentifiableEntitySchema.optional(),
880
+ designatedSubRegion: CodedIdentifiableEntitySchema.optional(),
881
+ designatedVariety: CodedIdentifiableEntitySchema.optional(),
882
+ program: zod.z.string().optional(),
883
+ productCategory: CodedIdentifiableEntitySchema.optional(),
884
+ designatedProduct: CodedIdentifiableEntitySchema.optional(),
885
+ grading: GradingSchema.optional()
886
+ });
887
+ var ProductStateSchema = zod.z.object({
888
+ id: zod.z.number().optional(),
889
+ name: zod.z.string().optional(),
890
+ expectedLossesPercentage: zod.z.number().optional()
891
+ });
892
+ var TaxDetailsSchema = zod.z.object({
893
+ bond: IdentifiableEntitySchema.optional(),
894
+ name: zod.z.string().optional(),
895
+ taxState: zod.z.string().optional(),
896
+ taxClass: IdentifiableEntitySchema.optional(),
897
+ federalName: zod.z.string().optional(),
898
+ stateName: zod.z.string().optional()
899
+ });
900
+ var AllocationSliceSchema = zod.z.object({
901
+ product: CodedIdentifiableEntitySchema.optional(),
902
+ vintage: zod.z.string().optional(),
903
+ itemCode: zod.z.string().optional(),
904
+ allocationVolume: MeasurementSchema.optional(),
905
+ allocationPercentageOfVessel: zod.z.number().optional()
906
+ });
907
+ var CompositionSliceSchema = zod.z.object({
908
+ vintage: zod.z.string().optional(),
909
+ variety: CodedIdentifiableEntitySchema.optional(),
910
+ region: CodedIdentifiableEntitySchema.optional(),
911
+ subRegion: CodedIdentifiableEntitySchema.optional(),
912
+ weighting: zod.z.number().optional(),
913
+ percentage: zod.z.number().optional(),
914
+ componentVolume: MeasurementSchema.optional()
915
+ });
916
+ var CostBreakdownSchema = zod.z.object({
917
+ total: zod.z.number().optional(),
918
+ fruit: zod.z.number().optional(),
919
+ overhead: zod.z.number().optional(),
920
+ storage: zod.z.number().optional(),
921
+ additive: zod.z.number().optional(),
922
+ bulk: zod.z.number().optional(),
923
+ packaging: zod.z.number().optional(),
924
+ operation: zod.z.number().optional(),
925
+ freight: zod.z.number().optional(),
926
+ other: zod.z.number().optional()
927
+ });
928
+ var LiveMetricSchema = zod.z.object({
929
+ name: zod.z.string().optional(),
930
+ value: zod.z.number().optional(),
931
+ interfaceMappedName: zod.z.string().optional()
932
+ });
933
+ var SparklingInfoSchema = zod.z.object({
934
+ state: zod.z.string().optional()
935
+ });
936
+ var BulkWineDetailsSchema = zod.z.object({
937
+ id: zod.z.number().optional(),
938
+ productId: zod.z.number().optional(),
939
+ name: zod.z.string().optional(),
940
+ description: zod.z.string().optional(),
941
+ vesselType: zod.z.string().optional(),
942
+ detailsAsAt: zod.z.number().optional(),
943
+ sparklingInfo: SparklingInfoSchema.optional(),
944
+ beverageType: IdentifiableEntitySchema.optional(),
945
+ owner: ExtIdentifiableEntitySchema.optional(),
946
+ winery: WinerySchema.optional(),
947
+ wineBatch: WineBatchDetailsSchema.optional(),
948
+ productState: ProductStateSchema.optional(),
949
+ volume: MeasurementSchema.optional(),
950
+ capacity: MeasurementSchema.optional(),
951
+ ullage: MeasurementSchema.optional(),
952
+ ttbDetails: TaxDetailsSchema.optional(),
953
+ liveMetrics: zod.z.array(LiveMetricSchema).optional(),
954
+ cost: CostBreakdownSchema.optional(),
955
+ composition: zod.z.array(CompositionSliceSchema).optional(),
956
+ allocations: zod.z.array(AllocationSliceSchema).optional(),
957
+ unallocatedVolume: MeasurementSchema.optional(),
958
+ unallocatedPercentageOfVessel: zod.z.number().optional()
959
+ });
960
+ var GetBulkWineDetailsReportResponseSchema = zod.z.object({
961
+ totalResults: zod.z.number().optional(),
962
+ offset: zod.z.number().optional(),
963
+ limit: zod.z.number().optional(),
964
+ first: zod.z.string().nullable().optional(),
965
+ previous: zod.z.string().nullable().optional(),
966
+ next: zod.z.string().nullable().optional(),
967
+ last: zod.z.string().nullable().optional(),
968
+ results: zod.z.array(BulkWineDetailsSchema).optional()
969
+ });
970
+ var ProductJobAttachmentSchema = zod.z.object({
971
+ id: zod.z.number().optional(),
972
+ name: zod.z.string().optional(),
973
+ url: zod.z.string().optional()
974
+ });
975
+ var ProductJobSchema = zod.z.object({
976
+ operationId: zod.z.number(),
977
+ processId: zod.z.number(),
978
+ operatorName: zod.z.string().optional(),
979
+ completedDate: zod.z.number().optional(),
980
+ completedDateText: zod.z.string().optional(),
981
+ summary: zod.z.string().optional(),
982
+ operationName: zod.z.string().optional(),
983
+ workOrderNumber: zod.z.string().nullable().optional(),
984
+ reversible: zod.z.boolean().optional(),
985
+ attachments: ProductJobAttachmentSchema.array().optional()
986
+ });
987
+ var ProductJobDetailsSchema = zod.z.object({
988
+ productId: zod.z.number(),
989
+ batchId: zod.z.number().optional(),
990
+ vesselId: zod.z.number().optional(),
991
+ batchCode: zod.z.string().nullable().optional(),
992
+ vesselCode: zod.z.string().nullable().optional(),
993
+ canReverseJobs: zod.z.boolean().optional(),
994
+ jobs: ProductJobSchema.array().optional()
995
+ });
996
+ var ProductJobResponseSchema = zod.z.object({
997
+ status: zod.z.string(),
998
+ message: zod.z.string().nullable().optional(),
999
+ jobDetails: ProductJobDetailsSchema
1000
+ });
1001
+
288
1002
  // src/client/VintraceClient.ts
289
1003
  var VintraceClient = class {
1004
+ /**
1005
+ * Creates a new VintraceClient instance.
1006
+ *
1007
+ * @param config - The client configuration containing baseUrl, organization, and token.
1008
+ */
290
1009
  constructor(config) {
291
1010
  this.baseUrl = config.baseUrl;
292
1011
  this.organization = config.organization;
@@ -295,6 +1014,15 @@ var VintraceClient = class {
295
1014
  this.v6 = new VintraceV6Api(this);
296
1015
  this.v7 = new VintraceV7Api(this);
297
1016
  }
1017
+ /**
1018
+ * Makes a request to the Vintrace API.
1019
+ *
1020
+ * @param endpoint - The API endpoint path (e.g., 'v6/workorders/list')
1021
+ * @param method - The HTTP method (GET, POST, PUT, PATCH, DELETE)
1022
+ * @param options - Request options including timeout, maxRetries, and validation settings
1023
+ * @param body - Optional request body for POST, PUT, PATCH requests
1024
+ * @returns A promise that resolves to a VintraceResult tuple [data, error]
1025
+ */
298
1026
  request(endpoint, method, options, body) {
299
1027
  return vintraceFetch(
300
1028
  this.baseUrl,
@@ -317,46 +1045,49 @@ var VintraceV6Api = class {
317
1045
  this.client = client;
318
1046
  }
319
1047
  get workOrders() {
320
- return new WorkOrdersClient(this.client);
1048
+ return this._workOrders ?? (this._workOrders = new WorkOrdersClient(this.client));
321
1049
  }
322
1050
  get salesOrders() {
323
- return new SalesOrdersClient(this.client);
1051
+ return this._salesOrders ?? (this._salesOrders = new SalesOrdersClient(this.client));
324
1052
  }
325
1053
  get refunds() {
326
- return new RefundsClient(this.client);
1054
+ return this._refunds ?? (this._refunds = new RefundsClient(this.client));
327
1055
  }
328
1056
  get parties() {
329
- return new PartiesClient(this.client);
1057
+ return this._parties ?? (this._parties = new PartiesClient(this.client));
330
1058
  }
331
1059
  get products() {
332
- return new ProductsClient(this.client);
1060
+ return this._products ?? (this._products = new ProductsClient(this.client));
333
1061
  }
334
1062
  get transactions() {
335
- return new TransactionsClient(this.client);
1063
+ return this._transactions ?? (this._transactions = new TransactionsClient(this.client));
336
1064
  }
337
1065
  get intakeOperations() {
338
- return new IntakeOperationsClient(this.client);
1066
+ return this._intakeOperations ?? (this._intakeOperations = new IntakeOperationsClient(this.client));
339
1067
  }
340
1068
  get sampleOperations() {
341
- return new SampleOperationsClient(this.client);
1069
+ return this._sampleOperations ?? (this._sampleOperations = new SampleOperationsClient(this.client));
342
1070
  }
343
1071
  get blockAssessments() {
344
- return new BlockAssessmentsClient(this.client);
1072
+ return this._blockAssessments ?? (this._blockAssessments = new BlockAssessmentsClient(this.client));
345
1073
  }
346
1074
  get mrpStock() {
347
- return new MrpStockClient(this.client);
1075
+ return this._mrpStock ?? (this._mrpStock = new MrpStockClient(this.client));
348
1076
  }
349
1077
  get inventory() {
350
- return new InventoryClient(this.client);
1078
+ return this._inventory ?? (this._inventory = new InventoryClient(this.client));
351
1079
  }
352
1080
  get search() {
353
- return new SearchClient(this.client);
1081
+ return this._search ?? (this._search = new SearchClient(this.client));
354
1082
  }
355
1083
  get productAnalysis() {
356
- return new ProductAnalysisClient(this.client);
1084
+ return this._productAnalysis ?? (this._productAnalysis = new ProductAnalysisClient(this.client));
357
1085
  }
358
1086
  get productComposition() {
359
- return new ProductCompositionClient(this.client);
1087
+ return this._productComposition ?? (this._productComposition = new ProductCompositionClient(this.client));
1088
+ }
1089
+ get productJobs() {
1090
+ return this._productJobs ?? (this._productJobs = new ProductJobsClient(this.client));
360
1091
  }
361
1092
  };
362
1093
  var VintraceV7Api = class {
@@ -364,224 +1095,436 @@ var VintraceV7Api = class {
364
1095
  this.client = client;
365
1096
  }
366
1097
  get blocks() {
367
- return new BlocksClient(this.client);
1098
+ return this._blocks ?? (this._blocks = new BlocksClient(this.client));
368
1099
  }
369
1100
  get bookings() {
370
- return new BookingsClient(this.client);
1101
+ return this._bookings ?? (this._bookings = new BookingsClient(this.client));
371
1102
  }
372
1103
  get vesselDetailsReport() {
373
- return new VesselDetailsReportClient(this.client);
1104
+ return this._vesselDetailsReport ?? (this._vesselDetailsReport = new VesselDetailsReportClient(this.client));
374
1105
  }
375
1106
  };
376
1107
  var WorkOrdersClient = class {
377
1108
  constructor(client) {
378
1109
  this.client = client;
379
1110
  }
380
- getAll(params) {
381
- return this.client.request("v6/workorders/list", "GET", {}, params);
1111
+ /**
1112
+ * List available work orders.
1113
+ *
1114
+ * By default returns a list of all work orders that are in "Ready",
1115
+ * "In progress", or "Submitted" states and are assigned to me or unassigned
1116
+ * with a date range from 7 days ago to 3 days from now.
1117
+ */
1118
+ async getAll(params) {
1119
+ const limit = params?.max ? parseInt(params.max, 10) : 100;
1120
+ const firstResponse = await this.client.request(
1121
+ "v6/workorders/list",
1122
+ "GET",
1123
+ { responseSchema: WorkOrderSearchResponseSchema },
1124
+ { ...params, max: String(limit), first: "0" }
1125
+ );
1126
+ if (firstResponse[1]) {
1127
+ return [null, firstResponse[1]];
1128
+ }
1129
+ const response = firstResponse[0];
1130
+ if (!response) {
1131
+ return [[], null];
1132
+ }
1133
+ const totalCount = response.totalResultCount ?? response.workOrders?.length ?? 0;
1134
+ if (totalCount <= limit) {
1135
+ return [response.workOrders ?? [], null];
1136
+ }
1137
+ const pagesNeeded = Math.ceil(totalCount / limit);
1138
+ const parallelLimit = this.client.options.parallelLimit;
1139
+ const allResults = [...response.workOrders ?? []];
1140
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1141
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1142
+ const batchPromises = [];
1143
+ for (let j = 0; j < batchSize; j++) {
1144
+ const offset = (i + j) * limit;
1145
+ batchPromises.push(
1146
+ this.client.request(
1147
+ "v6/workorders/list",
1148
+ "GET",
1149
+ { responseSchema: WorkOrderSearchResponseSchema },
1150
+ { ...params, max: String(limit), first: String(offset) }
1151
+ )
1152
+ );
1153
+ }
1154
+ const batchResults = await Promise.all(batchPromises);
1155
+ for (const [pageData, pageError] of batchResults) {
1156
+ if (pageError) {
1157
+ return [null, pageError];
1158
+ }
1159
+ if (pageData?.workOrders) {
1160
+ allResults.push(...pageData.workOrders);
1161
+ }
1162
+ }
1163
+ }
1164
+ return [allResults, null];
382
1165
  }
383
1166
  get(id) {
384
- return this.client.request(`v6/workorders/${id}`, "GET");
1167
+ return this.client.request(`v6/workorders/${id}`, "GET", {
1168
+ responseSchema: WorkOrderDetailSchema
1169
+ });
385
1170
  }
386
1171
  getByCode(code) {
387
- return this.client.request("v6/workorders", "GET", {}, { code });
1172
+ return this.client.request(
1173
+ "v6/workorders",
1174
+ "GET",
1175
+ { responseSchema: WorkOrderDetailSchema },
1176
+ { code }
1177
+ );
388
1178
  }
389
1179
  getJob(jobId) {
390
1180
  return this.client.request(`v6/workorders/jobs/${jobId}`, "GET");
391
1181
  }
392
1182
  assign(workOrderId) {
393
- return this.client.request("v6/workorders/assign", "POST", {}, { workOrderId });
1183
+ return this.client.request(
1184
+ "v6/workorders/assign",
1185
+ "POST",
1186
+ { responseSchema: AssignWorkResponseSchema, requestSchema: AssignWorkDataSchema },
1187
+ { workOrderId }
1188
+ );
394
1189
  }
395
1190
  submit(data) {
396
- return this.client.request("v6/workorders/submit", "POST", {}, data);
1191
+ return this.client.request(
1192
+ "v6/workorders/submit",
1193
+ "POST",
1194
+ { responseSchema: SubmitWorkOrderStepsResponseSchema, requestSchema: SubmitJobRequestSchema },
1195
+ data
1196
+ );
397
1197
  }
398
1198
  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];
1199
+ return batchFetch(ids, (id) => this.get(id));
421
1200
  }
422
1201
  };
423
1202
  var SalesOrdersClient = class {
424
1203
  constructor(client) {
425
1204
  this.client = client;
426
1205
  }
427
- getAll(params) {
428
- return this.client.request("v6/sales-order/list", "GET", {}, params);
1206
+ /**
1207
+ * List available sales orders.
1208
+ *
1209
+ * Returns a list of the first 100 sales orders.
1210
+ */
1211
+ async getAll(params) {
1212
+ const limit = params?.max ? parseInt(params.max, 10) : 100;
1213
+ const firstResponse = await this.client.request(
1214
+ "v6/sales-order/list",
1215
+ "GET",
1216
+ { responseSchema: SalesOrderResponseSchema },
1217
+ { ...params, max: String(limit), first: "0" }
1218
+ );
1219
+ if (firstResponse[1]) {
1220
+ return [null, firstResponse[1]];
1221
+ }
1222
+ const response = firstResponse[0];
1223
+ if (!response) {
1224
+ return [[], null];
1225
+ }
1226
+ const totalCount = response.totalResultCount ?? response.salesOrders?.length ?? 0;
1227
+ if (totalCount <= limit) {
1228
+ return [response.salesOrders ?? [], null];
1229
+ }
1230
+ const pagesNeeded = Math.ceil(totalCount / limit);
1231
+ const parallelLimit = this.client.options.parallelLimit;
1232
+ const allResults = [...response.salesOrders ?? []];
1233
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1234
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1235
+ const batchPromises = [];
1236
+ for (let j = 0; j < batchSize; j++) {
1237
+ const offset = (i + j) * limit;
1238
+ batchPromises.push(
1239
+ this.client.request(
1240
+ "v6/sales-order/list",
1241
+ "GET",
1242
+ { responseSchema: SalesOrderResponseSchema },
1243
+ { ...params, max: String(limit), first: String(offset) }
1244
+ )
1245
+ );
1246
+ }
1247
+ const batchResults = await Promise.all(batchPromises);
1248
+ for (const [pageData, pageError] of batchResults) {
1249
+ if (pageError) {
1250
+ return [null, pageError];
1251
+ }
1252
+ if (pageData?.salesOrders) {
1253
+ allResults.push(...pageData.salesOrders);
1254
+ }
1255
+ }
1256
+ }
1257
+ return [allResults, null];
429
1258
  }
430
1259
  get(id) {
431
- return this.client.request(`v6/sales-order/${id}`, "GET");
1260
+ return this.client.request(`v6/sales-order/${id}`, "GET", {
1261
+ responseSchema: SalesOrderSchema
1262
+ });
432
1263
  }
433
1264
  getByCode(code) {
434
- return this.client.request("v6/sales-order", "GET", {}, { code });
1265
+ return this.client.request(
1266
+ "v6/sales-order",
1267
+ "GET",
1268
+ { responseSchema: SalesOrderSchema },
1269
+ { code }
1270
+ );
435
1271
  }
436
1272
  create(data) {
437
- return this.client.request("v6/sales-order", "POST", {}, data);
1273
+ return this.client.request(
1274
+ "v6/sales-order",
1275
+ "POST",
1276
+ { responseSchema: SalesOrderUpdateResponseSchema, requestSchema: SalesOrderWriteSchema },
1277
+ data
1278
+ );
438
1279
  }
439
1280
  update(id, data) {
440
- return this.client.request(`v6/sales-order/${id}`, "PUT", {}, data);
1281
+ return this.client.request(
1282
+ `v6/sales-order/${id}`,
1283
+ "PUT",
1284
+ { responseSchema: SalesOrderUpdateResponseSchema, requestSchema: SalesOrderWriteSchema },
1285
+ data
1286
+ );
441
1287
  }
442
1288
  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];
1289
+ return batchFetch(ids, (id) => this.get(id));
465
1290
  }
466
1291
  };
467
1292
  var RefundsClient = class {
468
1293
  constructor(client) {
469
1294
  this.client = client;
470
1295
  }
471
- getAll(params) {
472
- return this.client.request("v6/refund/list", "GET", {}, params);
1296
+ /**
1297
+ * List available refunds.
1298
+ *
1299
+ * Returns a list of the first 100 refunds.
1300
+ */
1301
+ async getAll(params) {
1302
+ const limit = params?.max ? parseInt(params.max, 10) : 100;
1303
+ const firstResponse = await this.client.request(
1304
+ "v6/refund/list",
1305
+ "GET",
1306
+ { responseSchema: RefundResponseSchema },
1307
+ { ...params, max: String(limit), first: "0" }
1308
+ );
1309
+ if (firstResponse[1]) {
1310
+ return [null, firstResponse[1]];
1311
+ }
1312
+ const response = firstResponse[0];
1313
+ if (!response) {
1314
+ return [[], null];
1315
+ }
1316
+ const totalCount = response.totalResultCount ?? response.refunds?.length ?? 0;
1317
+ if (totalCount <= limit) {
1318
+ return [response.refunds ?? [], null];
1319
+ }
1320
+ const pagesNeeded = Math.ceil(totalCount / limit);
1321
+ const parallelLimit = this.client.options.parallelLimit;
1322
+ const allResults = [...response.refunds ?? []];
1323
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1324
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1325
+ const batchPromises = [];
1326
+ for (let j = 0; j < batchSize; j++) {
1327
+ const offset = (i + j) * limit;
1328
+ batchPromises.push(
1329
+ this.client.request(
1330
+ "v6/refund/list",
1331
+ "GET",
1332
+ { responseSchema: RefundResponseSchema },
1333
+ { ...params, max: String(limit), first: String(offset) }
1334
+ )
1335
+ );
1336
+ }
1337
+ const batchResults = await Promise.all(batchPromises);
1338
+ for (const [pageData, pageError] of batchResults) {
1339
+ if (pageError) {
1340
+ return [null, pageError];
1341
+ }
1342
+ if (pageData?.refunds) {
1343
+ allResults.push(...pageData.refunds);
1344
+ }
1345
+ }
1346
+ }
1347
+ return [allResults, null];
473
1348
  }
474
1349
  get(id) {
475
- return this.client.request(`v6/refund/${id}`, "GET");
1350
+ return this.client.request(`v6/refund/${id}`, "GET", { responseSchema: RefundSchema });
476
1351
  }
477
1352
  getByCode(code) {
478
- return this.client.request("v6/refund", "GET", {}, { code });
1353
+ return this.client.request(
1354
+ "v6/refund",
1355
+ "GET",
1356
+ { responseSchema: RefundSchema },
1357
+ { code }
1358
+ );
479
1359
  }
480
1360
  create(data) {
481
- return this.client.request("v6/refund", "POST", {}, data);
1361
+ return this.client.request(
1362
+ "v6/refund",
1363
+ "POST",
1364
+ { responseSchema: RefundUpdateResponseSchema, requestSchema: RefundWriteSchema },
1365
+ data
1366
+ );
482
1367
  }
483
1368
  update(id, data) {
484
- return this.client.request(`v6/refund/${id}`, "PUT", {}, data);
1369
+ return this.client.request(
1370
+ `v6/refund/${id}`,
1371
+ "PUT",
1372
+ { responseSchema: RefundUpdateResponseSchema, requestSchema: RefundWriteSchema },
1373
+ data
1374
+ );
485
1375
  }
486
1376
  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];
1377
+ return batchFetch(ids, (id) => this.get(id));
509
1378
  }
510
1379
  };
511
1380
  var PartiesClient = class {
512
1381
  constructor(client) {
513
1382
  this.client = client;
514
1383
  }
515
- getAll(params) {
516
- return this.client.request("v6/party/list", "GET", {}, params);
1384
+ /**
1385
+ * List parties.
1386
+ *
1387
+ * Returns a list of the first 100 parties.
1388
+ */
1389
+ async getAll(params) {
1390
+ const limit = params?.max ? parseInt(params.max, 10) : 100;
1391
+ const firstResponse = await this.client.request(
1392
+ "v6/party/list",
1393
+ "GET",
1394
+ { responseSchema: PartyResponseSchema },
1395
+ { ...params, max: String(limit), first: "0" }
1396
+ );
1397
+ if (firstResponse[1]) {
1398
+ return [null, firstResponse[1]];
1399
+ }
1400
+ const response = firstResponse[0];
1401
+ if (!response) {
1402
+ return [[], null];
1403
+ }
1404
+ const totalCount = response.totalResultCount ?? response.parties?.length ?? 0;
1405
+ if (totalCount <= limit) {
1406
+ return [response.parties ?? [], null];
1407
+ }
1408
+ const pagesNeeded = Math.ceil(totalCount / limit);
1409
+ const parallelLimit = this.client.options.parallelLimit;
1410
+ const allResults = [...response.parties ?? []];
1411
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1412
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1413
+ const batchPromises = [];
1414
+ for (let j = 0; j < batchSize; j++) {
1415
+ const offset = (i + j) * limit;
1416
+ batchPromises.push(
1417
+ this.client.request(
1418
+ "v6/party/list",
1419
+ "GET",
1420
+ { responseSchema: PartyResponseSchema },
1421
+ { ...params, max: String(limit), first: String(offset) }
1422
+ )
1423
+ );
1424
+ }
1425
+ const batchResults = await Promise.all(batchPromises);
1426
+ for (const [pageData, pageError] of batchResults) {
1427
+ if (pageError) {
1428
+ return [null, pageError];
1429
+ }
1430
+ if (pageData?.parties) {
1431
+ allResults.push(...pageData.parties);
1432
+ }
1433
+ }
1434
+ }
1435
+ return [allResults, null];
517
1436
  }
518
1437
  get(id) {
519
- return this.client.request(`v6/party/${id}`, "GET");
1438
+ return this.client.request(`v6/party/${id}`, "GET", { responseSchema: PartySchema });
520
1439
  }
521
1440
  getByName(name) {
522
- return this.client.request("v6/party", "GET", {}, { name });
1441
+ return this.client.request("v6/party", "GET", { responseSchema: PartySchema }, { name });
523
1442
  }
524
1443
  create(data) {
525
- return this.client.request("v6/party", "POST", {}, data);
1444
+ return this.client.request(
1445
+ "v6/party",
1446
+ "POST",
1447
+ { responseSchema: PartyUpdateResponseSchema, requestSchema: PartyWriteSchema },
1448
+ data
1449
+ );
526
1450
  }
527
1451
  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];
1452
+ return batchFetch(ids, (id) => this.get(id));
550
1453
  }
551
1454
  };
552
1455
  var ProductsClient = class {
553
1456
  constructor(client) {
554
1457
  this.client = client;
555
1458
  }
556
- getAll(params) {
557
- return this.client.request("v6/products/list", "GET", {}, params);
1459
+ /**
1460
+ * List available products.
1461
+ *
1462
+ * Returns a list of all active products.
1463
+ */
1464
+ async getAll(params) {
1465
+ const limit = params?.max ? parseInt(params.max, 10) : 100;
1466
+ const firstResponse = await this.client.request(
1467
+ "v6/products/list",
1468
+ "GET",
1469
+ { responseSchema: ProductListResponseSchema },
1470
+ { ...params, max: String(limit), first: "0" }
1471
+ );
1472
+ if (firstResponse[1]) {
1473
+ return [null, firstResponse[1]];
1474
+ }
1475
+ const response = firstResponse[0];
1476
+ if (!response) {
1477
+ return [[], null];
1478
+ }
1479
+ const totalCount = response.totalResultCount ?? response.products?.length ?? 0;
1480
+ if (totalCount <= limit) {
1481
+ return [response.products ?? [], null];
1482
+ }
1483
+ const pagesNeeded = Math.ceil(totalCount / limit);
1484
+ const parallelLimit = this.client.options.parallelLimit;
1485
+ const allResults = [...response.products ?? []];
1486
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1487
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1488
+ const batchPromises = [];
1489
+ for (let j = 0; j < batchSize; j++) {
1490
+ const offset = (i + j) * limit;
1491
+ batchPromises.push(
1492
+ this.client.request(
1493
+ "v6/products/list",
1494
+ "GET",
1495
+ { responseSchema: ProductListResponseSchema },
1496
+ { ...params, max: String(limit), first: String(offset) }
1497
+ )
1498
+ );
1499
+ }
1500
+ const batchResults = await Promise.all(batchPromises);
1501
+ for (const [pageData, pageError] of batchResults) {
1502
+ if (pageError) {
1503
+ return [null, pageError];
1504
+ }
1505
+ if (pageData?.products) {
1506
+ allResults.push(...pageData.products);
1507
+ }
1508
+ }
1509
+ }
1510
+ return [allResults, null];
558
1511
  }
559
1512
  get(id) {
560
- return this.client.request(`v6/products/${id}`, "GET");
561
- }
562
- getMany(ids) {
563
- return this.batchGet(ids, (id) => this.get(id));
1513
+ return this.client.request(`v6/products/${id}`, "GET", {
1514
+ responseSchema: ProductResponseSchema
1515
+ });
564
1516
  }
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)));
1517
+ async getMany(ids) {
1518
+ const results = await Promise.allSettled(ids.map((id) => this.get(id)));
576
1519
  const errors = [];
577
1520
  const data = [];
578
1521
  for (const result of results) {
579
1522
  if (result.status === "fulfilled") {
580
- const [item, error] = result.value;
1523
+ const [envelope, error] = result.value;
581
1524
  if (error) {
582
1525
  errors.push(error);
583
- } else if (item !== null) {
584
- data.push(item);
1526
+ } else if (envelope?.product) {
1527
+ data.push(envelope.product);
585
1528
  }
586
1529
  } else {
587
1530
  errors.push(new VintraceError(result.reason?.message ?? "Unknown error", 0));
@@ -592,19 +1535,98 @@ var ProductsClient = class {
592
1535
  }
593
1536
  return [data, null];
594
1537
  }
1538
+ create(data) {
1539
+ return this.client.request(
1540
+ "v6/products",
1541
+ "POST",
1542
+ { responseSchema: ProductResponseSchema, requestSchema: ProductSchema },
1543
+ data
1544
+ );
1545
+ }
1546
+ update(id, data) {
1547
+ return this.client.request(
1548
+ `v6/products/${id}`,
1549
+ "PUT",
1550
+ { responseSchema: ProductUpdateResponseSchema, requestSchema: ProductSchema },
1551
+ data
1552
+ );
1553
+ }
1554
+ updateFields(data) {
1555
+ return this.client.request(
1556
+ "v6/product-update",
1557
+ "POST",
1558
+ { responseSchema: ProductUpdateResponseSchema, requestSchema: ProductUpdateDataSchema },
1559
+ data
1560
+ );
1561
+ }
595
1562
  };
596
1563
  var BlocksClient = class {
597
1564
  constructor(client) {
598
1565
  this.client = client;
599
1566
  }
600
- getAll(params) {
601
- return this.client.request("v7/harvest/blocks", "GET", {}, params);
1567
+ /**
1568
+ * Get all blocks in the system.
1569
+ *
1570
+ * Get all the blocks that matches the provided query params in the system.
1571
+ * By default, the block data returned in this endpoint only includes:
1572
+ * id, code, name, description, grower, vineyard, region, subRegion, varietal,
1573
+ * rowNumbers, estate, intendedUse, grading, externalId, inactive
1574
+ *
1575
+ * API consumer can use the include and vintage query params to request including more information in the response.
1576
+ */
1577
+ async getAll(params) {
1578
+ const limit = params?.limit ? parseInt(String(params.limit), 10) : 100;
1579
+ const firstResponse = await this.client.request(
1580
+ "v7/harvest/blocks",
1581
+ "GET",
1582
+ { responseSchema: GetBlocksSuccessResponseSchema },
1583
+ { ...params, limit: String(limit), offset: "0" }
1584
+ );
1585
+ if (firstResponse[1]) {
1586
+ return [null, firstResponse[1]];
1587
+ }
1588
+ const response = firstResponse[0];
1589
+ if (!response) {
1590
+ return [[], null];
1591
+ }
1592
+ const totalCount = response.totalResults ?? 0;
1593
+ if (totalCount <= limit) {
1594
+ return [response.results ?? [], null];
1595
+ }
1596
+ const pagesNeeded = Math.ceil(totalCount / limit);
1597
+ const parallelLimit = this.client.options.parallelLimit;
1598
+ const allResults = [...response.results ?? []];
1599
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1600
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1601
+ const batchPromises = [];
1602
+ for (let j = 0; j < batchSize; j++) {
1603
+ const offset = (i + j) * limit;
1604
+ batchPromises.push(
1605
+ this.client.request(
1606
+ "v7/harvest/blocks",
1607
+ "GET",
1608
+ { responseSchema: GetBlocksSuccessResponseSchema },
1609
+ { ...params, limit: String(limit), offset: String(offset) }
1610
+ )
1611
+ );
1612
+ }
1613
+ const batchResults = await Promise.all(batchPromises);
1614
+ for (const [pageData, pageError] of batchResults) {
1615
+ if (pageError) {
1616
+ return [null, pageError];
1617
+ }
1618
+ if (pageData?.results) {
1619
+ allResults.push(...pageData.results);
1620
+ }
1621
+ }
1622
+ }
1623
+ return [allResults, null];
602
1624
  }
603
1625
  get(id) {
604
1626
  return this.client.request(`v7/harvest/blocks/${id}`, "GET");
605
1627
  }
606
1628
  getMany(ids) {
607
- return this.batchGet(ids, (id) => this.get(id));
1629
+ return batchFetch(ids, (id) => this.get(id));
608
1630
  }
609
1631
  post(data) {
610
1632
  return this.client.request("v7/harvest/blocks", "POST", {}, data);
@@ -612,27 +1634,6 @@ var BlocksClient = class {
612
1634
  patch(id, data) {
613
1635
  return this.client.request(`v7/harvest/blocks/${id}`, "PATCH", {}, data);
614
1636
  }
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
1637
  };
637
1638
  var BookingsClient = class {
638
1639
  constructor(client) {
@@ -649,38 +1650,203 @@ var VesselDetailsReportClient = class {
649
1650
  constructor(client) {
650
1651
  this.client = client;
651
1652
  }
1653
+ /**
1654
+ * Get vessel details report.
1655
+ *
1656
+ * Returns a vessel details report based on the provided parameters.
1657
+ */
652
1658
  get(params) {
653
- return this.client.request("v7/report/vessel-details-report", "GET", {}, params);
1659
+ return this.client.request(
1660
+ "v7/report/vessel-details-report",
1661
+ "GET",
1662
+ { responseSchema: GetBulkWineDetailsReportResponseSchema },
1663
+ params
1664
+ );
654
1665
  }
655
1666
  };
656
1667
  var TransactionsClient = class {
657
1668
  constructor(client) {
658
1669
  this.client = client;
659
1670
  }
660
- search(params) {
661
- return this.client.request("v6/transaction/search", "GET", {}, params);
1671
+ /**
1672
+ * Transaction search.
1673
+ *
1674
+ * Returns a list of transactions matching search criteria.
1675
+ */
1676
+ async search(params) {
1677
+ const limit = params?.maxResults ? params.maxResults : 100;
1678
+ const firstResponse = await this.client.request(
1679
+ "v6/transaction/search",
1680
+ "GET",
1681
+ { responseSchema: TransactionSearchResponseSchema },
1682
+ { ...params, maxResults: limit, firstResult: 0 }
1683
+ );
1684
+ if (firstResponse[1]) {
1685
+ return [null, firstResponse[1]];
1686
+ }
1687
+ const response = firstResponse[0];
1688
+ if (!response) {
1689
+ return [[], null];
1690
+ }
1691
+ const totalCount = response.totalResultCount ?? response.results?.length ?? 0;
1692
+ if (totalCount <= limit) {
1693
+ return [response.results ?? [], null];
1694
+ }
1695
+ const pagesNeeded = Math.ceil(totalCount / limit);
1696
+ const parallelLimit = this.client.options.parallelLimit;
1697
+ const allResults = [...response.results ?? []];
1698
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1699
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1700
+ const batchPromises = [];
1701
+ for (let j = 0; j < batchSize; j++) {
1702
+ const offset = (i + j) * limit;
1703
+ batchPromises.push(
1704
+ this.client.request(
1705
+ "v6/transaction/search",
1706
+ "GET",
1707
+ { responseSchema: TransactionSearchResponseSchema },
1708
+ { ...params, maxResults: limit, firstResult: offset }
1709
+ )
1710
+ );
1711
+ }
1712
+ const batchResults = await Promise.all(batchPromises);
1713
+ for (const [pageData, pageError] of batchResults) {
1714
+ if (pageError) {
1715
+ return [null, pageError];
1716
+ }
1717
+ if (pageData?.results) {
1718
+ allResults.push(...pageData.results);
1719
+ }
1720
+ }
1721
+ }
1722
+ return [allResults, null];
662
1723
  }
663
1724
  };
664
1725
  var IntakeOperationsClient = class {
665
1726
  constructor(client) {
666
1727
  this.client = client;
667
1728
  }
668
- search(params) {
669
- return this.client.request("v6/intake-operations/search", "GET", {}, params);
1729
+ /**
1730
+ * Fruit intake operation search.
1731
+ *
1732
+ * Returns a list of fruit intake operations matching search criteria.
1733
+ */
1734
+ async search(params) {
1735
+ const limit = params?.maxResults ? params.maxResults : 100;
1736
+ const firstResponse = await this.client.request(
1737
+ "v6/intake-operations/search",
1738
+ "GET",
1739
+ { responseSchema: IntakeOperationSearchResponseSchema },
1740
+ { ...params, maxResults: limit, firstResult: 0 }
1741
+ );
1742
+ if (firstResponse[1]) {
1743
+ return [null, firstResponse[1]];
1744
+ }
1745
+ const response = firstResponse[0];
1746
+ if (!response) {
1747
+ return [[], null];
1748
+ }
1749
+ const totalCount = response.totalResultCount ?? response.results?.length ?? 0;
1750
+ if (totalCount <= limit) {
1751
+ return [response.results ?? [], null];
1752
+ }
1753
+ const pagesNeeded = Math.ceil(totalCount / limit);
1754
+ const parallelLimit = this.client.options.parallelLimit;
1755
+ const allResults = [...response.results ?? []];
1756
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1757
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1758
+ const batchPromises = [];
1759
+ for (let j = 0; j < batchSize; j++) {
1760
+ const offset = (i + j) * limit;
1761
+ batchPromises.push(
1762
+ this.client.request(
1763
+ "v6/intake-operations/search",
1764
+ "GET",
1765
+ { responseSchema: IntakeOperationSearchResponseSchema },
1766
+ { ...params, maxResults: limit, firstResult: offset }
1767
+ )
1768
+ );
1769
+ }
1770
+ const batchResults = await Promise.all(batchPromises);
1771
+ for (const [pageData, pageError] of batchResults) {
1772
+ if (pageError) {
1773
+ return [null, pageError];
1774
+ }
1775
+ if (pageData?.results) {
1776
+ allResults.push(...pageData.results);
1777
+ }
1778
+ }
1779
+ }
1780
+ return [allResults, null];
670
1781
  }
671
1782
  };
672
1783
  var SampleOperationsClient = class {
673
1784
  constructor(client) {
674
1785
  this.client = client;
675
1786
  }
676
- search(params) {
677
- return this.client.request("v6/sample-operations/search", "GET", {}, params);
1787
+ /**
1788
+ * Maturity samples search.
1789
+ *
1790
+ * Returns a list of maturity samples matching search criteria.
1791
+ */
1792
+ async search(params) {
1793
+ const limit = params?.maxResults ? params.maxResults : 100;
1794
+ const firstResponse = await this.client.request(
1795
+ "v6/sample-operations/search",
1796
+ "GET",
1797
+ { responseSchema: SampleOperationSearchResponseSchema },
1798
+ { ...params, maxResults: limit, firstResult: 0 }
1799
+ );
1800
+ if (firstResponse[1]) {
1801
+ return [null, firstResponse[1]];
1802
+ }
1803
+ const response = firstResponse[0];
1804
+ if (!response) {
1805
+ return [[], null];
1806
+ }
1807
+ const totalCount = response.totalResultCount ?? response.results?.length ?? 0;
1808
+ if (totalCount <= limit) {
1809
+ return [response.results ?? [], null];
1810
+ }
1811
+ const pagesNeeded = Math.ceil(totalCount / limit);
1812
+ const parallelLimit = this.client.options.parallelLimit;
1813
+ const allResults = [...response.results ?? []];
1814
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1815
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1816
+ const batchPromises = [];
1817
+ for (let j = 0; j < batchSize; j++) {
1818
+ const offset = (i + j) * limit;
1819
+ batchPromises.push(
1820
+ this.client.request(
1821
+ "v6/sample-operations/search",
1822
+ "GET",
1823
+ { responseSchema: SampleOperationSearchResponseSchema },
1824
+ { ...params, maxResults: limit, firstResult: offset }
1825
+ )
1826
+ );
1827
+ }
1828
+ const batchResults = await Promise.all(batchPromises);
1829
+ for (const [pageData, pageError] of batchResults) {
1830
+ if (pageError) {
1831
+ return [null, pageError];
1832
+ }
1833
+ if (pageData?.results) {
1834
+ allResults.push(...pageData.results);
1835
+ }
1836
+ }
1837
+ }
1838
+ return [allResults, null];
678
1839
  }
679
1840
  };
680
1841
  var BlockAssessmentsClient = class {
681
1842
  constructor(client) {
682
1843
  this.client = client;
683
1844
  }
1845
+ /**
1846
+ * Create a block assessment.
1847
+ *
1848
+ * Upsert the assessment data for a block.
1849
+ */
684
1850
  create(data) {
685
1851
  return this.client.request("v6/block-assessments/create", "POST", {}, data);
686
1852
  }
@@ -689,8 +1855,18 @@ var MrpStockClient = class {
689
1855
  constructor(client) {
690
1856
  this.client = client;
691
1857
  }
1858
+ /**
1859
+ * View a single stock item.
1860
+ *
1861
+ * Get a single stock item by ID with optional expand parameter.
1862
+ */
692
1863
  get(id, expand) {
693
- return this.client.request(`v6/mrp/stock/${id}`, "GET", {}, expand ? { expand } : void 0);
1864
+ return this.client.request(
1865
+ `v6/mrp/stock/${id}`,
1866
+ "GET",
1867
+ {},
1868
+ expand ? { expand } : void 0
1869
+ );
694
1870
  }
695
1871
  getFields(id) {
696
1872
  return this.client.request(`v6/mrp/stock/${id}/fields`, "GET");
@@ -714,7 +1890,12 @@ var MrpStockClient = class {
714
1890
  return this.client.request(`v6/mrp/stock/${id}/notes/${noteId}`, "GET");
715
1891
  }
716
1892
  updateNote(id, noteId, data) {
717
- return this.client.request(`v6/mrp/stock/${id}/notes/${noteId}/updates`, "POST", {}, data);
1893
+ return this.client.request(
1894
+ `v6/mrp/stock/${id}/notes/${noteId}/updates`,
1895
+ "POST",
1896
+ {},
1897
+ data
1898
+ );
718
1899
  }
719
1900
  getBulkInfo(id) {
720
1901
  return this.client.request(`v6/mrp/stock/${id}/bulk-info`, "GET");
@@ -724,16 +1905,119 @@ var InventoryClient = class {
724
1905
  constructor(client) {
725
1906
  this.client = client;
726
1907
  }
727
- getAll(params) {
728
- return this.client.request("v6/inventory", "GET", {}, params);
1908
+ /**
1909
+ * List available stock.
1910
+ *
1911
+ * Returns a list of all stock items.
1912
+ */
1913
+ async getAll(params) {
1914
+ const limit = params?.max ? parseInt(params.max, 10) : 100;
1915
+ const firstResponse = await this.client.request(
1916
+ "v6/inventory",
1917
+ "GET",
1918
+ { responseSchema: InventoryResponseSchema },
1919
+ { ...params, max: String(limit), first: "0" }
1920
+ );
1921
+ if (firstResponse[1]) {
1922
+ return [null, firstResponse[1]];
1923
+ }
1924
+ const response = firstResponse[0];
1925
+ if (!response) {
1926
+ return [[], null];
1927
+ }
1928
+ const totalCount = response.totalResultCount ?? response.results?.length ?? 0;
1929
+ if (totalCount <= limit) {
1930
+ return [response.results ?? [], null];
1931
+ }
1932
+ const pagesNeeded = Math.ceil(totalCount / limit);
1933
+ const parallelLimit = this.client.options.parallelLimit;
1934
+ const allResults = [...response.results ?? []];
1935
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1936
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1937
+ const batchPromises = [];
1938
+ for (let j = 0; j < batchSize; j++) {
1939
+ const offset = (i + j) * limit;
1940
+ batchPromises.push(
1941
+ this.client.request(
1942
+ "v6/inventory",
1943
+ "GET",
1944
+ { responseSchema: InventoryResponseSchema },
1945
+ { ...params, max: String(limit), first: String(offset) }
1946
+ )
1947
+ );
1948
+ }
1949
+ const batchResults = await Promise.all(batchPromises);
1950
+ for (const [pageData, pageError] of batchResults) {
1951
+ if (pageError) {
1952
+ return [null, pageError];
1953
+ }
1954
+ if (pageData?.results) {
1955
+ allResults.push(...pageData.results);
1956
+ }
1957
+ }
1958
+ }
1959
+ return [allResults, null];
729
1960
  }
730
1961
  };
731
1962
  var SearchClient = class {
732
1963
  constructor(client) {
733
1964
  this.client = client;
734
1965
  }
735
- list(params) {
736
- return this.client.request("v6/search/list", "GET", {}, params);
1966
+ /**
1967
+ * List results for item type.
1968
+ *
1969
+ * Returns search results for a specific item type.
1970
+ * Supported types are grading, owner, program, varietal, vintage,
1971
+ * productState, region, block, grower, productCategory, batch, product, tank,
1972
+ * vessel, containerEquipment, barrel, bin.
1973
+ */
1974
+ async list(params) {
1975
+ const limit = params?.max ? parseInt(params.max, 10) : 100;
1976
+ const firstResponse = await this.client.request(
1977
+ "v6/search/list",
1978
+ "GET",
1979
+ { responseSchema: SearchListResponseSchema },
1980
+ { ...params, max: String(limit), first: "0" }
1981
+ );
1982
+ if (firstResponse[1]) {
1983
+ return [null, firstResponse[1]];
1984
+ }
1985
+ const response = firstResponse[0];
1986
+ if (!response) {
1987
+ return [[], null];
1988
+ }
1989
+ const totalCount = response.totalResultCount ?? response.results?.length ?? 0;
1990
+ if (totalCount <= limit) {
1991
+ return [response.results ?? [], null];
1992
+ }
1993
+ const pagesNeeded = Math.ceil(totalCount / limit);
1994
+ const parallelLimit = this.client.options.parallelLimit;
1995
+ const allResults = [...response.results ?? []];
1996
+ for (let i = 1; i < pagesNeeded; i += parallelLimit) {
1997
+ const batchSize = Math.min(parallelLimit, pagesNeeded - i);
1998
+ const batchPromises = [];
1999
+ for (let j = 0; j < batchSize; j++) {
2000
+ const offset = (i + j) * limit;
2001
+ batchPromises.push(
2002
+ this.client.request(
2003
+ "v6/search/list",
2004
+ "GET",
2005
+ { responseSchema: SearchListResponseSchema },
2006
+ { ...params, max: String(limit), first: String(offset) }
2007
+ )
2008
+ );
2009
+ }
2010
+ const batchResults = await Promise.all(batchPromises);
2011
+ for (const [pageData, pageError] of batchResults) {
2012
+ if (pageError) {
2013
+ return [null, pageError];
2014
+ }
2015
+ if (pageData?.results) {
2016
+ allResults.push(...pageData.results);
2017
+ }
2018
+ }
2019
+ }
2020
+ return [allResults, null];
737
2021
  }
738
2022
  };
739
2023
  var ProductAnalysisClient = class {
@@ -749,7 +2033,7 @@ var ProductAnalysisClient = class {
749
2033
  return this.client.request(
750
2034
  `v6/product-analysis/${productId}`,
751
2035
  "GET",
752
- {},
2036
+ { responseSchema: ProductAnalysisResponseSchema },
753
2037
  params
754
2038
  );
755
2039
  }
@@ -799,7 +2083,26 @@ var ProductCompositionClient = class {
799
2083
  get(productId) {
800
2084
  return this.client.request(
801
2085
  `v6/product-composition/${productId}`,
802
- "GET"
2086
+ "GET",
2087
+ { responseSchema: ProductCompositionResponseSchema }
2088
+ );
2089
+ }
2090
+ };
2091
+ var ProductJobsClient = class {
2092
+ constructor(client) {
2093
+ this.client = client;
2094
+ }
2095
+ /**
2096
+ * Get job history for a product by its numeric ID.
2097
+ * Returns the job details and history for a product including transfers,
2098
+ * treatments, and other operations performed on it.
2099
+ * e.g. GET v6/product-jobs/{productId}
2100
+ */
2101
+ get(productId) {
2102
+ return this.client.request(
2103
+ `v6/product-jobs/${productId}`,
2104
+ "GET",
2105
+ { responseSchema: ProductJobResponseSchema }
803
2106
  );
804
2107
  }
805
2108
  };