@proveanything/smartlinks 1.3.17 → 1.3.18
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.d.ts +134 -6
- package/dist/api/order.js +196 -6
- package/dist/docs/API_SUMMARY.md +140 -6
- package/dist/types/order.d.ts +108 -2
- package/docs/API_SUMMARY.md +140 -6
- package/package.json +1 -1
package/dist/api/order.d.ts
CHANGED
|
@@ -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 } 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
|
|
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,99 @@ 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>;
|
|
189
317
|
}
|
package/dist/api/order.js
CHANGED
|
@@ -40,21 +40,31 @@ export var order;
|
|
|
40
40
|
}
|
|
41
41
|
order.create = create;
|
|
42
42
|
/**
|
|
43
|
-
* Get a single order by ID
|
|
43
|
+
* Get a single order by ID.
|
|
44
44
|
*
|
|
45
45
|
* @param collectionId - Identifier of the parent collection
|
|
46
46
|
* @param orderId - Order ID
|
|
47
|
+
* @param params - Optional parameters (includeItems)
|
|
47
48
|
* @returns Promise resolving to a GetOrderResponse object
|
|
48
49
|
* @throws ErrorResponse if the request fails
|
|
49
50
|
*
|
|
50
51
|
* @example
|
|
51
52
|
* ```typescript
|
|
53
|
+
* // Get order without items (faster)
|
|
52
54
|
* const order = await order.get('coll_123', 'order_abc123')
|
|
53
55
|
* console.log(`Order has ${order.itemCount} items`)
|
|
56
|
+
*
|
|
57
|
+
* // Get order with items
|
|
58
|
+
* const orderWithItems = await order.get('coll_123', 'order_abc123', { includeItems: true })
|
|
59
|
+
* console.log(orderWithItems.items) // Items array available
|
|
54
60
|
* ```
|
|
55
61
|
*/
|
|
56
|
-
async function get(collectionId, orderId) {
|
|
57
|
-
const
|
|
62
|
+
async function get(collectionId, orderId, params) {
|
|
63
|
+
const queryParams = new URLSearchParams();
|
|
64
|
+
if (params === null || params === void 0 ? void 0 : params.includeItems)
|
|
65
|
+
queryParams.append('includeItems', 'true');
|
|
66
|
+
const query = queryParams.toString();
|
|
67
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}${query ? `?${query}` : ''}`;
|
|
58
68
|
return request(path);
|
|
59
69
|
}
|
|
60
70
|
order.get = get;
|
|
@@ -113,7 +123,7 @@ export var order;
|
|
|
113
123
|
*
|
|
114
124
|
* @example
|
|
115
125
|
* ```typescript
|
|
116
|
-
* // List all orders
|
|
126
|
+
* // List all orders (without items for better performance)
|
|
117
127
|
* const all = await order.list('coll_123')
|
|
118
128
|
*
|
|
119
129
|
* // List with filters
|
|
@@ -123,9 +133,10 @@ export var order;
|
|
|
123
133
|
* offset: 0
|
|
124
134
|
* })
|
|
125
135
|
*
|
|
126
|
-
* // Filter by customer
|
|
136
|
+
* // Filter by customer with items
|
|
127
137
|
* const customerOrders = await order.list('coll_123', {
|
|
128
|
-
* customerId: 'CUST-789'
|
|
138
|
+
* customerId: 'CUST-789',
|
|
139
|
+
* includeItems: true
|
|
129
140
|
* })
|
|
130
141
|
* ```
|
|
131
142
|
*/
|
|
@@ -141,11 +152,49 @@ export var order;
|
|
|
141
152
|
queryParams.append('orderRef', params.orderRef);
|
|
142
153
|
if (params === null || params === void 0 ? void 0 : params.customerId)
|
|
143
154
|
queryParams.append('customerId', params.customerId);
|
|
155
|
+
if (params === null || params === void 0 ? void 0 : params.includeItems)
|
|
156
|
+
queryParams.append('includeItems', 'true');
|
|
144
157
|
const query = queryParams.toString();
|
|
145
158
|
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders${query ? `?${query}` : ''}`;
|
|
146
159
|
return request(path);
|
|
147
160
|
}
|
|
148
161
|
order.list = list;
|
|
162
|
+
/**
|
|
163
|
+
* Get items from an order with pagination support.
|
|
164
|
+
* Use this for orders with many items instead of includeItems.
|
|
165
|
+
*
|
|
166
|
+
* @param collectionId - Identifier of the parent collection
|
|
167
|
+
* @param orderId - Order ID
|
|
168
|
+
* @param params - Optional pagination parameters
|
|
169
|
+
* @returns Promise resolving to a GetOrderItemsResponse object
|
|
170
|
+
* @throws ErrorResponse if the request fails
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // Get first page of items
|
|
175
|
+
* const page1 = await order.getItems('coll_123', 'order_abc123', {
|
|
176
|
+
* limit: 100,
|
|
177
|
+
* offset: 0
|
|
178
|
+
* })
|
|
179
|
+
*
|
|
180
|
+
* // Get next page
|
|
181
|
+
* const page2 = await order.getItems('coll_123', 'order_abc123', {
|
|
182
|
+
* limit: 100,
|
|
183
|
+
* offset: 100
|
|
184
|
+
* })
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
async function getItems(collectionId, orderId, params) {
|
|
188
|
+
const queryParams = new URLSearchParams();
|
|
189
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
190
|
+
queryParams.append('limit', params.limit.toString());
|
|
191
|
+
if (params === null || params === void 0 ? void 0 : params.offset)
|
|
192
|
+
queryParams.append('offset', params.offset.toString());
|
|
193
|
+
const query = queryParams.toString();
|
|
194
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}/items${query ? `?${query}` : ''}`;
|
|
195
|
+
return request(path);
|
|
196
|
+
}
|
|
197
|
+
order.getItems = getItems;
|
|
149
198
|
/**
|
|
150
199
|
* Add additional items to an existing order.
|
|
151
200
|
*
|
|
@@ -237,4 +286,145 @@ export var order;
|
|
|
237
286
|
return post(path, data);
|
|
238
287
|
}
|
|
239
288
|
order.lookup = lookup;
|
|
289
|
+
/**
|
|
290
|
+
* Advanced query for orders with date filtering, metadata search, and sorting.
|
|
291
|
+
* More powerful than the basic list() function.
|
|
292
|
+
*
|
|
293
|
+
* @param collectionId - Identifier of the parent collection
|
|
294
|
+
* @param data - Query parameters with filters, sorting, and pagination
|
|
295
|
+
* @returns Promise resolving to a QueryOrdersResponse
|
|
296
|
+
* @throws ErrorResponse if the request fails
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* // Find pending orders created in January 2026
|
|
301
|
+
* const result = await order.query('coll_123', {
|
|
302
|
+
* query: {
|
|
303
|
+
* status: 'pending',
|
|
304
|
+
* createdAfter: '2026-01-01T00:00:00Z',
|
|
305
|
+
* createdBefore: '2026-02-01T00:00:00Z',
|
|
306
|
+
* sortBy: 'createdAt',
|
|
307
|
+
* sortOrder: 'desc'
|
|
308
|
+
* },
|
|
309
|
+
* limit: 50
|
|
310
|
+
* })
|
|
311
|
+
*
|
|
312
|
+
* // Find orders with specific metadata and item count
|
|
313
|
+
* const highPriority = await order.query('coll_123', {
|
|
314
|
+
* query: {
|
|
315
|
+
* metadata: { priority: 'high' },
|
|
316
|
+
* minItemCount: 10,
|
|
317
|
+
* maxItemCount: 100
|
|
318
|
+
* },
|
|
319
|
+
* includeItems: true
|
|
320
|
+
* })
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
async function query(collectionId, data) {
|
|
324
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/query`;
|
|
325
|
+
return post(path, data);
|
|
326
|
+
}
|
|
327
|
+
order.query = query;
|
|
328
|
+
/**
|
|
329
|
+
* Get reports and aggregations for orders.
|
|
330
|
+
* Provides analytics grouped by status, customer, product, date, etc.
|
|
331
|
+
*
|
|
332
|
+
* @param collectionId - Identifier of the parent collection
|
|
333
|
+
* @param params - Report parameters specifying grouping and filters
|
|
334
|
+
* @returns Promise resolving to a ReportsResponse with aggregated data
|
|
335
|
+
* @throws ErrorResponse if the request fails
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* // Get order counts by status
|
|
340
|
+
* const statusReport = await order.reports('coll_123', {
|
|
341
|
+
* groupByStatus: true
|
|
342
|
+
* })
|
|
343
|
+
* console.log(statusReport.ordersByStatus)
|
|
344
|
+
* // { pending: 45, shipped: 123, completed: 789 }
|
|
345
|
+
*
|
|
346
|
+
* // Get comprehensive analytics
|
|
347
|
+
* const fullReport = await order.reports('coll_123', {
|
|
348
|
+
* groupByStatus: true,
|
|
349
|
+
* groupByProduct: true,
|
|
350
|
+
* includeItemStats: true,
|
|
351
|
+
* createdAfter: '2026-01-01T00:00:00Z'
|
|
352
|
+
* })
|
|
353
|
+
* console.log(fullReport.itemStats?.avgItemsPerOrder)
|
|
354
|
+
*
|
|
355
|
+
* // Get top 10 customers by order count
|
|
356
|
+
* const topCustomers = await order.reports('coll_123', {
|
|
357
|
+
* groupByCustomer: true,
|
|
358
|
+
* topN: 10
|
|
359
|
+
* })
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
async function reports(collectionId, params) {
|
|
363
|
+
const queryParams = new URLSearchParams();
|
|
364
|
+
if (params === null || params === void 0 ? void 0 : params.groupByStatus)
|
|
365
|
+
queryParams.append('groupByStatus', 'true');
|
|
366
|
+
if (params === null || params === void 0 ? void 0 : params.groupByCollection)
|
|
367
|
+
queryParams.append('groupByCollection', 'true');
|
|
368
|
+
if (params === null || params === void 0 ? void 0 : params.groupByCustomer)
|
|
369
|
+
queryParams.append('groupByCustomer', 'true');
|
|
370
|
+
if (params === null || params === void 0 ? void 0 : params.groupByDate)
|
|
371
|
+
queryParams.append('groupByDate', 'true');
|
|
372
|
+
if (params === null || params === void 0 ? void 0 : params.groupByItemType)
|
|
373
|
+
queryParams.append('groupByItemType', 'true');
|
|
374
|
+
if (params === null || params === void 0 ? void 0 : params.groupByProduct)
|
|
375
|
+
queryParams.append('groupByProduct', 'true');
|
|
376
|
+
if (params === null || params === void 0 ? void 0 : params.includeItemStats)
|
|
377
|
+
queryParams.append('includeItemStats', 'true');
|
|
378
|
+
if ((params === null || params === void 0 ? void 0 : params.includeCount) !== undefined)
|
|
379
|
+
queryParams.append('includeCount', params.includeCount.toString());
|
|
380
|
+
if (params === null || params === void 0 ? void 0 : params.topN)
|
|
381
|
+
queryParams.append('topN', params.topN.toString());
|
|
382
|
+
if (params === null || params === void 0 ? void 0 : params.status)
|
|
383
|
+
queryParams.append('status', params.status);
|
|
384
|
+
if (params === null || params === void 0 ? void 0 : params.createdAfter)
|
|
385
|
+
queryParams.append('createdAfter', params.createdAfter);
|
|
386
|
+
if (params === null || params === void 0 ? void 0 : params.createdBefore)
|
|
387
|
+
queryParams.append('createdBefore', params.createdBefore);
|
|
388
|
+
const query = queryParams.toString();
|
|
389
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/reports${query ? `?${query}` : ''}`;
|
|
390
|
+
return request(path);
|
|
391
|
+
}
|
|
392
|
+
order.reports = reports;
|
|
393
|
+
/**
|
|
394
|
+
* Find all orders containing items with a specific product ID.
|
|
395
|
+
* Uses the automatic productSummary tracking in order metadata.
|
|
396
|
+
*
|
|
397
|
+
* @param collectionId - Identifier of the parent collection
|
|
398
|
+
* @param productId - Product ID to search for
|
|
399
|
+
* @param params - Optional pagination and includeItems parameters
|
|
400
|
+
* @returns Promise resolving to a LookupByProductResponse
|
|
401
|
+
* @throws ErrorResponse if the request fails
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* // Find all orders with a specific product
|
|
406
|
+
* const result = await order.findByProduct('coll_123', 'product_abc123', {
|
|
407
|
+
* limit: 50,
|
|
408
|
+
* includeItems: false
|
|
409
|
+
* })
|
|
410
|
+
*
|
|
411
|
+
* result.orders.forEach(ord => {
|
|
412
|
+
* const count = ord.metadata.productSummary?.['product_abc123'] ?? 0
|
|
413
|
+
* console.log(`Order ${ord.orderRef} has ${count} items of this product`)
|
|
414
|
+
* })
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
async function findByProduct(collectionId, productId, params) {
|
|
418
|
+
const queryParams = new URLSearchParams();
|
|
419
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
420
|
+
queryParams.append('limit', params.limit.toString());
|
|
421
|
+
if (params === null || params === void 0 ? void 0 : params.offset)
|
|
422
|
+
queryParams.append('offset', params.offset.toString());
|
|
423
|
+
if (params === null || params === void 0 ? void 0 : params.includeItems)
|
|
424
|
+
queryParams.append('includeItems', 'true');
|
|
425
|
+
const query = queryParams.toString();
|
|
426
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/product/${encodeURIComponent(productId)}${query ? `?${query}` : ''}`;
|
|
427
|
+
return request(path);
|
|
428
|
+
}
|
|
429
|
+
order.findByProduct = findByProduct;
|
|
240
430
|
})(order || (order = {}));
|
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.18 | Generated: 2026-02-07T16:00:44.350Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -2186,8 +2186,11 @@ interface Order {
|
|
|
2186
2186
|
customerId?: string // Customer's own customer ID (can map to CRM/contacts)
|
|
2187
2187
|
status: string // e.g., "pending", "processing", "shipped", "completed"
|
|
2188
2188
|
itemCount: number // Cached count of items (maintained automatically)
|
|
2189
|
-
metadata:
|
|
2190
|
-
|
|
2189
|
+
metadata: {
|
|
2190
|
+
productSummary?: Record<string, number> // productId -> count (auto-maintained)
|
|
2191
|
+
[key: string]: any // Flexible additional data
|
|
2192
|
+
}
|
|
2193
|
+
items?: OrderItem[] // Array of items (only when includeItems=true)
|
|
2191
2194
|
createdAt: string // ISO 8601 timestamp
|
|
2192
2195
|
updatedAt: string // ISO 8601 timestamp
|
|
2193
2196
|
}
|
|
@@ -2208,6 +2211,13 @@ interface CreateOrderRequest {
|
|
|
2208
2211
|
}
|
|
2209
2212
|
```
|
|
2210
2213
|
|
|
2214
|
+
**GetOrderParams** (interface)
|
|
2215
|
+
```typescript
|
|
2216
|
+
interface GetOrderParams {
|
|
2217
|
+
includeItems?: boolean // Optional: Include items array (default: false)
|
|
2218
|
+
}
|
|
2219
|
+
```
|
|
2220
|
+
|
|
2211
2221
|
**UpdateOrderRequest** (interface)
|
|
2212
2222
|
```typescript
|
|
2213
2223
|
interface UpdateOrderRequest {
|
|
@@ -2233,6 +2243,7 @@ interface ListOrdersRequest {
|
|
|
2233
2243
|
status?: string // Optional: Filter by status
|
|
2234
2244
|
orderRef?: string // Optional: Filter by order reference
|
|
2235
2245
|
customerId?: string // Optional: Filter by customer ID
|
|
2246
|
+
includeItems?: boolean // Optional: Include items array (default: false)
|
|
2236
2247
|
}
|
|
2237
2248
|
```
|
|
2238
2249
|
|
|
@@ -2280,6 +2291,110 @@ interface LookupOrdersResponse {
|
|
|
2280
2291
|
}
|
|
2281
2292
|
```
|
|
2282
2293
|
|
|
2294
|
+
**GetOrderItemsParams** (interface)
|
|
2295
|
+
```typescript
|
|
2296
|
+
interface GetOrderItemsParams {
|
|
2297
|
+
limit?: number // Optional: Max results (default: 100)
|
|
2298
|
+
offset?: number // Optional: Pagination offset (default: 0)
|
|
2299
|
+
}
|
|
2300
|
+
```
|
|
2301
|
+
|
|
2302
|
+
**GetOrderItemsResponse** (interface)
|
|
2303
|
+
```typescript
|
|
2304
|
+
interface GetOrderItemsResponse {
|
|
2305
|
+
items: OrderItem[]
|
|
2306
|
+
limit: number
|
|
2307
|
+
offset: number
|
|
2308
|
+
}
|
|
2309
|
+
```
|
|
2310
|
+
|
|
2311
|
+
**QueryOrdersRequest** (interface)
|
|
2312
|
+
```typescript
|
|
2313
|
+
interface QueryOrdersRequest {
|
|
2314
|
+
query?: {
|
|
2315
|
+
status?: string
|
|
2316
|
+
orderRef?: string
|
|
2317
|
+
customerId?: string
|
|
2318
|
+
createdAfter?: string // ISO 8601 date
|
|
2319
|
+
createdBefore?: string // ISO 8601 date
|
|
2320
|
+
updatedAfter?: string // ISO 8601 date
|
|
2321
|
+
updatedBefore?: string // ISO 8601 date
|
|
2322
|
+
minItemCount?: number
|
|
2323
|
+
maxItemCount?: number
|
|
2324
|
+
metadata?: Record<string, any>
|
|
2325
|
+
sortBy?: string
|
|
2326
|
+
sortOrder?: 'asc' | 'desc'
|
|
2327
|
+
}
|
|
2328
|
+
limit?: number // Optional: Max results (default: 100)
|
|
2329
|
+
offset?: number // Optional: Pagination offset (default: 0)
|
|
2330
|
+
includeItems?: boolean // Optional: Include items array (default: false)
|
|
2331
|
+
}
|
|
2332
|
+
```
|
|
2333
|
+
|
|
2334
|
+
**QueryOrdersResponse** (interface)
|
|
2335
|
+
```typescript
|
|
2336
|
+
interface QueryOrdersResponse {
|
|
2337
|
+
orders: Order[]
|
|
2338
|
+
limit: number
|
|
2339
|
+
offset: number
|
|
2340
|
+
}
|
|
2341
|
+
```
|
|
2342
|
+
|
|
2343
|
+
**ReportsParams** (interface)
|
|
2344
|
+
```typescript
|
|
2345
|
+
interface ReportsParams {
|
|
2346
|
+
groupByStatus?: boolean
|
|
2347
|
+
groupByCollection?: boolean
|
|
2348
|
+
groupByCustomer?: boolean
|
|
2349
|
+
groupByDate?: boolean
|
|
2350
|
+
groupByItemType?: boolean
|
|
2351
|
+
groupByProduct?: boolean
|
|
2352
|
+
includeItemStats?: boolean
|
|
2353
|
+
includeCount?: boolean // default: true
|
|
2354
|
+
topN?: number // for customer/product grouping (default: 10)
|
|
2355
|
+
status?: string
|
|
2356
|
+
createdAfter?: string // ISO 8601 date
|
|
2357
|
+
createdBefore?: string // ISO 8601 date
|
|
2358
|
+
}
|
|
2359
|
+
```
|
|
2360
|
+
|
|
2361
|
+
**ReportsResponse** (interface)
|
|
2362
|
+
```typescript
|
|
2363
|
+
interface ReportsResponse {
|
|
2364
|
+
totalOrders?: number
|
|
2365
|
+
ordersByStatus?: Record<string, number>
|
|
2366
|
+
ordersByCollection?: Record<string, number>
|
|
2367
|
+
ordersByCustomer?: Record<string, number>
|
|
2368
|
+
ordersByDate?: Record<string, number>
|
|
2369
|
+
itemsByType?: Record<string, number>
|
|
2370
|
+
itemsByProduct?: Record<string, number>
|
|
2371
|
+
itemStats?: {
|
|
2372
|
+
totalItems: number
|
|
2373
|
+
avgItemsPerOrder: number
|
|
2374
|
+
maxItemsInOrder: number
|
|
2375
|
+
minItemsInOrder: number
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
```
|
|
2379
|
+
|
|
2380
|
+
**LookupByProductParams** (interface)
|
|
2381
|
+
```typescript
|
|
2382
|
+
interface LookupByProductParams {
|
|
2383
|
+
limit?: number // Optional: Max results (default: 100)
|
|
2384
|
+
offset?: number // Optional: Pagination offset (default: 0)
|
|
2385
|
+
includeItems?: boolean // Optional: Include items array (default: false)
|
|
2386
|
+
}
|
|
2387
|
+
```
|
|
2388
|
+
|
|
2389
|
+
**LookupByProductResponse** (interface)
|
|
2390
|
+
```typescript
|
|
2391
|
+
interface LookupByProductResponse {
|
|
2392
|
+
orders: Order[]
|
|
2393
|
+
limit: number
|
|
2394
|
+
offset: number
|
|
2395
|
+
}
|
|
2396
|
+
```
|
|
2397
|
+
|
|
2283
2398
|
### product
|
|
2284
2399
|
|
|
2285
2400
|
**Product** (interface)
|
|
@@ -4013,8 +4128,9 @@ Lookup a tag by its ID (public). GET /public/nfc/findByTag/:tagId
|
|
|
4013
4128
|
Create a new order with items. ```typescript const order = await order.create('coll_123', { orderRef: 'ORD-12345', customerId: 'CUST-789', items: [ { itemType: 'tag', itemId: 'TAG001' }, { itemType: 'tag', itemId: 'TAG002' }, { itemType: 'serial', itemId: 'SN12345' } ], status: 'pending', metadata: { shipmentId: 'SHIP-789', destination: 'Warehouse B' } }) ```
|
|
4014
4129
|
|
|
4015
4130
|
**get**(collectionId: string,
|
|
4016
|
-
orderId: string
|
|
4017
|
-
|
|
4131
|
+
orderId: string,
|
|
4132
|
+
params?: GetOrderParams) → `Promise<GetOrderResponse>`
|
|
4133
|
+
Get a single order by ID. ```typescript // Get order without items (faster) const order = await order.get('coll_123', 'order_abc123') console.log(`Order has ${order.itemCount} items`) // Get order with items const orderWithItems = await order.get('coll_123', 'order_abc123', { includeItems: true }) console.log(orderWithItems.items) // Items array available ```
|
|
4018
4134
|
|
|
4019
4135
|
**update**(collectionId: string,
|
|
4020
4136
|
orderId: string,
|
|
@@ -4027,7 +4143,12 @@ Delete an order and all its items (cascade delete). ```typescript await order.re
|
|
|
4027
4143
|
|
|
4028
4144
|
**list**(collectionId: string,
|
|
4029
4145
|
params?: ListOrdersRequest) → `Promise<ListOrdersResponse>`
|
|
4030
|
-
List orders for a collection with optional filters and pagination. Orders are returned in descending order by createdAt (newest first). ```typescript // List all orders const all = await order.list('coll_123') // List with filters const pending = await order.list('coll_123', { status: 'pending', limit: 50, offset: 0 }) // Filter by customer const customerOrders = await order.list('coll_123', { customerId: 'CUST-789' }) ```
|
|
4146
|
+
List orders for a collection with optional filters and pagination. Orders are returned in descending order by createdAt (newest first). ```typescript // List all orders (without items for better performance) const all = await order.list('coll_123') // List with filters const pending = await order.list('coll_123', { status: 'pending', limit: 50, offset: 0 }) // Filter by customer with items const customerOrders = await order.list('coll_123', { customerId: 'CUST-789', includeItems: true }) ```
|
|
4147
|
+
|
|
4148
|
+
**getItems**(collectionId: string,
|
|
4149
|
+
orderId: string,
|
|
4150
|
+
params?: GetOrderItemsParams) → `Promise<GetOrderItemsResponse>`
|
|
4151
|
+
Get items from an order with pagination support. Use this for orders with many items instead of includeItems. ```typescript // Get first page of items const page1 = await order.getItems('coll_123', 'order_abc123', { limit: 100, offset: 0 }) // Get next page const page2 = await order.getItems('coll_123', 'order_abc123', { limit: 100, offset: 100 }) ```
|
|
4031
4152
|
|
|
4032
4153
|
**addItems**(collectionId: string,
|
|
4033
4154
|
orderId: string,
|
|
@@ -4043,6 +4164,19 @@ Remove specific items from an order. ```typescript const updated = await order.r
|
|
|
4043
4164
|
data: LookupOrdersRequest) → `Promise<LookupOrdersResponse>`
|
|
4044
4165
|
Find all orders containing specific items (tags, proofs, or serial numbers). Use case: Scan a tag and immediately see if it's part of any order. ```typescript // Scan a tag and find associated orders const result = await order.lookup('coll_123', { items: [ { itemType: 'tag', itemId: 'TAG001' } ] }) if (result.orders.length > 0) { console.log(`Tag is part of ${result.orders.length} order(s)`) result.orders.forEach(ord => { console.log(`Order ${ord.orderRef}: ${ord.status}`) }) } // Batch lookup multiple items const batchResult = await order.lookup('coll_123', { items: [ { itemType: 'tag', itemId: 'TAG001' }, { itemType: 'serial', itemId: 'SN12345' }, { itemType: 'proof', itemId: 'proof_xyz' } ] }) ```
|
|
4045
4166
|
|
|
4167
|
+
**query**(collectionId: string,
|
|
4168
|
+
data: QueryOrdersRequest) → `Promise<QueryOrdersResponse>`
|
|
4169
|
+
Advanced query for orders with date filtering, metadata search, and sorting. More powerful than the basic list() function. ```typescript // Find pending orders created in January 2026 const result = await order.query('coll_123', { query: { status: 'pending', createdAfter: '2026-01-01T00:00:00Z', createdBefore: '2026-02-01T00:00:00Z', sortBy: 'createdAt', sortOrder: 'desc' }, limit: 50 }) // Find orders with specific metadata and item count const highPriority = await order.query('coll_123', { query: { metadata: { priority: 'high' }, minItemCount: 10, maxItemCount: 100 }, includeItems: true }) ```
|
|
4170
|
+
|
|
4171
|
+
**reports**(collectionId: string,
|
|
4172
|
+
params?: ReportsParams) → `Promise<ReportsResponse>`
|
|
4173
|
+
Get reports and aggregations for orders. Provides analytics grouped by status, customer, product, date, etc. ```typescript // Get order counts by status const statusReport = await order.reports('coll_123', { groupByStatus: true }) console.log(statusReport.ordersByStatus) // { pending: 45, shipped: 123, completed: 789 } // Get comprehensive analytics const fullReport = await order.reports('coll_123', { groupByStatus: true, groupByProduct: true, includeItemStats: true, createdAfter: '2026-01-01T00:00:00Z' }) console.log(fullReport.itemStats?.avgItemsPerOrder) // Get top 10 customers by order count const topCustomers = await order.reports('coll_123', { groupByCustomer: true, topN: 10 }) ```
|
|
4174
|
+
|
|
4175
|
+
**findByProduct**(collectionId: string,
|
|
4176
|
+
productId: string,
|
|
4177
|
+
params?: LookupByProductParams) → `Promise<LookupByProductResponse>`
|
|
4178
|
+
Find all orders containing items with a specific product ID. Uses the automatic productSummary tracking in order metadata. ```typescript // Find all orders with a specific product const result = await order.findByProduct('coll_123', 'product_abc123', { limit: 50, includeItems: false }) result.orders.forEach(ord => { const count = ord.metadata.productSummary?.['product_abc123'] ?? 0 console.log(`Order ${ord.orderRef} has ${count} items of this product`) }) ```
|
|
4179
|
+
|
|
4046
4180
|
### product
|
|
4047
4181
|
|
|
4048
4182
|
**get**(collectionId: string,
|
package/dist/types/order.d.ts
CHANGED
|
@@ -26,8 +26,11 @@ export interface Order {
|
|
|
26
26
|
customerId?: string;
|
|
27
27
|
status: string;
|
|
28
28
|
itemCount: number;
|
|
29
|
-
metadata:
|
|
30
|
-
|
|
29
|
+
metadata: {
|
|
30
|
+
productSummary?: Record<string, number>;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
33
|
+
items?: OrderItem[];
|
|
31
34
|
createdAt: string;
|
|
32
35
|
updatedAt: string;
|
|
33
36
|
}
|
|
@@ -50,6 +53,12 @@ export interface CreateOrderRequest {
|
|
|
50
53
|
*/
|
|
51
54
|
export interface CreateOrderResponse extends Order {
|
|
52
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Query parameters for getting a single order.
|
|
58
|
+
*/
|
|
59
|
+
export interface GetOrderParams {
|
|
60
|
+
includeItems?: boolean;
|
|
61
|
+
}
|
|
53
62
|
/**
|
|
54
63
|
* Response from getting a single order.
|
|
55
64
|
*/
|
|
@@ -85,6 +94,7 @@ export interface ListOrdersRequest {
|
|
|
85
94
|
status?: string;
|
|
86
95
|
orderRef?: string;
|
|
87
96
|
customerId?: string;
|
|
97
|
+
includeItems?: boolean;
|
|
88
98
|
}
|
|
89
99
|
/**
|
|
90
100
|
* Response from listing orders.
|
|
@@ -135,3 +145,99 @@ export interface LookupOrdersRequest {
|
|
|
135
145
|
export interface LookupOrdersResponse {
|
|
136
146
|
orders: Order[];
|
|
137
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Query parameters for getting order items.
|
|
150
|
+
*/
|
|
151
|
+
export interface GetOrderItemsParams {
|
|
152
|
+
limit?: number;
|
|
153
|
+
offset?: number;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Response from getting order items.
|
|
157
|
+
*/
|
|
158
|
+
export interface GetOrderItemsResponse {
|
|
159
|
+
items: OrderItem[];
|
|
160
|
+
limit: number;
|
|
161
|
+
offset: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Request for advanced order querying.
|
|
165
|
+
*/
|
|
166
|
+
export interface QueryOrdersRequest {
|
|
167
|
+
query?: {
|
|
168
|
+
status?: string;
|
|
169
|
+
orderRef?: string;
|
|
170
|
+
customerId?: string;
|
|
171
|
+
createdAfter?: string;
|
|
172
|
+
createdBefore?: string;
|
|
173
|
+
updatedAfter?: string;
|
|
174
|
+
updatedBefore?: string;
|
|
175
|
+
minItemCount?: number;
|
|
176
|
+
maxItemCount?: number;
|
|
177
|
+
metadata?: Record<string, any>;
|
|
178
|
+
sortBy?: string;
|
|
179
|
+
sortOrder?: 'asc' | 'desc';
|
|
180
|
+
};
|
|
181
|
+
limit?: number;
|
|
182
|
+
offset?: number;
|
|
183
|
+
includeItems?: boolean;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Response from advanced order querying.
|
|
187
|
+
*/
|
|
188
|
+
export interface QueryOrdersResponse {
|
|
189
|
+
orders: Order[];
|
|
190
|
+
limit: number;
|
|
191
|
+
offset: number;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Query parameters for order reports.
|
|
195
|
+
*/
|
|
196
|
+
export interface ReportsParams {
|
|
197
|
+
groupByStatus?: boolean;
|
|
198
|
+
groupByCollection?: boolean;
|
|
199
|
+
groupByCustomer?: boolean;
|
|
200
|
+
groupByDate?: boolean;
|
|
201
|
+
groupByItemType?: boolean;
|
|
202
|
+
groupByProduct?: boolean;
|
|
203
|
+
includeItemStats?: boolean;
|
|
204
|
+
includeCount?: boolean;
|
|
205
|
+
topN?: number;
|
|
206
|
+
status?: string;
|
|
207
|
+
createdAfter?: string;
|
|
208
|
+
createdBefore?: string;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Response from order reports.
|
|
212
|
+
*/
|
|
213
|
+
export interface ReportsResponse {
|
|
214
|
+
totalOrders?: number;
|
|
215
|
+
ordersByStatus?: Record<string, number>;
|
|
216
|
+
ordersByCollection?: Record<string, number>;
|
|
217
|
+
ordersByCustomer?: Record<string, number>;
|
|
218
|
+
ordersByDate?: Record<string, number>;
|
|
219
|
+
itemsByType?: Record<string, number>;
|
|
220
|
+
itemsByProduct?: Record<string, number>;
|
|
221
|
+
itemStats?: {
|
|
222
|
+
totalItems: number;
|
|
223
|
+
avgItemsPerOrder: number;
|
|
224
|
+
maxItemsInOrder: number;
|
|
225
|
+
minItemsInOrder: number;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Query parameters for looking up orders by product.
|
|
230
|
+
*/
|
|
231
|
+
export interface LookupByProductParams {
|
|
232
|
+
limit?: number;
|
|
233
|
+
offset?: number;
|
|
234
|
+
includeItems?: boolean;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Response from looking up orders by product.
|
|
238
|
+
*/
|
|
239
|
+
export interface LookupByProductResponse {
|
|
240
|
+
orders: Order[];
|
|
241
|
+
limit: number;
|
|
242
|
+
offset: number;
|
|
243
|
+
}
|
package/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.18 | Generated: 2026-02-07T16:00:44.350Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -2186,8 +2186,11 @@ interface Order {
|
|
|
2186
2186
|
customerId?: string // Customer's own customer ID (can map to CRM/contacts)
|
|
2187
2187
|
status: string // e.g., "pending", "processing", "shipped", "completed"
|
|
2188
2188
|
itemCount: number // Cached count of items (maintained automatically)
|
|
2189
|
-
metadata:
|
|
2190
|
-
|
|
2189
|
+
metadata: {
|
|
2190
|
+
productSummary?: Record<string, number> // productId -> count (auto-maintained)
|
|
2191
|
+
[key: string]: any // Flexible additional data
|
|
2192
|
+
}
|
|
2193
|
+
items?: OrderItem[] // Array of items (only when includeItems=true)
|
|
2191
2194
|
createdAt: string // ISO 8601 timestamp
|
|
2192
2195
|
updatedAt: string // ISO 8601 timestamp
|
|
2193
2196
|
}
|
|
@@ -2208,6 +2211,13 @@ interface CreateOrderRequest {
|
|
|
2208
2211
|
}
|
|
2209
2212
|
```
|
|
2210
2213
|
|
|
2214
|
+
**GetOrderParams** (interface)
|
|
2215
|
+
```typescript
|
|
2216
|
+
interface GetOrderParams {
|
|
2217
|
+
includeItems?: boolean // Optional: Include items array (default: false)
|
|
2218
|
+
}
|
|
2219
|
+
```
|
|
2220
|
+
|
|
2211
2221
|
**UpdateOrderRequest** (interface)
|
|
2212
2222
|
```typescript
|
|
2213
2223
|
interface UpdateOrderRequest {
|
|
@@ -2233,6 +2243,7 @@ interface ListOrdersRequest {
|
|
|
2233
2243
|
status?: string // Optional: Filter by status
|
|
2234
2244
|
orderRef?: string // Optional: Filter by order reference
|
|
2235
2245
|
customerId?: string // Optional: Filter by customer ID
|
|
2246
|
+
includeItems?: boolean // Optional: Include items array (default: false)
|
|
2236
2247
|
}
|
|
2237
2248
|
```
|
|
2238
2249
|
|
|
@@ -2280,6 +2291,110 @@ interface LookupOrdersResponse {
|
|
|
2280
2291
|
}
|
|
2281
2292
|
```
|
|
2282
2293
|
|
|
2294
|
+
**GetOrderItemsParams** (interface)
|
|
2295
|
+
```typescript
|
|
2296
|
+
interface GetOrderItemsParams {
|
|
2297
|
+
limit?: number // Optional: Max results (default: 100)
|
|
2298
|
+
offset?: number // Optional: Pagination offset (default: 0)
|
|
2299
|
+
}
|
|
2300
|
+
```
|
|
2301
|
+
|
|
2302
|
+
**GetOrderItemsResponse** (interface)
|
|
2303
|
+
```typescript
|
|
2304
|
+
interface GetOrderItemsResponse {
|
|
2305
|
+
items: OrderItem[]
|
|
2306
|
+
limit: number
|
|
2307
|
+
offset: number
|
|
2308
|
+
}
|
|
2309
|
+
```
|
|
2310
|
+
|
|
2311
|
+
**QueryOrdersRequest** (interface)
|
|
2312
|
+
```typescript
|
|
2313
|
+
interface QueryOrdersRequest {
|
|
2314
|
+
query?: {
|
|
2315
|
+
status?: string
|
|
2316
|
+
orderRef?: string
|
|
2317
|
+
customerId?: string
|
|
2318
|
+
createdAfter?: string // ISO 8601 date
|
|
2319
|
+
createdBefore?: string // ISO 8601 date
|
|
2320
|
+
updatedAfter?: string // ISO 8601 date
|
|
2321
|
+
updatedBefore?: string // ISO 8601 date
|
|
2322
|
+
minItemCount?: number
|
|
2323
|
+
maxItemCount?: number
|
|
2324
|
+
metadata?: Record<string, any>
|
|
2325
|
+
sortBy?: string
|
|
2326
|
+
sortOrder?: 'asc' | 'desc'
|
|
2327
|
+
}
|
|
2328
|
+
limit?: number // Optional: Max results (default: 100)
|
|
2329
|
+
offset?: number // Optional: Pagination offset (default: 0)
|
|
2330
|
+
includeItems?: boolean // Optional: Include items array (default: false)
|
|
2331
|
+
}
|
|
2332
|
+
```
|
|
2333
|
+
|
|
2334
|
+
**QueryOrdersResponse** (interface)
|
|
2335
|
+
```typescript
|
|
2336
|
+
interface QueryOrdersResponse {
|
|
2337
|
+
orders: Order[]
|
|
2338
|
+
limit: number
|
|
2339
|
+
offset: number
|
|
2340
|
+
}
|
|
2341
|
+
```
|
|
2342
|
+
|
|
2343
|
+
**ReportsParams** (interface)
|
|
2344
|
+
```typescript
|
|
2345
|
+
interface ReportsParams {
|
|
2346
|
+
groupByStatus?: boolean
|
|
2347
|
+
groupByCollection?: boolean
|
|
2348
|
+
groupByCustomer?: boolean
|
|
2349
|
+
groupByDate?: boolean
|
|
2350
|
+
groupByItemType?: boolean
|
|
2351
|
+
groupByProduct?: boolean
|
|
2352
|
+
includeItemStats?: boolean
|
|
2353
|
+
includeCount?: boolean // default: true
|
|
2354
|
+
topN?: number // for customer/product grouping (default: 10)
|
|
2355
|
+
status?: string
|
|
2356
|
+
createdAfter?: string // ISO 8601 date
|
|
2357
|
+
createdBefore?: string // ISO 8601 date
|
|
2358
|
+
}
|
|
2359
|
+
```
|
|
2360
|
+
|
|
2361
|
+
**ReportsResponse** (interface)
|
|
2362
|
+
```typescript
|
|
2363
|
+
interface ReportsResponse {
|
|
2364
|
+
totalOrders?: number
|
|
2365
|
+
ordersByStatus?: Record<string, number>
|
|
2366
|
+
ordersByCollection?: Record<string, number>
|
|
2367
|
+
ordersByCustomer?: Record<string, number>
|
|
2368
|
+
ordersByDate?: Record<string, number>
|
|
2369
|
+
itemsByType?: Record<string, number>
|
|
2370
|
+
itemsByProduct?: Record<string, number>
|
|
2371
|
+
itemStats?: {
|
|
2372
|
+
totalItems: number
|
|
2373
|
+
avgItemsPerOrder: number
|
|
2374
|
+
maxItemsInOrder: number
|
|
2375
|
+
minItemsInOrder: number
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
```
|
|
2379
|
+
|
|
2380
|
+
**LookupByProductParams** (interface)
|
|
2381
|
+
```typescript
|
|
2382
|
+
interface LookupByProductParams {
|
|
2383
|
+
limit?: number // Optional: Max results (default: 100)
|
|
2384
|
+
offset?: number // Optional: Pagination offset (default: 0)
|
|
2385
|
+
includeItems?: boolean // Optional: Include items array (default: false)
|
|
2386
|
+
}
|
|
2387
|
+
```
|
|
2388
|
+
|
|
2389
|
+
**LookupByProductResponse** (interface)
|
|
2390
|
+
```typescript
|
|
2391
|
+
interface LookupByProductResponse {
|
|
2392
|
+
orders: Order[]
|
|
2393
|
+
limit: number
|
|
2394
|
+
offset: number
|
|
2395
|
+
}
|
|
2396
|
+
```
|
|
2397
|
+
|
|
2283
2398
|
### product
|
|
2284
2399
|
|
|
2285
2400
|
**Product** (interface)
|
|
@@ -4013,8 +4128,9 @@ Lookup a tag by its ID (public). GET /public/nfc/findByTag/:tagId
|
|
|
4013
4128
|
Create a new order with items. ```typescript const order = await order.create('coll_123', { orderRef: 'ORD-12345', customerId: 'CUST-789', items: [ { itemType: 'tag', itemId: 'TAG001' }, { itemType: 'tag', itemId: 'TAG002' }, { itemType: 'serial', itemId: 'SN12345' } ], status: 'pending', metadata: { shipmentId: 'SHIP-789', destination: 'Warehouse B' } }) ```
|
|
4014
4129
|
|
|
4015
4130
|
**get**(collectionId: string,
|
|
4016
|
-
orderId: string
|
|
4017
|
-
|
|
4131
|
+
orderId: string,
|
|
4132
|
+
params?: GetOrderParams) → `Promise<GetOrderResponse>`
|
|
4133
|
+
Get a single order by ID. ```typescript // Get order without items (faster) const order = await order.get('coll_123', 'order_abc123') console.log(`Order has ${order.itemCount} items`) // Get order with items const orderWithItems = await order.get('coll_123', 'order_abc123', { includeItems: true }) console.log(orderWithItems.items) // Items array available ```
|
|
4018
4134
|
|
|
4019
4135
|
**update**(collectionId: string,
|
|
4020
4136
|
orderId: string,
|
|
@@ -4027,7 +4143,12 @@ Delete an order and all its items (cascade delete). ```typescript await order.re
|
|
|
4027
4143
|
|
|
4028
4144
|
**list**(collectionId: string,
|
|
4029
4145
|
params?: ListOrdersRequest) → `Promise<ListOrdersResponse>`
|
|
4030
|
-
List orders for a collection with optional filters and pagination. Orders are returned in descending order by createdAt (newest first). ```typescript // List all orders const all = await order.list('coll_123') // List with filters const pending = await order.list('coll_123', { status: 'pending', limit: 50, offset: 0 }) // Filter by customer const customerOrders = await order.list('coll_123', { customerId: 'CUST-789' }) ```
|
|
4146
|
+
List orders for a collection with optional filters and pagination. Orders are returned in descending order by createdAt (newest first). ```typescript // List all orders (without items for better performance) const all = await order.list('coll_123') // List with filters const pending = await order.list('coll_123', { status: 'pending', limit: 50, offset: 0 }) // Filter by customer with items const customerOrders = await order.list('coll_123', { customerId: 'CUST-789', includeItems: true }) ```
|
|
4147
|
+
|
|
4148
|
+
**getItems**(collectionId: string,
|
|
4149
|
+
orderId: string,
|
|
4150
|
+
params?: GetOrderItemsParams) → `Promise<GetOrderItemsResponse>`
|
|
4151
|
+
Get items from an order with pagination support. Use this for orders with many items instead of includeItems. ```typescript // Get first page of items const page1 = await order.getItems('coll_123', 'order_abc123', { limit: 100, offset: 0 }) // Get next page const page2 = await order.getItems('coll_123', 'order_abc123', { limit: 100, offset: 100 }) ```
|
|
4031
4152
|
|
|
4032
4153
|
**addItems**(collectionId: string,
|
|
4033
4154
|
orderId: string,
|
|
@@ -4043,6 +4164,19 @@ Remove specific items from an order. ```typescript const updated = await order.r
|
|
|
4043
4164
|
data: LookupOrdersRequest) → `Promise<LookupOrdersResponse>`
|
|
4044
4165
|
Find all orders containing specific items (tags, proofs, or serial numbers). Use case: Scan a tag and immediately see if it's part of any order. ```typescript // Scan a tag and find associated orders const result = await order.lookup('coll_123', { items: [ { itemType: 'tag', itemId: 'TAG001' } ] }) if (result.orders.length > 0) { console.log(`Tag is part of ${result.orders.length} order(s)`) result.orders.forEach(ord => { console.log(`Order ${ord.orderRef}: ${ord.status}`) }) } // Batch lookup multiple items const batchResult = await order.lookup('coll_123', { items: [ { itemType: 'tag', itemId: 'TAG001' }, { itemType: 'serial', itemId: 'SN12345' }, { itemType: 'proof', itemId: 'proof_xyz' } ] }) ```
|
|
4045
4166
|
|
|
4167
|
+
**query**(collectionId: string,
|
|
4168
|
+
data: QueryOrdersRequest) → `Promise<QueryOrdersResponse>`
|
|
4169
|
+
Advanced query for orders with date filtering, metadata search, and sorting. More powerful than the basic list() function. ```typescript // Find pending orders created in January 2026 const result = await order.query('coll_123', { query: { status: 'pending', createdAfter: '2026-01-01T00:00:00Z', createdBefore: '2026-02-01T00:00:00Z', sortBy: 'createdAt', sortOrder: 'desc' }, limit: 50 }) // Find orders with specific metadata and item count const highPriority = await order.query('coll_123', { query: { metadata: { priority: 'high' }, minItemCount: 10, maxItemCount: 100 }, includeItems: true }) ```
|
|
4170
|
+
|
|
4171
|
+
**reports**(collectionId: string,
|
|
4172
|
+
params?: ReportsParams) → `Promise<ReportsResponse>`
|
|
4173
|
+
Get reports and aggregations for orders. Provides analytics grouped by status, customer, product, date, etc. ```typescript // Get order counts by status const statusReport = await order.reports('coll_123', { groupByStatus: true }) console.log(statusReport.ordersByStatus) // { pending: 45, shipped: 123, completed: 789 } // Get comprehensive analytics const fullReport = await order.reports('coll_123', { groupByStatus: true, groupByProduct: true, includeItemStats: true, createdAfter: '2026-01-01T00:00:00Z' }) console.log(fullReport.itemStats?.avgItemsPerOrder) // Get top 10 customers by order count const topCustomers = await order.reports('coll_123', { groupByCustomer: true, topN: 10 }) ```
|
|
4174
|
+
|
|
4175
|
+
**findByProduct**(collectionId: string,
|
|
4176
|
+
productId: string,
|
|
4177
|
+
params?: LookupByProductParams) → `Promise<LookupByProductResponse>`
|
|
4178
|
+
Find all orders containing items with a specific product ID. Uses the automatic productSummary tracking in order metadata. ```typescript // Find all orders with a specific product const result = await order.findByProduct('coll_123', 'product_abc123', { limit: 50, includeItems: false }) result.orders.forEach(ord => { const count = ord.metadata.productSummary?.['product_abc123'] ?? 0 console.log(`Order ${ord.orderRef} has ${count} items of this product`) }) ```
|
|
4179
|
+
|
|
4046
4180
|
### product
|
|
4047
4181
|
|
|
4048
4182
|
**get**(collectionId: string,
|