|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { Client } from "../client.js" |
|
3
|
import { ClientHeaders } from "../types.js" |
|
4
|
|
|
5
|
export class Fulfillment { |
|
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 fulfillment. It sends a request to the |
|
19
|
* [Create Fulfillment](https://docs.medusajs.com/api/admin/fulfillments/create-fulfillment) |
|
20
|
* API route. |
|
21
|
* |
|
22
|
* @param body - The fulfillment's details. |
|
23
|
* @param query - Configure the fields to retrieve in the fulfillment. |
|
24
|
* @param headers - Headers to pass in the request. |
|
25
|
* @returns The fulfillment's details. |
|
26
|
* |
|
27
|
* @example |
|
28
|
* sdk.admin.fulfillment.create({ |
|
29
|
* location_id: "sloc_123", |
|
30
|
* provider_id: "my_fulfillment", |
|
31
|
* delivery_address: { |
|
32
|
* country_code: "us" |
|
33
|
* }, |
|
34
|
* items: [ |
|
35
|
* { |
|
36
|
* title: "Shirt", |
|
37
|
* sku: "SHIRT", |
|
38
|
* quantity: 1, |
|
39
|
* barcode: "123" |
|
40
|
* } |
|
41
|
* ], |
|
42
|
* labels: [], |
|
43
|
* order: {}, |
|
44
|
* order_id: "order_123" |
|
45
|
* }) |
|
46
|
* .then(({ fulfillment }) => { |
|
47
|
* console.log(fulfillment) |
|
48
|
* }) |
|
49
|
*/ |
|
50
|
async create( |
|
51
|
body: HttpTypes.AdminCreateFulfillment, |
|
52
|
query?: HttpTypes.SelectParams, |
|
53
|
headers?: ClientHeaders |
|
54
|
) { |
|
55
|
return await this.client.fetch<HttpTypes.AdminFulfillmentResponse>( |
|
56
|
`/admin/fulfillments`, |
|
57
|
{ |
|
58
|
method: "POST", |
|
59
|
headers, |
|
60
|
body, |
|
61
|
query, |
|
62
|
} |
|
63
|
) |
|
64
|
} |
|
65
|
|
|
66
|
/** |
|
67
|
* This method cancels a fulfillment. It sends a request to the |
|
68
|
* [Cancel Fulfillment](https://docs.medusajs.com/api/admin/fulfillments/cancel-a-fulfillment) |
|
69
|
* API route. |
|
70
|
* |
|
71
|
* @param id - The fulfillment's ID. |
|
72
|
* @param query - Configure the fields to retrieve in the fulfillment. |
|
73
|
* @param headers - Headers to pass in the request. |
|
74
|
* @returns The fulfillment's details. |
|
75
|
* |
|
76
|
* @example |
|
77
|
* sdk.admin.fulfillment.cancel("ful_123") |
|
78
|
* .then(({ fulfillment }) => { |
|
79
|
* console.log(fulfillment) |
|
80
|
* }) |
|
81
|
*/ |
|
82
|
async cancel( |
|
83
|
id: string, |
|
84
|
query?: HttpTypes.SelectParams, |
|
85
|
headers?: ClientHeaders |
|
86
|
) { |
|
87
|
return await this.client.fetch<HttpTypes.AdminFulfillmentResponse>( |
|
88
|
`/admin/fulfillments/${id}/cancel`, |
|
89
|
{ |
|
90
|
method: "POST", |
|
91
|
body: {}, |
|
92
|
headers, |
|
93
|
query |
|
94
|
} |
|
95
|
) |
|
96
|
} |
|
97
|
|
|
98
|
/** |
|
99
|
* This method creates a shipment for a fulfillment. It sends a request to the |
|
100
|
* [Create Shipment](https://docs.medusajs.com/api/admin/fulfillments/create-shipment) |
|
101
|
* API route. |
|
102
|
* |
|
103
|
* @param id - The fulfillment's ID. |
|
104
|
* @param body - The shipment's details. |
|
105
|
* @param query - Configure the fields to retrieve in the fulfillment. |
|
106
|
* @param headers - Headers to pass in the request. |
|
107
|
* @returns The fulfillment's details. |
|
108
|
* |
|
109
|
* @example |
|
110
|
* sdk.admin.fulfillment.createShipment("ful_123", { |
|
111
|
* labels: [ |
|
112
|
* { |
|
113
|
* tracking_number: "123", |
|
114
|
* tracking_url: "example.com", |
|
115
|
* label_url: "example.com" |
|
116
|
* } |
|
117
|
* ] |
|
118
|
* }) |
|
119
|
* .then(({ fulfillment }) => { |
|
120
|
* console.log(fulfillment) |
|
121
|
* }) |
|
122
|
*/ |
|
123
|
async createShipment( |
|
124
|
id: string, |
|
125
|
body: HttpTypes.AdminCreateFulfillmentShipment, |
|
126
|
query?: HttpTypes.SelectParams, |
|
127
|
headers?: ClientHeaders |
|
128
|
) { |
|
129
|
return await this.client.fetch<HttpTypes.AdminFulfillmentResponse>( |
|
130
|
`/admin/fulfillments/${id}/shipment`, |
|
131
|
{ |
|
132
|
method: "POST", |
|
133
|
headers, |
|
134
|
body, |
|
135
|
query, |
|
136
|
} |
|
137
|
) |
|
138
|
} |
|
139
|
} |