1 import { HttpTypes } from "@medusajs/types"
2 import { Client } from "../client.js"
3 import { ClientHeaders } from "../types.js"
4
5 export class FulfillmentProvider {
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 retrieves a paginated list of fulfillment providers. It sends a request to the
19 * [List Fulfillment Providers](https://docs.medusajs.com/api/admin/fulfillment-providers/list-fulfillment-providers)
20 * API route.
21 *
22 * @param query - Filters and pagination configurations.
23 * @param headers - Headers to pass in the request.
24 * @returns The paginated list of providers.
25 *
26 * @example
27 * To retrieve the list of fulfillment providers:
28 *
29 * ```ts
30 * sdk.admin.fulfillmentProvider.list()
31 * .then(({ fulfillment_providers, count, limit, offset }) => {
32 * console.log(fulfillment_providers)
33 * })
34 * ```
35 *
36 * To configure the pagination, pass the `limit` and `offset` query parameters.
37 *
38 * For example, to retrieve only 10 items and skip 10 items:
39 *
40 * ```ts
41 * sdk.admin.fulfillmentProvider.list({
42 * limit: 10,
43 * offset: 10
44 * })
45 * .then(({ fulfillment_providers, count, limit, offset }) => {
46 * console.log(fulfillment_providers)
47 * })
48 * ```
49 *
50 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
51 * in each fulfillment provider:
52 *
53 * ```ts
54 * sdk.admin.fulfillmentProvider.list({
55 * fields: "id"
56 * })
57 * .then(({ fulfillment_providers, count, limit, offset }) => {
58 * console.log(fulfillment_providers)
59 * })
60 * ```
61 *
62 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
63 */
64 async list(
65 query?: HttpTypes.AdminGetFulfillmentProvidersParams,
66 headers?: ClientHeaders
67 ) {
68 return await this.client.fetch<HttpTypes.AdminFulfillmentProviderListResponse>(
69 `/admin/fulfillment-providers`,
70 {
71 method: "GET",
72 headers,
73 query,
74 }
75 )
76 }
77
78 /**
79 * This method retrieves a list of fulfillment options for a given fulfillment provider. It sends a request to the
80 * [List Fulfillment Options](https://docs.medusajs.com/api/admin/fulfillment-providers/list-fulfillment-options)
81 * API route.
82 *
83 * @param id - The ID of the fulfillment provider.
84 * @param headers - Headers to pass in the request.
85 * @returns The list of fulfillment options.
86 *
87 * @example
88 * sdk.admin.fulfillmentProvider.listFulfillmentOptions("fp_123")
89 * .then(({ fulfillment_options }) => {
90 * console.log(fulfillment_options)
91 * })
92 */
93 async listFulfillmentOptions(id: string, headers?: ClientHeaders) {
94 return await this.client.fetch<HttpTypes.AdminFulfillmentProviderOptionsListResponse>(
95 `/admin/fulfillment-providers/${id}/options`,
96 {
97 method: "GET",
98 headers,
99 }
100 )
101 }
102 }