@proveanything/smartlinks 1.3.16 → 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/README.md +7 -1
- package/dist/api/ai.d.ts +435 -0
- package/dist/api/ai.js +248 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/order.d.ts +134 -6
- package/dist/api/order.js +196 -6
- package/dist/docs/API_SUMMARY.md +635 -7
- package/dist/docs/ai.md +1565 -0
- package/dist/types/order.d.ts +108 -2
- package/docs/API_SUMMARY.md +635 -7
- package/docs/ai.md +1565 -0
- package/package.json +1 -1
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 = {}));
|