@proveanything/smartlinks 1.3.17 → 1.3.19

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 { CreateOrderRequest, CreateOrderResponse, GetOrderResponse, UpdateOrderRequest, UpdateOrderResponse, DeleteOrderResponse, ListOrdersRequest, ListOrdersResponse, AddItemsRequest, AddItemsResponse, RemoveItemsRequest, RemoveItemsResponse, LookupOrdersRequest, LookupOrdersResponse } 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 } from "../types/order";
2
2
  /**
3
3
  * Order Management API
4
4
  *
@@ -34,20 +34,26 @@ export declare namespace order {
34
34
  */
35
35
  function create(collectionId: string, data: CreateOrderRequest): Promise<CreateOrderResponse>;
36
36
  /**
37
- * Get a single order by ID with all its items.
37
+ * Get a single order by ID.
38
38
  *
39
39
  * @param collectionId - Identifier of the parent collection
40
40
  * @param orderId - Order ID
41
+ * @param params - Optional parameters (includeItems)
41
42
  * @returns Promise resolving to a GetOrderResponse object
42
43
  * @throws ErrorResponse if the request fails
43
44
  *
44
45
  * @example
45
46
  * ```typescript
47
+ * // Get order without items (faster)
46
48
  * const order = await order.get('coll_123', 'order_abc123')
47
49
  * console.log(`Order has ${order.itemCount} items`)
50
+ *
51
+ * // Get order with items
52
+ * const orderWithItems = await order.get('coll_123', 'order_abc123', { includeItems: true })
53
+ * console.log(orderWithItems.items) // Items array available
48
54
  * ```
49
55
  */
50
- function get(collectionId: string, orderId: string): Promise<GetOrderResponse>;
56
+ function get(collectionId: string, orderId: string, params?: GetOrderParams): Promise<GetOrderResponse>;
51
57
  /**
52
58
  * Update order status or metadata.
53
59
  * Items are managed separately via addItems/removeItems.
@@ -95,7 +101,7 @@ export declare namespace order {
95
101
  *
96
102
  * @example
97
103
  * ```typescript
98
- * // List all orders
104
+ * // List all orders (without items for better performance)
99
105
  * const all = await order.list('coll_123')
100
106
  *
101
107
  * // List with filters
@@ -105,13 +111,40 @@ export declare namespace order {
105
111
  * offset: 0
106
112
  * })
107
113
  *
108
- * // Filter by customer
114
+ * // Filter by customer with items
109
115
  * const customerOrders = await order.list('coll_123', {
110
- * customerId: 'CUST-789'
116
+ * customerId: 'CUST-789',
117
+ * includeItems: true
111
118
  * })
112
119
  * ```
113
120
  */
114
121
  function list(collectionId: string, params?: ListOrdersRequest): Promise<ListOrdersResponse>;
122
+ /**
123
+ * Get items from an order with pagination support.
124
+ * Use this for orders with many items instead of includeItems.
125
+ *
126
+ * @param collectionId - Identifier of the parent collection
127
+ * @param orderId - Order ID
128
+ * @param params - Optional pagination parameters
129
+ * @returns Promise resolving to a GetOrderItemsResponse object
130
+ * @throws ErrorResponse if the request fails
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * // Get first page of items
135
+ * const page1 = await order.getItems('coll_123', 'order_abc123', {
136
+ * limit: 100,
137
+ * offset: 0
138
+ * })
139
+ *
140
+ * // Get next page
141
+ * const page2 = await order.getItems('coll_123', 'order_abc123', {
142
+ * limit: 100,
143
+ * offset: 100
144
+ * })
145
+ * ```
146
+ */
147
+ function getItems(collectionId: string, orderId: string, params?: GetOrderItemsParams): Promise<GetOrderItemsResponse>;
115
148
  /**
116
149
  * Add additional items to an existing order.
117
150
  *
@@ -186,4 +219,228 @@ export declare namespace order {
186
219
  * ```
187
220
  */
188
221
  function lookup(collectionId: string, data: LookupOrdersRequest): Promise<LookupOrdersResponse>;
222
+ /**
223
+ * Advanced query for orders with date filtering, metadata search, and sorting.
224
+ * More powerful than the basic list() function.
225
+ *
226
+ * @param collectionId - Identifier of the parent collection
227
+ * @param data - Query parameters with filters, sorting, and pagination
228
+ * @returns Promise resolving to a QueryOrdersResponse
229
+ * @throws ErrorResponse if the request fails
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * // Find pending orders created in January 2026
234
+ * const result = await order.query('coll_123', {
235
+ * query: {
236
+ * status: 'pending',
237
+ * createdAfter: '2026-01-01T00:00:00Z',
238
+ * createdBefore: '2026-02-01T00:00:00Z',
239
+ * sortBy: 'createdAt',
240
+ * sortOrder: 'desc'
241
+ * },
242
+ * limit: 50
243
+ * })
244
+ *
245
+ * // Find orders with specific metadata and item count
246
+ * const highPriority = await order.query('coll_123', {
247
+ * query: {
248
+ * metadata: { priority: 'high' },
249
+ * minItemCount: 10,
250
+ * maxItemCount: 100
251
+ * },
252
+ * includeItems: true
253
+ * })
254
+ * ```
255
+ */
256
+ function query(collectionId: string, data: QueryOrdersRequest): Promise<QueryOrdersResponse>;
257
+ /**
258
+ * Get reports and aggregations for orders.
259
+ * Provides analytics grouped by status, customer, product, date, etc.
260
+ *
261
+ * @param collectionId - Identifier of the parent collection
262
+ * @param params - Report parameters specifying grouping and filters
263
+ * @returns Promise resolving to a ReportsResponse with aggregated data
264
+ * @throws ErrorResponse if the request fails
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * // Get order counts by status
269
+ * const statusReport = await order.reports('coll_123', {
270
+ * groupByStatus: true
271
+ * })
272
+ * console.log(statusReport.ordersByStatus)
273
+ * // { pending: 45, shipped: 123, completed: 789 }
274
+ *
275
+ * // Get comprehensive analytics
276
+ * const fullReport = await order.reports('coll_123', {
277
+ * groupByStatus: true,
278
+ * groupByProduct: true,
279
+ * includeItemStats: true,
280
+ * createdAfter: '2026-01-01T00:00:00Z'
281
+ * })
282
+ * console.log(fullReport.itemStats?.avgItemsPerOrder)
283
+ *
284
+ * // Get top 10 customers by order count
285
+ * const topCustomers = await order.reports('coll_123', {
286
+ * groupByCustomer: true,
287
+ * topN: 10
288
+ * })
289
+ * ```
290
+ */
291
+ function reports(collectionId: string, params?: ReportsParams): Promise<ReportsResponse>;
292
+ /**
293
+ * Find all orders containing items with a specific product ID.
294
+ * Uses the automatic productSummary tracking in order metadata.
295
+ *
296
+ * @param collectionId - Identifier of the parent collection
297
+ * @param productId - Product ID to search for
298
+ * @param params - Optional pagination and includeItems parameters
299
+ * @returns Promise resolving to a LookupByProductResponse
300
+ * @throws ErrorResponse if the request fails
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * // Find all orders with a specific product
305
+ * const result = await order.findByProduct('coll_123', 'product_abc123', {
306
+ * limit: 50,
307
+ * includeItems: false
308
+ * })
309
+ *
310
+ * result.orders.forEach(ord => {
311
+ * const count = ord.metadata.productSummary?.['product_abc123'] ?? 0
312
+ * console.log(`Order ${ord.orderRef} has ${count} items of this product`)
313
+ * })
314
+ * ```
315
+ */
316
+ function findByProduct(collectionId: string, productId: string, params?: LookupByProductParams): Promise<LookupByProductResponse>;
317
+ /**
318
+ * Get comprehensive scan analytics for all tags in an order.
319
+ * Returns scan counts, timestamps, locations, devices, and per-tag summaries.
320
+ *
321
+ * @param collectionId - Identifier of the parent collection
322
+ * @param orderId - Order ID
323
+ * @returns Promise resolving to an OrderAnalyticsResponse with scan analytics
324
+ * @throws ErrorResponse if the request fails
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * const analytics = await order.getAnalytics('coll_123', 'order_abc123')
329
+ *
330
+ * if (analytics.analytics) {
331
+ * console.log(`Total scans: ${analytics.analytics.totalScans}`)
332
+ * console.log(`Admin scans: ${analytics.analytics.adminScans}`)
333
+ * console.log(`Created at: ${analytics.analytics.estimatedCreatedAt}`)
334
+ * console.log(`Unique locations: ${analytics.analytics.uniqueLocations}`)
335
+ *
336
+ * analytics.analytics.tagSummaries.forEach(tag => {
337
+ * console.log(`Tag ${tag.tagId}: ${tag.totalScans} scans`)
338
+ * })
339
+ * }
340
+ * ```
341
+ */
342
+ function getAnalytics(collectionId: string, orderId: string): Promise<OrderAnalyticsResponse>;
343
+ /**
344
+ * Get chronological timeline of all scan events for an order's tags.
345
+ * Supports filtering by date range and admin/customer scans.
346
+ *
347
+ * @param collectionId - Identifier of the parent collection
348
+ * @param orderId - Order ID
349
+ * @param params - Optional filters (limit, date range, isAdmin)
350
+ * @returns Promise resolving to a TimelineResponse with scan events
351
+ * @throws ErrorResponse if the request fails
352
+ *
353
+ * @example
354
+ * ```typescript
355
+ * // Get all scan events
356
+ * const timeline = await order.getTimeline('coll_123', 'order_abc123')
357
+ *
358
+ * timeline.timeline.forEach(event => {
359
+ * console.log(`${event.timestamp}: ${event.eventType} by ${event.isAdmin ? 'admin' : 'customer'}`)
360
+ * })
361
+ *
362
+ * // Get admin scans only from last week
363
+ * const adminScans = await order.getTimeline('coll_123', 'order_abc123', {
364
+ * isAdmin: true,
365
+ * from: '2026-02-01T00:00:00Z',
366
+ * limit: 500
367
+ * })
368
+ * ```
369
+ */
370
+ function getTimeline(collectionId: string, orderId: string, params?: TimelineRequest): Promise<TimelineResponse>;
371
+ /**
372
+ * Get location-based scan history for an order's tags.
373
+ * Shows where the order's tags have been scanned.
374
+ *
375
+ * @param collectionId - Identifier of the parent collection
376
+ * @param orderId - Order ID
377
+ * @param params - Optional limit parameter
378
+ * @returns Promise resolving to a LocationResponse with location scans
379
+ * @throws ErrorResponse if the request fails
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * const locations = await order.getLocationHistory('coll_123', 'order_abc123', {
384
+ * limit: 100
385
+ * })
386
+ *
387
+ * console.log(`Order scanned in ${locations.count} locations`)
388
+ * locations.locations.forEach(scan => {
389
+ * console.log(`${scan.location} at ${scan.timestamp}`)
390
+ * })
391
+ * ```
392
+ */
393
+ function getLocationHistory(collectionId: string, orderId: string, params?: LocationRequest): Promise<LocationResponse>;
394
+ /**
395
+ * Get analytics summary for multiple orders at once.
396
+ * Efficient way to retrieve scan data for many orders.
397
+ *
398
+ * @param collectionId - Identifier of the parent collection
399
+ * @param data - Request with array of order IDs and optional date filters
400
+ * @returns Promise resolving to a BulkAnalyticsResponse with summaries
401
+ * @throws ErrorResponse if the request fails
402
+ *
403
+ * @example
404
+ * ```typescript
405
+ * const bulk = await order.getBulkAnalytics('coll_123', {
406
+ * orderIds: ['order_1', 'order_2', 'order_3'],
407
+ * from: '2026-01-01T00:00:00Z'
408
+ * })
409
+ *
410
+ * bulk.results.forEach(result => {
411
+ * if (result.analytics) {
412
+ * console.log(`${result.orderRef}: ${result.analytics.totalScans} scans`)
413
+ * }
414
+ * })
415
+ * ```
416
+ */
417
+ function getBulkAnalytics(collectionId: string, data: BulkAnalyticsRequest): Promise<BulkAnalyticsResponse>;
418
+ /**
419
+ * Get collection-wide analytics summary across all orders.
420
+ * Returns daily scan counts and admin activity overview.
421
+ *
422
+ * @param collectionId - Identifier of the parent collection
423
+ * @param params - Optional date range filters
424
+ * @returns Promise resolving to a CollectionSummaryResponse
425
+ * @throws ErrorResponse if the request fails
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * // Get all-time collection summary
430
+ * const summary = await order.getCollectionSummary('coll_123')
431
+ *
432
+ * console.log(`Admin activity count: ${summary.adminActivity.count}`)
433
+ * console.log('Scans by day:')
434
+ * summary.scansByDay.forEach(day => {
435
+ * console.log(` ${day.date}: ${day.scanCount} scans`)
436
+ * })
437
+ *
438
+ * // Get summary for last 30 days
439
+ * const recentSummary = await order.getCollectionSummary('coll_123', {
440
+ * from: '2026-01-08T00:00:00Z',
441
+ * to: '2026-02-08T00:00:00Z'
442
+ * })
443
+ * ```
444
+ */
445
+ function getCollectionSummary(collectionId: string, params?: SummaryRequest): Promise<CollectionSummaryResponse>;
189
446
  }