|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { Client } from "../client.js" |
|
3
|
import { ClientHeaders } from "../types.js" |
|
4
|
|
|
5
|
export class ShippingProfile { |
|
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 a new shipping profile. It sends a request to the |
|
19
|
* [Create Shipping Profile](https://docs.medusajs.com/api/admin/shipping-profiles/create-shipping-profile) |
|
20
|
* API route. |
|
21
|
* |
|
22
|
* @param body - The details of the shipping profile to create. |
|
23
|
* @param query - Configure the fields and relations to retrieve in the shipping profile. |
|
24
|
* @param headers - Headers to pass in the request. |
|
25
|
* @returns The shipping profile's details. |
|
26
|
* |
|
27
|
* @example |
|
28
|
* sdk.admin.shippingProfile.create({ |
|
29
|
* name: "Default Shipping Profile", |
|
30
|
* }) |
|
31
|
* .then(({ shipping_profile }) => { |
|
32
|
* console.log(shipping_profile) |
|
33
|
* }) |
|
34
|
*/ |
|
35
|
async create( |
|
36
|
body: HttpTypes.AdminCreateShippingProfile, |
|
37
|
query?: HttpTypes.SelectParams, |
|
38
|
headers?: ClientHeaders |
|
39
|
) { |
|
40
|
return await this.client.fetch<HttpTypes.AdminShippingProfileResponse>( |
|
41
|
`/admin/shipping-profiles`, |
|
42
|
{ |
|
43
|
method: "POST", |
|
44
|
headers, |
|
45
|
body, |
|
46
|
query, |
|
47
|
} |
|
48
|
) |
|
49
|
} |
|
50
|
|
|
51
|
/** |
|
52
|
* This method updates a shipping profile. It sends a request to the |
|
53
|
* [Update Shipping Profile](https://docs.medusajs.com/api/admin/shipping-profiles/update-a-shipping-profile) |
|
54
|
* API route. |
|
55
|
* |
|
56
|
* @param id - The ID of the shipping profile to update. |
|
57
|
* @param body - The details of the shipping profile to update. |
|
58
|
* @param query - Configure the fields and relations to retrieve in the shipping profile. |
|
59
|
* @param headers - Headers to pass in the request. |
|
60
|
* @returns The shipping profile's details. |
|
61
|
* |
|
62
|
* @example |
|
63
|
* sdk.admin.shippingProfile.update("sp_123", { |
|
64
|
* name: "Updated Shipping Profile", |
|
65
|
* }) |
|
66
|
* .then(({ shipping_profile }) => { |
|
67
|
* console.log(shipping_profile) |
|
68
|
* }) |
|
69
|
*/ |
|
70
|
async update( |
|
71
|
id: string, |
|
72
|
body: HttpTypes.AdminUpdateShippingProfile, |
|
73
|
query?: HttpTypes.SelectParams, |
|
74
|
headers?: ClientHeaders |
|
75
|
) { |
|
76
|
return await this.client.fetch<HttpTypes.AdminShippingProfileResponse>( |
|
77
|
`/admin/shipping-profiles/${id}`, |
|
78
|
{ |
|
79
|
method: "POST", |
|
80
|
headers, |
|
81
|
body, |
|
82
|
query, |
|
83
|
} |
|
84
|
) |
|
85
|
} |
|
86
|
|
|
87
|
/** |
|
88
|
* This method deletes a shipping profile. It sends a request to the |
|
89
|
* [Delete Shipping Profile](https://docs.medusajs.com/api/admin/shipping-profiles/delete-a-shipping-profile) |
|
90
|
* API route. |
|
91
|
* |
|
92
|
* @param id - The ID of the shipping profile to delete. |
|
93
|
* @param headers - Headers to pass in the request. |
|
94
|
* @returns The deletion's details. |
|
95
|
* |
|
96
|
* @example |
|
97
|
* sdk.admin.shippingProfile.delete("sp_123") |
|
98
|
* .then(({ deleted }) => { |
|
99
|
* console.log(deleted) |
|
100
|
* }) |
|
101
|
*/ |
|
102
|
async delete(id: string, headers?: ClientHeaders) { |
|
103
|
return await this.client.fetch<HttpTypes.AdminShippingProfileDeleteResponse>( |
|
104
|
`/admin/shipping-profiles/${id}`, |
|
105
|
{ |
|
106
|
method: "DELETE", |
|
107
|
headers, |
|
108
|
} |
|
109
|
) |
|
110
|
} |
|
111
|
|
|
112
|
/** |
|
113
|
* This method retrieves a list of shipping profiles. It sends a request to the |
|
114
|
* [List Shipping Profiles](https://docs.medusajs.com/api/admin/shipping-profiles/list-shipping-profiles) |
|
115
|
* API route. |
|
116
|
* |
|
117
|
* @param query - Filters and pagination configurations. |
|
118
|
* @param headers - Headers to pass in the request. |
|
119
|
* @returns The list of shipping profiles. |
|
120
|
* |
|
121
|
* @example |
|
122
|
* To retrieve the list of shipping profiles: |
|
123
|
* |
|
124
|
* ```ts |
|
125
|
* sdk.admin.shippingProfile.list() |
|
126
|
* .then(({ shipping_profiles, count, limit, offset }) => { |
|
127
|
* console.log(shipping_profiles) |
|
128
|
* }) |
|
129
|
* ``` |
|
130
|
* |
|
131
|
* To configure the pagination, pass the `limit` and `offset` query parameters. |
|
132
|
* |
|
133
|
* For example, to retrieve only 10 items and skip 10 items: |
|
134
|
* |
|
135
|
* ```ts |
|
136
|
* sdk.admin.shippingProfile.list({ |
|
137
|
* limit: 10, |
|
138
|
* offset: 10 |
|
139
|
* }) |
|
140
|
* .then(({ shipping_profiles, count, limit, offset }) => { |
|
141
|
* console.log(shipping_profiles) |
|
142
|
* }) |
|
143
|
* ``` |
|
144
|
* |
|
145
|
* Using the `fields` query parameter, you can specify the fields and relations to retrieve |
|
146
|
* in each shipping profile: |
|
147
|
* |
|
148
|
* ```ts |
|
149
|
* sdk.admin.shippingProfile.list({ |
|
150
|
* fields: "id,name" |
|
151
|
* }) |
|
152
|
* .then(({ shipping_profiles, count, limit, offset }) => { |
|
153
|
* console.log(shipping_profiles) |
|
154
|
* }) |
|
155
|
* ``` |
|
156
|
* |
|
157
|
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin/select-fields-and-relations). |
|
158
|
*/ |
|
159
|
async list( |
|
160
|
query?: HttpTypes.AdminShippingProfileListParams, |
|
161
|
headers?: ClientHeaders |
|
162
|
) { |
|
163
|
return await this.client.fetch<HttpTypes.AdminShippingProfileListResponse>( |
|
164
|
`/admin/shipping-profiles`, |
|
165
|
{ |
|
166
|
method: "GET", |
|
167
|
headers, |
|
168
|
query, |
|
169
|
} |
|
170
|
) |
|
171
|
} |
|
172
|
|
|
173
|
/** |
|
174
|
* This method retrieves a shipping profile. It sends a request to the |
|
175
|
* [Get Shipping Profile](https://docs.medusajs.com/api/admin/shipping-profiles/get-a-shipping-profile) |
|
176
|
* API route. |
|
177
|
* |
|
178
|
* @param id - The ID of the shipping profile to retrieve. |
|
179
|
* @param query - Configure the fields and relations to retrieve in the shipping profile. |
|
180
|
* @param headers - Headers to pass in the request. |
|
181
|
* @returns The shipping profile's details. |
|
182
|
* |
|
183
|
* @example |
|
184
|
* To retrieve a shipping profile by its ID: |
|
185
|
* |
|
186
|
* ```ts |
|
187
|
* sdk.admin.shippingProfile.retrieve("sp_123") |
|
188
|
* .then(({ shipping_profile }) => { |
|
189
|
* console.log(shipping_profile) |
|
190
|
* }) |
|
191
|
* ``` |
|
192
|
* |
|
193
|
* To specify the fields and relations to retrieve: |
|
194
|
* |
|
195
|
* ```ts |
|
196
|
* sdk.admin.shippingProfile.retrieve("sp_123", { |
|
197
|
* fields: "id,name" |
|
198
|
* }) |
|
199
|
* .then(({ shipping_profile }) => { |
|
200
|
* console.log(shipping_profile) |
|
201
|
* }) |
|
202
|
* ``` |
|
203
|
* |
|
204
|
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin/select-fields-and-relations). |
|
205
|
*/ |
|
206
|
async retrieve( |
|
207
|
id: string, |
|
208
|
query?: HttpTypes.SelectParams, |
|
209
|
headers?: ClientHeaders |
|
210
|
) { |
|
211
|
return await this.client.fetch<HttpTypes.AdminShippingProfileResponse>( |
|
212
|
`/admin/shipping-profiles/${id}`, |
|
213
|
{ |
|
214
|
method: "GET", |
|
215
|
headers, |
|
216
|
query, |
|
217
|
} |
|
218
|
) |
|
219
|
} |
|
220
|
} |