|
1
|
import { HttpTypes, SelectParams } from "@medusajs/types" |
|
2
|
import { Client } from "../client.js" |
|
3
|
import { ClientHeaders } from "../types.js" |
|
4
|
|
|
5
|
export class Store { |
|
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 store by its ID. It sends a request to the |
|
19
|
* [Get Store](https://docs.medusajs.com/api/admin/stores/get-a-store) |
|
20
|
* API route. |
|
21
|
* |
|
22
|
* @param id - The ID of the store to retrieve. |
|
23
|
* @param query - Configure the fields and relations to retrieve in the store. |
|
24
|
* @param headers - Headers to pass in the request. |
|
25
|
* @returns The store's details. |
|
26
|
* |
|
27
|
* @example |
|
28
|
* To retrieve a store by its ID: |
|
29
|
* |
|
30
|
* ```ts |
|
31
|
* sdk.admin.store.retrieve("store_123") |
|
32
|
* .then(({ store }) => { |
|
33
|
* console.log(store) |
|
34
|
* }) |
|
35
|
* ``` |
|
36
|
* |
|
37
|
* To specify the fields and relations to retrieve: |
|
38
|
* |
|
39
|
* ```ts |
|
40
|
* sdk.admin.store.retrieve("store_123", { |
|
41
|
* fields: "id,*supported_currencies" |
|
42
|
* }) |
|
43
|
* .then(({ store }) => { |
|
44
|
* console.log(store) |
|
45
|
* }) |
|
46
|
* ``` |
|
47
|
* |
|
48
|
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin/select-fields-and-relations). |
|
49
|
*/ |
|
50
|
async retrieve( |
|
51
|
id: string, |
|
52
|
query?: HttpTypes.AdminStoreParams, |
|
53
|
headers?: ClientHeaders |
|
54
|
) { |
|
55
|
return await this.client.fetch<HttpTypes.AdminStoreResponse>( |
|
56
|
`/admin/stores/${id}`, |
|
57
|
{ |
|
58
|
method: "GET", |
|
59
|
headers, |
|
60
|
query, |
|
61
|
} |
|
62
|
) |
|
63
|
} |
|
64
|
|
|
65
|
/** |
|
66
|
* This method retrieves a list of stores. It sends a request to the |
|
67
|
* [List Stores](https://docs.medusajs.com/api/admin/stores/list-stores) |
|
68
|
* API route. |
|
69
|
* |
|
70
|
* @param query - Filters and pagination configurations. |
|
71
|
* @param headers - Headers to pass in the request. |
|
72
|
* @returns The list of stores. |
|
73
|
* |
|
74
|
* @example |
|
75
|
* To retrieve the list of stores: |
|
76
|
* |
|
77
|
* ```ts |
|
78
|
* sdk.admin.store.list() |
|
79
|
* .then(({ stores, count, limit, offset }) => { |
|
80
|
* console.log(stores) |
|
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.store.list({ |
|
90
|
* limit: 10, |
|
91
|
* offset: 10 |
|
92
|
* }) |
|
93
|
* .then(({ stores, count, limit, offset }) => { |
|
94
|
* console.log(stores) |
|
95
|
* }) |
|
96
|
* ``` |
|
97
|
* |
|
98
|
* Using the `fields` query parameter, you can specify the fields and relations to retrieve |
|
99
|
* in each store: |
|
100
|
* |
|
101
|
* ```ts |
|
102
|
* sdk.admin.store.list({ |
|
103
|
* fields: "id,*supported_currencies" |
|
104
|
* }) |
|
105
|
* .then(({ stores, count, limit, offset }) => { |
|
106
|
* console.log(stores) |
|
107
|
* }) |
|
108
|
* ``` |
|
109
|
* |
|
110
|
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin/select-fields-and-relations). |
|
111
|
*/ |
|
112
|
async list(query?: HttpTypes.AdminStoreListParams, headers?: ClientHeaders) { |
|
113
|
return await this.client.fetch<HttpTypes.AdminStoreListResponse>( |
|
114
|
`/admin/stores`, |
|
115
|
{ |
|
116
|
method: "GET", |
|
117
|
headers, |
|
118
|
query, |
|
119
|
} |
|
120
|
) |
|
121
|
} |
|
122
|
|
|
123
|
/** |
|
124
|
* This method updates a store. It sends a request to the |
|
125
|
* [Update Store](https://docs.medusajs.com/api/admin/stores/update-a-store) |
|
126
|
* API route. |
|
127
|
* |
|
128
|
* @param id - The ID of the store to update. |
|
129
|
* @param body - The details of the store to update. |
|
130
|
* @param query - Configure the fields and relations to retrieve in the store. |
|
131
|
* @param headers - Headers to pass in the request. |
|
132
|
* @returns The store's details. |
|
133
|
* |
|
134
|
* @example |
|
135
|
* sdk.admin.store.update("store_123", { |
|
136
|
* name: "My Store", |
|
137
|
* }) |
|
138
|
* .then(({ store }) => { |
|
139
|
* console.log(store) |
|
140
|
* }) |
|
141
|
*/ |
|
142
|
async update( |
|
143
|
id: string, |
|
144
|
body: HttpTypes.AdminUpdateStore, |
|
145
|
query?: SelectParams, |
|
146
|
headers?: ClientHeaders |
|
147
|
) { |
|
148
|
return await this.client.fetch<HttpTypes.AdminStoreResponse>( |
|
149
|
`/admin/stores/${id}`, |
|
150
|
{ |
|
151
|
method: "POST", |
|
152
|
headers, |
|
153
|
body, |
|
154
|
query, |
|
155
|
} |
|
156
|
) |
|
157
|
} |
|
158
|
} |