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