@proveanything/smartlinks 1.7.5 → 1.7.8

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.
@@ -220,7 +220,7 @@ export declare namespace order {
220
220
  */
221
221
  function lookup(collectionId: string, data: LookupOrdersRequest): Promise<LookupOrdersResponse>;
222
222
  /**
223
- * Advanced query for orders with date filtering, metadata search, and sorting.
223
+ * Advanced query for orders with order-level and item-level filtering.
224
224
  * More powerful than the basic list() function.
225
225
  *
226
226
  * @param collectionId - Identifier of the parent collection
@@ -251,6 +251,17 @@ export declare namespace order {
251
251
  * },
252
252
  * includeItems: true
253
253
  * })
254
+ *
255
+ * // Find orders containing a specific product batch
256
+ * const batchOrders = await order.query('coll_123', {
257
+ * query: {
258
+ * item: {
259
+ * productId: 'prod_789',
260
+ * batchId: 'BATCH-2024-001'
261
+ * }
262
+ * },
263
+ * includeItems: true
264
+ * })
254
265
  * ```
255
266
  */
256
267
  function query(collectionId: string, data: QueryOrdersRequest): Promise<QueryOrdersResponse>;
@@ -443,30 +454,6 @@ export declare namespace order {
443
454
  * ```
444
455
  */
445
456
  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
457
  /**
471
458
  * Find all orders containing items from a specific product.
472
459
  * Uses indexed queries for fast lookups across order items.
@@ -488,54 +475,6 @@ export declare namespace order {
488
475
  * ```
489
476
  */
490
477
  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
478
  /**
540
479
  * Get individual order items for a specific product.
541
480
  * Returns all matching items with optional order summary.
@@ -558,46 +497,18 @@ export declare namespace order {
558
497
  */
559
498
  function findItemsByProduct(collectionId: string, productId: string, params?: FindItemsByAttributeParams): Promise<FindItemsByAttributeResponse>;
560
499
  /**
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.
500
+ * Get unique order IDs containing items for a specific product.
582
501
  * Lightweight query that only returns order IDs, not full order objects.
583
502
  *
584
503
  * @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
504
+ * @param attribute - Attribute to search by ('productId')
505
+ * @param value - Product ID to search for
587
506
  * @param params - Optional pagination parameters
588
507
  * @returns Promise resolving to a GetOrderIdsResponse
589
508
  * @throws ErrorResponse if the request fails
590
509
  *
591
510
  * @example
592
511
  * ```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
512
  * // Get order IDs for a product
602
513
  * const productOrders = await order.getOrderIdsByAttribute(
603
514
  * 'coll_123',
@@ -607,5 +518,5 @@ export declare namespace order {
607
518
  * )
608
519
  * ```
609
520
  */
610
- function getOrderIdsByAttribute(collectionId: string, attribute: 'batchId' | 'productId' | 'variantId', value: string, params?: GetOrderIdsParams): Promise<GetOrderIdsResponse>;
521
+ function getOrderIdsByAttribute(collectionId: string, attribute: 'productId', value: string, params?: GetOrderIdsParams): Promise<GetOrderIdsResponse>;
611
522
  }
package/dist/api/order.js CHANGED
@@ -286,8 +286,14 @@ export var order;
286
286
  return post(path, data);
287
287
  }
288
288
  order.lookup = lookup;
289
+ function validateOrderQuery(data) {
290
+ var _a;
291
+ if (((_a = data.query) === null || _a === void 0 ? void 0 : _a.item) && !data.query.item.productId) {
292
+ throw new Error('query.item.productId is required when using item-level order filters');
293
+ }
294
+ }
289
295
  /**
290
- * Advanced query for orders with date filtering, metadata search, and sorting.
296
+ * Advanced query for orders with order-level and item-level filtering.
291
297
  * More powerful than the basic list() function.
292
298
  *
293
299
  * @param collectionId - Identifier of the parent collection
@@ -318,9 +324,21 @@ export var order;
318
324
  * },
319
325
  * includeItems: true
320
326
  * })
327
+ *
328
+ * // Find orders containing a specific product batch
329
+ * const batchOrders = await order.query('coll_123', {
330
+ * query: {
331
+ * item: {
332
+ * productId: 'prod_789',
333
+ * batchId: 'BATCH-2024-001'
334
+ * }
335
+ * },
336
+ * includeItems: true
337
+ * })
321
338
  * ```
322
339
  */
323
340
  async function query(collectionId, data) {
341
+ validateOrderQuery(data);
324
342
  const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/query`;
325
343
  return post(path, data);
326
344
  }
@@ -576,42 +594,6 @@ export var order;
576
594
  return post(path, params || {});
577
595
  }
578
596
  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
597
  /**
616
598
  * Find all orders containing items from a specific product.
617
599
  * Uses indexed queries for fast lookups across order items.
@@ -645,78 +627,6 @@ export var order;
645
627
  return request(path);
646
628
  }
647
629
  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
630
  /**
721
631
  * Get individual order items for a specific product.
722
632
  * Returns all matching items with optional order summary.
@@ -751,58 +661,18 @@ export var order;
751
661
  }
752
662
  order.findItemsByProduct = findItemsByProduct;
753
663
  /**
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.
664
+ * Get unique order IDs containing items for a specific product.
787
665
  * Lightweight query that only returns order IDs, not full order objects.
788
666
  *
789
667
  * @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
668
+ * @param attribute - Attribute to search by ('productId')
669
+ * @param value - Product ID to search for
792
670
  * @param params - Optional pagination parameters
793
671
  * @returns Promise resolving to a GetOrderIdsResponse
794
672
  * @throws ErrorResponse if the request fails
795
673
  *
796
674
  * @example
797
675
  * ```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
676
  * // Get order IDs for a product
807
677
  * const productOrders = await order.getOrderIdsByAttribute(
808
678
  * 'coll_123',