@proveanything/smartlinks 1.3.18 → 1.3.20
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/crate.d.ts +96 -7
- package/dist/api/crate.js +104 -8
- package/dist/api/order.d.ts +130 -1
- package/dist/api/order.js +149 -0
- package/dist/docs/API_SUMMARY.md +278 -11
- package/dist/types/crate.d.ts +79 -0
- package/dist/types/crate.js +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/order.d.ts +162 -0
- package/docs/API_SUMMARY.md +278 -11
- package/package.json +1 -1
package/dist/api/crate.d.ts
CHANGED
|
@@ -1,22 +1,111 @@
|
|
|
1
|
+
import { GetCrateResponse, CreateCrateRequest, CreateCrateResponse, UpdateCrateRequest, UpdateCrateResponse, DeleteCrateResponse, ListCratesRequest, ListCratesResponse } from "../types/crate";
|
|
2
|
+
/**
|
|
3
|
+
* Crate Management API
|
|
4
|
+
*
|
|
5
|
+
* Manage crates (containers for tags/products) within collections.
|
|
6
|
+
*/
|
|
1
7
|
export declare namespace crate {
|
|
2
8
|
/**
|
|
3
|
-
*
|
|
9
|
+
* List crates for a collection with pagination support.
|
|
10
|
+
* Returns crates in pages, with support for soft-deleted crates.
|
|
11
|
+
*
|
|
12
|
+
* @param collectionId - Identifier of the parent collection
|
|
13
|
+
* @param params - Optional query parameters for pagination and filtering
|
|
14
|
+
* @returns Promise resolving to a ListCratesResponse object
|
|
15
|
+
* @throws ErrorResponse if the request fails
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Get first page
|
|
20
|
+
* const page1 = await crate.list('coll_123', { limit: 100 })
|
|
21
|
+
* console.log(`Found ${page1.items.length} crates`)
|
|
22
|
+
*
|
|
23
|
+
* // Get next page
|
|
24
|
+
* if (page1.hasMore) {
|
|
25
|
+
* const page2 = await crate.list('coll_123', {
|
|
26
|
+
* limit: 100,
|
|
27
|
+
* startAfter: page1.lastId
|
|
28
|
+
* })
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // Include soft-deleted crates
|
|
32
|
+
* const withDeleted = await crate.list('coll_123', {
|
|
33
|
+
* includeDeleted: true
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
4
36
|
*/
|
|
5
|
-
function
|
|
37
|
+
function list(collectionId: string, params?: ListCratesRequest): Promise<ListCratesResponse>;
|
|
6
38
|
/**
|
|
7
|
-
*
|
|
39
|
+
* Get a single crate by ID for a collection (admin only).
|
|
40
|
+
*
|
|
41
|
+
* @param collectionId - Identifier of the parent collection
|
|
42
|
+
* @param crateId - Crate ID
|
|
43
|
+
* @returns Promise resolving to a GetCrateResponse object
|
|
44
|
+
* @throws ErrorResponse if the request fails
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const crate = await crate.get('coll_123', 'crate_abc123')
|
|
49
|
+
* console.log(`Crate has ${crate.items?.length ?? 0} items`)
|
|
50
|
+
* ```
|
|
8
51
|
*/
|
|
9
|
-
function
|
|
52
|
+
function get(collectionId: string, crateId: string): Promise<GetCrateResponse>;
|
|
10
53
|
/**
|
|
11
54
|
* Create a new crate for a collection (admin only).
|
|
55
|
+
*
|
|
56
|
+
* @param collectionId - Identifier of the parent collection
|
|
57
|
+
* @param data - Crate creation data
|
|
58
|
+
* @returns Promise resolving to a CreateCrateResponse object
|
|
59
|
+
* @throws ErrorResponse if the request fails
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const newCrate = await crate.create('coll_123', {
|
|
64
|
+
* items: [
|
|
65
|
+
* {
|
|
66
|
+
* id: 'tag_001',
|
|
67
|
+
* codeId: 'ABC123',
|
|
68
|
+
* productId: 'prod_1',
|
|
69
|
+
* productName: 'Product Name'
|
|
70
|
+
* }
|
|
71
|
+
* ]
|
|
72
|
+
* })
|
|
73
|
+
* console.log(`Created crate ${newCrate.id}`)
|
|
74
|
+
* ```
|
|
12
75
|
*/
|
|
13
|
-
function create(collectionId: string, data:
|
|
76
|
+
function create(collectionId: string, data: CreateCrateRequest): Promise<CreateCrateResponse>;
|
|
14
77
|
/**
|
|
15
78
|
* Update a crate for a collection (admin only).
|
|
79
|
+
*
|
|
80
|
+
* @param collectionId - Identifier of the parent collection
|
|
81
|
+
* @param crateId - Crate ID
|
|
82
|
+
* @param data - Update data
|
|
83
|
+
* @returns Promise resolving to an UpdateCrateResponse object
|
|
84
|
+
* @throws ErrorResponse if the request fails
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const updated = await crate.update('coll_123', 'crate_abc123', {
|
|
89
|
+
* items: [
|
|
90
|
+
* { id: 'tag_002', codeId: 'XYZ789', productId: 'prod_2' }
|
|
91
|
+
* ]
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
16
94
|
*/
|
|
17
|
-
function update(collectionId: string, crateId: string, data:
|
|
95
|
+
function update(collectionId: string, crateId: string, data: UpdateCrateRequest): Promise<UpdateCrateResponse>;
|
|
18
96
|
/**
|
|
19
97
|
* Delete a crate for a collection (admin only).
|
|
98
|
+
* This performs a soft delete.
|
|
99
|
+
*
|
|
100
|
+
* @param collectionId - Identifier of the parent collection
|
|
101
|
+
* @param crateId - Crate ID
|
|
102
|
+
* @returns Promise resolving to a DeleteCrateResponse object
|
|
103
|
+
* @throws ErrorResponse if the request fails
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* await crate.remove('coll_123', 'crate_abc123')
|
|
108
|
+
* ```
|
|
20
109
|
*/
|
|
21
|
-
function remove(collectionId: string, crateId: string): Promise<
|
|
110
|
+
function remove(collectionId: string, crateId: string): Promise<DeleteCrateResponse>;
|
|
22
111
|
}
|
package/dist/api/crate.js
CHANGED
|
@@ -1,24 +1,94 @@
|
|
|
1
1
|
import { request, post, put, del } from "../http";
|
|
2
|
+
/**
|
|
3
|
+
* Crate Management API
|
|
4
|
+
*
|
|
5
|
+
* Manage crates (containers for tags/products) within collections.
|
|
6
|
+
*/
|
|
2
7
|
export var crate;
|
|
3
8
|
(function (crate) {
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
10
|
+
* List crates for a collection with pagination support.
|
|
11
|
+
* Returns crates in pages, with support for soft-deleted crates.
|
|
12
|
+
*
|
|
13
|
+
* @param collectionId - Identifier of the parent collection
|
|
14
|
+
* @param params - Optional query parameters for pagination and filtering
|
|
15
|
+
* @returns Promise resolving to a ListCratesResponse object
|
|
16
|
+
* @throws ErrorResponse if the request fails
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Get first page
|
|
21
|
+
* const page1 = await crate.list('coll_123', { limit: 100 })
|
|
22
|
+
* console.log(`Found ${page1.items.length} crates`)
|
|
23
|
+
*
|
|
24
|
+
* // Get next page
|
|
25
|
+
* if (page1.hasMore) {
|
|
26
|
+
* const page2 = await crate.list('coll_123', {
|
|
27
|
+
* limit: 100,
|
|
28
|
+
* startAfter: page1.lastId
|
|
29
|
+
* })
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Include soft-deleted crates
|
|
33
|
+
* const withDeleted = await crate.list('coll_123', {
|
|
34
|
+
* includeDeleted: true
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
6
37
|
*/
|
|
7
|
-
async function
|
|
8
|
-
const
|
|
38
|
+
async function list(collectionId, params) {
|
|
39
|
+
const queryParams = new URLSearchParams();
|
|
40
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
41
|
+
queryParams.append('limit', params.limit.toString());
|
|
42
|
+
if (params === null || params === void 0 ? void 0 : params.startAfter)
|
|
43
|
+
queryParams.append('startAfter', params.startAfter);
|
|
44
|
+
if (params === null || params === void 0 ? void 0 : params.includeDeleted)
|
|
45
|
+
queryParams.append('includeDeleted', 'true');
|
|
46
|
+
const query = queryParams.toString();
|
|
47
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/crate${query ? `?${query}` : ''}`;
|
|
9
48
|
return request(path);
|
|
10
49
|
}
|
|
11
|
-
crate.
|
|
50
|
+
crate.list = list;
|
|
12
51
|
/**
|
|
13
|
-
*
|
|
52
|
+
* Get a single crate by ID for a collection (admin only).
|
|
53
|
+
*
|
|
54
|
+
* @param collectionId - Identifier of the parent collection
|
|
55
|
+
* @param crateId - Crate ID
|
|
56
|
+
* @returns Promise resolving to a GetCrateResponse object
|
|
57
|
+
* @throws ErrorResponse if the request fails
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const crate = await crate.get('coll_123', 'crate_abc123')
|
|
62
|
+
* console.log(`Crate has ${crate.items?.length ?? 0} items`)
|
|
63
|
+
* ```
|
|
14
64
|
*/
|
|
15
|
-
async function
|
|
16
|
-
const path = `/admin/collection/${encodeURIComponent(collectionId)}/crate`;
|
|
65
|
+
async function get(collectionId, crateId) {
|
|
66
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/crate/${encodeURIComponent(crateId)}`;
|
|
17
67
|
return request(path);
|
|
18
68
|
}
|
|
19
|
-
crate.
|
|
69
|
+
crate.get = get;
|
|
20
70
|
/**
|
|
21
71
|
* Create a new crate for a collection (admin only).
|
|
72
|
+
*
|
|
73
|
+
* @param collectionId - Identifier of the parent collection
|
|
74
|
+
* @param data - Crate creation data
|
|
75
|
+
* @returns Promise resolving to a CreateCrateResponse object
|
|
76
|
+
* @throws ErrorResponse if the request fails
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const newCrate = await crate.create('coll_123', {
|
|
81
|
+
* items: [
|
|
82
|
+
* {
|
|
83
|
+
* id: 'tag_001',
|
|
84
|
+
* codeId: 'ABC123',
|
|
85
|
+
* productId: 'prod_1',
|
|
86
|
+
* productName: 'Product Name'
|
|
87
|
+
* }
|
|
88
|
+
* ]
|
|
89
|
+
* })
|
|
90
|
+
* console.log(`Created crate ${newCrate.id}`)
|
|
91
|
+
* ```
|
|
22
92
|
*/
|
|
23
93
|
async function create(collectionId, data) {
|
|
24
94
|
const path = `/admin/collection/${encodeURIComponent(collectionId)}/crate`;
|
|
@@ -27,6 +97,21 @@ export var crate;
|
|
|
27
97
|
crate.create = create;
|
|
28
98
|
/**
|
|
29
99
|
* Update a crate for a collection (admin only).
|
|
100
|
+
*
|
|
101
|
+
* @param collectionId - Identifier of the parent collection
|
|
102
|
+
* @param crateId - Crate ID
|
|
103
|
+
* @param data - Update data
|
|
104
|
+
* @returns Promise resolving to an UpdateCrateResponse object
|
|
105
|
+
* @throws ErrorResponse if the request fails
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const updated = await crate.update('coll_123', 'crate_abc123', {
|
|
110
|
+
* items: [
|
|
111
|
+
* { id: 'tag_002', codeId: 'XYZ789', productId: 'prod_2' }
|
|
112
|
+
* ]
|
|
113
|
+
* })
|
|
114
|
+
* ```
|
|
30
115
|
*/
|
|
31
116
|
async function update(collectionId, crateId, data) {
|
|
32
117
|
const path = `/admin/collection/${encodeURIComponent(collectionId)}/crate/${encodeURIComponent(crateId)}`;
|
|
@@ -35,6 +120,17 @@ export var crate;
|
|
|
35
120
|
crate.update = update;
|
|
36
121
|
/**
|
|
37
122
|
* Delete a crate for a collection (admin only).
|
|
123
|
+
* This performs a soft delete.
|
|
124
|
+
*
|
|
125
|
+
* @param collectionId - Identifier of the parent collection
|
|
126
|
+
* @param crateId - Crate ID
|
|
127
|
+
* @returns Promise resolving to a DeleteCrateResponse object
|
|
128
|
+
* @throws ErrorResponse if the request fails
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* await crate.remove('coll_123', 'crate_abc123')
|
|
133
|
+
* ```
|
|
38
134
|
*/
|
|
39
135
|
async function remove(collectionId, crateId) {
|
|
40
136
|
const path = `/admin/collection/${encodeURIComponent(collectionId)}/crate/${encodeURIComponent(crateId)}`;
|
package/dist/api/order.d.ts
CHANGED
|
@@ -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 } 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
|
*
|
|
@@ -314,4 +314,133 @@ export declare namespace order {
|
|
|
314
314
|
* ```
|
|
315
315
|
*/
|
|
316
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>;
|
|
317
446
|
}
|
package/dist/api/order.js
CHANGED
|
@@ -427,4 +427,153 @@ export var order;
|
|
|
427
427
|
return request(path);
|
|
428
428
|
}
|
|
429
429
|
order.findByProduct = findByProduct;
|
|
430
|
+
/**
|
|
431
|
+
* Get comprehensive scan analytics for all tags in an order.
|
|
432
|
+
* Returns scan counts, timestamps, locations, devices, and per-tag summaries.
|
|
433
|
+
*
|
|
434
|
+
* @param collectionId - Identifier of the parent collection
|
|
435
|
+
* @param orderId - Order ID
|
|
436
|
+
* @returns Promise resolving to an OrderAnalyticsResponse with scan analytics
|
|
437
|
+
* @throws ErrorResponse if the request fails
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* const analytics = await order.getAnalytics('coll_123', 'order_abc123')
|
|
442
|
+
*
|
|
443
|
+
* if (analytics.analytics) {
|
|
444
|
+
* console.log(`Total scans: ${analytics.analytics.totalScans}`)
|
|
445
|
+
* console.log(`Admin scans: ${analytics.analytics.adminScans}`)
|
|
446
|
+
* console.log(`Created at: ${analytics.analytics.estimatedCreatedAt}`)
|
|
447
|
+
* console.log(`Unique locations: ${analytics.analytics.uniqueLocations}`)
|
|
448
|
+
*
|
|
449
|
+
* analytics.analytics.tagSummaries.forEach(tag => {
|
|
450
|
+
* console.log(`Tag ${tag.tagId}: ${tag.totalScans} scans`)
|
|
451
|
+
* })
|
|
452
|
+
* }
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
async function getAnalytics(collectionId, orderId) {
|
|
456
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/analytics/${encodeURIComponent(orderId)}`;
|
|
457
|
+
return post(path, {});
|
|
458
|
+
}
|
|
459
|
+
order.getAnalytics = getAnalytics;
|
|
460
|
+
/**
|
|
461
|
+
* Get chronological timeline of all scan events for an order's tags.
|
|
462
|
+
* Supports filtering by date range and admin/customer scans.
|
|
463
|
+
*
|
|
464
|
+
* @param collectionId - Identifier of the parent collection
|
|
465
|
+
* @param orderId - Order ID
|
|
466
|
+
* @param params - Optional filters (limit, date range, isAdmin)
|
|
467
|
+
* @returns Promise resolving to a TimelineResponse with scan events
|
|
468
|
+
* @throws ErrorResponse if the request fails
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```typescript
|
|
472
|
+
* // Get all scan events
|
|
473
|
+
* const timeline = await order.getTimeline('coll_123', 'order_abc123')
|
|
474
|
+
*
|
|
475
|
+
* timeline.timeline.forEach(event => {
|
|
476
|
+
* console.log(`${event.timestamp}: ${event.eventType} by ${event.isAdmin ? 'admin' : 'customer'}`)
|
|
477
|
+
* })
|
|
478
|
+
*
|
|
479
|
+
* // Get admin scans only from last week
|
|
480
|
+
* const adminScans = await order.getTimeline('coll_123', 'order_abc123', {
|
|
481
|
+
* isAdmin: true,
|
|
482
|
+
* from: '2026-02-01T00:00:00Z',
|
|
483
|
+
* limit: 500
|
|
484
|
+
* })
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
async function getTimeline(collectionId, orderId, params) {
|
|
488
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/analytics/${encodeURIComponent(orderId)}/timeline`;
|
|
489
|
+
return post(path, params || {});
|
|
490
|
+
}
|
|
491
|
+
order.getTimeline = getTimeline;
|
|
492
|
+
/**
|
|
493
|
+
* Get location-based scan history for an order's tags.
|
|
494
|
+
* Shows where the order's tags have been scanned.
|
|
495
|
+
*
|
|
496
|
+
* @param collectionId - Identifier of the parent collection
|
|
497
|
+
* @param orderId - Order ID
|
|
498
|
+
* @param params - Optional limit parameter
|
|
499
|
+
* @returns Promise resolving to a LocationResponse with location scans
|
|
500
|
+
* @throws ErrorResponse if the request fails
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* const locations = await order.getLocationHistory('coll_123', 'order_abc123', {
|
|
505
|
+
* limit: 100
|
|
506
|
+
* })
|
|
507
|
+
*
|
|
508
|
+
* console.log(`Order scanned in ${locations.count} locations`)
|
|
509
|
+
* locations.locations.forEach(scan => {
|
|
510
|
+
* console.log(`${scan.location} at ${scan.timestamp}`)
|
|
511
|
+
* })
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
async function getLocationHistory(collectionId, orderId, params) {
|
|
515
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/analytics/${encodeURIComponent(orderId)}/locations`;
|
|
516
|
+
return post(path, params || {});
|
|
517
|
+
}
|
|
518
|
+
order.getLocationHistory = getLocationHistory;
|
|
519
|
+
/**
|
|
520
|
+
* Get analytics summary for multiple orders at once.
|
|
521
|
+
* Efficient way to retrieve scan data for many orders.
|
|
522
|
+
*
|
|
523
|
+
* @param collectionId - Identifier of the parent collection
|
|
524
|
+
* @param data - Request with array of order IDs and optional date filters
|
|
525
|
+
* @returns Promise resolving to a BulkAnalyticsResponse with summaries
|
|
526
|
+
* @throws ErrorResponse if the request fails
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```typescript
|
|
530
|
+
* const bulk = await order.getBulkAnalytics('coll_123', {
|
|
531
|
+
* orderIds: ['order_1', 'order_2', 'order_3'],
|
|
532
|
+
* from: '2026-01-01T00:00:00Z'
|
|
533
|
+
* })
|
|
534
|
+
*
|
|
535
|
+
* bulk.results.forEach(result => {
|
|
536
|
+
* if (result.analytics) {
|
|
537
|
+
* console.log(`${result.orderRef}: ${result.analytics.totalScans} scans`)
|
|
538
|
+
* }
|
|
539
|
+
* })
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
async function getBulkAnalytics(collectionId, data) {
|
|
543
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/analytics/bulk`;
|
|
544
|
+
return post(path, data);
|
|
545
|
+
}
|
|
546
|
+
order.getBulkAnalytics = getBulkAnalytics;
|
|
547
|
+
/**
|
|
548
|
+
* Get collection-wide analytics summary across all orders.
|
|
549
|
+
* Returns daily scan counts and admin activity overview.
|
|
550
|
+
*
|
|
551
|
+
* @param collectionId - Identifier of the parent collection
|
|
552
|
+
* @param params - Optional date range filters
|
|
553
|
+
* @returns Promise resolving to a CollectionSummaryResponse
|
|
554
|
+
* @throws ErrorResponse if the request fails
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```typescript
|
|
558
|
+
* // Get all-time collection summary
|
|
559
|
+
* const summary = await order.getCollectionSummary('coll_123')
|
|
560
|
+
*
|
|
561
|
+
* console.log(`Admin activity count: ${summary.adminActivity.count}`)
|
|
562
|
+
* console.log('Scans by day:')
|
|
563
|
+
* summary.scansByDay.forEach(day => {
|
|
564
|
+
* console.log(` ${day.date}: ${day.scanCount} scans`)
|
|
565
|
+
* })
|
|
566
|
+
*
|
|
567
|
+
* // Get summary for last 30 days
|
|
568
|
+
* const recentSummary = await order.getCollectionSummary('coll_123', {
|
|
569
|
+
* from: '2026-01-08T00:00:00Z',
|
|
570
|
+
* to: '2026-02-08T00:00:00Z'
|
|
571
|
+
* })
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
async function getCollectionSummary(collectionId, params) {
|
|
575
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/analytics/summary`;
|
|
576
|
+
return post(path, params || {});
|
|
577
|
+
}
|
|
578
|
+
order.getCollectionSummary = getCollectionSummary;
|
|
430
579
|
})(order || (order = {}));
|