|
1
|
import { HttpTypes, SelectParams } from "@medusajs/types" |
|
2
|
import { Client } from "../client.js" |
|
3
|
import { ClientHeaders } from "../types.js" |
|
4
|
|
|
5
|
export class InventoryItem { |
|
6
|
/** |
|
7
|
* @ignore |
|
8
|
*/ |
|
9
|
private client: Client |
|
10
|
/** |
|
11
|
* @ignore |
|
12
|
*/ |
|
13
|
constructor(client: Client) { |
|
14
|
this.client = client |
|
15
|
} |
|
16
|
|
|
17
|
/** |
|
18
|
* This method creates an inventory item. It sends a request to the |
|
19
|
* [Create Inventory Item](https://docs.medusajs.com/api/admin/inventory-items/create-inventory-item) |
|
20
|
* API route. |
|
21
|
* |
|
22
|
* @param body - The inventory item's details. |
|
23
|
* @param query - Configure the fields to retrieve in the inventory item. |
|
24
|
* @param headers - Headers to pass in the request. |
|
25
|
* @returns The inventory item's details. |
|
26
|
* |
|
27
|
* @example |
|
28
|
* sdk.admin.inventoryItem.create({ |
|
29
|
* sku: "SHIRT" |
|
30
|
* }) |
|
31
|
* .then(({ inventory_item }) => { |
|
32
|
* console.log(inventory_item) |
|
33
|
* }) |
|
34
|
*/ |
|
35
|
async create( |
|
36
|
body: HttpTypes.AdminCreateInventoryItem, |
|
37
|
query?: HttpTypes.SelectParams, |
|
38
|
headers?: ClientHeaders |
|
39
|
) { |
|
40
|
return await this.client.fetch<HttpTypes.AdminInventoryItemResponse>( |
|
41
|
`/admin/inventory-items`, |
|
42
|
{ |
|
43
|
method: "POST", |
|
44
|
headers, |
|
45
|
body, |
|
46
|
query, |
|
47
|
} |
|
48
|
) |
|
49
|
} |
|
50
|
|
|
51
|
/** |
|
52
|
* This method updates an inventory level. It sends a request to the |
|
53
|
* [Update Inventory Item](https://docs.medusajs.com/api/admin/inventory-items/update-an-inventory-item) |
|
54
|
* API route. |
|
55
|
* |
|
56
|
* @param id - The inventory item's ID. |
|
57
|
* @param body - The data to update. |
|
58
|
* @param query - Configure the fields to retrieve in the inventory item. |
|
59
|
* @param headers - Headers to pass in the request. |
|
60
|
* @returns The inventory item's details. |
|
61
|
* |
|
62
|
* @example |
|
63
|
* sdk.admin.inventoryItem.update("iitem_123", { |
|
64
|
* sku: "SHIRT" |
|
65
|
* }) |
|
66
|
* .then(({ inventory_item }) => { |
|
67
|
* console.log(inventory_item) |
|
68
|
* }) |
|
69
|
*/ |
|
70
|
async update( |
|
71
|
id: string, |
|
72
|
body: HttpTypes.AdminUpdateInventoryItem, |
|
73
|
query?: SelectParams, |
|
74
|
headers?: ClientHeaders |
|
75
|
) { |
|
76
|
return await this.client.fetch<HttpTypes.AdminInventoryItemResponse>( |
|
77
|
`/admin/inventory-items/${id}`, |
|
78
|
{ |
|
79
|
method: "POST", |
|
80
|
headers, |
|
81
|
body, |
|
82
|
query, |
|
83
|
} |
|
84
|
) |
|
85
|
} |
|
86
|
|
|
87
|
/** |
|
88
|
* This method exports inventory items to a CSV file. The CSV file includes the |
|
89
|
* inventory levels of each item per stock location. It sends a request to the |
|
90
|
* [Export Inventory Items](https://docs.medusajs.com/api/admin/inventory-items/export-inventory-items) |
|
91
|
* API route. |
|
92
|
* |
|
93
|
* The export is processed asynchronously. Once it's done, admin users receive |
|
94
|
* a notification with the URL to download the exported file. |
|
95
|
* |
|
96
|
* @param body - The export's details. |
|
97
|
* @param query - Filters to select which inventory items to export. |
|
98
|
* @param headers - Headers to pass in the request. |
|
99
|
* @returns The ID of the workflow transaction processing the export. |
|
100
|
* |
|
101
|
* @example |
|
102
|
* sdk.admin.inventoryItem.export({}) |
|
103
|
* .then(({ transaction_id }) => { |
|
104
|
* console.log(transaction_id) |
|
105
|
* }) |
|
106
|
*/ |
|
107
|
async export( |
|
108
|
body: HttpTypes.AdminExportInventoryItemRequest, |
|
109
|
query?: HttpTypes.AdminInventoryItemsParams, |
|
110
|
headers?: ClientHeaders |
|
111
|
) { |
|
112
|
return await this.client.fetch<HttpTypes.AdminExportInventoryItemResponse>( |
|
113
|
`/admin/inventory-items/export`, |
|
114
|
{ |
|
115
|
method: "POST", |
|
116
|
headers, |
|
117
|
body, |
|
118
|
query, |
|
119
|
} |
|
120
|
) |
|
121
|
} |
|
122
|
|
|
123
|
/** |
|
124
|
* This method retrieves a paginated list of inventory items. It sends a request to the |
|
125
|
* [List Inventory Items](https://docs.medusajs.com/api/admin/inventory-items/list-inventory-items) |
|
126
|
* API route. |
|
127
|
* |
|
128
|
* @param query - Filters and pagination configurations. |
|
129
|
* @param headers - Headers to pass in the request. |
|
130
|
* @returns The paginated list of inventory items. |
|
131
|
* |
|
132
|
* @example |
|
133
|
* To retrieve the list of inventory items: |
|
134
|
* |
|
135
|
* ```ts |
|
136
|
* sdk.admin.inventoryItem.list() |
|
137
|
* .then(({ inventory_items, count, limit, offset }) => { |
|
138
|
* console.log(inventory_items) |
|
139
|
* }) |
|
140
|
* ``` |
|
141
|
* |
|
142
|
* To configure the pagination, pass the `limit` and `offset` query parameters. |
|
143
|
* |
|
144
|
* For example, to retrieve only 10 items and skip 10 items: |
|
145
|
* |
|
146
|
* ```ts |
|
147
|
* sdk.admin.inventoryItem.list({ |
|
148
|
* limit: 10, |
|
149
|
* offset: 10 |
|
150
|
* }) |
|
151
|
* .then(({ inventory_items, count, limit, offset }) => { |
|
152
|
* console.log(inventory_items) |
|
153
|
* }) |
|
154
|
* ``` |
|
155
|
* |
|
156
|
* Using the `fields` query parameter, you can specify the fields and relations to retrieve |
|
157
|
* in each inventory item: |
|
158
|
* |
|
159
|
* ```ts |
|
160
|
* sdk.admin.inventoryItem.list({ |
|
161
|
* fields: "id,*location_levels" |
|
162
|
* }) |
|
163
|
* .then(({ inventory_items, count, limit, offset }) => { |
|
164
|
* console.log(inventory_items) |
|
165
|
* }) |
|
166
|
* ``` |
|
167
|
* |
|
168
|
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations). |
|
169
|
*/ |
|
170
|
async list( |
|
171
|
query?: HttpTypes.AdminInventoryItemsParams, |
|
172
|
headers?: ClientHeaders |
|
173
|
) { |
|
174
|
return await this.client.fetch<HttpTypes.AdminInventoryItemListResponse>( |
|
175
|
`/admin/inventory-items`, |
|
176
|
{ |
|
177
|
query, |
|
178
|
headers, |
|
179
|
} |
|
180
|
) |
|
181
|
} |
|
182
|
|
|
183
|
/** |
|
184
|
* This method retrieves an inventory item by its ID. It sends a request to the |
|
185
|
* [Get Inventory Item](https://docs.medusajs.com/api/admin/inventory-items/get-a-inventory-item) API route. |
|
186
|
* |
|
187
|
* @param id - The inventory item's ID. |
|
188
|
* @param query - Configure the fields to retrieve in the inventory item. |
|
189
|
* @param headers - Headers to pass in the request |
|
190
|
* @returns The inventory item's details. |
|
191
|
* |
|
192
|
* @example |
|
193
|
* To retrieve an inventory item by its ID: |
|
194
|
* |
|
195
|
* ```ts |
|
196
|
* sdk.admin.inventoryItem.retrieve("iitem_123") |
|
197
|
* .then(({ inventory_item }) => { |
|
198
|
* console.log(inventory_item) |
|
199
|
* }) |
|
200
|
* ``` |
|
201
|
* |
|
202
|
* To specify the fields and relations to retrieve: |
|
203
|
* |
|
204
|
* ```ts |
|
205
|
* sdk.admin.inventoryItem.retrieve("iitem_123", { |
|
206
|
* fields: "id,*location_levels" |
|
207
|
* }) |
|
208
|
* .then(({ inventory_item }) => { |
|
209
|
* console.log(inventory_item) |
|
210
|
* }) |
|
211
|
* ``` |
|
212
|
* |
|
213
|
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations). |
|
214
|
*/ |
|
215
|
async retrieve(id: string, query?: SelectParams, headers?: ClientHeaders) { |
|
216
|
return await this.client.fetch<HttpTypes.AdminInventoryItemResponse>( |
|
217
|
`/admin/inventory-items/${id}`, |
|
218
|
{ |
|
219
|
query, |
|
220
|
headers, |
|
221
|
} |
|
222
|
) |
|
223
|
} |
|
224
|
|
|
225
|
/** |
|
226
|
* This method deletes an inventory item. This sends a request to the |
|
227
|
* [Delete Inventory Item](https://docs.medusajs.com/api/admin/inventory-items/delete-inventory-item) |
|
228
|
* API route. |
|
229
|
* |
|
230
|
* @param id - The inventory item's ID. |
|
231
|
* @param headers - Headers to pass in the request |
|
232
|
* @returns The deletion's details. |
|
233
|
* |
|
234
|
* @example |
|
235
|
* sdk.admin.inventoryItem.delete("iitem_123") |
|
236
|
* .then(({ deleted }) => { |
|
237
|
* console.log(deleted) |
|
238
|
* }) |
|
239
|
*/ |
|
240
|
async delete(id: string, headers?: ClientHeaders) { |
|
241
|
return await this.client.fetch<HttpTypes.AdminInventoryItemDeleteResponse>( |
|
242
|
`/admin/inventory-items/${id}`, |
|
243
|
{ |
|
244
|
method: "DELETE", |
|
245
|
headers, |
|
246
|
} |
|
247
|
) |
|
248
|
} |
|
249
|
|
|
250
|
/** |
|
251
|
* This method retrieves a paginated list of inventory levels that belong to an inventory item. |
|
252
|
* It sends a request to the [List Inventory Items](https://docs.medusajs.com/api/admin/inventory-items/list-inventory-items) |
|
253
|
* API route. |
|
254
|
* |
|
255
|
* @param id - The inventory item's ID. |
|
256
|
* @param query - Filters and pagination configurations. |
|
257
|
* @param headers - Headers to pass in the request. |
|
258
|
* @returns The paginated list of inventory levels. |
|
259
|
* |
|
260
|
* @example |
|
261
|
* To retrieve the list of inventory levels: |
|
262
|
* |
|
263
|
* ```ts |
|
264
|
* sdk.admin.inventoryItem.listLevels("iitem_123") |
|
265
|
* .then(({ inventory_levels, count, limit, offset }) => { |
|
266
|
* console.log(inventory_levels) |
|
267
|
* }) |
|
268
|
* ``` |
|
269
|
* |
|
270
|
* To configure the pagination, pass the `limit` and `offset` query parameters. |
|
271
|
* |
|
272
|
* For example, to retrieve only 10 items and skip 10 items: |
|
273
|
* |
|
274
|
* ```ts |
|
275
|
* sdk.admin.inventoryItem.listLevels("iitem_123", { |
|
276
|
* limit: 10, |
|
277
|
* offset: 10 |
|
278
|
* }) |
|
279
|
* .then(({ inventory_levels, count, limit, offset }) => { |
|
280
|
* console.log(inventory_levels) |
|
281
|
* }) |
|
282
|
* ``` |
|
283
|
* |
|
284
|
* Using the `fields` query parameter, you can specify the fields and relations to retrieve |
|
285
|
* in each inventory level: |
|
286
|
* |
|
287
|
* ```ts |
|
288
|
* sdk.admin.inventoryItem.listLevels("iitem_123", { |
|
289
|
* fields: "id,*inventory_item" |
|
290
|
* }) |
|
291
|
* .then(({ inventory_levels, count, limit, offset }) => { |
|
292
|
* console.log(inventory_levels) |
|
293
|
* }) |
|
294
|
* ``` |
|
295
|
* |
|
296
|
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations). |
|
297
|
*/ |
|
298
|
async listLevels( |
|
299
|
id: string, |
|
300
|
query?: HttpTypes.AdminInventoryLevelFilters, |
|
301
|
headers?: ClientHeaders |
|
302
|
) { |
|
303
|
return await this.client.fetch<HttpTypes.AdminInventoryLevelListResponse>( |
|
304
|
`/admin/inventory-items/${id}/location-levels`, |
|
305
|
{ |
|
306
|
query, |
|
307
|
headers, |
|
308
|
} |
|
309
|
) |
|
310
|
} |
|
311
|
|
|
312
|
/** |
|
313
|
* This method updates the inventory level of the specified inventory item and |
|
314
|
* stock location. |
|
315
|
* |
|
316
|
* This method sends a request to the |
|
317
|
* [Update Inventory Level](https://docs.medusajs.com/api/admin/inventory-items/update-inventory-level) |
|
318
|
* API route. |
|
319
|
* |
|
320
|
* @param id - The inventory item's ID. |
|
321
|
* @param locationId - The stock location's ID. |
|
322
|
* @param body - The details to update. |
|
323
|
* @param query - Configure the fields to retrieve in the inventory item. |
|
324
|
* @param headers - Headers to pass in the request |
|
325
|
* @returns The inventory item's details. |
|
326
|
* |
|
327
|
* @example |
|
328
|
* sdk.admin.inventoryItem.updateLevel( |
|
329
|
* "iitem_123", |
|
330
|
* "sloc_123", |
|
331
|
* { |
|
332
|
* stocked_quantity: 10 |
|
333
|
* } |
|
334
|
* ) |
|
335
|
* .then(({ inventory_item }) => { |
|
336
|
* console.log(inventory_item) |
|
337
|
* }) |
|
338
|
*/ |
|
339
|
async updateLevel( |
|
340
|
id: string, |
|
341
|
locationId: string, |
|
342
|
body: HttpTypes.AdminUpdateInventoryLevel, |
|
343
|
query?: SelectParams, |
|
344
|
headers?: ClientHeaders |
|
345
|
) { |
|
346
|
return await this.client.fetch<HttpTypes.AdminInventoryItemResponse>( |
|
347
|
`/admin/inventory-items/${id}/location-levels/${locationId}`, |
|
348
|
{ |
|
349
|
method: "POST", |
|
350
|
headers, |
|
351
|
body, |
|
352
|
query, |
|
353
|
} |
|
354
|
) |
|
355
|
} |
|
356
|
|
|
357
|
/** |
|
358
|
* This method deletes an inventory level associated with an inventory item |
|
359
|
* and a stock location. |
|
360
|
* |
|
361
|
* This method sends a request to the |
|
362
|
* [Remove Inventory Level](https://docs.medusajs.com/api/admin/inventory-items/remove-inventory-level) |
|
363
|
* API route. |
|
364
|
* |
|
365
|
* @param id - The inventory item's ID. |
|
366
|
* @param locationId - The stock location's ID. |
|
367
|
* @param headers - Headers to pass in the request |
|
368
|
* @returns The deletion's details. |
|
369
|
* |
|
370
|
* @example |
|
371
|
* sdk.admin.inventoryItem.deleteLevel( |
|
372
|
* "iitem_123", |
|
373
|
* "sloc_123", |
|
374
|
* ) |
|
375
|
* .then(({ deleted, parent: inventoryItem }) => { |
|
376
|
* console.log(deleted, inventoryItem) |
|
377
|
* }) |
|
378
|
*/ |
|
379
|
async deleteLevel(id: string, locationId: string, headers?: ClientHeaders) { |
|
380
|
return await this.client.fetch<HttpTypes.AdminInventoryLevelDeleteResponse>( |
|
381
|
`/admin/inventory-items/${id}/location-levels/${locationId}`, |
|
382
|
{ |
|
383
|
method: "DELETE", |
|
384
|
headers, |
|
385
|
} |
|
386
|
) |
|
387
|
} |
|
388
|
|
|
389
|
/** |
|
390
|
* This method manages the inventory levels of an inventory item. It sends a request to the |
|
391
|
* [Manage Inventory Levels](https://docs.medusajs.com/api/admin/inventory-items/manage-inventory-levels-2) |
|
392
|
* API route. |
|
393
|
* |
|
394
|
* @deprecated Use `batchInventoryItemLocationLevels` instead. |
|
395
|
* |
|
396
|
* @param id - The inventory item's ID. |
|
397
|
* @param body - The inventory levels to create or delete. |
|
398
|
* @param query - Configure the fields to retrieve in the inventory item. |
|
399
|
* @param headers - Headers to pass in the request |
|
400
|
* @returns The inventory item's details. |
|
401
|
* |
|
402
|
* @example |
|
403
|
* sdk.admin.inventoryItem.batchUpdateLevels("iitem_123", { |
|
404
|
* create: [{ |
|
405
|
* location_id: "sloc_123", |
|
406
|
* stocked_quantity: 10 |
|
407
|
* }], |
|
408
|
* delete: ["ilvl_123"] |
|
409
|
* }) |
|
410
|
* .then(({ created, updated, deleted }) => { |
|
411
|
* console.log(created, updated, deleted) |
|
412
|
* }) |
|
413
|
*/ |
|
414
|
async batchUpdateLevels( |
|
415
|
id: string, |
|
416
|
body: HttpTypes.AdminBatchInventoryItemLocationLevels, |
|
417
|
query?: SelectParams, |
|
418
|
headers?: ClientHeaders |
|
419
|
) { |
|
420
|
return await this.client.fetch<HttpTypes.AdminBatchInventoryItemLocationLevelsResponse>( |
|
421
|
`/admin/inventory-items/${id}/location-levels/batch`, |
|
422
|
{ |
|
423
|
method: "POST", |
|
424
|
headers, |
|
425
|
body, |
|
426
|
query, |
|
427
|
} |
|
428
|
) |
|
429
|
} |
|
430
|
|
|
431
|
/** |
|
432
|
* This method manages the inventory levels of an inventory item. It sends a request to the |
|
433
|
* [Manage Inventory Levels](https://docs.medusajs.com/api/admin/inventory-items/manage-inventory-levels-2) |
|
434
|
* API route. |
|
435
|
* |
|
436
|
* @param id - The inventory item's ID. |
|
437
|
* @param body - The inventory levels to create, update or delete, and an optional `force` flag. |
|
438
|
* @param headers - Headers to pass in the request |
|
439
|
* @returns The inventory item's details. |
|
440
|
* |
|
441
|
* @example |
|
442
|
* sdk.admin.inventoryItem.batchInventoryItemLocationLevels("iitem_123", { |
|
443
|
* create: [{ |
|
444
|
* location_id: "sloc_123", |
|
445
|
* stocked_quantity: 10 |
|
446
|
* }], |
|
447
|
* delete: ["ilvl_123"] |
|
448
|
* }) |
|
449
|
* .then(({ created, updated, deleted }) => { |
|
450
|
* console.log(created, updated, deleted) |
|
451
|
* }) |
|
452
|
*/ |
|
453
|
async batchInventoryItemLocationLevels( |
|
454
|
id: string, |
|
455
|
body: HttpTypes.AdminBatchInventoryItemLocationLevels, |
|
456
|
headers?: ClientHeaders |
|
457
|
) { |
|
458
|
return await this.client.fetch<HttpTypes.AdminBatchInventoryItemLocationLevelsResponse>( |
|
459
|
`/admin/inventory-items/${id}/location-levels/batch`, |
|
460
|
{ |
|
461
|
method: "POST", |
|
462
|
headers, |
|
463
|
body, |
|
464
|
} |
|
465
|
) |
|
466
|
} |
|
467
|
|
|
468
|
/** |
|
469
|
* This method manages the inventory levels of multiple inventory items. |
|
470
|
* |
|
471
|
* @param body - The inventory levels to create, update or delete, and an optional `force` flag. |
|
472
|
* @param headers - Headers to pass in the request |
|
473
|
* @returns The inventory item's details. |
|
474
|
* |
|
475
|
* @example |
|
476
|
* sdk.admin.inventoryItem.batchInventoryItemsLocationLevels({ |
|
477
|
* create: [{ |
|
478
|
* inventory_item_id: "iitem_123", |
|
479
|
* location_id: "sloc_123", |
|
480
|
* stocked_quantity: 10 |
|
481
|
* }], |
|
482
|
* delete: ["ilvl_123"] |
|
483
|
* }) |
|
484
|
* .then(({ created, updated, deleted }) => { |
|
485
|
* console.log(created, updated, deleted) |
|
486
|
* }) |
|
487
|
*/ |
|
488
|
async batchInventoryItemsLocationLevels( |
|
489
|
body: HttpTypes.AdminBatchInventoryItemsLocationLevels, |
|
490
|
headers?: ClientHeaders |
|
491
|
) { |
|
492
|
return await this.client.fetch<HttpTypes.AdminBatchInventoryItemsLocationLevelsResponse>( |
|
493
|
`/admin/inventory-items/location-levels/batch`, |
|
494
|
{ |
|
495
|
method: "POST", |
|
496
|
headers, |
|
497
|
body, |
|
498
|
} |
|
499
|
) |
|
500
|
} |
|
501
|
} |