@proveanything/smartlinks 1.3.19 → 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.
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.19 | Generated: 2026-02-08T09:16:59.107Z
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
+ ```
647
+
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
+ ```
657
+
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
+ ```
629
666
 
630
- **BatchCreateRequest** = `any`
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
+ ```
631
675
 
632
- **BatchUpdateRequest** = `any`
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
 
@@ -1493,6 +1548,74 @@ interface ContactSchema {
1493
1548
 
1494
1549
  **FieldType** = ``
1495
1550
 
1551
+ ### crate
1552
+
1553
+ **CrateItem** (interface)
1554
+ ```typescript
1555
+ interface CrateItem {
1556
+ id: string // Item ID (tag ID)
1557
+ codeId: string // Code identifier
1558
+ batchId?: string // Batch identifier
1559
+ productId?: string // Product identifier
1560
+ claimId?: string // Claim identifier
1561
+ productName?: string // Product name
1562
+ productGtin?: string // Product GTIN
1563
+ productImage?: string // Product image URL
1564
+ data?: Record<string, any> // Additional item data
1565
+ }
1566
+ ```
1567
+
1568
+ **Crate** (interface)
1569
+ ```typescript
1570
+ interface Crate {
1571
+ id: string // Crate ID
1572
+ items?: CrateItem[] // Array of items in the crate
1573
+ deleted?: boolean // Whether the crate is soft-deleted
1574
+ deletedAt?: string | null // ISO 8601 timestamp when deleted
1575
+ }
1576
+ ```
1577
+
1578
+ **ListCratesRequest** (interface)
1579
+ ```typescript
1580
+ interface ListCratesRequest {
1581
+ limit?: number // Number of results per page (default: 100, max: 100)
1582
+ startAfter?: string // Crate ID to start after for pagination
1583
+ includeDeleted?: boolean // Include soft-deleted crates (default: false)
1584
+ }
1585
+ ```
1586
+
1587
+ **ListCratesResponse** (interface)
1588
+ ```typescript
1589
+ interface ListCratesResponse {
1590
+ items: Crate[] // Array of crates
1591
+ hasMore: boolean // Whether more results are available
1592
+ lastId: string | null // ID of last crate (use as startAfter for next page)
1593
+ }
1594
+ ```
1595
+
1596
+ **CreateCrateRequest** (interface)
1597
+ ```typescript
1598
+ interface CreateCrateRequest {
1599
+ items?: CrateItem[] // Initial items for the crate
1600
+ [key: string]: any // Additional fields
1601
+ }
1602
+ ```
1603
+
1604
+ **UpdateCrateRequest** (interface)
1605
+ ```typescript
1606
+ interface UpdateCrateRequest {
1607
+ items?: CrateItem[] // Updated items
1608
+ [key: string]: any // Additional fields
1609
+ }
1610
+ ```
1611
+
1612
+ **DeleteCrateResponse** (interface)
1613
+ ```typescript
1614
+ interface DeleteCrateResponse {
1615
+ success: boolean
1616
+ }
1617
+ ```
1618
+
1496
1619
  ### error
1497
1620
 
1498
1621
  **ErrorResponse** (interface)
@@ -2171,8 +2294,24 @@ interface OrderItem {
2171
2294
  orderId: string // Parent order ID
2172
2295
  itemType: 'tag' | 'proof' | 'serial' // Type of item
2173
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
2174
2301
  metadata: Record<string, any> // Item-specific metadata
2175
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
2176
2315
  }
2177
2316
  ```
2178
2317
 
@@ -2395,6 +2534,61 @@ interface LookupByProductResponse {
2395
2534
  }
2396
2535
  ```
2397
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
+
2398
2592
  **TagScanSummary** (interface)
2399
2593
  ```typescript
2400
2594
  interface TagScanSummary {
@@ -3875,6 +4069,19 @@ Get serial numbers for a batch (admin only).
3875
4069
  codeId: string) → `Promise<any>`
3876
4070
  Look up a serial number by code for a batch (admin only).
3877
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
+
3878
4085
  ### broadcasts
3879
4086
 
3880
4087
  **create**(collectionId: string,
@@ -4123,20 +4330,26 @@ Public: Get contact update schema for a collection Fetches the public contact sc
4123
4330
 
4124
4331
  ### crate
4125
4332
 
4126
- **get**(collectionId: string, crateId: string) → `Promise<any>`
4127
- Get a single crate by ID for a collection (admin only).
4333
+ **list**(collectionId: string,
4334
+ params?: ListCratesRequest) `Promise<ListCratesResponse>`
4335
+ List crates for a collection with pagination support. Returns crates in pages, with support for soft-deleted crates. ```typescript // Get first page const page1 = await crate.list('coll_123', { limit: 100 }) console.log(`Found ${page1.items.length} crates`) // Get next page if (page1.hasMore) { const page2 = await crate.list('coll_123', { limit: 100, startAfter: page1.lastId }) } // Include soft-deleted crates const withDeleted = await crate.list('coll_123', { includeDeleted: true }) ```
4128
4336
 
4129
- **list**(collectionId: string) → `Promise<any[]>`
4130
- List all crates for a collection (admin only).
4337
+ **get**(collectionId: string,
4338
+ crateId: string) `Promise<GetCrateResponse>`
4339
+ Get a single crate by ID for a collection (admin only). ```typescript const crate = await crate.get('coll_123', 'crate_abc123') console.log(`Crate has ${crate.items?.length ?? 0} items`) ```
4131
4340
 
4132
- **create**(collectionId: string, data: any) → `Promise<any>`
4133
- Create a new crate for a collection (admin only).
4341
+ **create**(collectionId: string,
4342
+ data: CreateCrateRequest) `Promise<CreateCrateResponse>`
4343
+ Create a new crate for a collection (admin only). ```typescript const newCrate = await crate.create('coll_123', { items: [ { id: 'tag_001', codeId: 'ABC123', productId: 'prod_1', productName: 'Product Name' } ] }) console.log(`Created crate ${newCrate.id}`) ```
4134
4344
 
4135
- **update**(collectionId: string, crateId: string, data: any) → `Promise<any>`
4136
- Update a crate for a collection (admin only).
4345
+ **update**(collectionId: string,
4346
+ crateId: string,
4347
+ data: UpdateCrateRequest) → `Promise<UpdateCrateResponse>`
4348
+ Update a crate for a collection (admin only). ```typescript const updated = await crate.update('coll_123', 'crate_abc123', { items: [ { id: 'tag_002', codeId: 'XYZ789', productId: 'prod_2' } ] }) ```
4137
4349
 
4138
- **remove**(collectionId: string, crateId: string) → `Promise<void>`
4139
- Delete a crate for a collection (admin only).
4350
+ **remove**(collectionId: string,
4351
+ crateId: string) `Promise<DeleteCrateResponse>`
4352
+ Delete a crate for a collection (admin only). This performs a soft delete. ```typescript await crate.remove('coll_123', 'crate_abc123') ```
4140
4353
 
4141
4354
  ### form
4142
4355
 
@@ -4370,6 +4583,42 @@ Get analytics summary for multiple orders at once. Efficient way to retrieve sca
4370
4583
  params?: SummaryRequest) → `Promise<CollectionSummaryResponse>`
4371
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' }) ```
4372
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
+
4373
4622
  ### product
4374
4623
 
4375
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
+ }