@proveanything/smartlinks 1.3.20 → 1.3.21

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.
@@ -1,4 +1,4 @@
1
- import { BatchResponse, BatchCreateRequest, BatchUpdateRequest } from "../types/batch";
1
+ import { BatchResponse, BatchCreateRequest, BatchUpdateRequest, SearchBatchesRequest, BatchTag } from "../types/batch";
2
2
  export declare namespace batch {
3
3
  /**
4
4
  * Get a single batch by ID for a collection and product (admin only).
@@ -75,4 +75,84 @@ export declare namespace batch {
75
75
  * @throws ErrorResponse if the request fails
76
76
  */
77
77
  function lookupSN(collectionId: string, productId: string, batchId: string, codeId: string): Promise<any>;
78
+ /**
79
+ * Search for batches across all products in a collection.
80
+ * Allows searching by batch ID or name, with optional product filtering.
81
+ *
82
+ * @param collectionId - Identifier of the collection
83
+ * @param params - Optional search parameters (search term, productId filter, limit)
84
+ * @returns Promise resolving to an array of matching BatchResponse objects
85
+ * @throws ErrorResponse if the request fails
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Search for batches containing "2024"
90
+ * const batches = await batch.searchInCollection('coll_123', {
91
+ * search: 'BATCH-2024',
92
+ * limit: 50
93
+ * })
94
+ *
95
+ * // Filter batches for a specific product
96
+ * const productBatches = await batch.searchInCollection('coll_123', {
97
+ * productId: 'prod_abc',
98
+ * limit: 100
99
+ * })
100
+ *
101
+ * // Get all batches in collection
102
+ * const allBatches = await batch.searchInCollection('coll_123')
103
+ *
104
+ * // Check for expired batches
105
+ * batches.forEach(batch => {
106
+ * if (batch.expiryDate?.seconds) {
107
+ * const expiryDate = new Date(batch.expiryDate.seconds * 1000)
108
+ * if (expiryDate < new Date()) {
109
+ * console.log(`Batch ${batch.id} is expired`)
110
+ * }
111
+ * }
112
+ * })
113
+ * ```
114
+ */
115
+ function searchInCollection(collectionId: string, params?: SearchBatchesRequest): Promise<BatchResponse[]>;
116
+ /**
117
+ * Find a specific batch by ID across all products in a collection.
118
+ * Returns the batch along with the productId it belongs to.
119
+ *
120
+ * @param collectionId - Identifier of the collection
121
+ * @param batchId - Batch ID to find
122
+ * @returns Promise resolving to a BatchResponse with productId
123
+ * @throws ErrorResponse if the request fails (404 if not found)
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // Find which product contains a specific batch
128
+ * const batch = await batch.findInCollection('coll_123', 'BATCH-2024-001')
129
+ * console.log(`Batch found in product: ${batch.productId}`)
130
+ * console.log(`Expires: ${batch.expiryDate}`)
131
+ * ```
132
+ */
133
+ function findInCollection(collectionId: string, batchId: string): Promise<BatchResponse>;
134
+ /**
135
+ * Get all tags/codes assigned to a specific batch.
136
+ * Shows which claim set codes have been assigned to this batch.
137
+ *
138
+ * @param collectionId - Identifier of the collection
139
+ * @param batchId - Batch ID
140
+ * @param claimSetId - Optional claim set ID to filter results
141
+ * @returns Promise resolving to an array of BatchTag objects
142
+ * @throws ErrorResponse if the request fails
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * // Get all tags assigned to a batch
147
+ * const tags = await batch.getBatchTags('coll_123', 'BATCH-2024-001')
148
+ * console.log(`Batch has ${tags.length} tags assigned`)
149
+ * tags.forEach(tag => {
150
+ * console.log(`Code: ${tag.code}, ClaimSet: ${tag.claimSetId}, TagID: ${tag.tagId}`)
151
+ * })
152
+ *
153
+ * // Get tags from a specific claim set
154
+ * const claimSetTags = await batch.getBatchTags('coll_123', 'BATCH-2024-001', '000001')
155
+ * ```
156
+ */
157
+ function getBatchTags(collectionId: string, batchId: string, claimSetId?: string): Promise<BatchTag[]>;
78
158
  }
package/dist/api/batch.js CHANGED
@@ -115,4 +115,108 @@ export var batch;
115
115
  return request(path);
116
116
  }
117
117
  batch.lookupSN = lookupSN;
118
+ /**
119
+ * Search for batches across all products in a collection.
120
+ * Allows searching by batch ID or name, with optional product filtering.
121
+ *
122
+ * @param collectionId - Identifier of the collection
123
+ * @param params - Optional search parameters (search term, productId filter, limit)
124
+ * @returns Promise resolving to an array of matching BatchResponse objects
125
+ * @throws ErrorResponse if the request fails
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // Search for batches containing "2024"
130
+ * const batches = await batch.searchInCollection('coll_123', {
131
+ * search: 'BATCH-2024',
132
+ * limit: 50
133
+ * })
134
+ *
135
+ * // Filter batches for a specific product
136
+ * const productBatches = await batch.searchInCollection('coll_123', {
137
+ * productId: 'prod_abc',
138
+ * limit: 100
139
+ * })
140
+ *
141
+ * // Get all batches in collection
142
+ * const allBatches = await batch.searchInCollection('coll_123')
143
+ *
144
+ * // Check for expired batches
145
+ * batches.forEach(batch => {
146
+ * if (batch.expiryDate?.seconds) {
147
+ * const expiryDate = new Date(batch.expiryDate.seconds * 1000)
148
+ * if (expiryDate < new Date()) {
149
+ * console.log(`Batch ${batch.id} is expired`)
150
+ * }
151
+ * }
152
+ * })
153
+ * ```
154
+ */
155
+ async function searchInCollection(collectionId, params) {
156
+ const queryParams = new URLSearchParams();
157
+ if (params === null || params === void 0 ? void 0 : params.search)
158
+ queryParams.append('search', params.search);
159
+ if (params === null || params === void 0 ? void 0 : params.productId)
160
+ queryParams.append('productId', params.productId);
161
+ if (params === null || params === void 0 ? void 0 : params.limit)
162
+ queryParams.append('limit', params.limit.toString());
163
+ const query = queryParams.toString();
164
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/batch${query ? `?${query}` : ''}`;
165
+ return request(path);
166
+ }
167
+ batch.searchInCollection = searchInCollection;
168
+ /**
169
+ * Find a specific batch by ID across all products in a collection.
170
+ * Returns the batch along with the productId it belongs to.
171
+ *
172
+ * @param collectionId - Identifier of the collection
173
+ * @param batchId - Batch ID to find
174
+ * @returns Promise resolving to a BatchResponse with productId
175
+ * @throws ErrorResponse if the request fails (404 if not found)
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * // Find which product contains a specific batch
180
+ * const batch = await batch.findInCollection('coll_123', 'BATCH-2024-001')
181
+ * console.log(`Batch found in product: ${batch.productId}`)
182
+ * console.log(`Expires: ${batch.expiryDate}`)
183
+ * ```
184
+ */
185
+ async function findInCollection(collectionId, batchId) {
186
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/batch/${encodeURIComponent(batchId)}`;
187
+ return request(path);
188
+ }
189
+ batch.findInCollection = findInCollection;
190
+ /**
191
+ * Get all tags/codes assigned to a specific batch.
192
+ * Shows which claim set codes have been assigned to this batch.
193
+ *
194
+ * @param collectionId - Identifier of the collection
195
+ * @param batchId - Batch ID
196
+ * @param claimSetId - Optional claim set ID to filter results
197
+ * @returns Promise resolving to an array of BatchTag objects
198
+ * @throws ErrorResponse if the request fails
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * // Get all tags assigned to a batch
203
+ * const tags = await batch.getBatchTags('coll_123', 'BATCH-2024-001')
204
+ * console.log(`Batch has ${tags.length} tags assigned`)
205
+ * tags.forEach(tag => {
206
+ * console.log(`Code: ${tag.code}, ClaimSet: ${tag.claimSetId}, TagID: ${tag.tagId}`)
207
+ * })
208
+ *
209
+ * // Get tags from a specific claim set
210
+ * const claimSetTags = await batch.getBatchTags('coll_123', 'BATCH-2024-001', '000001')
211
+ * ```
212
+ */
213
+ async function getBatchTags(collectionId, batchId, claimSetId) {
214
+ const queryParams = new URLSearchParams();
215
+ if (claimSetId)
216
+ queryParams.append('claimSetId', claimSetId);
217
+ const query = queryParams.toString();
218
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/batch/${encodeURIComponent(batchId)}/tags${query ? `?${query}` : ''}`;
219
+ return request(path);
220
+ }
221
+ batch.getBatchTags = getBatchTags;
118
222
  })(batch || (batch = {}));
@@ -1,4 +1,4 @@
1
- import { CreateOrderRequest, CreateOrderResponse, GetOrderParams, GetOrderResponse, UpdateOrderRequest, UpdateOrderResponse, DeleteOrderResponse, ListOrdersRequest, ListOrdersResponse, GetOrderItemsParams, GetOrderItemsResponse, AddItemsRequest, AddItemsResponse, RemoveItemsRequest, RemoveItemsResponse, QueryOrdersRequest, QueryOrdersResponse, ReportsParams, ReportsResponse, LookupOrdersRequest, LookupOrdersResponse, LookupByProductParams, LookupByProductResponse, OrderAnalyticsResponse, TimelineRequest, TimelineResponse, LocationRequest, LocationResponse, BulkAnalyticsRequest, BulkAnalyticsResponse, SummaryRequest, CollectionSummaryResponse } from "../types/order";
1
+ import { CreateOrderRequest, CreateOrderResponse, GetOrderParams, GetOrderResponse, UpdateOrderRequest, UpdateOrderResponse, DeleteOrderResponse, ListOrdersRequest, ListOrdersResponse, GetOrderItemsParams, GetOrderItemsResponse, AddItemsRequest, AddItemsResponse, RemoveItemsRequest, RemoveItemsResponse, QueryOrdersRequest, QueryOrdersResponse, ReportsParams, ReportsResponse, LookupOrdersRequest, LookupOrdersResponse, LookupByProductParams, LookupByProductResponse, OrderAnalyticsResponse, TimelineRequest, TimelineResponse, LocationRequest, LocationResponse, BulkAnalyticsRequest, BulkAnalyticsResponse, SummaryRequest, CollectionSummaryResponse, FindOrdersByAttributeParams, FindOrdersByAttributeResponse, FindItemsByAttributeParams, FindItemsByAttributeResponse, GetOrderIdsParams, GetOrderIdsResponse } from "../types/order";
2
2
  /**
3
3
  * Order Management API
4
4
  *
@@ -443,4 +443,169 @@ export declare namespace order {
443
443
  * ```
444
444
  */
445
445
  function getCollectionSummary(collectionId: string, params?: SummaryRequest): Promise<CollectionSummaryResponse>;
446
+ /**
447
+ * Find all orders containing items from a specific batch.
448
+ * Uses indexed queries for fast lookups across order items.
449
+ *
450
+ * @param collectionId - Identifier of the parent collection
451
+ * @param batchId - Batch ID to search for
452
+ * @param params - Optional pagination and includeItems parameters
453
+ * @returns Promise resolving to a FindOrdersByAttributeResponse
454
+ * @throws ErrorResponse if the request fails
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * // Find orders with items from a specific batch
459
+ * const { orders } = await order.findByBatch('coll_123', 'BATCH-2024-001', {
460
+ * includeItems: true,
461
+ * limit: 50
462
+ * })
463
+ *
464
+ * // Get unique customers who received this batch
465
+ * const customers = [...new Set(orders.map(o => o.customerId).filter(Boolean))]
466
+ * console.log(`Batch delivered to ${customers.length} customers`)
467
+ * ```
468
+ */
469
+ function findByBatch(collectionId: string, batchId: string, params?: FindOrdersByAttributeParams): Promise<FindOrdersByAttributeResponse>;
470
+ /**
471
+ * Find all orders containing items from a specific product.
472
+ * Uses indexed queries for fast lookups across order items.
473
+ *
474
+ * @param collectionId - Identifier of the parent collection
475
+ * @param productId - Product ID to search for
476
+ * @param params - Optional pagination and includeItems parameters
477
+ * @returns Promise resolving to a FindOrdersByAttributeResponse
478
+ * @throws ErrorResponse if the request fails
479
+ *
480
+ * @example
481
+ * ```typescript
482
+ * // Find all orders containing a product
483
+ * const { orders, limit, offset } = await order.findOrdersByProduct('coll_123', 'prod_789', {
484
+ * limit: 100
485
+ * })
486
+ *
487
+ * console.log(`Product appears in ${orders.length} orders`)
488
+ * ```
489
+ */
490
+ function findOrdersByProduct(collectionId: string, productId: string, params?: FindOrdersByAttributeParams): Promise<FindOrdersByAttributeResponse>;
491
+ /**
492
+ * Find all orders containing items from a specific variant.
493
+ * Uses indexed queries for fast lookups across order items.
494
+ *
495
+ * @param collectionId - Identifier of the parent collection
496
+ * @param variantId - Variant ID to search for
497
+ * @param params - Optional pagination and includeItems parameters
498
+ * @returns Promise resolving to a FindOrdersByAttributeResponse
499
+ * @throws ErrorResponse if the request fails
500
+ *
501
+ * @example
502
+ * ```typescript
503
+ * // Find orders with a specific variant
504
+ * const { orders } = await order.findByVariant('coll_123', 'var_456', {
505
+ * includeItems: true
506
+ * })
507
+ *
508
+ * console.log(`Variant ${variantId} in ${orders.length} orders`)
509
+ * ```
510
+ */
511
+ function findByVariant(collectionId: string, variantId: string, params?: FindOrdersByAttributeParams): Promise<FindOrdersByAttributeResponse>;
512
+ /**
513
+ * Get individual order items (not full orders) for a specific batch.
514
+ * Returns all matching items with optional order summary.
515
+ *
516
+ * @param collectionId - Identifier of the parent collection
517
+ * @param batchId - Batch ID to search for
518
+ * @param params - Optional pagination and includeOrder parameters
519
+ * @returns Promise resolving to a FindItemsByAttributeResponse
520
+ * @throws ErrorResponse if the request fails
521
+ *
522
+ * @example
523
+ * ```typescript
524
+ * // Get items from a batch with order info
525
+ * const { items, count } = await order.findItemsByBatch('coll_123', 'BATCH-2024-001', {
526
+ * includeOrder: true,
527
+ * limit: 100
528
+ * })
529
+ *
530
+ * // Group by order status
531
+ * const byStatus = items.reduce((acc, item) => {
532
+ * const status = item.order?.status || 'unknown'
533
+ * acc[status] = (acc[status] || 0) + 1
534
+ * return acc
535
+ * }, {})
536
+ * ```
537
+ */
538
+ function findItemsByBatch(collectionId: string, batchId: string, params?: FindItemsByAttributeParams): Promise<FindItemsByAttributeResponse>;
539
+ /**
540
+ * Get individual order items for a specific product.
541
+ * Returns all matching items with optional order summary.
542
+ *
543
+ * @param collectionId - Identifier of the parent collection
544
+ * @param productId - Product ID to search for
545
+ * @param params - Optional pagination and includeOrder parameters
546
+ * @returns Promise resolving to a FindItemsByAttributeResponse
547
+ * @throws ErrorResponse if the request fails
548
+ *
549
+ * @example
550
+ * ```typescript
551
+ * // Get all items for a product
552
+ * const { items } = await order.findItemsByProduct('coll_123', 'prod_789', {
553
+ * includeOrder: true
554
+ * })
555
+ *
556
+ * console.log(`Product delivered in ${items.length} order items`)
557
+ * ```
558
+ */
559
+ function findItemsByProduct(collectionId: string, productId: string, params?: FindItemsByAttributeParams): Promise<FindItemsByAttributeResponse>;
560
+ /**
561
+ * Get individual order items for a specific variant.
562
+ * Returns all matching items with optional order summary.
563
+ *
564
+ * @param collectionId - Identifier of the parent collection
565
+ * @param variantId - Variant ID to search for
566
+ * @param params - Optional pagination and includeOrder parameters
567
+ * @returns Promise resolving to a FindItemsByAttributeResponse
568
+ * @throws ErrorResponse if the request fails
569
+ *
570
+ * @example
571
+ * ```typescript
572
+ * // Get variant items with order details
573
+ * const { items, count } = await order.findItemsByVariant('coll_123', 'var_456', {
574
+ * includeOrder: true,
575
+ * limit: 50
576
+ * })
577
+ * ```
578
+ */
579
+ function findItemsByVariant(collectionId: string, variantId: string, params?: FindItemsByAttributeParams): Promise<FindItemsByAttributeResponse>;
580
+ /**
581
+ * Get unique order IDs containing items matching the specified attribute.
582
+ * Lightweight query that only returns order IDs, not full order objects.
583
+ *
584
+ * @param collectionId - Identifier of the parent collection
585
+ * @param attribute - Attribute to search by ('batchId', 'productId', or 'variantId')
586
+ * @param value - Value to search for
587
+ * @param params - Optional pagination parameters
588
+ * @returns Promise resolving to a GetOrderIdsResponse
589
+ * @throws ErrorResponse if the request fails
590
+ *
591
+ * @example
592
+ * ```typescript
593
+ * // Get order IDs for a batch (fast count)
594
+ * const { orderIds, count } = await order.getOrderIdsByAttribute(
595
+ * 'coll_123',
596
+ * 'batchId',
597
+ * 'BATCH-2024-001'
598
+ * )
599
+ * console.log(`Batch appears in ${count} orders`)
600
+ *
601
+ * // Get order IDs for a product
602
+ * const productOrders = await order.getOrderIdsByAttribute(
603
+ * 'coll_123',
604
+ * 'productId',
605
+ * 'prod_789',
606
+ * { limit: 500 }
607
+ * )
608
+ * ```
609
+ */
610
+ function getOrderIdsByAttribute(collectionId: string, attribute: 'batchId' | 'productId' | 'variantId', value: string, params?: GetOrderIdsParams): Promise<GetOrderIdsResponse>;
446
611
  }
package/dist/api/order.js CHANGED
@@ -576,4 +576,251 @@ export var order;
576
576
  return post(path, params || {});
577
577
  }
578
578
  order.getCollectionSummary = getCollectionSummary;
579
+ /**
580
+ * Find all orders containing items from a specific batch.
581
+ * Uses indexed queries for fast lookups across order items.
582
+ *
583
+ * @param collectionId - Identifier of the parent collection
584
+ * @param batchId - Batch ID to search for
585
+ * @param params - Optional pagination and includeItems parameters
586
+ * @returns Promise resolving to a FindOrdersByAttributeResponse
587
+ * @throws ErrorResponse if the request fails
588
+ *
589
+ * @example
590
+ * ```typescript
591
+ * // Find orders with items from a specific batch
592
+ * const { orders } = await order.findByBatch('coll_123', 'BATCH-2024-001', {
593
+ * includeItems: true,
594
+ * limit: 50
595
+ * })
596
+ *
597
+ * // Get unique customers who received this batch
598
+ * const customers = [...new Set(orders.map(o => o.customerId).filter(Boolean))]
599
+ * console.log(`Batch delivered to ${customers.length} customers`)
600
+ * ```
601
+ */
602
+ async function findByBatch(collectionId, batchId, params) {
603
+ const queryParams = new URLSearchParams();
604
+ if (params === null || params === void 0 ? void 0 : params.limit)
605
+ queryParams.append('limit', params.limit.toString());
606
+ if (params === null || params === void 0 ? void 0 : params.offset)
607
+ queryParams.append('offset', params.offset.toString());
608
+ if (params === null || params === void 0 ? void 0 : params.includeItems)
609
+ queryParams.append('includeItems', 'true');
610
+ const query = queryParams.toString();
611
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/batch/${encodeURIComponent(batchId)}${query ? `?${query}` : ''}`;
612
+ return request(path);
613
+ }
614
+ order.findByBatch = findByBatch;
615
+ /**
616
+ * Find all orders containing items from a specific product.
617
+ * Uses indexed queries for fast lookups across order items.
618
+ *
619
+ * @param collectionId - Identifier of the parent collection
620
+ * @param productId - Product ID to search for
621
+ * @param params - Optional pagination and includeItems parameters
622
+ * @returns Promise resolving to a FindOrdersByAttributeResponse
623
+ * @throws ErrorResponse if the request fails
624
+ *
625
+ * @example
626
+ * ```typescript
627
+ * // Find all orders containing a product
628
+ * const { orders, limit, offset } = await order.findOrdersByProduct('coll_123', 'prod_789', {
629
+ * limit: 100
630
+ * })
631
+ *
632
+ * console.log(`Product appears in ${orders.length} orders`)
633
+ * ```
634
+ */
635
+ async function findOrdersByProduct(collectionId, productId, params) {
636
+ const queryParams = new URLSearchParams();
637
+ if (params === null || params === void 0 ? void 0 : params.limit)
638
+ queryParams.append('limit', params.limit.toString());
639
+ if (params === null || params === void 0 ? void 0 : params.offset)
640
+ queryParams.append('offset', params.offset.toString());
641
+ if (params === null || params === void 0 ? void 0 : params.includeItems)
642
+ queryParams.append('includeItems', 'true');
643
+ const query = queryParams.toString();
644
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/product/${encodeURIComponent(productId)}${query ? `?${query}` : ''}`;
645
+ return request(path);
646
+ }
647
+ order.findOrdersByProduct = findOrdersByProduct;
648
+ /**
649
+ * Find all orders containing items from a specific variant.
650
+ * Uses indexed queries for fast lookups across order items.
651
+ *
652
+ * @param collectionId - Identifier of the parent collection
653
+ * @param variantId - Variant ID to search for
654
+ * @param params - Optional pagination and includeItems parameters
655
+ * @returns Promise resolving to a FindOrdersByAttributeResponse
656
+ * @throws ErrorResponse if the request fails
657
+ *
658
+ * @example
659
+ * ```typescript
660
+ * // Find orders with a specific variant
661
+ * const { orders } = await order.findByVariant('coll_123', 'var_456', {
662
+ * includeItems: true
663
+ * })
664
+ *
665
+ * console.log(`Variant ${variantId} in ${orders.length} orders`)
666
+ * ```
667
+ */
668
+ async function findByVariant(collectionId, variantId, params) {
669
+ const queryParams = new URLSearchParams();
670
+ if (params === null || params === void 0 ? void 0 : params.limit)
671
+ queryParams.append('limit', params.limit.toString());
672
+ if (params === null || params === void 0 ? void 0 : params.offset)
673
+ queryParams.append('offset', params.offset.toString());
674
+ if (params === null || params === void 0 ? void 0 : params.includeItems)
675
+ queryParams.append('includeItems', 'true');
676
+ const query = queryParams.toString();
677
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/variant/${encodeURIComponent(variantId)}${query ? `?${query}` : ''}`;
678
+ return request(path);
679
+ }
680
+ order.findByVariant = findByVariant;
681
+ /**
682
+ * Get individual order items (not full orders) for a specific batch.
683
+ * Returns all matching items with optional order summary.
684
+ *
685
+ * @param collectionId - Identifier of the parent collection
686
+ * @param batchId - Batch ID to search for
687
+ * @param params - Optional pagination and includeOrder parameters
688
+ * @returns Promise resolving to a FindItemsByAttributeResponse
689
+ * @throws ErrorResponse if the request fails
690
+ *
691
+ * @example
692
+ * ```typescript
693
+ * // Get items from a batch with order info
694
+ * const { items, count } = await order.findItemsByBatch('coll_123', 'BATCH-2024-001', {
695
+ * includeOrder: true,
696
+ * limit: 100
697
+ * })
698
+ *
699
+ * // Group by order status
700
+ * const byStatus = items.reduce((acc, item) => {
701
+ * const status = item.order?.status || 'unknown'
702
+ * acc[status] = (acc[status] || 0) + 1
703
+ * return acc
704
+ * }, {})
705
+ * ```
706
+ */
707
+ async function findItemsByBatch(collectionId, batchId, params) {
708
+ const queryParams = new URLSearchParams();
709
+ if (params === null || params === void 0 ? void 0 : params.limit)
710
+ queryParams.append('limit', params.limit.toString());
711
+ if (params === null || params === void 0 ? void 0 : params.offset)
712
+ queryParams.append('offset', params.offset.toString());
713
+ if (params === null || params === void 0 ? void 0 : params.includeOrder)
714
+ queryParams.append('includeOrder', 'true');
715
+ const query = queryParams.toString();
716
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/batch/${encodeURIComponent(batchId)}/items${query ? `?${query}` : ''}`;
717
+ return request(path);
718
+ }
719
+ order.findItemsByBatch = findItemsByBatch;
720
+ /**
721
+ * Get individual order items for a specific product.
722
+ * Returns all matching items with optional order summary.
723
+ *
724
+ * @param collectionId - Identifier of the parent collection
725
+ * @param productId - Product ID to search for
726
+ * @param params - Optional pagination and includeOrder parameters
727
+ * @returns Promise resolving to a FindItemsByAttributeResponse
728
+ * @throws ErrorResponse if the request fails
729
+ *
730
+ * @example
731
+ * ```typescript
732
+ * // Get all items for a product
733
+ * const { items } = await order.findItemsByProduct('coll_123', 'prod_789', {
734
+ * includeOrder: true
735
+ * })
736
+ *
737
+ * console.log(`Product delivered in ${items.length} order items`)
738
+ * ```
739
+ */
740
+ async function findItemsByProduct(collectionId, productId, params) {
741
+ const queryParams = new URLSearchParams();
742
+ if (params === null || params === void 0 ? void 0 : params.limit)
743
+ queryParams.append('limit', params.limit.toString());
744
+ if (params === null || params === void 0 ? void 0 : params.offset)
745
+ queryParams.append('offset', params.offset.toString());
746
+ if (params === null || params === void 0 ? void 0 : params.includeOrder)
747
+ queryParams.append('includeOrder', 'true');
748
+ const query = queryParams.toString();
749
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/product/${encodeURIComponent(productId)}/items${query ? `?${query}` : ''}`;
750
+ return request(path);
751
+ }
752
+ order.findItemsByProduct = findItemsByProduct;
753
+ /**
754
+ * Get individual order items for a specific variant.
755
+ * Returns all matching items with optional order summary.
756
+ *
757
+ * @param collectionId - Identifier of the parent collection
758
+ * @param variantId - Variant ID to search for
759
+ * @param params - Optional pagination and includeOrder parameters
760
+ * @returns Promise resolving to a FindItemsByAttributeResponse
761
+ * @throws ErrorResponse if the request fails
762
+ *
763
+ * @example
764
+ * ```typescript
765
+ * // Get variant items with order details
766
+ * const { items, count } = await order.findItemsByVariant('coll_123', 'var_456', {
767
+ * includeOrder: true,
768
+ * limit: 50
769
+ * })
770
+ * ```
771
+ */
772
+ async function findItemsByVariant(collectionId, variantId, params) {
773
+ const queryParams = new URLSearchParams();
774
+ if (params === null || params === void 0 ? void 0 : params.limit)
775
+ queryParams.append('limit', params.limit.toString());
776
+ if (params === null || params === void 0 ? void 0 : params.offset)
777
+ queryParams.append('offset', params.offset.toString());
778
+ if (params === null || params === void 0 ? void 0 : params.includeOrder)
779
+ queryParams.append('includeOrder', 'true');
780
+ const query = queryParams.toString();
781
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/variant/${encodeURIComponent(variantId)}/items${query ? `?${query}` : ''}`;
782
+ return request(path);
783
+ }
784
+ order.findItemsByVariant = findItemsByVariant;
785
+ /**
786
+ * Get unique order IDs containing items matching the specified attribute.
787
+ * Lightweight query that only returns order IDs, not full order objects.
788
+ *
789
+ * @param collectionId - Identifier of the parent collection
790
+ * @param attribute - Attribute to search by ('batchId', 'productId', or 'variantId')
791
+ * @param value - Value to search for
792
+ * @param params - Optional pagination parameters
793
+ * @returns Promise resolving to a GetOrderIdsResponse
794
+ * @throws ErrorResponse if the request fails
795
+ *
796
+ * @example
797
+ * ```typescript
798
+ * // Get order IDs for a batch (fast count)
799
+ * const { orderIds, count } = await order.getOrderIdsByAttribute(
800
+ * 'coll_123',
801
+ * 'batchId',
802
+ * 'BATCH-2024-001'
803
+ * )
804
+ * console.log(`Batch appears in ${count} orders`)
805
+ *
806
+ * // Get order IDs for a product
807
+ * const productOrders = await order.getOrderIdsByAttribute(
808
+ * 'coll_123',
809
+ * 'productId',
810
+ * 'prod_789',
811
+ * { limit: 500 }
812
+ * )
813
+ * ```
814
+ */
815
+ async function getOrderIdsByAttribute(collectionId, attribute, value, params) {
816
+ const queryParams = new URLSearchParams();
817
+ if (params === null || params === void 0 ? void 0 : params.limit)
818
+ queryParams.append('limit', params.limit.toString());
819
+ if (params === null || params === void 0 ? void 0 : params.offset)
820
+ queryParams.append('offset', params.offset.toString());
821
+ const query = queryParams.toString();
822
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/ids/${attribute}/${encodeURIComponent(value)}${query ? `?${query}` : ''}`;
823
+ return request(path);
824
+ }
825
+ order.getOrderIdsByAttribute = getOrderIdsByAttribute;
579
826
  })(order || (order = {}));
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.3.20 | Generated: 2026-02-08T14:25:23.483Z
3
+ Version: 1.3.21 | Generated: 2026-02-09T12:29:22.158Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -625,11 +625,66 @@ interface AuthKitConfig {
625
625
 
626
626
  ### batch
627
627
 
628
- **BatchResponse** = `any`
628
+ **FirebaseTimestamp** (interface)
629
+ ```typescript
630
+ interface FirebaseTimestamp {
631
+ seconds: number // Unix timestamp in seconds
632
+ nanoseconds?: number // Nanoseconds component
633
+ }
634
+ ```
635
+
636
+ **BatchResponse** (interface)
637
+ ```typescript
638
+ interface BatchResponse {
639
+ id: string // Batch ID
640
+ name?: string // Batch name
641
+ expiryDate?: FirebaseTimestamp | string // Firebase timestamp or ISO 8601 date
642
+ productId?: string // Product ID (for collection-level searches)
643
+ collectionId?: string // Collection ID
644
+ [key: string]: any // Additional batch fields
645
+ }
646
+ ```
629
647
 
630
- **BatchCreateRequest** = `any`
648
+ **BatchCreateRequest** (interface)
649
+ ```typescript
650
+ interface BatchCreateRequest {
651
+ id: string // Batch ID
652
+ name?: string // Batch name
653
+ expiryDate?: FirebaseTimestamp | string // Firebase timestamp or ISO 8601 date
654
+ [key: string]: any // Additional batch fields
655
+ }
656
+ ```
631
657
 
632
- **BatchUpdateRequest** = `any`
658
+ **BatchUpdateRequest** (interface)
659
+ ```typescript
660
+ interface BatchUpdateRequest {
661
+ name?: string // Batch name
662
+ expiryDate?: FirebaseTimestamp | string // Firebase timestamp or ISO 8601 date
663
+ [key: string]: any // Additional batch fields
664
+ }
665
+ ```
666
+
667
+ **SearchBatchesRequest** (interface)
668
+ ```typescript
669
+ interface SearchBatchesRequest {
670
+ search?: string // Search term (batch ID or name)
671
+ productId?: string // Filter by specific product
672
+ limit?: number // Max results (default: 100)
673
+ }
674
+ ```
675
+
676
+ **BatchTag** (interface)
677
+ ```typescript
678
+ interface BatchTag {
679
+ code: string // Code/tag ID
680
+ claimSetId: string // Claim set ID
681
+ collectionId?: string // Collection ID
682
+ productId?: string // Associated product ID
683
+ batchId?: string // Batch ID
684
+ tagId?: string // Tag identifier
685
+ index?: number // Position in claim set
686
+ }
687
+ ```
633
688
 
634
689
  ### broadcasts
635
690
 
@@ -2239,8 +2294,24 @@ interface OrderItem {
2239
2294
  orderId: string // Parent order ID
2240
2295
  itemType: 'tag' | 'proof' | 'serial' // Type of item
2241
2296
  itemId: string // The tag ID, proof ID, or serial number
2297
+ collectionId?: string // Collection ID
2298
+ productId?: string // Product ID
2299
+ variantId?: string | null // Variant ID
2300
+ batchId?: string | null // Batch ID
2242
2301
  metadata: Record<string, any> // Item-specific metadata
2243
2302
  createdAt: string // ISO 8601 timestamp
2303
+ order?: OrderSummary // Optional order summary (when includeOrder=true)
2304
+ }
2305
+ ```
2306
+
2307
+ **OrderSummary** (interface)
2308
+ ```typescript
2309
+ interface OrderSummary {
2310
+ id: string // Order ID
2311
+ orderRef?: string // Order reference
2312
+ status: string // Order status
2313
+ customerId?: string // Customer ID
2314
+ createdAt: string // ISO 8601 timestamp
2244
2315
  }
2245
2316
  ```
2246
2317
 
@@ -2463,6 +2534,61 @@ interface LookupByProductResponse {
2463
2534
  }
2464
2535
  ```
2465
2536
 
2537
+ **FindOrdersByAttributeParams** (interface)
2538
+ ```typescript
2539
+ interface FindOrdersByAttributeParams {
2540
+ limit?: number // Max results (default: 100)
2541
+ offset?: number // Pagination offset (default: 0)
2542
+ includeItems?: boolean // Include items array (default: false)
2543
+ }
2544
+ ```
2545
+
2546
+ **FindOrdersByAttributeResponse** (interface)
2547
+ ```typescript
2548
+ interface FindOrdersByAttributeResponse {
2549
+ orders: Order[]
2550
+ limit: number
2551
+ offset: number
2552
+ }
2553
+ ```
2554
+
2555
+ **FindItemsByAttributeParams** (interface)
2556
+ ```typescript
2557
+ interface FindItemsByAttributeParams {
2558
+ limit?: number // Max results (default: 100)
2559
+ offset?: number // Pagination offset (default: 0)
2560
+ includeOrder?: boolean // Include order summary (default: false)
2561
+ }
2562
+ ```
2563
+
2564
+ **FindItemsByAttributeResponse** (interface)
2565
+ ```typescript
2566
+ interface FindItemsByAttributeResponse {
2567
+ items: OrderItem[]
2568
+ count: number
2569
+ limit: number
2570
+ offset: number
2571
+ }
2572
+ ```
2573
+
2574
+ **GetOrderIdsParams** (interface)
2575
+ ```typescript
2576
+ interface GetOrderIdsParams {
2577
+ limit?: number // Max results (default: 1000)
2578
+ offset?: number // Pagination offset (default: 0)
2579
+ }
2580
+ ```
2581
+
2582
+ **GetOrderIdsResponse** (interface)
2583
+ ```typescript
2584
+ interface GetOrderIdsResponse {
2585
+ orderIds: string[]
2586
+ count: number
2587
+ attribute: 'batchId' | 'productId' | 'variantId'
2588
+ value: string
2589
+ }
2590
+ ```
2591
+
2466
2592
  **TagScanSummary** (interface)
2467
2593
  ```typescript
2468
2594
  interface TagScanSummary {
@@ -3943,6 +4069,19 @@ Get serial numbers for a batch (admin only).
3943
4069
  codeId: string) → `Promise<any>`
3944
4070
  Look up a serial number by code for a batch (admin only).
3945
4071
 
4072
+ **searchInCollection**(collectionId: string,
4073
+ params?: SearchBatchesRequest) → `Promise<BatchResponse[]>`
4074
+ Search for batches across all products in a collection. Allows searching by batch ID or name, with optional product filtering. ```typescript // Search for batches containing "2024" const batches = await batch.searchInCollection('coll_123', { search: 'BATCH-2024', limit: 50 }) // Filter batches for a specific product const productBatches = await batch.searchInCollection('coll_123', { productId: 'prod_abc', limit: 100 }) // Get all batches in collection const allBatches = await batch.searchInCollection('coll_123') // Check for expired batches batches.forEach(batch => { if (batch.expiryDate?.seconds) { const expiryDate = new Date(batch.expiryDate.seconds * 1000) if (expiryDate < new Date()) { console.log(`Batch ${batch.id} is expired`) } } }) ```
4075
+
4076
+ **findInCollection**(collectionId: string,
4077
+ batchId: string) → `Promise<BatchResponse>`
4078
+ Find a specific batch by ID across all products in a collection. Returns the batch along with the productId it belongs to. ```typescript // Find which product contains a specific batch const batch = await batch.findInCollection('coll_123', 'BATCH-2024-001') console.log(`Batch found in product: ${batch.productId}`) console.log(`Expires: ${batch.expiryDate}`) ```
4079
+
4080
+ **getBatchTags**(collectionId: string,
4081
+ batchId: string,
4082
+ claimSetId?: string) → `Promise<BatchTag[]>`
4083
+ Get all tags/codes assigned to a specific batch. Shows which claim set codes have been assigned to this batch. ```typescript // Get all tags assigned to a batch const tags = await batch.getBatchTags('coll_123', 'BATCH-2024-001') console.log(`Batch has ${tags.length} tags assigned`) tags.forEach(tag => { console.log(`Code: ${tag.code}, ClaimSet: ${tag.claimSetId}, TagID: ${tag.tagId}`) }) // Get tags from a specific claim set const claimSetTags = await batch.getBatchTags('coll_123', 'BATCH-2024-001', '000001') ```
4084
+
3946
4085
  ### broadcasts
3947
4086
 
3948
4087
  **create**(collectionId: string,
@@ -4444,6 +4583,42 @@ Get analytics summary for multiple orders at once. Efficient way to retrieve sca
4444
4583
  params?: SummaryRequest) → `Promise<CollectionSummaryResponse>`
4445
4584
  Get collection-wide analytics summary across all orders. Returns daily scan counts and admin activity overview. ```typescript // Get all-time collection summary const summary = await order.getCollectionSummary('coll_123') console.log(`Admin activity count: ${summary.adminActivity.count}`) console.log('Scans by day:') summary.scansByDay.forEach(day => { console.log(` ${day.date}: ${day.scanCount} scans`) }) // Get summary for last 30 days const recentSummary = await order.getCollectionSummary('coll_123', { from: '2026-01-08T00:00:00Z', to: '2026-02-08T00:00:00Z' }) ```
4446
4585
 
4586
+ **findByBatch**(collectionId: string,
4587
+ batchId: string,
4588
+ params?: FindOrdersByAttributeParams) → `Promise<FindOrdersByAttributeResponse>`
4589
+ Find all orders containing items from a specific batch. Uses indexed queries for fast lookups across order items. ```typescript // Find orders with items from a specific batch const { orders } = await order.findByBatch('coll_123', 'BATCH-2024-001', { includeItems: true, limit: 50 }) // Get unique customers who received this batch const customers = [...new Set(orders.map(o => o.customerId).filter(Boolean))] console.log(`Batch delivered to ${customers.length} customers`) ```
4590
+
4591
+ **findOrdersByProduct**(collectionId: string,
4592
+ productId: string,
4593
+ params?: FindOrdersByAttributeParams) → `Promise<FindOrdersByAttributeResponse>`
4594
+ Find all orders containing items from a specific product. Uses indexed queries for fast lookups across order items. ```typescript // Find all orders containing a product const { orders, limit, offset } = await order.findOrdersByProduct('coll_123', 'prod_789', { limit: 100 }) console.log(`Product appears in ${orders.length} orders`) ```
4595
+
4596
+ **findByVariant**(collectionId: string,
4597
+ variantId: string,
4598
+ params?: FindOrdersByAttributeParams) → `Promise<FindOrdersByAttributeResponse>`
4599
+ Find all orders containing items from a specific variant. Uses indexed queries for fast lookups across order items. ```typescript // Find orders with a specific variant const { orders } = await order.findByVariant('coll_123', 'var_456', { includeItems: true }) console.log(`Variant ${variantId} in ${orders.length} orders`) ```
4600
+
4601
+ **findItemsByBatch**(collectionId: string,
4602
+ batchId: string,
4603
+ params?: FindItemsByAttributeParams) → `Promise<FindItemsByAttributeResponse>`
4604
+ Get individual order items (not full orders) for a specific batch. Returns all matching items with optional order summary. ```typescript // Get items from a batch with order info const { items, count } = await order.findItemsByBatch('coll_123', 'BATCH-2024-001', { includeOrder: true, limit: 100 }) // Group by order status const byStatus = items.reduce((acc, item) => { const status = item.order?.status || 'unknown' acc[status] = (acc[status] || 0) + 1 return acc }, {}) ```
4605
+
4606
+ **findItemsByProduct**(collectionId: string,
4607
+ productId: string,
4608
+ params?: FindItemsByAttributeParams) → `Promise<FindItemsByAttributeResponse>`
4609
+ Get individual order items for a specific product. Returns all matching items with optional order summary. ```typescript // Get all items for a product const { items } = await order.findItemsByProduct('coll_123', 'prod_789', { includeOrder: true }) console.log(`Product delivered in ${items.length} order items`) ```
4610
+
4611
+ **findItemsByVariant**(collectionId: string,
4612
+ variantId: string,
4613
+ params?: FindItemsByAttributeParams) → `Promise<FindItemsByAttributeResponse>`
4614
+ Get individual order items for a specific variant. Returns all matching items with optional order summary. ```typescript // Get variant items with order details const { items, count } = await order.findItemsByVariant('coll_123', 'var_456', { includeOrder: true, limit: 50 }) ```
4615
+
4616
+ **getOrderIdsByAttribute**(collectionId: string,
4617
+ attribute: 'batchId' | 'productId' | 'variantId',
4618
+ value: string,
4619
+ params?: GetOrderIdsParams) → `Promise<GetOrderIdsResponse>`
4620
+ Get unique order IDs containing items matching the specified attribute. Lightweight query that only returns order IDs, not full order objects. ```typescript // Get order IDs for a batch (fast count) const { orderIds, count } = await order.getOrderIdsByAttribute( 'coll_123', 'batchId', 'BATCH-2024-001' ) console.log(`Batch appears in ${count} orders`) // Get order IDs for a product const productOrders = await order.getOrderIdsByAttribute( 'coll_123', 'productId', 'prod_789', { limit: 500 } ) ```
4621
+
4447
4622
  ### product
4448
4623
 
4449
4624
  **get**(collectionId: string,
@@ -1,12 +1,55 @@
1
+ /**
2
+ * Firebase Timestamp object.
3
+ */
4
+ export interface FirebaseTimestamp {
5
+ seconds: number;
6
+ nanoseconds?: number;
7
+ }
1
8
  /**
2
9
  * Represents a Batch object.
3
10
  */
4
- export type BatchResponse = any;
11
+ export interface BatchResponse {
12
+ id: string;
13
+ name?: string;
14
+ expiryDate?: FirebaseTimestamp | string;
15
+ productId?: string;
16
+ collectionId?: string;
17
+ [key: string]: any;
18
+ }
5
19
  /**
6
20
  * Request payload for creating a new batch.
7
21
  */
8
- export type BatchCreateRequest = any;
22
+ export interface BatchCreateRequest {
23
+ id: string;
24
+ name?: string;
25
+ expiryDate?: FirebaseTimestamp | string;
26
+ [key: string]: any;
27
+ }
9
28
  /**
10
29
  * Request payload for updating an existing batch.
11
30
  */
12
- export type BatchUpdateRequest = any;
31
+ export interface BatchUpdateRequest {
32
+ name?: string;
33
+ expiryDate?: FirebaseTimestamp | string;
34
+ [key: string]: any;
35
+ }
36
+ /**
37
+ * Query parameters for searching batches in a collection.
38
+ */
39
+ export interface SearchBatchesRequest {
40
+ search?: string;
41
+ productId?: string;
42
+ limit?: number;
43
+ }
44
+ /**
45
+ * Tag/code assigned to a batch.
46
+ */
47
+ export interface BatchTag {
48
+ code: string;
49
+ claimSetId: string;
50
+ collectionId?: string;
51
+ productId?: string;
52
+ batchId?: string;
53
+ tagId?: string;
54
+ index?: number;
55
+ }
@@ -12,8 +12,23 @@ export interface OrderItem {
12
12
  orderId: string;
13
13
  itemType: 'tag' | 'proof' | 'serial';
14
14
  itemId: string;
15
+ collectionId?: string;
16
+ productId?: string;
17
+ variantId?: string | null;
18
+ batchId?: string | null;
15
19
  metadata: Record<string, any>;
16
20
  createdAt: string;
21
+ order?: OrderSummary;
22
+ }
23
+ /**
24
+ * Summary of order details (included with items when requested).
25
+ */
26
+ export interface OrderSummary {
27
+ id: string;
28
+ orderRef?: string;
29
+ status: string;
30
+ customerId?: string;
31
+ createdAt: string;
17
32
  }
18
33
  /**
19
34
  * Represents an order containing multiple items.
@@ -241,6 +256,55 @@ export interface LookupByProductResponse {
241
256
  limit: number;
242
257
  offset: number;
243
258
  }
259
+ /**
260
+ * Query parameters for finding orders by batch/product/variant.
261
+ */
262
+ export interface FindOrdersByAttributeParams {
263
+ limit?: number;
264
+ offset?: number;
265
+ includeItems?: boolean;
266
+ }
267
+ /**
268
+ * Response from finding orders by batch/product/variant.
269
+ */
270
+ export interface FindOrdersByAttributeResponse {
271
+ orders: Order[];
272
+ limit: number;
273
+ offset: number;
274
+ }
275
+ /**
276
+ * Query parameters for finding items by batch/product/variant.
277
+ */
278
+ export interface FindItemsByAttributeParams {
279
+ limit?: number;
280
+ offset?: number;
281
+ includeOrder?: boolean;
282
+ }
283
+ /**
284
+ * Response from finding items by batch/product/variant.
285
+ */
286
+ export interface FindItemsByAttributeResponse {
287
+ items: OrderItem[];
288
+ count: number;
289
+ limit: number;
290
+ offset: number;
291
+ }
292
+ /**
293
+ * Query parameters for getting order IDs by attribute.
294
+ */
295
+ export interface GetOrderIdsParams {
296
+ limit?: number;
297
+ offset?: number;
298
+ }
299
+ /**
300
+ * Response from getting order IDs by attribute.
301
+ */
302
+ export interface GetOrderIdsResponse {
303
+ orderIds: string[];
304
+ count: number;
305
+ attribute: 'batchId' | 'productId' | 'variantId';
306
+ value: string;
307
+ }
244
308
  /**
245
309
  * Summary of scans for a single tag.
246
310
  */
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.3.20 | Generated: 2026-02-08T14:25:23.483Z
3
+ Version: 1.3.21 | Generated: 2026-02-09T12:29:22.158Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -625,11 +625,66 @@ interface AuthKitConfig {
625
625
 
626
626
  ### batch
627
627
 
628
- **BatchResponse** = `any`
628
+ **FirebaseTimestamp** (interface)
629
+ ```typescript
630
+ interface FirebaseTimestamp {
631
+ seconds: number // Unix timestamp in seconds
632
+ nanoseconds?: number // Nanoseconds component
633
+ }
634
+ ```
635
+
636
+ **BatchResponse** (interface)
637
+ ```typescript
638
+ interface BatchResponse {
639
+ id: string // Batch ID
640
+ name?: string // Batch name
641
+ expiryDate?: FirebaseTimestamp | string // Firebase timestamp or ISO 8601 date
642
+ productId?: string // Product ID (for collection-level searches)
643
+ collectionId?: string // Collection ID
644
+ [key: string]: any // Additional batch fields
645
+ }
646
+ ```
629
647
 
630
- **BatchCreateRequest** = `any`
648
+ **BatchCreateRequest** (interface)
649
+ ```typescript
650
+ interface BatchCreateRequest {
651
+ id: string // Batch ID
652
+ name?: string // Batch name
653
+ expiryDate?: FirebaseTimestamp | string // Firebase timestamp or ISO 8601 date
654
+ [key: string]: any // Additional batch fields
655
+ }
656
+ ```
631
657
 
632
- **BatchUpdateRequest** = `any`
658
+ **BatchUpdateRequest** (interface)
659
+ ```typescript
660
+ interface BatchUpdateRequest {
661
+ name?: string // Batch name
662
+ expiryDate?: FirebaseTimestamp | string // Firebase timestamp or ISO 8601 date
663
+ [key: string]: any // Additional batch fields
664
+ }
665
+ ```
666
+
667
+ **SearchBatchesRequest** (interface)
668
+ ```typescript
669
+ interface SearchBatchesRequest {
670
+ search?: string // Search term (batch ID or name)
671
+ productId?: string // Filter by specific product
672
+ limit?: number // Max results (default: 100)
673
+ }
674
+ ```
675
+
676
+ **BatchTag** (interface)
677
+ ```typescript
678
+ interface BatchTag {
679
+ code: string // Code/tag ID
680
+ claimSetId: string // Claim set ID
681
+ collectionId?: string // Collection ID
682
+ productId?: string // Associated product ID
683
+ batchId?: string // Batch ID
684
+ tagId?: string // Tag identifier
685
+ index?: number // Position in claim set
686
+ }
687
+ ```
633
688
 
634
689
  ### broadcasts
635
690
 
@@ -2239,8 +2294,24 @@ interface OrderItem {
2239
2294
  orderId: string // Parent order ID
2240
2295
  itemType: 'tag' | 'proof' | 'serial' // Type of item
2241
2296
  itemId: string // The tag ID, proof ID, or serial number
2297
+ collectionId?: string // Collection ID
2298
+ productId?: string // Product ID
2299
+ variantId?: string | null // Variant ID
2300
+ batchId?: string | null // Batch ID
2242
2301
  metadata: Record<string, any> // Item-specific metadata
2243
2302
  createdAt: string // ISO 8601 timestamp
2303
+ order?: OrderSummary // Optional order summary (when includeOrder=true)
2304
+ }
2305
+ ```
2306
+
2307
+ **OrderSummary** (interface)
2308
+ ```typescript
2309
+ interface OrderSummary {
2310
+ id: string // Order ID
2311
+ orderRef?: string // Order reference
2312
+ status: string // Order status
2313
+ customerId?: string // Customer ID
2314
+ createdAt: string // ISO 8601 timestamp
2244
2315
  }
2245
2316
  ```
2246
2317
 
@@ -2463,6 +2534,61 @@ interface LookupByProductResponse {
2463
2534
  }
2464
2535
  ```
2465
2536
 
2537
+ **FindOrdersByAttributeParams** (interface)
2538
+ ```typescript
2539
+ interface FindOrdersByAttributeParams {
2540
+ limit?: number // Max results (default: 100)
2541
+ offset?: number // Pagination offset (default: 0)
2542
+ includeItems?: boolean // Include items array (default: false)
2543
+ }
2544
+ ```
2545
+
2546
+ **FindOrdersByAttributeResponse** (interface)
2547
+ ```typescript
2548
+ interface FindOrdersByAttributeResponse {
2549
+ orders: Order[]
2550
+ limit: number
2551
+ offset: number
2552
+ }
2553
+ ```
2554
+
2555
+ **FindItemsByAttributeParams** (interface)
2556
+ ```typescript
2557
+ interface FindItemsByAttributeParams {
2558
+ limit?: number // Max results (default: 100)
2559
+ offset?: number // Pagination offset (default: 0)
2560
+ includeOrder?: boolean // Include order summary (default: false)
2561
+ }
2562
+ ```
2563
+
2564
+ **FindItemsByAttributeResponse** (interface)
2565
+ ```typescript
2566
+ interface FindItemsByAttributeResponse {
2567
+ items: OrderItem[]
2568
+ count: number
2569
+ limit: number
2570
+ offset: number
2571
+ }
2572
+ ```
2573
+
2574
+ **GetOrderIdsParams** (interface)
2575
+ ```typescript
2576
+ interface GetOrderIdsParams {
2577
+ limit?: number // Max results (default: 1000)
2578
+ offset?: number // Pagination offset (default: 0)
2579
+ }
2580
+ ```
2581
+
2582
+ **GetOrderIdsResponse** (interface)
2583
+ ```typescript
2584
+ interface GetOrderIdsResponse {
2585
+ orderIds: string[]
2586
+ count: number
2587
+ attribute: 'batchId' | 'productId' | 'variantId'
2588
+ value: string
2589
+ }
2590
+ ```
2591
+
2466
2592
  **TagScanSummary** (interface)
2467
2593
  ```typescript
2468
2594
  interface TagScanSummary {
@@ -3943,6 +4069,19 @@ Get serial numbers for a batch (admin only).
3943
4069
  codeId: string) → `Promise<any>`
3944
4070
  Look up a serial number by code for a batch (admin only).
3945
4071
 
4072
+ **searchInCollection**(collectionId: string,
4073
+ params?: SearchBatchesRequest) → `Promise<BatchResponse[]>`
4074
+ Search for batches across all products in a collection. Allows searching by batch ID or name, with optional product filtering. ```typescript // Search for batches containing "2024" const batches = await batch.searchInCollection('coll_123', { search: 'BATCH-2024', limit: 50 }) // Filter batches for a specific product const productBatches = await batch.searchInCollection('coll_123', { productId: 'prod_abc', limit: 100 }) // Get all batches in collection const allBatches = await batch.searchInCollection('coll_123') // Check for expired batches batches.forEach(batch => { if (batch.expiryDate?.seconds) { const expiryDate = new Date(batch.expiryDate.seconds * 1000) if (expiryDate < new Date()) { console.log(`Batch ${batch.id} is expired`) } } }) ```
4075
+
4076
+ **findInCollection**(collectionId: string,
4077
+ batchId: string) → `Promise<BatchResponse>`
4078
+ Find a specific batch by ID across all products in a collection. Returns the batch along with the productId it belongs to. ```typescript // Find which product contains a specific batch const batch = await batch.findInCollection('coll_123', 'BATCH-2024-001') console.log(`Batch found in product: ${batch.productId}`) console.log(`Expires: ${batch.expiryDate}`) ```
4079
+
4080
+ **getBatchTags**(collectionId: string,
4081
+ batchId: string,
4082
+ claimSetId?: string) → `Promise<BatchTag[]>`
4083
+ Get all tags/codes assigned to a specific batch. Shows which claim set codes have been assigned to this batch. ```typescript // Get all tags assigned to a batch const tags = await batch.getBatchTags('coll_123', 'BATCH-2024-001') console.log(`Batch has ${tags.length} tags assigned`) tags.forEach(tag => { console.log(`Code: ${tag.code}, ClaimSet: ${tag.claimSetId}, TagID: ${tag.tagId}`) }) // Get tags from a specific claim set const claimSetTags = await batch.getBatchTags('coll_123', 'BATCH-2024-001', '000001') ```
4084
+
3946
4085
  ### broadcasts
3947
4086
 
3948
4087
  **create**(collectionId: string,
@@ -4444,6 +4583,42 @@ Get analytics summary for multiple orders at once. Efficient way to retrieve sca
4444
4583
  params?: SummaryRequest) → `Promise<CollectionSummaryResponse>`
4445
4584
  Get collection-wide analytics summary across all orders. Returns daily scan counts and admin activity overview. ```typescript // Get all-time collection summary const summary = await order.getCollectionSummary('coll_123') console.log(`Admin activity count: ${summary.adminActivity.count}`) console.log('Scans by day:') summary.scansByDay.forEach(day => { console.log(` ${day.date}: ${day.scanCount} scans`) }) // Get summary for last 30 days const recentSummary = await order.getCollectionSummary('coll_123', { from: '2026-01-08T00:00:00Z', to: '2026-02-08T00:00:00Z' }) ```
4446
4585
 
4586
+ **findByBatch**(collectionId: string,
4587
+ batchId: string,
4588
+ params?: FindOrdersByAttributeParams) → `Promise<FindOrdersByAttributeResponse>`
4589
+ Find all orders containing items from a specific batch. Uses indexed queries for fast lookups across order items. ```typescript // Find orders with items from a specific batch const { orders } = await order.findByBatch('coll_123', 'BATCH-2024-001', { includeItems: true, limit: 50 }) // Get unique customers who received this batch const customers = [...new Set(orders.map(o => o.customerId).filter(Boolean))] console.log(`Batch delivered to ${customers.length} customers`) ```
4590
+
4591
+ **findOrdersByProduct**(collectionId: string,
4592
+ productId: string,
4593
+ params?: FindOrdersByAttributeParams) → `Promise<FindOrdersByAttributeResponse>`
4594
+ Find all orders containing items from a specific product. Uses indexed queries for fast lookups across order items. ```typescript // Find all orders containing a product const { orders, limit, offset } = await order.findOrdersByProduct('coll_123', 'prod_789', { limit: 100 }) console.log(`Product appears in ${orders.length} orders`) ```
4595
+
4596
+ **findByVariant**(collectionId: string,
4597
+ variantId: string,
4598
+ params?: FindOrdersByAttributeParams) → `Promise<FindOrdersByAttributeResponse>`
4599
+ Find all orders containing items from a specific variant. Uses indexed queries for fast lookups across order items. ```typescript // Find orders with a specific variant const { orders } = await order.findByVariant('coll_123', 'var_456', { includeItems: true }) console.log(`Variant ${variantId} in ${orders.length} orders`) ```
4600
+
4601
+ **findItemsByBatch**(collectionId: string,
4602
+ batchId: string,
4603
+ params?: FindItemsByAttributeParams) → `Promise<FindItemsByAttributeResponse>`
4604
+ Get individual order items (not full orders) for a specific batch. Returns all matching items with optional order summary. ```typescript // Get items from a batch with order info const { items, count } = await order.findItemsByBatch('coll_123', 'BATCH-2024-001', { includeOrder: true, limit: 100 }) // Group by order status const byStatus = items.reduce((acc, item) => { const status = item.order?.status || 'unknown' acc[status] = (acc[status] || 0) + 1 return acc }, {}) ```
4605
+
4606
+ **findItemsByProduct**(collectionId: string,
4607
+ productId: string,
4608
+ params?: FindItemsByAttributeParams) → `Promise<FindItemsByAttributeResponse>`
4609
+ Get individual order items for a specific product. Returns all matching items with optional order summary. ```typescript // Get all items for a product const { items } = await order.findItemsByProduct('coll_123', 'prod_789', { includeOrder: true }) console.log(`Product delivered in ${items.length} order items`) ```
4610
+
4611
+ **findItemsByVariant**(collectionId: string,
4612
+ variantId: string,
4613
+ params?: FindItemsByAttributeParams) → `Promise<FindItemsByAttributeResponse>`
4614
+ Get individual order items for a specific variant. Returns all matching items with optional order summary. ```typescript // Get variant items with order details const { items, count } = await order.findItemsByVariant('coll_123', 'var_456', { includeOrder: true, limit: 50 }) ```
4615
+
4616
+ **getOrderIdsByAttribute**(collectionId: string,
4617
+ attribute: 'batchId' | 'productId' | 'variantId',
4618
+ value: string,
4619
+ params?: GetOrderIdsParams) → `Promise<GetOrderIdsResponse>`
4620
+ Get unique order IDs containing items matching the specified attribute. Lightweight query that only returns order IDs, not full order objects. ```typescript // Get order IDs for a batch (fast count) const { orderIds, count } = await order.getOrderIdsByAttribute( 'coll_123', 'batchId', 'BATCH-2024-001' ) console.log(`Batch appears in ${count} orders`) // Get order IDs for a product const productOrders = await order.getOrderIdsByAttribute( 'coll_123', 'productId', 'prod_789', { limit: 500 } ) ```
4621
+
4447
4622
  ### product
4448
4623
 
4449
4624
  **get**(collectionId: string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.3.20",
3
+ "version": "1.3.21",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",