4
4
import { LocationsEndpoint } from './mli-locations'
5
5
import { Identifiable , Resource , ResourcePage } from './core'
6
6
7
- type StockType = 'stock'
7
+ /**
8
+ * Multi Location Inventory Types
9
+ */
10
+ export type InventoryResourceType = 'stock'
8
11
9
- export interface StockMeta {
10
- timestamps : {
11
- created_at : string
12
- updated_at : string
13
- }
12
+ /**
13
+ * Base Types
14
+ */
15
+ export interface Timestamps {
16
+ created_at : string
17
+ updated_at : string
18
+ }
19
+
20
+ /**
21
+ * Location-specific inventory quantities
22
+ */
23
+ export interface LocationQuantities {
24
+ available : number
25
+ allocated : number
26
+ total : number
27
+ }
28
+
29
+ /**
30
+ * Create Operation Types
31
+ */
32
+ export interface LocationCreateQuantity {
33
+ available : number
14
34
}
15
35
16
- export interface StockBaseLocations {
17
- [ key : string ] : {
18
- available : number
36
+ export interface StockCreate {
37
+ available ?: number
38
+ locations ?: {
39
+ [ locationId : string ] : LocationCreateQuantity
19
40
}
20
41
}
21
42
22
- export interface StockBaseAttributes {
23
- product_id : string
24
- locations : StockBaseLocations
43
+ /**
44
+ * Update Operation Types
45
+ */
46
+ export interface LocationUpdateQuantity {
47
+ allocated ?: number
48
+ available ?: number
25
49
}
26
50
27
- export interface StockResponseLocations {
28
- [ key : string ] : {
29
- available : number
30
- allocated : number
31
- total : number
51
+ export interface StockUpdate {
52
+ locations ?: {
53
+ [ locationId : string ] : LocationUpdateQuantity | null
32
54
}
33
55
}
34
- export interface StockResponseAttributes extends StockBaseAttributes {
56
+
57
+ /**
58
+ * Response Types
59
+ */
60
+ export interface StockLocationsMap {
61
+ [ locationId : string ] : LocationQuantities
62
+ }
63
+
64
+ export interface StockAttributes {
35
65
allocated : number
66
+ available : number
36
67
total : number
37
- locations : StockResponseLocations
68
+ locations : StockLocationsMap
38
69
}
39
70
40
- export interface StockResponse extends Identifiable , StockMeta {
41
- type : StockType
42
- attributes : StockResponseAttributes
71
+ export interface StockResponse extends Identifiable {
72
+ type : InventoryResourceType
73
+ attributes : StockAttributes
74
+ timestamps : Timestamps
43
75
}
44
76
45
77
/**
46
- * Multi Location Inventories Endpoints
78
+ * Multi Location Inventories Endpoint Interface
47
79
*/
48
80
export interface MultiLocationInventoriesEndpoint {
49
81
endpoint : 'inventory'
50
-
51
82
Locations : LocationsEndpoint
52
83
53
84
/**
@@ -57,21 +88,35 @@ export interface MultiLocationInventoriesEndpoint {
57
88
58
89
/**
59
90
* Get Stock for Product
60
- * @param productId The ID of the product.
91
+ * @param inventoryId - The inventory identifier
61
92
*/
62
- Get ( productId : string ) : Promise < Resource < StockResponse > >
93
+ Get ( inventoryId : string ) : Promise < Resource < StockResponse > >
63
94
64
95
/**
65
96
* Create Stock for Product
66
- * @param body - The base attributes of the inventory stock.
97
+ * @param payload - Initial stock information with overall availability or per-location quantities
98
+ * @param productId - Optional product identifier
99
+ */
100
+ Create (
101
+ payload : StockCreate ,
102
+ productId ?: string
103
+ ) : Promise < Resource < StockResponse > >
104
+
105
+ /**
106
+ * Update Stock for Product
107
+ * @param inventoryId - The inventory identifier
108
+ * @param payload - Location-specific updates. Set location to null to remove it
67
109
*/
68
- Create ( body : StockBaseAttributes ) : Promise < Resource < StockResponse > >
110
+ Update (
111
+ inventoryId : string ,
112
+ payload : StockUpdate
113
+ ) : Promise < Resource < StockResponse > >
69
114
70
115
/**
71
116
* Delete Stock for Product
72
- * @param productId The ID of the product.
117
+ * @param inventoryId - The inventory identifier
73
118
*/
74
- Delete ( productId : string ) : Promise < { } >
119
+ Delete ( inventoryId : string ) : Promise < { } >
75
120
76
121
Limit ( value : number ) : MultiLocationInventoriesEndpoint
77
122
0 commit comments