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.mjs
CHANGED
|
@@ -38,14 +38,14 @@ var AuthenticationError = class _AuthenticationError extends ColaCloudError {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
var RateLimitError = class _RateLimitError extends ColaCloudError {
|
|
41
|
-
/**
|
|
42
|
-
|
|
41
|
+
/** Quota information from headers */
|
|
42
|
+
quota;
|
|
43
43
|
/** Seconds until the rate limit resets */
|
|
44
44
|
retryAfter;
|
|
45
|
-
constructor(message = "Rate limit exceeded",
|
|
45
|
+
constructor(message = "Rate limit exceeded", quota = null, retryAfter = null) {
|
|
46
46
|
super(message, 429, "rate_limit_exceeded");
|
|
47
47
|
this.name = "RateLimitError";
|
|
48
|
-
this.
|
|
48
|
+
this.quota = quota;
|
|
49
49
|
this.retryAfter = retryAfter;
|
|
50
50
|
if (Error.captureStackTrace) {
|
|
51
51
|
Error.captureStackTrace(this, _RateLimitError);
|
|
@@ -131,9 +131,15 @@ function createPaginatedIterator(options) {
|
|
|
131
131
|
done = true;
|
|
132
132
|
break;
|
|
133
133
|
}
|
|
134
|
-
if (pagination !== null
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
if (pagination !== null) {
|
|
135
|
+
if (pagination.has_more === false) {
|
|
136
|
+
done = true;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (pagination.pages !== null && currentPage > pagination.pages) {
|
|
140
|
+
done = true;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
137
143
|
}
|
|
138
144
|
const result = await fetchPage({
|
|
139
145
|
...params,
|
|
@@ -171,7 +177,7 @@ function createPaginatedIteratorWithMetadata(options) {
|
|
|
171
177
|
let currentItems = [];
|
|
172
178
|
let currentIndex = 0;
|
|
173
179
|
let pagination = null;
|
|
174
|
-
let
|
|
180
|
+
let quota = null;
|
|
175
181
|
let pagesFetched = 0;
|
|
176
182
|
let done = false;
|
|
177
183
|
return {
|
|
@@ -181,16 +187,22 @@ function createPaginatedIteratorWithMetadata(options) {
|
|
|
181
187
|
done = true;
|
|
182
188
|
break;
|
|
183
189
|
}
|
|
184
|
-
if (pagination !== null
|
|
185
|
-
|
|
186
|
-
|
|
190
|
+
if (pagination !== null) {
|
|
191
|
+
if (pagination.has_more === false) {
|
|
192
|
+
done = true;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (pagination.pages !== null && currentPage > pagination.pages) {
|
|
196
|
+
done = true;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
187
199
|
}
|
|
188
200
|
const result = await fetchPage({
|
|
189
201
|
...params,
|
|
190
202
|
page: currentPage
|
|
191
203
|
});
|
|
192
204
|
pagination = result.response.pagination;
|
|
193
|
-
|
|
205
|
+
quota = result.quota;
|
|
194
206
|
currentItems = result.response.data;
|
|
195
207
|
currentIndex = 0;
|
|
196
208
|
currentPage++;
|
|
@@ -211,7 +223,7 @@ function createPaginatedIteratorWithMetadata(options) {
|
|
|
211
223
|
// We already incremented after fetch
|
|
212
224
|
indexInPage: currentIndex,
|
|
213
225
|
total: pagination?.total ?? 0,
|
|
214
|
-
|
|
226
|
+
quota
|
|
215
227
|
};
|
|
216
228
|
currentIndex++;
|
|
217
229
|
return { done: false, value: result };
|
|
@@ -248,14 +260,20 @@ function toSnakeCase(params) {
|
|
|
248
260
|
}
|
|
249
261
|
return result;
|
|
250
262
|
}
|
|
251
|
-
function
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
263
|
+
function parseQuotaHeaders(headers) {
|
|
264
|
+
const reset = headers.get("X-Quota-Reset");
|
|
265
|
+
if (reset === null) return null;
|
|
266
|
+
let limit = headers.get("X-Detail-Views-Limit");
|
|
267
|
+
let remaining = headers.get("X-Detail-Views-Remaining");
|
|
268
|
+
let meter = "detail_views";
|
|
269
|
+
if (limit === null) {
|
|
270
|
+
limit = headers.get("X-List-Records-Limit");
|
|
271
|
+
remaining = headers.get("X-List-Records-Remaining");
|
|
272
|
+
meter = "list_records";
|
|
273
|
+
}
|
|
274
|
+
if (limit === null || remaining === null) return null;
|
|
258
275
|
return {
|
|
276
|
+
meter,
|
|
259
277
|
limit: parseInt(limit, 10),
|
|
260
278
|
remaining: parseInt(remaining, 10),
|
|
261
279
|
reset: parseInt(reset, 10)
|
|
@@ -273,6 +291,12 @@ var ColaCloud = class {
|
|
|
273
291
|
barcodes;
|
|
274
292
|
/** Usage statistics endpoint */
|
|
275
293
|
usage;
|
|
294
|
+
/** Processing times reference data endpoints */
|
|
295
|
+
processingTimes;
|
|
296
|
+
/** Production reports reference data endpoints */
|
|
297
|
+
productionReports;
|
|
298
|
+
/** AVA (American Viticultural Area) reference data endpoints */
|
|
299
|
+
avas;
|
|
276
300
|
/**
|
|
277
301
|
* Create a new COLA Cloud API client
|
|
278
302
|
* @param config Configuration options
|
|
@@ -288,6 +312,9 @@ var ColaCloud = class {
|
|
|
288
312
|
this.permittees = new PermitteesResource(this);
|
|
289
313
|
this.barcodes = new BarcodesResource(this);
|
|
290
314
|
this.usage = new UsageResource(this);
|
|
315
|
+
this.processingTimes = new ProcessingTimesResource(this);
|
|
316
|
+
this.productionReports = new ProductionReportsResource(this);
|
|
317
|
+
this.avas = new AvasResource(this);
|
|
291
318
|
}
|
|
292
319
|
/**
|
|
293
320
|
* Make an authenticated request to the API
|
|
@@ -312,12 +339,12 @@ var ColaCloud = class {
|
|
|
312
339
|
signal: controller.signal
|
|
313
340
|
});
|
|
314
341
|
clearTimeout(timeoutId);
|
|
315
|
-
const
|
|
342
|
+
const quota = parseQuotaHeaders(response.headers);
|
|
316
343
|
if (!response.ok) {
|
|
317
|
-
await this.handleErrorResponse(response,
|
|
344
|
+
await this.handleErrorResponse(response, quota);
|
|
318
345
|
}
|
|
319
346
|
const data = await response.json();
|
|
320
|
-
return { data,
|
|
347
|
+
return { data, quota };
|
|
321
348
|
} catch (error) {
|
|
322
349
|
clearTimeout(timeoutId);
|
|
323
350
|
if (error instanceof Error && error.name === "AbortError") {
|
|
@@ -335,7 +362,7 @@ var ColaCloud = class {
|
|
|
335
362
|
/**
|
|
336
363
|
* Handle error responses from the API
|
|
337
364
|
*/
|
|
338
|
-
async handleErrorResponse(response,
|
|
365
|
+
async handleErrorResponse(response, quota) {
|
|
339
366
|
let errorData;
|
|
340
367
|
try {
|
|
341
368
|
errorData = await response.json();
|
|
@@ -352,7 +379,7 @@ var ColaCloud = class {
|
|
|
352
379
|
const retryAfter = response.headers.get("Retry-After");
|
|
353
380
|
throw new RateLimitError(
|
|
354
381
|
message,
|
|
355
|
-
|
|
382
|
+
quota,
|
|
356
383
|
retryAfter ? parseInt(retryAfter, 10) : null
|
|
357
384
|
);
|
|
358
385
|
}
|
|
@@ -387,11 +414,11 @@ var ColasResource = class {
|
|
|
387
414
|
return result.data;
|
|
388
415
|
}
|
|
389
416
|
/**
|
|
390
|
-
* List COLAs with
|
|
417
|
+
* List COLAs with quota information
|
|
391
418
|
* @param params Search and filter parameters
|
|
392
|
-
* @returns Paginated list with
|
|
419
|
+
* @returns Paginated list with quota info
|
|
393
420
|
*/
|
|
394
|
-
async
|
|
421
|
+
async listWithQuota(params = {}) {
|
|
395
422
|
return this.client.request(
|
|
396
423
|
"GET",
|
|
397
424
|
"/colas",
|
|
@@ -418,17 +445,17 @@ var ColasResource = class {
|
|
|
418
445
|
}
|
|
419
446
|
}
|
|
420
447
|
/**
|
|
421
|
-
* Get a single COLA with
|
|
448
|
+
* Get a single COLA with quota information
|
|
422
449
|
* @param ttbId The unique TTB identifier
|
|
423
|
-
* @returns COLA details with
|
|
450
|
+
* @returns COLA details with quota info
|
|
424
451
|
*/
|
|
425
|
-
async
|
|
452
|
+
async getWithQuota(ttbId) {
|
|
426
453
|
try {
|
|
427
454
|
const result = await this.client.request(
|
|
428
455
|
"GET",
|
|
429
456
|
`/colas/${encodeURIComponent(ttbId)}`
|
|
430
457
|
);
|
|
431
|
-
return { data: result.data.data,
|
|
458
|
+
return { data: result.data.data, quota: result.quota };
|
|
432
459
|
} catch (error) {
|
|
433
460
|
if (error instanceof NotFoundError) {
|
|
434
461
|
throw new NotFoundError("COLA", ttbId);
|
|
@@ -457,7 +484,7 @@ var ColasResource = class {
|
|
|
457
484
|
"/colas",
|
|
458
485
|
p
|
|
459
486
|
);
|
|
460
|
-
return { response: result.data,
|
|
487
|
+
return { response: result.data, quota: result.quota };
|
|
461
488
|
}
|
|
462
489
|
});
|
|
463
490
|
}
|
|
@@ -480,11 +507,11 @@ var PermitteesResource = class {
|
|
|
480
507
|
return result.data;
|
|
481
508
|
}
|
|
482
509
|
/**
|
|
483
|
-
* List permittees with
|
|
510
|
+
* List permittees with quota information
|
|
484
511
|
* @param params Search and filter parameters
|
|
485
|
-
* @returns Paginated list with
|
|
512
|
+
* @returns Paginated list with quota info
|
|
486
513
|
*/
|
|
487
|
-
async
|
|
514
|
+
async listWithQuota(params = {}) {
|
|
488
515
|
return this.client.request(
|
|
489
516
|
"GET",
|
|
490
517
|
"/permittees",
|
|
@@ -511,17 +538,17 @@ var PermitteesResource = class {
|
|
|
511
538
|
}
|
|
512
539
|
}
|
|
513
540
|
/**
|
|
514
|
-
* Get a single permittee with
|
|
541
|
+
* Get a single permittee with quota information
|
|
515
542
|
* @param permitNumber The unique permit number
|
|
516
|
-
* @returns Permittee details with
|
|
543
|
+
* @returns Permittee details with quota info
|
|
517
544
|
*/
|
|
518
|
-
async
|
|
545
|
+
async getWithQuota(permitNumber) {
|
|
519
546
|
try {
|
|
520
547
|
const result = await this.client.request(
|
|
521
548
|
"GET",
|
|
522
549
|
`/permittees/${encodeURIComponent(permitNumber)}`
|
|
523
550
|
);
|
|
524
|
-
return { data: result.data.data,
|
|
551
|
+
return { data: result.data.data, quota: result.quota };
|
|
525
552
|
} catch (error) {
|
|
526
553
|
if (error instanceof NotFoundError) {
|
|
527
554
|
throw new NotFoundError("Permittee", permitNumber);
|
|
@@ -546,7 +573,7 @@ var PermitteesResource = class {
|
|
|
546
573
|
params,
|
|
547
574
|
fetchPage: async (p) => {
|
|
548
575
|
const result = await this.client.request("GET", "/permittees", p);
|
|
549
|
-
return { response: result.data,
|
|
576
|
+
return { response: result.data, quota: result.quota };
|
|
550
577
|
}
|
|
551
578
|
});
|
|
552
579
|
}
|
|
@@ -572,14 +599,14 @@ var BarcodesResource = class {
|
|
|
572
599
|
}
|
|
573
600
|
}
|
|
574
601
|
/**
|
|
575
|
-
* Look up barcode with
|
|
602
|
+
* Look up barcode with quota information
|
|
576
603
|
* @param barcodeValue The barcode to search for
|
|
577
|
-
* @returns Barcode lookup result with
|
|
604
|
+
* @returns Barcode lookup result with quota info
|
|
578
605
|
*/
|
|
579
|
-
async
|
|
606
|
+
async lookupWithQuota(barcodeValue) {
|
|
580
607
|
try {
|
|
581
608
|
const result = await this.client.request("GET", `/barcode/${encodeURIComponent(barcodeValue)}`);
|
|
582
|
-
return { data: result.data.data,
|
|
609
|
+
return { data: result.data.data, quota: result.quota };
|
|
583
610
|
} catch (error) {
|
|
584
611
|
if (error instanceof NotFoundError) {
|
|
585
612
|
throw new NotFoundError("Barcode", barcodeValue);
|
|
@@ -604,15 +631,95 @@ var UsageResource = class {
|
|
|
604
631
|
return result.data.data;
|
|
605
632
|
}
|
|
606
633
|
/**
|
|
607
|
-
* Get usage statistics with
|
|
608
|
-
* @returns Usage statistics with
|
|
634
|
+
* Get usage statistics with quota information
|
|
635
|
+
* @returns Usage statistics with quota info
|
|
609
636
|
*/
|
|
610
|
-
async
|
|
637
|
+
async getWithQuota() {
|
|
611
638
|
const result = await this.client.request(
|
|
612
639
|
"GET",
|
|
613
640
|
"/usage"
|
|
614
641
|
);
|
|
615
|
-
return { data: result.data.data,
|
|
642
|
+
return { data: result.data.data, quota: result.quota };
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
var ProcessingTimesResource = class {
|
|
646
|
+
constructor(client) {
|
|
647
|
+
this.client = client;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Get processing times overview
|
|
651
|
+
* @param params Optional filter parameters
|
|
652
|
+
* @returns Processing times data with total count
|
|
653
|
+
*/
|
|
654
|
+
async list(params = {}) {
|
|
655
|
+
const result = await this.client.request("GET", "/processing-times", params);
|
|
656
|
+
return result.data;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Get formula processing times
|
|
660
|
+
* @param params Optional filter parameters
|
|
661
|
+
* @returns Formula processing times data with total count
|
|
662
|
+
*/
|
|
663
|
+
async formula(params = {}) {
|
|
664
|
+
const result = await this.client.request("GET", "/processing-times/formula", params);
|
|
665
|
+
return result.data;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Get registration processing times
|
|
669
|
+
* @param params Optional filter parameters
|
|
670
|
+
* @returns Registration processing times data with total count
|
|
671
|
+
*/
|
|
672
|
+
async registration(params = {}) {
|
|
673
|
+
const result = await this.client.request(
|
|
674
|
+
"GET",
|
|
675
|
+
"/processing-times/registration",
|
|
676
|
+
params
|
|
677
|
+
);
|
|
678
|
+
return result.data;
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
var ProductionReportsResource = class {
|
|
682
|
+
constructor(client) {
|
|
683
|
+
this.client = client;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* List production reports with pagination
|
|
687
|
+
* @param params Filter and pagination parameters
|
|
688
|
+
* @returns Paginated production reports data
|
|
689
|
+
*/
|
|
690
|
+
async list(params = {}) {
|
|
691
|
+
const result = await this.client.request("GET", "/production-reports", params);
|
|
692
|
+
return result.data;
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
var AvasResource = class {
|
|
696
|
+
constructor(client) {
|
|
697
|
+
this.client = client;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* List and search AVAs
|
|
701
|
+
* @param params Optional filter parameters
|
|
702
|
+
* @returns AVA data with total count
|
|
703
|
+
*/
|
|
704
|
+
async list(params = {}) {
|
|
705
|
+
const result = await this.client.request("GET", "/avas", params);
|
|
706
|
+
return result.data;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Get a single AVA by ID
|
|
710
|
+
* @param avaId The unique AVA identifier
|
|
711
|
+
* @returns Full AVA details
|
|
712
|
+
*/
|
|
713
|
+
async get(avaId) {
|
|
714
|
+
try {
|
|
715
|
+
const result = await this.client.request("GET", `/avas/${encodeURIComponent(avaId)}`);
|
|
716
|
+
return result.data.data;
|
|
717
|
+
} catch (error) {
|
|
718
|
+
if (error instanceof NotFoundError) {
|
|
719
|
+
throw new NotFoundError("AVA", avaId);
|
|
720
|
+
}
|
|
721
|
+
throw error;
|
|
722
|
+
}
|
|
616
723
|
}
|
|
617
724
|
};
|
|
618
725
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "colacloud",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Official JavaScript/TypeScript SDK for the COLA Cloud API - access the TTB COLA Registry of alcohol product label approvals",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|