colacloud 1.2.0 → 1.4.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 +1 -1
- package/dist/index.d.mts +242 -39
- package/dist/index.d.ts +242 -39
- package/dist/index.js +156 -49
- package/dist/index.mjs +156 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -76,14 +76,14 @@ var AuthenticationError = class _AuthenticationError extends ColaCloudError {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
var RateLimitError = class _RateLimitError extends ColaCloudError {
|
|
79
|
-
/**
|
|
80
|
-
|
|
79
|
+
/** Quota information from headers */
|
|
80
|
+
quota;
|
|
81
81
|
/** Seconds until the rate limit resets */
|
|
82
82
|
retryAfter;
|
|
83
|
-
constructor(message = "Rate limit exceeded",
|
|
83
|
+
constructor(message = "Rate limit exceeded", quota = null, retryAfter = null) {
|
|
84
84
|
super(message, 429, "rate_limit_exceeded");
|
|
85
85
|
this.name = "RateLimitError";
|
|
86
|
-
this.
|
|
86
|
+
this.quota = quota;
|
|
87
87
|
this.retryAfter = retryAfter;
|
|
88
88
|
if (Error.captureStackTrace) {
|
|
89
89
|
Error.captureStackTrace(this, _RateLimitError);
|
|
@@ -169,9 +169,15 @@ function createPaginatedIterator(options) {
|
|
|
169
169
|
done = true;
|
|
170
170
|
break;
|
|
171
171
|
}
|
|
172
|
-
if (pagination !== null
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
if (pagination !== null) {
|
|
173
|
+
if (pagination.has_more === false) {
|
|
174
|
+
done = true;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (pagination.pages !== null && currentPage > pagination.pages) {
|
|
178
|
+
done = true;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
175
181
|
}
|
|
176
182
|
const result = await fetchPage({
|
|
177
183
|
...params,
|
|
@@ -209,7 +215,7 @@ function createPaginatedIteratorWithMetadata(options) {
|
|
|
209
215
|
let currentItems = [];
|
|
210
216
|
let currentIndex = 0;
|
|
211
217
|
let pagination = null;
|
|
212
|
-
let
|
|
218
|
+
let quota = null;
|
|
213
219
|
let pagesFetched = 0;
|
|
214
220
|
let done = false;
|
|
215
221
|
return {
|
|
@@ -219,16 +225,22 @@ function createPaginatedIteratorWithMetadata(options) {
|
|
|
219
225
|
done = true;
|
|
220
226
|
break;
|
|
221
227
|
}
|
|
222
|
-
if (pagination !== null
|
|
223
|
-
|
|
224
|
-
|
|
228
|
+
if (pagination !== null) {
|
|
229
|
+
if (pagination.has_more === false) {
|
|
230
|
+
done = true;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
if (pagination.pages !== null && currentPage > pagination.pages) {
|
|
234
|
+
done = true;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
225
237
|
}
|
|
226
238
|
const result = await fetchPage({
|
|
227
239
|
...params,
|
|
228
240
|
page: currentPage
|
|
229
241
|
});
|
|
230
242
|
pagination = result.response.pagination;
|
|
231
|
-
|
|
243
|
+
quota = result.quota;
|
|
232
244
|
currentItems = result.response.data;
|
|
233
245
|
currentIndex = 0;
|
|
234
246
|
currentPage++;
|
|
@@ -249,7 +261,7 @@ function createPaginatedIteratorWithMetadata(options) {
|
|
|
249
261
|
// We already incremented after fetch
|
|
250
262
|
indexInPage: currentIndex,
|
|
251
263
|
total: pagination?.total ?? 0,
|
|
252
|
-
|
|
264
|
+
quota
|
|
253
265
|
};
|
|
254
266
|
currentIndex++;
|
|
255
267
|
return { done: false, value: result };
|
|
@@ -286,14 +298,20 @@ function toSnakeCase(params) {
|
|
|
286
298
|
}
|
|
287
299
|
return result;
|
|
288
300
|
}
|
|
289
|
-
function
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
301
|
+
function parseQuotaHeaders(headers) {
|
|
302
|
+
const reset = headers.get("X-Quota-Reset");
|
|
303
|
+
if (reset === null) return null;
|
|
304
|
+
let limit = headers.get("X-Detail-Views-Limit");
|
|
305
|
+
let remaining = headers.get("X-Detail-Views-Remaining");
|
|
306
|
+
let meter = "detail_views";
|
|
307
|
+
if (limit === null) {
|
|
308
|
+
limit = headers.get("X-List-Records-Limit");
|
|
309
|
+
remaining = headers.get("X-List-Records-Remaining");
|
|
310
|
+
meter = "list_records";
|
|
311
|
+
}
|
|
312
|
+
if (limit === null || remaining === null) return null;
|
|
296
313
|
return {
|
|
314
|
+
meter,
|
|
297
315
|
limit: parseInt(limit, 10),
|
|
298
316
|
remaining: parseInt(remaining, 10),
|
|
299
317
|
reset: parseInt(reset, 10)
|
|
@@ -311,6 +329,12 @@ var ColaCloud = class {
|
|
|
311
329
|
barcodes;
|
|
312
330
|
/** Usage statistics endpoint */
|
|
313
331
|
usage;
|
|
332
|
+
/** Processing times reference data endpoints */
|
|
333
|
+
processingTimes;
|
|
334
|
+
/** Production reports reference data endpoints */
|
|
335
|
+
productionReports;
|
|
336
|
+
/** AVA (American Viticultural Area) reference data endpoints */
|
|
337
|
+
avas;
|
|
314
338
|
/**
|
|
315
339
|
* Create a new COLA Cloud API client
|
|
316
340
|
* @param config Configuration options
|
|
@@ -326,6 +350,9 @@ var ColaCloud = class {
|
|
|
326
350
|
this.permittees = new PermitteesResource(this);
|
|
327
351
|
this.barcodes = new BarcodesResource(this);
|
|
328
352
|
this.usage = new UsageResource(this);
|
|
353
|
+
this.processingTimes = new ProcessingTimesResource(this);
|
|
354
|
+
this.productionReports = new ProductionReportsResource(this);
|
|
355
|
+
this.avas = new AvasResource(this);
|
|
329
356
|
}
|
|
330
357
|
/**
|
|
331
358
|
* Make an authenticated request to the API
|
|
@@ -350,12 +377,12 @@ var ColaCloud = class {
|
|
|
350
377
|
signal: controller.signal
|
|
351
378
|
});
|
|
352
379
|
clearTimeout(timeoutId);
|
|
353
|
-
const
|
|
380
|
+
const quota = parseQuotaHeaders(response.headers);
|
|
354
381
|
if (!response.ok) {
|
|
355
|
-
await this.handleErrorResponse(response,
|
|
382
|
+
await this.handleErrorResponse(response, quota);
|
|
356
383
|
}
|
|
357
384
|
const data = await response.json();
|
|
358
|
-
return { data,
|
|
385
|
+
return { data, quota };
|
|
359
386
|
} catch (error) {
|
|
360
387
|
clearTimeout(timeoutId);
|
|
361
388
|
if (error instanceof Error && error.name === "AbortError") {
|
|
@@ -373,7 +400,7 @@ var ColaCloud = class {
|
|
|
373
400
|
/**
|
|
374
401
|
* Handle error responses from the API
|
|
375
402
|
*/
|
|
376
|
-
async handleErrorResponse(response,
|
|
403
|
+
async handleErrorResponse(response, quota) {
|
|
377
404
|
let errorData;
|
|
378
405
|
try {
|
|
379
406
|
errorData = await response.json();
|
|
@@ -390,7 +417,7 @@ var ColaCloud = class {
|
|
|
390
417
|
const retryAfter = response.headers.get("Retry-After");
|
|
391
418
|
throw new RateLimitError(
|
|
392
419
|
message,
|
|
393
|
-
|
|
420
|
+
quota,
|
|
394
421
|
retryAfter ? parseInt(retryAfter, 10) : null
|
|
395
422
|
);
|
|
396
423
|
}
|
|
@@ -425,11 +452,11 @@ var ColasResource = class {
|
|
|
425
452
|
return result.data;
|
|
426
453
|
}
|
|
427
454
|
/**
|
|
428
|
-
* List COLAs with
|
|
455
|
+
* List COLAs with quota information
|
|
429
456
|
* @param params Search and filter parameters
|
|
430
|
-
* @returns Paginated list with
|
|
457
|
+
* @returns Paginated list with quota info
|
|
431
458
|
*/
|
|
432
|
-
async
|
|
459
|
+
async listWithQuota(params = {}) {
|
|
433
460
|
return this.client.request(
|
|
434
461
|
"GET",
|
|
435
462
|
"/colas",
|
|
@@ -456,17 +483,17 @@ var ColasResource = class {
|
|
|
456
483
|
}
|
|
457
484
|
}
|
|
458
485
|
/**
|
|
459
|
-
* Get a single COLA with
|
|
486
|
+
* Get a single COLA with quota information
|
|
460
487
|
* @param ttbId The unique TTB identifier
|
|
461
|
-
* @returns COLA details with
|
|
488
|
+
* @returns COLA details with quota info
|
|
462
489
|
*/
|
|
463
|
-
async
|
|
490
|
+
async getWithQuota(ttbId) {
|
|
464
491
|
try {
|
|
465
492
|
const result = await this.client.request(
|
|
466
493
|
"GET",
|
|
467
494
|
`/colas/${encodeURIComponent(ttbId)}`
|
|
468
495
|
);
|
|
469
|
-
return { data: result.data.data,
|
|
496
|
+
return { data: result.data.data, quota: result.quota };
|
|
470
497
|
} catch (error) {
|
|
471
498
|
if (error instanceof NotFoundError) {
|
|
472
499
|
throw new NotFoundError("COLA", ttbId);
|
|
@@ -495,7 +522,7 @@ var ColasResource = class {
|
|
|
495
522
|
"/colas",
|
|
496
523
|
p
|
|
497
524
|
);
|
|
498
|
-
return { response: result.data,
|
|
525
|
+
return { response: result.data, quota: result.quota };
|
|
499
526
|
}
|
|
500
527
|
});
|
|
501
528
|
}
|
|
@@ -518,11 +545,11 @@ var PermitteesResource = class {
|
|
|
518
545
|
return result.data;
|
|
519
546
|
}
|
|
520
547
|
/**
|
|
521
|
-
* List permittees with
|
|
548
|
+
* List permittees with quota information
|
|
522
549
|
* @param params Search and filter parameters
|
|
523
|
-
* @returns Paginated list with
|
|
550
|
+
* @returns Paginated list with quota info
|
|
524
551
|
*/
|
|
525
|
-
async
|
|
552
|
+
async listWithQuota(params = {}) {
|
|
526
553
|
return this.client.request(
|
|
527
554
|
"GET",
|
|
528
555
|
"/permittees",
|
|
@@ -549,17 +576,17 @@ var PermitteesResource = class {
|
|
|
549
576
|
}
|
|
550
577
|
}
|
|
551
578
|
/**
|
|
552
|
-
* Get a single permittee with
|
|
579
|
+
* Get a single permittee with quota information
|
|
553
580
|
* @param permitNumber The unique permit number
|
|
554
|
-
* @returns Permittee details with
|
|
581
|
+
* @returns Permittee details with quota info
|
|
555
582
|
*/
|
|
556
|
-
async
|
|
583
|
+
async getWithQuota(permitNumber) {
|
|
557
584
|
try {
|
|
558
585
|
const result = await this.client.request(
|
|
559
586
|
"GET",
|
|
560
587
|
`/permittees/${encodeURIComponent(permitNumber)}`
|
|
561
588
|
);
|
|
562
|
-
return { data: result.data.data,
|
|
589
|
+
return { data: result.data.data, quota: result.quota };
|
|
563
590
|
} catch (error) {
|
|
564
591
|
if (error instanceof NotFoundError) {
|
|
565
592
|
throw new NotFoundError("Permittee", permitNumber);
|
|
@@ -584,7 +611,7 @@ var PermitteesResource = class {
|
|
|
584
611
|
params,
|
|
585
612
|
fetchPage: async (p) => {
|
|
586
613
|
const result = await this.client.request("GET", "/permittees", p);
|
|
587
|
-
return { response: result.data,
|
|
614
|
+
return { response: result.data, quota: result.quota };
|
|
588
615
|
}
|
|
589
616
|
});
|
|
590
617
|
}
|
|
@@ -610,14 +637,14 @@ var BarcodesResource = class {
|
|
|
610
637
|
}
|
|
611
638
|
}
|
|
612
639
|
/**
|
|
613
|
-
* Look up barcode with
|
|
640
|
+
* Look up barcode with quota information
|
|
614
641
|
* @param barcodeValue The barcode to search for
|
|
615
|
-
* @returns Barcode lookup result with
|
|
642
|
+
* @returns Barcode lookup result with quota info
|
|
616
643
|
*/
|
|
617
|
-
async
|
|
644
|
+
async lookupWithQuota(barcodeValue) {
|
|
618
645
|
try {
|
|
619
646
|
const result = await this.client.request("GET", `/barcode/${encodeURIComponent(barcodeValue)}`);
|
|
620
|
-
return { data: result.data.data,
|
|
647
|
+
return { data: result.data.data, quota: result.quota };
|
|
621
648
|
} catch (error) {
|
|
622
649
|
if (error instanceof NotFoundError) {
|
|
623
650
|
throw new NotFoundError("Barcode", barcodeValue);
|
|
@@ -642,15 +669,95 @@ var UsageResource = class {
|
|
|
642
669
|
return result.data.data;
|
|
643
670
|
}
|
|
644
671
|
/**
|
|
645
|
-
* Get usage statistics with
|
|
646
|
-
* @returns Usage statistics with
|
|
672
|
+
* Get usage statistics with quota information
|
|
673
|
+
* @returns Usage statistics with quota info
|
|
647
674
|
*/
|
|
648
|
-
async
|
|
675
|
+
async getWithQuota() {
|
|
649
676
|
const result = await this.client.request(
|
|
650
677
|
"GET",
|
|
651
678
|
"/usage"
|
|
652
679
|
);
|
|
653
|
-
return { data: result.data.data,
|
|
680
|
+
return { data: result.data.data, quota: result.quota };
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
var ProcessingTimesResource = class {
|
|
684
|
+
constructor(client) {
|
|
685
|
+
this.client = client;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Get processing times overview
|
|
689
|
+
* @param params Optional filter parameters
|
|
690
|
+
* @returns Processing times data with total count
|
|
691
|
+
*/
|
|
692
|
+
async list(params = {}) {
|
|
693
|
+
const result = await this.client.request("GET", "/processing-times", params);
|
|
694
|
+
return result.data;
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Get formula processing times
|
|
698
|
+
* @param params Optional filter parameters
|
|
699
|
+
* @returns Formula processing times data with total count
|
|
700
|
+
*/
|
|
701
|
+
async formula(params = {}) {
|
|
702
|
+
const result = await this.client.request("GET", "/processing-times/formula", params);
|
|
703
|
+
return result.data;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Get registration processing times
|
|
707
|
+
* @param params Optional filter parameters
|
|
708
|
+
* @returns Registration processing times data with total count
|
|
709
|
+
*/
|
|
710
|
+
async registration(params = {}) {
|
|
711
|
+
const result = await this.client.request(
|
|
712
|
+
"GET",
|
|
713
|
+
"/processing-times/registration",
|
|
714
|
+
params
|
|
715
|
+
);
|
|
716
|
+
return result.data;
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
var ProductionReportsResource = class {
|
|
720
|
+
constructor(client) {
|
|
721
|
+
this.client = client;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* List production reports with pagination
|
|
725
|
+
* @param params Filter and pagination parameters
|
|
726
|
+
* @returns Paginated production reports data
|
|
727
|
+
*/
|
|
728
|
+
async list(params = {}) {
|
|
729
|
+
const result = await this.client.request("GET", "/production-reports", params);
|
|
730
|
+
return result.data;
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
var AvasResource = class {
|
|
734
|
+
constructor(client) {
|
|
735
|
+
this.client = client;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* List and search AVAs
|
|
739
|
+
* @param params Optional filter parameters
|
|
740
|
+
* @returns AVA data with total count
|
|
741
|
+
*/
|
|
742
|
+
async list(params = {}) {
|
|
743
|
+
const result = await this.client.request("GET", "/avas", params);
|
|
744
|
+
return result.data;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Get a single AVA by ID
|
|
748
|
+
* @param avaId The unique AVA identifier
|
|
749
|
+
* @returns Full AVA details
|
|
750
|
+
*/
|
|
751
|
+
async get(avaId) {
|
|
752
|
+
try {
|
|
753
|
+
const result = await this.client.request("GET", `/avas/${encodeURIComponent(avaId)}`);
|
|
754
|
+
return result.data.data;
|
|
755
|
+
} catch (error) {
|
|
756
|
+
if (error instanceof NotFoundError) {
|
|
757
|
+
throw new NotFoundError("AVA", avaId);
|
|
758
|
+
}
|
|
759
|
+
throw error;
|
|
760
|
+
}
|
|
654
761
|
}
|
|
655
762
|
};
|
|
656
763
|
// Annotate the CommonJS export names for ESM import in node:
|