@proveanything/smartlinks 1.3.1 → 1.3.3
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 +13 -4
- package/dist/api/contact.d.ts +12 -0
- package/dist/api/contact.js +12 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/order.d.ts +189 -0
- package/dist/api/order.js +240 -0
- package/dist/api/tags.d.ts +194 -0
- package/dist/api/tags.js +258 -0
- package/dist/docs/API_SUMMARY.md +587 -221
- package/dist/i18n.md +287 -0
- package/dist/liquid-templates.md +484 -0
- package/dist/realtime.md +764 -0
- package/dist/theme-defaults.md +100 -0
- package/dist/theme.system.md +338 -0
- package/dist/types/contact.d.ts +32 -1
- package/dist/types/contact.js +35 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/order.d.ts +137 -0
- package/dist/types/order.js +7 -0
- package/dist/types/tags.d.ts +172 -0
- package/dist/types/tags.js +7 -0
- package/dist/widgets.md +510 -0
- package/docs/API_SUMMARY.md +3596 -0
- package/docs/i18n.md +287 -0
- package/docs/liquid-templates.md +484 -0
- package/docs/realtime.md +764 -0
- package/docs/theme-defaults.md +100 -0
- package/docs/theme.system.md +338 -0
- package/docs/widgets.md +510 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -151,9 +151,7 @@ try {
|
|
|
151
151
|
- `error.isRateLimited()` - 429
|
|
152
152
|
- `error.toJSON()` - Serializable object for logging
|
|
153
153
|
|
|
154
|
-
For comprehensive error handling examples and migration guidance, see
|
|
155
|
-
- [examples/error-handling-demo.ts](examples/error-handling-demo.ts) - Complete error handling patterns
|
|
156
|
-
- [docs/ERROR_HANDLING_MIGRATION.md](docs/ERROR_HANDLING_MIGRATION.md) - Migration guide from old error handling
|
|
154
|
+
For comprehensive error handling examples and migration guidance, see [examples/error-handling-demo.ts](examples/error-handling-demo.ts).
|
|
157
155
|
|
|
158
156
|
## Common tasks
|
|
159
157
|
|
|
@@ -556,7 +554,18 @@ setExtraHeaders({ 'X-Debug': '1' })
|
|
|
556
554
|
|
|
557
555
|
Explore every function, parameter, and type here:
|
|
558
556
|
|
|
559
|
-
-
|
|
557
|
+
- [API_SUMMARY.md](docs/API_SUMMARY.md) - Complete API reference
|
|
558
|
+
|
|
559
|
+
## Additional Documentation
|
|
560
|
+
|
|
561
|
+
The SDK includes comprehensive guides for advanced features:
|
|
562
|
+
|
|
563
|
+
- **[Liquid Templates](docs/liquid-templates.md)** - Dynamic templating for emails and notifications with personalized data
|
|
564
|
+
- **[Real-Time Messaging](docs/realtime.md)** - Ably integration for live chat, presence, and real-time updates
|
|
565
|
+
- **[Theme System](docs/theme.system.md)** - Dynamic theming for iframe apps with CSS variables and postMessage
|
|
566
|
+
- **[Theme Defaults](docs/theme-defaults.md)** - Default theme configuration reference
|
|
567
|
+
- **[Widgets](docs/widgets.md)** - React widget system for embeddable components
|
|
568
|
+
- **[Internationalization](docs/i18n.md)** - Multi-language support and localization
|
|
560
569
|
|
|
561
570
|
## Requirements
|
|
562
571
|
|
package/dist/api/contact.d.ts
CHANGED
|
@@ -19,6 +19,18 @@ export declare namespace contact {
|
|
|
19
19
|
function publicUpsert(collectionId: string, data: PublicContactUpsertRequest): Promise<PublicContactUpsertResponse>;
|
|
20
20
|
function publicGetMine(collectionId: string): Promise<PublicGetMyContactResponse>;
|
|
21
21
|
function publicUpdateMine(collectionId: string, data: ContactPatch): Promise<PublicUpdateMyContactResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Public: Get contact update schema for a collection
|
|
24
|
+
*
|
|
25
|
+
* Fetches the public contact schema including core fields, custom fields with
|
|
26
|
+
* conditional visibility rules, and visibility/editability settings.
|
|
27
|
+
*
|
|
28
|
+
* Custom fields may include a `condition` property that specifies when the field
|
|
29
|
+
* should be displayed. Apps rendering these forms should:
|
|
30
|
+
* 1. Evaluate each field's `condition` against current form values
|
|
31
|
+
* 2. Hide fields whose conditions are not met
|
|
32
|
+
* 3. Skip validation for hidden fields (they shouldn't be required when not visible)
|
|
33
|
+
*/
|
|
22
34
|
function publicGetSchema(collectionId: string): Promise<ContactSchema>;
|
|
23
35
|
function erase(collectionId: string, contactId: string, body?: any): Promise<ContactResponse>;
|
|
24
36
|
function getUser(collectionId: string, userId: string): Promise<UserSearchResponse>;
|
package/dist/api/contact.js
CHANGED
|
@@ -71,7 +71,18 @@ export var contact;
|
|
|
71
71
|
return patch(path, data);
|
|
72
72
|
}
|
|
73
73
|
contact.publicUpdateMine = publicUpdateMine;
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Public: Get contact update schema for a collection
|
|
76
|
+
*
|
|
77
|
+
* Fetches the public contact schema including core fields, custom fields with
|
|
78
|
+
* conditional visibility rules, and visibility/editability settings.
|
|
79
|
+
*
|
|
80
|
+
* Custom fields may include a `condition` property that specifies when the field
|
|
81
|
+
* should be displayed. Apps rendering these forms should:
|
|
82
|
+
* 1. Evaluate each field's `condition` against current form values
|
|
83
|
+
* 2. Hide fields whose conditions are not met
|
|
84
|
+
* 3. Skip validation for hidden fields (they shouldn't be required when not visible)
|
|
85
|
+
*/
|
|
75
86
|
async function publicGetSchema(collectionId) {
|
|
76
87
|
const path = `/public/collection/${encodeURIComponent(collectionId)}/contact/schema`;
|
|
77
88
|
return request(path);
|
package/dist/api/index.d.ts
CHANGED
|
@@ -27,4 +27,6 @@ export { template } from "./template";
|
|
|
27
27
|
export { interactions } from "./interactions";
|
|
28
28
|
export { location } from "./location";
|
|
29
29
|
export * as realtime from "./realtime";
|
|
30
|
+
export { tags } from "./tags";
|
|
31
|
+
export { order } from "./order";
|
|
30
32
|
export type { AIGenerateContentRequest, AIGenerateImageRequest, AISearchPhotosRequest, AISearchPhotosPhoto } from "./ai";
|
package/dist/api/index.js
CHANGED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { CreateOrderRequest, CreateOrderResponse, GetOrderResponse, UpdateOrderRequest, UpdateOrderResponse, DeleteOrderResponse, ListOrdersRequest, ListOrdersResponse, AddItemsRequest, AddItemsResponse, RemoveItemsRequest, RemoveItemsResponse, LookupOrdersRequest, LookupOrdersResponse } from "../types/order";
|
|
2
|
+
/**
|
|
3
|
+
* Order Management API
|
|
4
|
+
*
|
|
5
|
+
* Group scanned tags, proofs, or serial numbers into orders with flexible metadata.
|
|
6
|
+
* Designed for fulfillment, shipping, batch processing, and audit trails.
|
|
7
|
+
*/
|
|
8
|
+
export declare namespace order {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new order with items.
|
|
11
|
+
*
|
|
12
|
+
* @param collectionId - Identifier of the parent collection
|
|
13
|
+
* @param data - Order creation data including items
|
|
14
|
+
* @returns Promise resolving to a CreateOrderResponse object
|
|
15
|
+
* @throws ErrorResponse if the request fails
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const order = await order.create('coll_123', {
|
|
20
|
+
* orderRef: 'ORD-12345',
|
|
21
|
+
* customerId: 'CUST-789',
|
|
22
|
+
* items: [
|
|
23
|
+
* { itemType: 'tag', itemId: 'TAG001' },
|
|
24
|
+
* { itemType: 'tag', itemId: 'TAG002' },
|
|
25
|
+
* { itemType: 'serial', itemId: 'SN12345' }
|
|
26
|
+
* ],
|
|
27
|
+
* status: 'pending',
|
|
28
|
+
* metadata: {
|
|
29
|
+
* shipmentId: 'SHIP-789',
|
|
30
|
+
* destination: 'Warehouse B'
|
|
31
|
+
* }
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function create(collectionId: string, data: CreateOrderRequest): Promise<CreateOrderResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Get a single order by ID with all its items.
|
|
38
|
+
*
|
|
39
|
+
* @param collectionId - Identifier of the parent collection
|
|
40
|
+
* @param orderId - Order ID
|
|
41
|
+
* @returns Promise resolving to a GetOrderResponse object
|
|
42
|
+
* @throws ErrorResponse if the request fails
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const order = await order.get('coll_123', 'order_abc123')
|
|
47
|
+
* console.log(`Order has ${order.itemCount} items`)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function get(collectionId: string, orderId: string): Promise<GetOrderResponse>;
|
|
51
|
+
/**
|
|
52
|
+
* Update order status or metadata.
|
|
53
|
+
* Items are managed separately via addItems/removeItems.
|
|
54
|
+
*
|
|
55
|
+
* @param collectionId - Identifier of the parent collection
|
|
56
|
+
* @param orderId - Order ID
|
|
57
|
+
* @param data - Update data (only include fields to update)
|
|
58
|
+
* @returns Promise resolving to an UpdateOrderResponse object
|
|
59
|
+
* @throws ErrorResponse if the request fails
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const updated = await order.update('coll_123', 'order_abc123', {
|
|
64
|
+
* status: 'shipped',
|
|
65
|
+
* metadata: {
|
|
66
|
+
* trackingNumber: '1Z999AA10123456784',
|
|
67
|
+
* shippedAt: '2026-02-02T14:30:00Z'
|
|
68
|
+
* }
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function update(collectionId: string, orderId: string, data: UpdateOrderRequest): Promise<UpdateOrderResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Delete an order and all its items (cascade delete).
|
|
75
|
+
*
|
|
76
|
+
* @param collectionId - Identifier of the parent collection
|
|
77
|
+
* @param orderId - Order ID
|
|
78
|
+
* @returns Promise resolving to a DeleteOrderResponse object
|
|
79
|
+
* @throws ErrorResponse if the request fails
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* await order.remove('coll_123', 'order_abc123')
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
function remove(collectionId: string, orderId: string): Promise<DeleteOrderResponse>;
|
|
87
|
+
/**
|
|
88
|
+
* List orders for a collection with optional filters and pagination.
|
|
89
|
+
* Orders are returned in descending order by createdAt (newest first).
|
|
90
|
+
*
|
|
91
|
+
* @param collectionId - Identifier of the parent collection
|
|
92
|
+
* @param params - Optional query parameters for filtering and pagination
|
|
93
|
+
* @returns Promise resolving to a ListOrdersResponse object
|
|
94
|
+
* @throws ErrorResponse if the request fails
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // List all orders
|
|
99
|
+
* const all = await order.list('coll_123')
|
|
100
|
+
*
|
|
101
|
+
* // List with filters
|
|
102
|
+
* const pending = await order.list('coll_123', {
|
|
103
|
+
* status: 'pending',
|
|
104
|
+
* limit: 50,
|
|
105
|
+
* offset: 0
|
|
106
|
+
* })
|
|
107
|
+
*
|
|
108
|
+
* // Filter by customer
|
|
109
|
+
* const customerOrders = await order.list('coll_123', {
|
|
110
|
+
* customerId: 'CUST-789'
|
|
111
|
+
* })
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
function list(collectionId: string, params?: ListOrdersRequest): Promise<ListOrdersResponse>;
|
|
115
|
+
/**
|
|
116
|
+
* Add additional items to an existing order.
|
|
117
|
+
*
|
|
118
|
+
* @param collectionId - Identifier of the parent collection
|
|
119
|
+
* @param orderId - Order ID
|
|
120
|
+
* @param data - Items to add
|
|
121
|
+
* @returns Promise resolving to an AddItemsResponse object (updated order)
|
|
122
|
+
* @throws ErrorResponse if the request fails
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const updated = await order.addItems('coll_123', 'order_abc123', {
|
|
127
|
+
* items: [
|
|
128
|
+
* { itemType: 'tag', itemId: 'TAG003' },
|
|
129
|
+
* { itemType: 'proof', itemId: 'proof_xyz' }
|
|
130
|
+
* ]
|
|
131
|
+
* })
|
|
132
|
+
* console.log(`Order now has ${updated.itemCount} items`)
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
function addItems(collectionId: string, orderId: string, data: AddItemsRequest): Promise<AddItemsResponse>;
|
|
136
|
+
/**
|
|
137
|
+
* Remove specific items from an order.
|
|
138
|
+
*
|
|
139
|
+
* @param collectionId - Identifier of the parent collection
|
|
140
|
+
* @param orderId - Order ID
|
|
141
|
+
* @param data - Item IDs to remove
|
|
142
|
+
* @returns Promise resolving to a RemoveItemsResponse object (updated order)
|
|
143
|
+
* @throws ErrorResponse if the request fails
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const updated = await order.removeItems('coll_123', 'order_abc123', {
|
|
148
|
+
* itemIds: ['item_001', 'item_002']
|
|
149
|
+
* })
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
function removeItems(collectionId: string, orderId: string, data: RemoveItemsRequest): Promise<RemoveItemsResponse>;
|
|
153
|
+
/**
|
|
154
|
+
* Find all orders containing specific items (tags, proofs, or serial numbers).
|
|
155
|
+
* Use case: Scan a tag and immediately see if it's part of any order.
|
|
156
|
+
*
|
|
157
|
+
* @param collectionId - Identifier of the parent collection
|
|
158
|
+
* @param data - Items to look up
|
|
159
|
+
* @returns Promise resolving to a LookupOrdersResponse with matching orders
|
|
160
|
+
* @throws ErrorResponse if the request fails
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // Scan a tag and find associated orders
|
|
165
|
+
* const result = await order.lookup('coll_123', {
|
|
166
|
+
* items: [
|
|
167
|
+
* { itemType: 'tag', itemId: 'TAG001' }
|
|
168
|
+
* ]
|
|
169
|
+
* })
|
|
170
|
+
*
|
|
171
|
+
* if (result.orders.length > 0) {
|
|
172
|
+
* console.log(`Tag is part of ${result.orders.length} order(s)`)
|
|
173
|
+
* result.orders.forEach(ord => {
|
|
174
|
+
* console.log(`Order ${ord.orderRef}: ${ord.status}`)
|
|
175
|
+
* })
|
|
176
|
+
* }
|
|
177
|
+
*
|
|
178
|
+
* // Batch lookup multiple items
|
|
179
|
+
* const batchResult = await order.lookup('coll_123', {
|
|
180
|
+
* items: [
|
|
181
|
+
* { itemType: 'tag', itemId: 'TAG001' },
|
|
182
|
+
* { itemType: 'serial', itemId: 'SN12345' },
|
|
183
|
+
* { itemType: 'proof', itemId: 'proof_xyz' }
|
|
184
|
+
* ]
|
|
185
|
+
* })
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
function lookup(collectionId: string, data: LookupOrdersRequest): Promise<LookupOrdersResponse>;
|
|
189
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// src/api/order.ts
|
|
2
|
+
import { request, post, put, del, requestWithOptions } from "../http";
|
|
3
|
+
/**
|
|
4
|
+
* Order Management API
|
|
5
|
+
*
|
|
6
|
+
* Group scanned tags, proofs, or serial numbers into orders with flexible metadata.
|
|
7
|
+
* Designed for fulfillment, shipping, batch processing, and audit trails.
|
|
8
|
+
*/
|
|
9
|
+
export var order;
|
|
10
|
+
(function (order) {
|
|
11
|
+
/**
|
|
12
|
+
* Create a new order with items.
|
|
13
|
+
*
|
|
14
|
+
* @param collectionId - Identifier of the parent collection
|
|
15
|
+
* @param data - Order creation data including items
|
|
16
|
+
* @returns Promise resolving to a CreateOrderResponse object
|
|
17
|
+
* @throws ErrorResponse if the request fails
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const order = await order.create('coll_123', {
|
|
22
|
+
* orderRef: 'ORD-12345',
|
|
23
|
+
* customerId: 'CUST-789',
|
|
24
|
+
* items: [
|
|
25
|
+
* { itemType: 'tag', itemId: 'TAG001' },
|
|
26
|
+
* { itemType: 'tag', itemId: 'TAG002' },
|
|
27
|
+
* { itemType: 'serial', itemId: 'SN12345' }
|
|
28
|
+
* ],
|
|
29
|
+
* status: 'pending',
|
|
30
|
+
* metadata: {
|
|
31
|
+
* shipmentId: 'SHIP-789',
|
|
32
|
+
* destination: 'Warehouse B'
|
|
33
|
+
* }
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
async function create(collectionId, data) {
|
|
38
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders`;
|
|
39
|
+
return post(path, data);
|
|
40
|
+
}
|
|
41
|
+
order.create = create;
|
|
42
|
+
/**
|
|
43
|
+
* Get a single order by ID with all its items.
|
|
44
|
+
*
|
|
45
|
+
* @param collectionId - Identifier of the parent collection
|
|
46
|
+
* @param orderId - Order ID
|
|
47
|
+
* @returns Promise resolving to a GetOrderResponse object
|
|
48
|
+
* @throws ErrorResponse if the request fails
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const order = await order.get('coll_123', 'order_abc123')
|
|
53
|
+
* console.log(`Order has ${order.itemCount} items`)
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async function get(collectionId, orderId) {
|
|
57
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}`;
|
|
58
|
+
return request(path);
|
|
59
|
+
}
|
|
60
|
+
order.get = get;
|
|
61
|
+
/**
|
|
62
|
+
* Update order status or metadata.
|
|
63
|
+
* Items are managed separately via addItems/removeItems.
|
|
64
|
+
*
|
|
65
|
+
* @param collectionId - Identifier of the parent collection
|
|
66
|
+
* @param orderId - Order ID
|
|
67
|
+
* @param data - Update data (only include fields to update)
|
|
68
|
+
* @returns Promise resolving to an UpdateOrderResponse object
|
|
69
|
+
* @throws ErrorResponse if the request fails
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const updated = await order.update('coll_123', 'order_abc123', {
|
|
74
|
+
* status: 'shipped',
|
|
75
|
+
* metadata: {
|
|
76
|
+
* trackingNumber: '1Z999AA10123456784',
|
|
77
|
+
* shippedAt: '2026-02-02T14:30:00Z'
|
|
78
|
+
* }
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
async function update(collectionId, orderId, data) {
|
|
83
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}`;
|
|
84
|
+
return put(path, data);
|
|
85
|
+
}
|
|
86
|
+
order.update = update;
|
|
87
|
+
/**
|
|
88
|
+
* Delete an order and all its items (cascade delete).
|
|
89
|
+
*
|
|
90
|
+
* @param collectionId - Identifier of the parent collection
|
|
91
|
+
* @param orderId - Order ID
|
|
92
|
+
* @returns Promise resolving to a DeleteOrderResponse object
|
|
93
|
+
* @throws ErrorResponse if the request fails
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* await order.remove('coll_123', 'order_abc123')
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
async function remove(collectionId, orderId) {
|
|
101
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}`;
|
|
102
|
+
return del(path);
|
|
103
|
+
}
|
|
104
|
+
order.remove = remove;
|
|
105
|
+
/**
|
|
106
|
+
* List orders for a collection with optional filters and pagination.
|
|
107
|
+
* Orders are returned in descending order by createdAt (newest first).
|
|
108
|
+
*
|
|
109
|
+
* @param collectionId - Identifier of the parent collection
|
|
110
|
+
* @param params - Optional query parameters for filtering and pagination
|
|
111
|
+
* @returns Promise resolving to a ListOrdersResponse object
|
|
112
|
+
* @throws ErrorResponse if the request fails
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // List all orders
|
|
117
|
+
* const all = await order.list('coll_123')
|
|
118
|
+
*
|
|
119
|
+
* // List with filters
|
|
120
|
+
* const pending = await order.list('coll_123', {
|
|
121
|
+
* status: 'pending',
|
|
122
|
+
* limit: 50,
|
|
123
|
+
* offset: 0
|
|
124
|
+
* })
|
|
125
|
+
*
|
|
126
|
+
* // Filter by customer
|
|
127
|
+
* const customerOrders = await order.list('coll_123', {
|
|
128
|
+
* customerId: 'CUST-789'
|
|
129
|
+
* })
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
async function list(collectionId, params) {
|
|
133
|
+
const queryParams = new URLSearchParams();
|
|
134
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
135
|
+
queryParams.append('limit', params.limit.toString());
|
|
136
|
+
if (params === null || params === void 0 ? void 0 : params.offset)
|
|
137
|
+
queryParams.append('offset', params.offset.toString());
|
|
138
|
+
if (params === null || params === void 0 ? void 0 : params.status)
|
|
139
|
+
queryParams.append('status', params.status);
|
|
140
|
+
if (params === null || params === void 0 ? void 0 : params.orderRef)
|
|
141
|
+
queryParams.append('orderRef', params.orderRef);
|
|
142
|
+
if (params === null || params === void 0 ? void 0 : params.customerId)
|
|
143
|
+
queryParams.append('customerId', params.customerId);
|
|
144
|
+
const query = queryParams.toString();
|
|
145
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders${query ? `?${query}` : ''}`;
|
|
146
|
+
return request(path);
|
|
147
|
+
}
|
|
148
|
+
order.list = list;
|
|
149
|
+
/**
|
|
150
|
+
* Add additional items to an existing order.
|
|
151
|
+
*
|
|
152
|
+
* @param collectionId - Identifier of the parent collection
|
|
153
|
+
* @param orderId - Order ID
|
|
154
|
+
* @param data - Items to add
|
|
155
|
+
* @returns Promise resolving to an AddItemsResponse object (updated order)
|
|
156
|
+
* @throws ErrorResponse if the request fails
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const updated = await order.addItems('coll_123', 'order_abc123', {
|
|
161
|
+
* items: [
|
|
162
|
+
* { itemType: 'tag', itemId: 'TAG003' },
|
|
163
|
+
* { itemType: 'proof', itemId: 'proof_xyz' }
|
|
164
|
+
* ]
|
|
165
|
+
* })
|
|
166
|
+
* console.log(`Order now has ${updated.itemCount} items`)
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
async function addItems(collectionId, orderId, data) {
|
|
170
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}/items`;
|
|
171
|
+
return post(path, data);
|
|
172
|
+
}
|
|
173
|
+
order.addItems = addItems;
|
|
174
|
+
/**
|
|
175
|
+
* Remove specific items from an order.
|
|
176
|
+
*
|
|
177
|
+
* @param collectionId - Identifier of the parent collection
|
|
178
|
+
* @param orderId - Order ID
|
|
179
|
+
* @param data - Item IDs to remove
|
|
180
|
+
* @returns Promise resolving to a RemoveItemsResponse object (updated order)
|
|
181
|
+
* @throws ErrorResponse if the request fails
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const updated = await order.removeItems('coll_123', 'order_abc123', {
|
|
186
|
+
* itemIds: ['item_001', 'item_002']
|
|
187
|
+
* })
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
async function removeItems(collectionId, orderId, data) {
|
|
191
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}/items`;
|
|
192
|
+
// DELETE with body requires requestWithOptions since del() doesn't send body
|
|
193
|
+
return requestWithOptions(path, {
|
|
194
|
+
method: 'DELETE',
|
|
195
|
+
headers: { 'Content-Type': 'application/json' },
|
|
196
|
+
body: JSON.stringify(data)
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
order.removeItems = removeItems;
|
|
200
|
+
/**
|
|
201
|
+
* Find all orders containing specific items (tags, proofs, or serial numbers).
|
|
202
|
+
* Use case: Scan a tag and immediately see if it's part of any order.
|
|
203
|
+
*
|
|
204
|
+
* @param collectionId - Identifier of the parent collection
|
|
205
|
+
* @param data - Items to look up
|
|
206
|
+
* @returns Promise resolving to a LookupOrdersResponse with matching orders
|
|
207
|
+
* @throws ErrorResponse if the request fails
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // Scan a tag and find associated orders
|
|
212
|
+
* const result = await order.lookup('coll_123', {
|
|
213
|
+
* items: [
|
|
214
|
+
* { itemType: 'tag', itemId: 'TAG001' }
|
|
215
|
+
* ]
|
|
216
|
+
* })
|
|
217
|
+
*
|
|
218
|
+
* if (result.orders.length > 0) {
|
|
219
|
+
* console.log(`Tag is part of ${result.orders.length} order(s)`)
|
|
220
|
+
* result.orders.forEach(ord => {
|
|
221
|
+
* console.log(`Order ${ord.orderRef}: ${ord.status}`)
|
|
222
|
+
* })
|
|
223
|
+
* }
|
|
224
|
+
*
|
|
225
|
+
* // Batch lookup multiple items
|
|
226
|
+
* const batchResult = await order.lookup('coll_123', {
|
|
227
|
+
* items: [
|
|
228
|
+
* { itemType: 'tag', itemId: 'TAG001' },
|
|
229
|
+
* { itemType: 'serial', itemId: 'SN12345' },
|
|
230
|
+
* { itemType: 'proof', itemId: 'proof_xyz' }
|
|
231
|
+
* ]
|
|
232
|
+
* })
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
async function lookup(collectionId, data) {
|
|
236
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/lookup`;
|
|
237
|
+
return post(path, data);
|
|
238
|
+
}
|
|
239
|
+
order.lookup = lookup;
|
|
240
|
+
})(order || (order = {}));
|