@devite/shopware-client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/dist/index.cjs +1330 -0
  4. package/dist/index.d.cts +2186 -0
  5. package/dist/index.d.mts +2186 -0
  6. package/dist/index.d.ts +2186 -0
  7. package/dist/index.mjs +1314 -0
  8. package/dist/src/ShopwareClient.d.ts +31 -0
  9. package/dist/src/auth/AuthenticationStore.d.ts +8 -0
  10. package/dist/src/auth/AuthenticationType.d.ts +5 -0
  11. package/dist/src/auth/entries/AuthenticationEntry.d.ts +10 -0
  12. package/dist/src/auth/entries/ContextTokenEntry.d.ts +13 -0
  13. package/dist/src/auth/entries/OAuthEntry.d.ts +15 -0
  14. package/dist/src/auth/entries/index.d.ts +3 -0
  15. package/dist/src/auth/errors/ExpiredError.d.ts +4 -0
  16. package/dist/src/auth/errors/NotSavedError.d.ts +4 -0
  17. package/dist/src/auth/errors/index.d.ts +2 -0
  18. package/dist/src/auth/index.d.ts +4 -0
  19. package/dist/src/clients/AccountClient.d.ts +16 -0
  20. package/dist/src/clients/AddressClient.d.ts +11 -0
  21. package/dist/src/clients/CartClient.d.ts +10 -0
  22. package/dist/src/clients/CategoryClient.d.ts +8 -0
  23. package/dist/src/clients/Client.d.ts +16 -0
  24. package/dist/src/clients/ContentClient.d.ts +9 -0
  25. package/dist/src/clients/ContextClient.d.ts +7 -0
  26. package/dist/src/clients/CustomerAuthenticationClient.d.ts +11 -0
  27. package/dist/src/clients/DocumentClient.d.ts +6 -0
  28. package/dist/src/clients/GatewayClient.d.ts +6 -0
  29. package/dist/src/clients/NewsletterClient.d.ts +8 -0
  30. package/dist/src/clients/OrderClient.d.ts +10 -0
  31. package/dist/src/clients/PaymentClient.d.ts +6 -0
  32. package/dist/src/clients/ProductClient.d.ts +14 -0
  33. package/dist/src/clients/SeoClient.d.ts +8 -0
  34. package/dist/src/clients/SystemClient.d.ts +12 -0
  35. package/dist/src/clients/WishlistClient.d.ts +9 -0
  36. package/dist/src/clients/index.d.ts +17 -0
  37. package/dist/src/index.d.ts +1 -0
  38. package/dist/src/payloads/BinaryPayload.d.ts +10 -0
  39. package/dist/src/payloads/JsonPayload.d.ts +10 -0
  40. package/dist/src/payloads/Payload.d.ts +6 -0
  41. package/dist/src/payloads/index.d.ts +3 -0
  42. package/dist/tests/auth/AuthenticationStore.test.d.ts +1 -0
  43. package/dist/tests/auth/entries/ContextTokenEntry.test.d.ts +1 -0
  44. package/dist/tests/auth/entries/OAuthEntry.test.d.ts +1 -0
  45. package/dist/types/ClientRequestOptions.d.ts +8 -0
  46. package/dist/types/ClientResponse.d.ts +7 -0
  47. package/dist/types/HTTPRequestMethod.d.ts +8 -0
  48. package/dist/types/RequestCacheEntry.d.ts +5 -0
  49. package/dist/types/auth/OAuthResponseBody.d.ts +5 -0
  50. package/dist/types/auth/index.d.ts +1 -0
  51. package/dist/types/clients/AccountClient.d.ts +70 -0
  52. package/dist/types/clients/AddressClient.d.ts +7 -0
  53. package/dist/types/clients/CartClient.d.ts +17 -0
  54. package/dist/types/clients/CategoryClient.d.ts +12 -0
  55. package/dist/types/clients/ContentClient.d.ts +29 -0
  56. package/dist/types/clients/ContextClient.d.ts +18 -0
  57. package/dist/types/clients/CustomerAuthenticationClient.d.ts +44 -0
  58. package/dist/types/clients/DocumentClient.d.ts +3 -0
  59. package/dist/types/clients/GatewayClient.d.ts +18 -0
  60. package/dist/types/clients/NewsletterClient.d.ts +21 -0
  61. package/dist/types/clients/OrderClient.d.ts +26 -0
  62. package/dist/types/clients/PaymentClient.d.ts +8 -0
  63. package/dist/types/clients/ProductClient.d.ts +49 -0
  64. package/dist/types/clients/SeoClient.d.ts +7 -0
  65. package/dist/types/clients/SystemClient.d.ts +33 -0
  66. package/dist/types/clients/WishlistClient.d.ts +21 -0
  67. package/dist/types/clients/index.d.ts +16 -0
  68. package/dist/types/index.d.ts +7 -0
  69. package/dist/types/storeApi/Currency.d.ts +26 -0
  70. package/dist/types/storeApi/DeliveryTime.d.ts +12 -0
  71. package/dist/types/storeApi/EntitySearchResult.d.ts +7 -0
  72. package/dist/types/storeApi/GenericRecord.d.ts +3 -0
  73. package/dist/types/storeApi/PaymentMethod.d.ts +24 -0
  74. package/dist/types/storeApi/Rule.d.ts +10 -0
  75. package/dist/types/storeApi/Salutation.d.ts +11 -0
  76. package/dist/types/storeApi/StateMachineState.d.ts +10 -0
  77. package/dist/types/storeApi/Tag.d.ts +6 -0
  78. package/dist/types/storeApi/Tax.d.ts +10 -0
  79. package/dist/types/storeApi/TotalCountMode.d.ts +1 -0
  80. package/dist/types/storeApi/Unit.d.ts +10 -0
  81. package/dist/types/storeApi/aggregation/AggregationEntity.d.ts +6 -0
  82. package/dist/types/storeApi/aggregation/AggregationFilter.d.ts +6 -0
  83. package/dist/types/storeApi/aggregation/AggregationHistogram.d.ts +8 -0
  84. package/dist/types/storeApi/aggregation/AggregationMetrics.d.ts +5 -0
  85. package/dist/types/storeApi/aggregation/AggregationRange.d.ts +13 -0
  86. package/dist/types/storeApi/aggregation/AggregationTerms.d.ts +8 -0
  87. package/dist/types/storeApi/aggregation/Aggregations.d.ts +2 -0
  88. package/dist/types/storeApi/aggregation/index.d.ts +7 -0
  89. package/dist/types/storeApi/cart/Cart.d.ts +19 -0
  90. package/dist/types/storeApi/cart/CartDelivery.d.ts +13 -0
  91. package/dist/types/storeApi/cart/CartDeliveryDate.d.ts +4 -0
  92. package/dist/types/storeApi/cart/CartDeliveryInformation.d.ts +12 -0
  93. package/dist/types/storeApi/cart/CartDeliveryPosition.d.ts +9 -0
  94. package/dist/types/storeApi/cart/CartDeliveryShippingLocation.d.ts +7 -0
  95. package/dist/types/storeApi/cart/CartDeliveryTime.d.ts +7 -0
  96. package/dist/types/storeApi/cart/CartError.d.ts +8 -0
  97. package/dist/types/storeApi/cart/CartItems.d.ts +2 -0
  98. package/dist/types/storeApi/cart/index.d.ts +9 -0
  99. package/dist/types/storeApi/category/Category.d.ts +50 -0
  100. package/dist/types/storeApi/category/MainCategory.d.ts +10 -0
  101. package/dist/types/storeApi/category/index.d.ts +2 -0
  102. package/dist/types/storeApi/cms/BackgroundMediaMode.d.ts +1 -0
  103. package/dist/types/storeApi/cms/CmsBlock.d.ts +28 -0
  104. package/dist/types/storeApi/cms/CmsPage.d.ts +23 -0
  105. package/dist/types/storeApi/cms/CmsSection.d.ts +25 -0
  106. package/dist/types/storeApi/cms/CmsSlot.d.ts +20 -0
  107. package/dist/types/storeApi/cms/LandingPage.d.ts +23 -0
  108. package/dist/types/storeApi/cms/Visibility.d.ts +5 -0
  109. package/dist/types/storeApi/cms/index.d.ts +7 -0
  110. package/dist/types/storeApi/country/Country.d.ts +40 -0
  111. package/dist/types/storeApi/country/CountryState.d.ts +13 -0
  112. package/dist/types/storeApi/country/index.d.ts +2 -0
  113. package/dist/types/storeApi/customer/Customer.d.ts +61 -0
  114. package/dist/types/storeApi/customer/CustomerAddress.d.ts +7 -0
  115. package/dist/types/storeApi/customer/CustomerAddressBody.d.ts +23 -0
  116. package/dist/types/storeApi/customer/CustomerGroup.d.ts +20 -0
  117. package/dist/types/storeApi/customer/index.d.ts +4 -0
  118. package/dist/types/storeApi/document/ShopwareDocument.d.ts +29 -0
  119. package/dist/types/storeApi/document/ShopwareDocumentBaseConfig.d.ts +17 -0
  120. package/dist/types/storeApi/document/ShopwareDocumentType.d.ts +10 -0
  121. package/dist/types/storeApi/document/index.d.ts +3 -0
  122. package/dist/types/storeApi/filter/EqualsFilter.d.ts +5 -0
  123. package/dist/types/storeApi/filter/Filters.d.ts +2 -0
  124. package/dist/types/storeApi/filter/MultiNotFilter.d.ts +6 -0
  125. package/dist/types/storeApi/filter/RangeFilter.d.ts +10 -0
  126. package/dist/types/storeApi/filter/SimpleFilter.d.ts +5 -0
  127. package/dist/types/storeApi/filter/index.d.ts +5 -0
  128. package/dist/types/storeApi/index.d.ts +32 -0
  129. package/dist/types/storeApi/lineItem/LineItem.d.ts +32 -0
  130. package/dist/types/storeApi/lineItem/LineItemPayload.d.ts +74 -0
  131. package/dist/types/storeApi/lineItem/LineItemType.d.ts +1 -0
  132. package/dist/types/storeApi/lineItem/index.d.ts +3 -0
  133. package/dist/types/storeApi/link/Link.d.ts +4 -0
  134. package/dist/types/storeApi/link/Links.d.ts +2 -0
  135. package/dist/types/storeApi/link/index.d.ts +2 -0
  136. package/dist/types/storeApi/locale/Language.d.ts +16 -0
  137. package/dist/types/storeApi/locale/Locale.d.ts +11 -0
  138. package/dist/types/storeApi/locale/index.d.ts +2 -0
  139. package/dist/types/storeApi/media/Media.d.ts +25 -0
  140. package/dist/types/storeApi/media/MediaThumbnail.d.ts +12 -0
  141. package/dist/types/storeApi/media/ProductMedia.d.ts +15 -0
  142. package/dist/types/storeApi/media/index.d.ts +3 -0
  143. package/dist/types/storeApi/order/Order.d.ts +58 -0
  144. package/dist/types/storeApi/order/OrderAddress.d.ts +8 -0
  145. package/dist/types/storeApi/order/OrderCustomer.d.ts +18 -0
  146. package/dist/types/storeApi/order/OrderDelivery.d.ts +24 -0
  147. package/dist/types/storeApi/order/OrderDeliveryPosition.d.ts +17 -0
  148. package/dist/types/storeApi/order/OrderLineItem.d.ts +43 -0
  149. package/dist/types/storeApi/order/OrderLineItemDownload.d.ts +17 -0
  150. package/dist/types/storeApi/order/OrderReturn.d.ts +14 -0
  151. package/dist/types/storeApi/order/OrderReturnLineItem.d.ts +14 -0
  152. package/dist/types/storeApi/order/OrderReturnLineItemReason.d.ts +6 -0
  153. package/dist/types/storeApi/order/OrderTransaction.d.ts +22 -0
  154. package/dist/types/storeApi/order/OrderTransactionCapture.d.ts +20 -0
  155. package/dist/types/storeApi/order/OrderTransactionCaptureRefund.d.ts +21 -0
  156. package/dist/types/storeApi/order/OrderTransactionCaptureRefundPosition.d.ts +21 -0
  157. package/dist/types/storeApi/order/index.d.ts +14 -0
  158. package/dist/types/storeApi/price/CalculatedPrice.d.ts +25 -0
  159. package/dist/types/storeApi/price/CartListPrice.d.ts +6 -0
  160. package/dist/types/storeApi/price/CartPriceQuantity.d.ts +16 -0
  161. package/dist/types/storeApi/price/CartPriceReference.d.ts +12 -0
  162. package/dist/types/storeApi/price/CartRegulationPrice.d.ts +4 -0
  163. package/dist/types/storeApi/price/Price.d.ts +18 -0
  164. package/dist/types/storeApi/price/index.d.ts +6 -0
  165. package/dist/types/storeApi/product/Product.d.ts +107 -0
  166. package/dist/types/storeApi/product/ProductConfiguratorSetting.d.ts +17 -0
  167. package/dist/types/storeApi/product/ProductDownload.d.ts +16 -0
  168. package/dist/types/storeApi/product/ProductListingResult.d.ts +29 -0
  169. package/dist/types/storeApi/product/ProductManufacturer.d.ts +15 -0
  170. package/dist/types/storeApi/product/ProductReview.d.ts +16 -0
  171. package/dist/types/storeApi/product/ProductReviewSummary.d.ts +8 -0
  172. package/dist/types/storeApi/product/ProductStream.d.ts +10 -0
  173. package/dist/types/storeApi/product/crossSelling/CrossSellingElement.d.ts +9 -0
  174. package/dist/types/storeApi/product/crossSelling/ProductCrossSelling.d.ts +13 -0
  175. package/dist/types/storeApi/product/crossSelling/index.d.ts +2 -0
  176. package/dist/types/storeApi/product/index.d.ts +9 -0
  177. package/dist/types/storeApi/propertyGroup/PropertyGroup.d.ts +17 -0
  178. package/dist/types/storeApi/propertyGroup/PropertyGroupOption.d.ts +18 -0
  179. package/dist/types/storeApi/propertyGroup/index.d.ts +2 -0
  180. package/dist/types/storeApi/query/Criteria.d.ts +20 -0
  181. package/dist/types/storeApi/query/Include.d.ts +1 -0
  182. package/dist/types/storeApi/query/Query.d.ts +5 -0
  183. package/dist/types/storeApi/query/Sort.d.ts +6 -0
  184. package/dist/types/storeApi/query/index.d.ts +5 -0
  185. package/dist/types/storeApi/query/product/ProductListingCriteria.d.ts +25 -0
  186. package/dist/types/storeApi/query/product/ProductListingFlags.d.ts +4 -0
  187. package/dist/types/storeApi/query/product/index.d.ts +2 -0
  188. package/dist/types/storeApi/salesChannel/SalesChannel.d.ts +23 -0
  189. package/dist/types/storeApi/salesChannel/SalesChannelContext.d.ts +38 -0
  190. package/dist/types/storeApi/salesChannel/index.d.ts +2 -0
  191. package/dist/types/storeApi/seo/SeoUrlEntity.d.ts +18 -0
  192. package/dist/types/storeApi/seo/Sitemap.d.ts +4 -0
  193. package/dist/types/storeApi/seo/index.d.ts +2 -0
  194. package/dist/types/storeApi/shippingMethod/ShippingMethod.d.ts +29 -0
  195. package/dist/types/storeApi/shippingMethod/ShippingMethodPrice.d.ts +15 -0
  196. package/dist/types/storeApi/shippingMethod/index.d.ts +2 -0
  197. package/package.json +45 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,1314 @@
1
+ import { ofetch } from 'ofetch';
2
+ import * as crypto from 'node:crypto';
3
+
4
+ var HTTPRequestMethod = /* @__PURE__ */ ((HTTPRequestMethod2) => {
5
+ HTTPRequestMethod2["GET"] = "GET";
6
+ HTTPRequestMethod2["POST"] = "POST";
7
+ HTTPRequestMethod2["DELETE"] = "DELETE";
8
+ HTTPRequestMethod2["PATCH"] = "PATCH";
9
+ HTTPRequestMethod2["PUT"] = "PUT";
10
+ HTTPRequestMethod2["OPTIONS"] = "OPTIONS";
11
+ return HTTPRequestMethod2;
12
+ })(HTTPRequestMethod || {});
13
+
14
+ var __defProp$5 = Object.defineProperty;
15
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
16
+ var __publicField$5 = (obj, key, value) => {
17
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
18
+ return value;
19
+ };
20
+ class Client {
21
+ constructor(client) {
22
+ __publicField$5(this, "client");
23
+ this.client = client;
24
+ }
25
+ doRequest(method, path, options) {
26
+ return this.client.doRequest(path, { ...options, method });
27
+ }
28
+ get(path, options) {
29
+ return this.doRequest(HTTPRequestMethod.GET, path, options);
30
+ }
31
+ post(path, options) {
32
+ return this.doRequest(HTTPRequestMethod.POST, path, options);
33
+ }
34
+ delete(path, options) {
35
+ return this.doRequest(HTTPRequestMethod.DELETE, path, options);
36
+ }
37
+ patch(path, options) {
38
+ return this.doRequest(HTTPRequestMethod.PATCH, path, options);
39
+ }
40
+ put(path, options) {
41
+ return this.doRequest(HTTPRequestMethod.PUT, path, options);
42
+ }
43
+ options(path, options) {
44
+ return this.doRequest(HTTPRequestMethod.OPTIONS, path, options);
45
+ }
46
+ withContextToken(options = {}) {
47
+ return this.client.withContextToken(options);
48
+ }
49
+ async withOAuth(options = {}) {
50
+ return this.client.withOAuth(options);
51
+ }
52
+ }
53
+
54
+ class Payload {
55
+ }
56
+
57
+ var __defProp$4 = Object.defineProperty;
58
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
59
+ var __publicField$4 = (obj, key, value) => {
60
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
61
+ return value;
62
+ };
63
+ const _JsonPayload = class _JsonPayload extends Payload {
64
+ constructor(data) {
65
+ super();
66
+ __publicField$4(this, "data");
67
+ this.data = data;
68
+ }
69
+ contentType() {
70
+ return _JsonPayload.CONTENT_TYPE;
71
+ }
72
+ /**
73
+ * @throws {SyntaxError} if the data is not a valid JSON string
74
+ */
75
+ async deserialize(data) {
76
+ this.data = JSON.parse(await data.text());
77
+ }
78
+ serialize() {
79
+ if (!this.data)
80
+ return void 0;
81
+ return JSON.stringify(this.data);
82
+ }
83
+ };
84
+ __publicField$4(_JsonPayload, "CONTENT_TYPE", "application/json");
85
+ let JsonPayload = _JsonPayload;
86
+
87
+ var __defProp$3 = Object.defineProperty;
88
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
89
+ var __publicField$3 = (obj, key, value) => {
90
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
91
+ return value;
92
+ };
93
+ const _BinaryPayload = class _BinaryPayload extends Payload {
94
+ constructor(data) {
95
+ super();
96
+ __publicField$3(this, "data");
97
+ this.data = data;
98
+ }
99
+ contentType() {
100
+ return _BinaryPayload.CONTENT_TYPE;
101
+ }
102
+ /**
103
+ * @throws {SyntaxError} if the data is not a valid JSON string
104
+ */
105
+ async deserialize(data) {
106
+ this.data = data;
107
+ }
108
+ serialize() {
109
+ return this.data;
110
+ }
111
+ };
112
+ __publicField$3(_BinaryPayload, "CONTENT_TYPE", "application/octet-stream");
113
+ let BinaryPayload = _BinaryPayload;
114
+
115
+ class AccountClient extends Client {
116
+ /**
117
+ * @throws {Error} if the request fails
118
+ */
119
+ async getNewsletterRecipientList(request = {}) {
120
+ const response = await this.post(
121
+ `/account/newsletter-recipient`,
122
+ this.withContextToken({
123
+ body: new JsonPayload(request)
124
+ })
125
+ );
126
+ if (response.statusCode === 200)
127
+ return response.body.data;
128
+ throw new Error(
129
+ `Failed to fetch newsletter recipient list: ${response.statusCode} ${response.statusMessage}`
130
+ );
131
+ }
132
+ /**
133
+ * @throws {Error} if the request fails
134
+ */
135
+ async changeProfile(request) {
136
+ const response = await this.post(
137
+ `/account/change-profile`,
138
+ this.withContextToken({
139
+ body: new JsonPayload(request)
140
+ })
141
+ );
142
+ if (response.statusCode === 200)
143
+ return response.body.data;
144
+ throw new Error(`Failed to change profile: ${response.statusCode} ${response.statusMessage}`);
145
+ }
146
+ /**
147
+ * @throws {Error} if the request fails
148
+ */
149
+ async changeEmail(request) {
150
+ const response = await this.post(
151
+ `/account/change-email`,
152
+ this.withContextToken({
153
+ body: new JsonPayload(request)
154
+ })
155
+ );
156
+ if (response.statusCode === 200)
157
+ return response.body.data;
158
+ throw new Error(`Failed to change email: ${response.statusCode} ${response.statusMessage}`);
159
+ }
160
+ /**
161
+ * @throws {Error} if the request fails
162
+ */
163
+ async changeLanguage(request) {
164
+ const response = await this.post(
165
+ `/account/change-language`,
166
+ this.withContextToken({
167
+ body: new JsonPayload(request)
168
+ })
169
+ );
170
+ if (response.statusCode === 200)
171
+ return response.body.data;
172
+ throw new Error(`Failed to change language: ${response.statusCode} ${response.statusMessage}`);
173
+ }
174
+ /**
175
+ * @throws {Error} if the request fails
176
+ */
177
+ async changePassword(request) {
178
+ const response = await this.post(
179
+ `/account/change-password`,
180
+ this.withContextToken({
181
+ body: new JsonPayload(request)
182
+ })
183
+ );
184
+ if (response.statusCode === 200)
185
+ return response.body.data;
186
+ throw new Error(`Failed to change password: ${response.statusCode} ${response.statusMessage}`);
187
+ }
188
+ /**
189
+ * @throws {Error} if the request fails
190
+ */
191
+ async changePaymentMethod(paymentMethodId) {
192
+ const response = await this.post(
193
+ `/account/change-payment-method/${paymentMethodId}`,
194
+ this.withContextToken()
195
+ );
196
+ if (response.statusCode === 200)
197
+ return response.body.data;
198
+ throw new Error(
199
+ `Failed to change payment method: ${response.statusCode} ${response.statusMessage}`
200
+ );
201
+ }
202
+ /**
203
+ * @throws {Error} if the request fails
204
+ */
205
+ async isCustomerRecoveryExpired(request) {
206
+ const response = await this.post(
207
+ `/account/customer-recovery-is-expired`,
208
+ this.withContextToken({
209
+ body: new JsonPayload(request)
210
+ })
211
+ );
212
+ if (response.statusCode === 200)
213
+ return response.body.data;
214
+ throw new Error(
215
+ `Failed to check if customer recovery is expired: ${response.statusCode} ${response.statusMessage}`
216
+ );
217
+ }
218
+ /**
219
+ * @throws {Error} if the request fails
220
+ */
221
+ async getCustomer(request = {}) {
222
+ const response = await this.get(
223
+ `/account/customer`,
224
+ this.withContextToken({
225
+ body: new JsonPayload(request)
226
+ })
227
+ );
228
+ if (response.statusCode === 200)
229
+ return response.body.data;
230
+ throw new Error(`Failed to fetch customer: ${response.statusCode} ${response.statusMessage}`);
231
+ }
232
+ /**
233
+ * @throws {Error} if the request fails
234
+ */
235
+ async deleteCustomer() {
236
+ const response = await this.delete(`/account/customer`, this.withContextToken());
237
+ if (response.statusCode === 200)
238
+ return void 0;
239
+ throw new Error(`Failed to delete customer: ${response.statusCode} ${response.statusMessage}`);
240
+ }
241
+ /**
242
+ * @throws {Error} if the request fails
243
+ */
244
+ async confirmRecoveryPassword(request) {
245
+ const response = await this.post(
246
+ `/account/recovery-password-confirm`,
247
+ this.withContextToken({
248
+ body: new JsonPayload(request)
249
+ })
250
+ );
251
+ if (response.statusCode === 200)
252
+ return response.body.data;
253
+ throw new Error(
254
+ `Failed to confirm recovery password: ${response.statusCode} ${response.statusMessage}`
255
+ );
256
+ }
257
+ /**
258
+ * @throws {Error} if the request fails
259
+ */
260
+ async requestPasswordRecoveryMail(request) {
261
+ const response = await this.post(
262
+ `/account/recovery-password`,
263
+ this.withContextToken({
264
+ body: new JsonPayload(request)
265
+ })
266
+ );
267
+ if (response.statusCode === 200)
268
+ return response.body.data;
269
+ throw new Error(
270
+ `Failed to request password recovery mail: ${response.statusCode} ${response.statusMessage}`
271
+ );
272
+ }
273
+ }
274
+
275
+ class AddressClient extends Client {
276
+ /**
277
+ * @throws {Error} if the request fails
278
+ */
279
+ async deleteAddress(addressId) {
280
+ const response = await this.delete(`/account/address/${addressId}`, this.withContextToken());
281
+ if (response.statusCode === 200)
282
+ return void 0;
283
+ throw new Error(`Failed to delete address: ${response.statusCode} ${response.statusMessage}`);
284
+ }
285
+ /**
286
+ * @throws {Error} if the request fails
287
+ */
288
+ async updateAddress(addressId, request) {
289
+ const response = await this.put(
290
+ `/account/address/${addressId}`,
291
+ this.withContextToken({
292
+ body: new JsonPayload(request)
293
+ })
294
+ );
295
+ if (response.statusCode === 200)
296
+ return response.body.data;
297
+ throw new Error(`Failed to update address: ${response.statusCode} ${response.statusMessage}`);
298
+ }
299
+ /**
300
+ * @throws {Error} if the request fails
301
+ */
302
+ async getAddressList(request = {}) {
303
+ const response = await this.post(
304
+ "/account/list-address",
305
+ this.withContextToken({
306
+ body: new JsonPayload(request)
307
+ })
308
+ );
309
+ if (response.statusCode === 200)
310
+ return response.body.data;
311
+ throw new Error(
312
+ `Failed to fetch address list: ${response.statusCode} ${response.statusMessage}`
313
+ );
314
+ }
315
+ /**
316
+ * @throws {Error} if the request fails
317
+ */
318
+ async changeDefaultShippingAddress(addressId) {
319
+ const response = await this.post(
320
+ `/account/address/default-shipping/${addressId}`,
321
+ this.withContextToken()
322
+ );
323
+ if (response.statusCode === 200)
324
+ return void 0;
325
+ throw new Error(
326
+ `Failed to change default shipping address: ${response.statusCode} ${response.statusMessage}`
327
+ );
328
+ }
329
+ /**
330
+ * @throws {Error} if the request fails
331
+ */
332
+ async changeDefaultBillingAddress(addressId) {
333
+ const response = await this.post(
334
+ `/account/address/default-billing/${addressId}`,
335
+ this.withContextToken()
336
+ );
337
+ if (response.statusCode === 200)
338
+ return void 0;
339
+ throw new Error(
340
+ `Failed to change default billing address: ${response.statusCode} ${response.statusMessage}`
341
+ );
342
+ }
343
+ /**
344
+ * @throws {Error} if the request fails
345
+ */
346
+ async createAddress(request) {
347
+ const response = await this.post(
348
+ "/account/address",
349
+ this.withContextToken({
350
+ body: new JsonPayload(request)
351
+ })
352
+ );
353
+ if (response.statusCode === 200)
354
+ return response.body.data;
355
+ throw new Error(`Failed to add address: ${response.statusCode} ${response.statusMessage}`);
356
+ }
357
+ }
358
+
359
+ class CartClient extends Client {
360
+ /**
361
+ * @throws {Error} if the request fails
362
+ */
363
+ async getOrCreateCart() {
364
+ const response = await this.get("/checkout/cart");
365
+ if (response.statusCode === 200)
366
+ return response.body.data;
367
+ throw new Error(
368
+ `Failed to get or create cart: ${response.statusCode} ${response.statusMessage}`
369
+ );
370
+ }
371
+ /**
372
+ * @throws {Error} if the request fails
373
+ */
374
+ async deleteCart() {
375
+ const response = await this.delete("/checkout/cart");
376
+ if (response.statusCode === 200)
377
+ return response.body.data;
378
+ throw new Error(`Failed to delete cart: ${response.statusCode} ${response.statusMessage}`);
379
+ }
380
+ /**
381
+ * @throws {Error} if the request fails
382
+ */
383
+ async addLineItemsToCart(request) {
384
+ const response = await this.post("/checkout/cart/line-item", {
385
+ body: new JsonPayload(request)
386
+ });
387
+ if (response.statusCode === 200)
388
+ return response.body.data;
389
+ throw new Error(
390
+ `Failed to add line items to cart: ${response.statusCode} ${response.statusMessage}`
391
+ );
392
+ }
393
+ /**
394
+ * @throws {Error} if the request fails
395
+ */
396
+ async removeLineItemsFromCart(request) {
397
+ const response = await this.post("/checkout/cart/line-item/delete", {
398
+ body: new JsonPayload(request)
399
+ });
400
+ if (response.statusCode === 200)
401
+ return response.body.data;
402
+ throw new Error(
403
+ `Failed to remove line items from cart: ${response.statusCode} ${response.statusMessage}`
404
+ );
405
+ }
406
+ /**
407
+ * @throws {Error} if the request fails
408
+ */
409
+ async updateLineItemsInCart(request) {
410
+ const response = await this.patch("/checkout/cart/line-item", {
411
+ body: new JsonPayload(request)
412
+ });
413
+ if (response.statusCode === 200)
414
+ return response.body.data;
415
+ throw new Error(
416
+ `Failed to update line items in cart: ${response.statusCode} ${response.statusMessage}`
417
+ );
418
+ }
419
+ }
420
+
421
+ class CategoryClient extends Client {
422
+ /**
423
+ * @throws {Error} if the request fails
424
+ */
425
+ async getCategoryList(request = {}) {
426
+ const response = await this.post("/category", {
427
+ body: new JsonPayload(request)
428
+ });
429
+ if (response.statusCode === 200)
430
+ return response.body.data;
431
+ throw new Error(
432
+ `Failed to fetch category list: ${response.statusCode} ${response.statusMessage}`
433
+ );
434
+ }
435
+ /**
436
+ * @throws {Error} if the request fails
437
+ */
438
+ async getCategory(categoryId, includeSeoUrls, request) {
439
+ const response = await this.post(`/category/${categoryId}`, {
440
+ headers: { "sw-include-seo-urls": includeSeoUrls.toString() },
441
+ body: new JsonPayload(request)
442
+ });
443
+ if (response.statusCode === 200)
444
+ return response.body.data;
445
+ throw new Error(`Failed to fetch category: ${response.statusCode} ${response.statusMessage}`);
446
+ }
447
+ /**
448
+ * @throws {Error} if the request fails
449
+ */
450
+ async getNavigationMenu(activeId, rootId, includeSeoUrls, request = {}) {
451
+ const response = await this.post(`/navigation/${activeId}/${rootId}`, {
452
+ headers: { "sw-include-seo-urls": includeSeoUrls.toString() },
453
+ body: new JsonPayload(request)
454
+ });
455
+ if (response.statusCode === 200)
456
+ return response.body.data;
457
+ throw new Error(
458
+ `Failed to fetch navigation menu: ${response.statusCode} ${response.statusMessage}`
459
+ );
460
+ }
461
+ }
462
+
463
+ class ContentClient extends Client {
464
+ /**
465
+ * @throws {Error} if the request fails
466
+ */
467
+ async submitContactForm(request) {
468
+ const response = await this.post("/contact-form", {
469
+ body: new JsonPayload(request)
470
+ });
471
+ if (response.statusCode === 200)
472
+ return response.body.data;
473
+ throw new Error(
474
+ `Failed to submit contact form: ${response.statusCode} ${response.statusMessage}`
475
+ );
476
+ }
477
+ /**
478
+ * @throws {Error} if the request fails
479
+ */
480
+ async resolveCMSPage(id) {
481
+ const response = await this.get(`/cms/${id}`);
482
+ if (response.statusCode === 200)
483
+ return response.body.data;
484
+ throw new Error(`Failed to resolve CMS page: ${response.statusCode} ${response.statusMessage}`);
485
+ }
486
+ /**
487
+ * @throws {Error} if the request fails
488
+ */
489
+ async resolveMedia(request) {
490
+ const response = await this.post("/media", {
491
+ body: new JsonPayload(request)
492
+ });
493
+ if (response.statusCode === 200)
494
+ return response.body.data;
495
+ throw new Error(`Failed to resolve media: ${response.statusCode} ${response.statusMessage}`);
496
+ }
497
+ /**
498
+ * @throws {Error} if the request fails
499
+ */
500
+ async resolveLandingPage(landingPageId, request) {
501
+ const response = await this.post(`/landing-page/${landingPageId}`, {
502
+ body: new JsonPayload(request)
503
+ });
504
+ if (response.statusCode === 200)
505
+ return response.body.data;
506
+ throw new Error(
507
+ `Failed to resolve landing page: ${response.statusCode} ${response.statusMessage}`
508
+ );
509
+ }
510
+ }
511
+
512
+ class ContextClient extends Client {
513
+ /**
514
+ * @throws {Error} if the request fails
515
+ */
516
+ async getContext() {
517
+ const response = await this.get("/context");
518
+ if (response.statusCode === 200)
519
+ return response.body;
520
+ throw new Error(`Failed to fetch context: ${response.statusCode} ${response.statusMessage}`);
521
+ }
522
+ /**
523
+ * @throws {Error} if the request fails
524
+ */
525
+ async updateContext(context) {
526
+ const response = await this.patch("/context", {
527
+ body: new JsonPayload(context)
528
+ });
529
+ if (response.statusCode === 200)
530
+ return response.body.data;
531
+ throw new Error(`Failed to update context: ${response.statusCode} ${response.statusMessage}`);
532
+ }
533
+ }
534
+
535
+ var __defProp$2 = Object.defineProperty;
536
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
537
+ var __publicField$2 = (obj, key, value) => {
538
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
539
+ return value;
540
+ };
541
+ class ContextTokenEntry {
542
+ constructor(token = null) {
543
+ __publicField$2(this, "token", null);
544
+ this.token = token;
545
+ }
546
+ getType() {
547
+ return AuthenticationType$1.CONTEXT_TOKEN;
548
+ }
549
+ isSaved() {
550
+ return this.token !== null;
551
+ }
552
+ save(response) {
553
+ this.token = response.headers?.get("sw-context-token") || null;
554
+ }
555
+ clear() {
556
+ this.token = null;
557
+ }
558
+ load() {
559
+ if (!this.isSaved()) {
560
+ throw new NotSavedError$1("Context token is not saved");
561
+ }
562
+ return {
563
+ headers: { "sw-context-token": this.token || "" }
564
+ };
565
+ }
566
+ }
567
+
568
+ class NotSavedError extends Error {
569
+ constructor(message) {
570
+ super(message);
571
+ this.name = "NotSavedError";
572
+ }
573
+ }
574
+ const NotSavedError$1 = NotSavedError;
575
+
576
+ class ExpiredError extends Error {
577
+ constructor(message) {
578
+ super(message);
579
+ this.name = "ExpiredError";
580
+ }
581
+ }
582
+ const ExpiredError$1 = ExpiredError;
583
+
584
+ var __defProp$1 = Object.defineProperty;
585
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
586
+ var __publicField$1 = (obj, key, value) => {
587
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
588
+ return value;
589
+ };
590
+ class AuthenticationStore {
591
+ constructor() {
592
+ __publicField$1(this, "entries", /* @__PURE__ */ new Map());
593
+ }
594
+ getOrCreateEntry(entry) {
595
+ const existingEntry = this.getEntry(entry.getType());
596
+ if (existingEntry) {
597
+ return existingEntry;
598
+ }
599
+ this.entries.set(entry.getType(), entry);
600
+ return entry;
601
+ }
602
+ getEntry(type) {
603
+ return this.entries.get(type);
604
+ }
605
+ }
606
+
607
+ var AuthenticationType = /* @__PURE__ */ ((AuthenticationType2) => {
608
+ AuthenticationType2["CONTEXT_TOKEN"] = "context_token";
609
+ AuthenticationType2["OAUTH"] = "oauth";
610
+ return AuthenticationType2;
611
+ })(AuthenticationType || {});
612
+ const AuthenticationType$1 = AuthenticationType;
613
+
614
+ class CustomerAuthenticationClient extends Client {
615
+ /**
616
+ * @throws {Error} if the request fails
617
+ */
618
+ async login(request) {
619
+ const response = await this.post("/account/login", {
620
+ body: new JsonPayload(request)
621
+ });
622
+ if (response.statusCode === 200) {
623
+ this.client.authStore.getOrCreateEntry(new ContextTokenEntry()).save(response);
624
+ return response.body.data;
625
+ }
626
+ throw new Error(`Failed to login: ${response.statusCode} ${response.statusMessage}`);
627
+ }
628
+ /**
629
+ * @throws {Error} if the request fails
630
+ */
631
+ async imitateLogin(request) {
632
+ const response = await this.post("/account/login/imitate-customer", {
633
+ body: new JsonPayload(request)
634
+ });
635
+ if (response.statusCode === 200)
636
+ return response.body.data;
637
+ throw new Error(`Failed to imitate login: ${response.statusCode} ${response.statusMessage}`);
638
+ }
639
+ /**
640
+ * @throws {Error} if the request fails
641
+ */
642
+ async logout() {
643
+ const response = await this.post("/account/logout", this.withContextToken());
644
+ if (response.statusCode === 200) {
645
+ this.client.authStore.getEntry(AuthenticationType$1.CONTEXT_TOKEN)?.clear();
646
+ return response.body.data;
647
+ }
648
+ throw new Error(`Failed to logout: ${response.statusCode} ${response.statusMessage}`);
649
+ }
650
+ /**
651
+ * @throws {Error} if the request fails
652
+ */
653
+ async confirmRegistration(request) {
654
+ const response = await this.post("/account/register-confirm", {
655
+ body: new JsonPayload(request)
656
+ });
657
+ if (response.statusCode === 200)
658
+ return void 0;
659
+ throw new Error(
660
+ `Failed to confirm registration: ${response.statusCode} ${response.statusMessage}`
661
+ );
662
+ }
663
+ /**
664
+ * @throws {Error} if the request fails
665
+ */
666
+ async register(request) {
667
+ const response = await this.post("/account/register", {
668
+ body: new JsonPayload(request)
669
+ });
670
+ if (response.statusCode === 200) {
671
+ this.client.authStore.getOrCreateEntry(new ContextTokenEntry()).save(response);
672
+ return response.body.data;
673
+ }
674
+ throw new Error(`Failed to register: ${response.statusCode} ${response.statusMessage}`);
675
+ }
676
+ /**
677
+ * @throws {Error} if the request fails
678
+ */
679
+ async getRegistrationSettingsForGroup(customerGroupId) {
680
+ const response = await this.get(`/customer-group-registration/config/${customerGroupId}`);
681
+ if (response.statusCode === 200)
682
+ return response.body.data;
683
+ throw new Error(
684
+ `Failed to fetch registration settings for group: ${response.statusCode} ${response.statusMessage}`
685
+ );
686
+ }
687
+ }
688
+
689
+ class DocumentClient extends Client {
690
+ /**
691
+ * @throws {Error} if the request fails
692
+ */
693
+ async downloadDocument(deepLinkCode, documentId, request) {
694
+ const response = await this.post(`/document/download/${deepLinkCode}/${documentId}`, {
695
+ body: new JsonPayload(request)
696
+ });
697
+ if (response.statusCode === 200)
698
+ return response.body.data;
699
+ throw new Error(
700
+ `Failed to download document: ${response.statusCode} ${response.statusMessage}`
701
+ );
702
+ }
703
+ }
704
+
705
+ class GatewayClient extends Client {
706
+ /**
707
+ * @throws {Error} if the request fails
708
+ */
709
+ async checkout() {
710
+ const response = await this.post("/checkout/gateway");
711
+ if (response.statusCode === 200)
712
+ return response.body.data;
713
+ throw new Error(`Failed to checkout: ${response.statusCode} ${response.statusMessage}`);
714
+ }
715
+ }
716
+
717
+ class NewsletterClient extends Client {
718
+ /**
719
+ * @throws {Error} if the request fails
720
+ */
721
+ async confirmSubscription(request) {
722
+ const response = await this.post(`/newsletter/confirm`, {
723
+ body: new JsonPayload(request)
724
+ });
725
+ if (response.statusCode === 200)
726
+ return void 0;
727
+ throw new Error(
728
+ `Failed to confirm newsletter subscription: ${response.statusCode} ${response.statusMessage}`
729
+ );
730
+ }
731
+ /**
732
+ * @throws {Error} if the request fails
733
+ */
734
+ async updateSubscription(request) {
735
+ const response = await this.post(`/newsletter/subscribe`, {
736
+ body: new JsonPayload(request)
737
+ });
738
+ if (response.statusCode === 200)
739
+ return void 0;
740
+ throw new Error(
741
+ `Failed to update newsletter subscription: ${response.statusCode} ${response.statusMessage}`
742
+ );
743
+ }
744
+ /**
745
+ * @throws {Error} if the request fails
746
+ */
747
+ async unsubscribe(request) {
748
+ const response = await this.post(`/newsletter/unsubscribe`, {
749
+ body: new JsonPayload(request)
750
+ });
751
+ if (response.statusCode === 200)
752
+ return void 0;
753
+ throw new Error(
754
+ `Failed to unsubscribe newsletter subscription: ${response.statusCode} ${response.statusMessage}`
755
+ );
756
+ }
757
+ }
758
+
759
+ class OrderClient extends Client {
760
+ /**
761
+ * @throws {Error} if the request fails
762
+ */
763
+ async cancelOrder(request) {
764
+ const response = await this.post(
765
+ "/order/state/cancel",
766
+ this.withContextToken({
767
+ body: new JsonPayload(request)
768
+ })
769
+ );
770
+ if (response.statusCode === 200)
771
+ return response.body.data;
772
+ throw new Error(`Failed to cancel order: ${response.statusCode} ${response.statusMessage}`);
773
+ }
774
+ /**
775
+ * @throws {Error} if the request fails
776
+ */
777
+ async getOrderList(request = {}) {
778
+ const response = await this.post(
779
+ "/order",
780
+ this.withContextToken({
781
+ body: new JsonPayload(request)
782
+ })
783
+ );
784
+ if (response.statusCode === 200)
785
+ return response.body.data;
786
+ throw new Error(`Failed to fetch order list: ${response.statusCode} ${response.statusMessage}`);
787
+ }
788
+ /**
789
+ * @throws {Error} if the request fails
790
+ */
791
+ async updateOrderPaymentMethod(request) {
792
+ const response = await this.post(
793
+ "/order/payment",
794
+ this.withContextToken({
795
+ body: new JsonPayload(request)
796
+ })
797
+ );
798
+ if (response.statusCode === 200)
799
+ return response.body.data;
800
+ throw new Error(
801
+ `Failed to update order payment method: ${response.statusCode} ${response.statusMessage}`
802
+ );
803
+ }
804
+ /**
805
+ * @throws {Error} if the request fails
806
+ */
807
+ async downloadPurchasedFile(downloadId, orderId) {
808
+ const response = await this.get(
809
+ `/order/download/${orderId}/${downloadId}`,
810
+ this.withContextToken()
811
+ );
812
+ if (response.statusCode === 200)
813
+ return response.body.data;
814
+ throw new Error(
815
+ `Failed to download purchased file: ${response.statusCode} ${response.statusMessage}`
816
+ );
817
+ }
818
+ /**
819
+ * @throws {Error} if the request fails
820
+ */
821
+ async createOrderFromCart(request = {}) {
822
+ const response = await this.post(
823
+ "/checkout/order",
824
+ this.withContextToken({
825
+ body: new JsonPayload(request)
826
+ })
827
+ );
828
+ if (response.statusCode === 200)
829
+ return response.body.data;
830
+ throw new Error(
831
+ `Failed to create order from cart: ${response.statusCode} ${response.statusMessage}`
832
+ );
833
+ }
834
+ }
835
+
836
+ class PaymentClient extends Client {
837
+ /**
838
+ * @throws {Error} if the request fails
839
+ */
840
+ async initiateOrderPayment(request) {
841
+ const response = await this.post("/handle-payment", {
842
+ body: new JsonPayload(request)
843
+ });
844
+ if (response.statusCode === 200)
845
+ return response.body.data;
846
+ throw new Error(
847
+ `Failed to initiate order payment: ${response.statusCode} ${response.statusMessage}`
848
+ );
849
+ }
850
+ }
851
+
852
+ class ProductClient extends Client {
853
+ /**
854
+ * @throws {Error} if the request fails
855
+ */
856
+ async getProductListingByCategory(categoryId, request = {}) {
857
+ const response = await this.post(`/product-listing/${categoryId}`, {
858
+ body: new JsonPayload(request)
859
+ });
860
+ if (response.statusCode === 200)
861
+ return response.body.data;
862
+ throw new Error(
863
+ `Failed to fetch product listing by category: ${response.statusCode} ${response.statusMessage}`
864
+ );
865
+ }
866
+ /**
867
+ * @throws {Error} if the request fails
868
+ */
869
+ async getCrossSellingGroupsForProduct(productId) {
870
+ const response = await this.post(`/product/${productId}/cross-selling`);
871
+ if (response.statusCode === 200)
872
+ return response.body.data;
873
+ throw new Error(
874
+ `Failed to fetch cross selling groups for product: ${response.statusCode} ${response.statusMessage}`
875
+ );
876
+ }
877
+ /**
878
+ * @throws {Error} if the request fails
879
+ */
880
+ async getProduct(productId, includeSeoUrls, request = {}) {
881
+ const response = await this.post(`/product/${productId}`, {
882
+ headers: { "sw-include-seo-urls": includeSeoUrls.toString() },
883
+ body: new JsonPayload(request)
884
+ });
885
+ if (response.statusCode === 200)
886
+ return response.body.data;
887
+ throw new Error(`Failed to fetch product: ${response.statusCode} ${response.statusMessage}`);
888
+ }
889
+ /**
890
+ * @throws {Error} if the request fails
891
+ */
892
+ async getProductList(request = {}) {
893
+ const response = await this.post("/product", {
894
+ body: new JsonPayload(request)
895
+ });
896
+ if (response.statusCode === 200)
897
+ return response.body.data;
898
+ throw new Error(
899
+ `Failed to fetch product list: ${response.statusCode} ${response.statusMessage}`
900
+ );
901
+ }
902
+ /**
903
+ * @throws {Error} if the request fails
904
+ */
905
+ async getReviewsForProduct(productId, request = {}) {
906
+ const response = await this.post(`/product/${productId}/reviews`, {
907
+ body: new JsonPayload(request)
908
+ });
909
+ if (response.statusCode === 200)
910
+ return response.body.data;
911
+ throw new Error(
912
+ `Failed to fetch reviews for product: ${response.statusCode} ${response.statusMessage}`
913
+ );
914
+ }
915
+ /**
916
+ * @throws {Error} if the request fails
917
+ */
918
+ async saveReviewForProduct(productId, request) {
919
+ const response = await this.post(`/product/${productId}/review`, {
920
+ body: new JsonPayload(request)
921
+ });
922
+ if (response.statusCode === 200)
923
+ return void 0;
924
+ throw new Error(
925
+ `Failed to save review for product: ${response.statusCode} ${response.statusMessage}`
926
+ );
927
+ }
928
+ /**
929
+ * @throws {Error} if the request fails
930
+ */
931
+ async findProductVariantWithOptions(productId, request) {
932
+ const response = await this.post(`/product/${productId}/find-variant`, {
933
+ body: new JsonPayload(request)
934
+ });
935
+ if (response.statusCode === 200)
936
+ return response.body.data;
937
+ throw new Error(
938
+ `Failed to find product variant: ${response.statusCode} ${response.statusMessage}`
939
+ );
940
+ }
941
+ // search products,get search suggestions
942
+ /**
943
+ * @throws {Error} if the request fails
944
+ */
945
+ async searchProducts(request) {
946
+ const response = await this.post("/search", {
947
+ body: new JsonPayload(request)
948
+ });
949
+ if (response.statusCode === 200)
950
+ return response.body.data;
951
+ throw new Error(
952
+ `Failed to search for products: ${response.statusCode} ${response.statusMessage}`
953
+ );
954
+ }
955
+ /**
956
+ * @throws {Error} if the request fails
957
+ */
958
+ async getSearchSuggestions(request) {
959
+ const response = await this.post("/search-suggest", {
960
+ body: new JsonPayload(request)
961
+ });
962
+ if (response.statusCode === 200)
963
+ return response.body.data;
964
+ throw new Error(
965
+ `Failed to fetch search suggestions: ${response.statusCode} ${response.statusMessage}`
966
+ );
967
+ }
968
+ }
969
+
970
+ class SeoClient extends Client {
971
+ /**
972
+ * @throws {Error} if the request fails
973
+ */
974
+ async getSeoRouteList(request = {}) {
975
+ const response = await this.post("/seo-url", {
976
+ body: new JsonPayload(request)
977
+ });
978
+ if (response.statusCode === 200)
979
+ return response.body.data;
980
+ throw new Error(
981
+ `Failed to fetch SEO route list: ${response.statusCode} ${response.statusMessage}`
982
+ );
983
+ }
984
+ /**
985
+ * @throws {Error} if the request fails
986
+ */
987
+ async fetchSitemapList() {
988
+ const response = await this.get("/sitemap");
989
+ if (response.statusCode === 200)
990
+ return response.body.data;
991
+ throw new Error(
992
+ `Failed to fetch sitemap list: ${response.statusCode} ${response.statusMessage}`
993
+ );
994
+ }
995
+ /**
996
+ * @throws {Error} if the request fails
997
+ */
998
+ async downloadSitemap(filePath) {
999
+ const response = await this.get(`/sitemap/${filePath}`);
1000
+ if (response.statusCode === 200)
1001
+ return response.body.data;
1002
+ throw new Error(`Failed to download sitemap: ${response.statusCode} ${response.statusMessage}`);
1003
+ }
1004
+ }
1005
+
1006
+ class SystemClient extends Client {
1007
+ /**
1008
+ * @throws {Error} if the request fails
1009
+ */
1010
+ async getLanguageList(request = {}) {
1011
+ const response = await this.post("/language", {
1012
+ body: new JsonPayload(request)
1013
+ });
1014
+ if (response.statusCode === 200)
1015
+ return response.body.data;
1016
+ throw new Error(
1017
+ `Failed to fetch language list: ${response.statusCode} ${response.statusMessage}`
1018
+ );
1019
+ }
1020
+ /**
1021
+ * @throws {Error} if the request fails
1022
+ */
1023
+ async getSalutationList(request = {}) {
1024
+ const response = await this.post("/salutation", {
1025
+ body: new JsonPayload(request)
1026
+ });
1027
+ if (response.statusCode === 200)
1028
+ return response.body.data;
1029
+ throw new Error(
1030
+ `Failed to fetch salutations list: ${response.statusCode} ${response.statusMessage}`
1031
+ );
1032
+ }
1033
+ /**
1034
+ * @throws {Error} if the request fails
1035
+ */
1036
+ async getCurrencyList(request = {}) {
1037
+ const response = await this.post("/currency", {
1038
+ body: new JsonPayload(request)
1039
+ });
1040
+ if (response.statusCode === 200)
1041
+ return response.body.data;
1042
+ throw new Error(
1043
+ `Failed to fetch currency list: ${response.statusCode} ${response.statusMessage}`
1044
+ );
1045
+ }
1046
+ /**
1047
+ * @throws {Error} if the request fails
1048
+ */
1049
+ async getCountryStateList(countryId, request = {}) {
1050
+ const response = await this.post(`/country-state/${countryId}`, {
1051
+ body: new JsonPayload(request)
1052
+ });
1053
+ if (response.statusCode === 200)
1054
+ return response.body.data;
1055
+ throw new Error(
1056
+ `Failed to fetch country state list: ${response.statusCode} ${response.statusMessage}`
1057
+ );
1058
+ }
1059
+ /**
1060
+ * @throws {Error} if the request fails
1061
+ */
1062
+ async getCountryList(request = {}) {
1063
+ const response = await this.post("/country", {
1064
+ body: new JsonPayload(request)
1065
+ });
1066
+ if (response.statusCode === 200)
1067
+ return response.body.data;
1068
+ throw new Error(
1069
+ `Failed to fetch country list: ${response.statusCode} ${response.statusMessage}`
1070
+ );
1071
+ }
1072
+ /**
1073
+ * @throws {Error} if the request fails
1074
+ */
1075
+ async getShippingMethodList(request = {}) {
1076
+ const response = await this.post(`/shipping-method`, {
1077
+ body: new JsonPayload(request)
1078
+ });
1079
+ if (response.statusCode === 200)
1080
+ return response.body.data;
1081
+ throw new Error(
1082
+ `Failed to fetch shipping methods: ${response.statusCode} ${response.statusMessage}`
1083
+ );
1084
+ }
1085
+ /**
1086
+ * @throws {Error} if the request fails
1087
+ */
1088
+ async getPaymentMethodList(request = {}) {
1089
+ const response = await this.post(`/payment-method`, {
1090
+ body: new JsonPayload(request)
1091
+ });
1092
+ if (response.statusCode === 200)
1093
+ return response.body.data;
1094
+ throw new Error(
1095
+ `Failed to fetch payment methods: ${response.statusCode} ${response.statusMessage}`
1096
+ );
1097
+ }
1098
+ }
1099
+
1100
+ class WishlistClient extends Client {
1101
+ /**
1102
+ * @throws {Error} if the request fails
1103
+ */
1104
+ async addProductToWishlist(productId) {
1105
+ const response = await this.post(
1106
+ `/customer/wishlist/add/${productId}`,
1107
+ this.withContextToken()
1108
+ );
1109
+ if (response.statusCode === 200)
1110
+ return response.body.data;
1111
+ throw new Error(
1112
+ `Failed to add product to wishlist: ${response.statusCode} ${response.statusMessage}`
1113
+ );
1114
+ }
1115
+ /**
1116
+ * @throws {Error} if the request fails
1117
+ */
1118
+ async getWishlist(request = {}) {
1119
+ const response = await this.post(
1120
+ "/customer/wishlist",
1121
+ this.withContextToken({
1122
+ body: new JsonPayload(request)
1123
+ })
1124
+ );
1125
+ if (response.statusCode === 200)
1126
+ return response.body.data;
1127
+ throw new Error(`Failed to fetch wishlist: ${response.statusCode} ${response.statusMessage}`);
1128
+ }
1129
+ /**
1130
+ * @throws {Error} if the request fails
1131
+ */
1132
+ async mergeOrCreateWishlist(request) {
1133
+ const response = await this.post(
1134
+ "/customer/wishlist/merge",
1135
+ this.withContextToken({
1136
+ body: new JsonPayload(request)
1137
+ })
1138
+ );
1139
+ if (response.statusCode === 200)
1140
+ return response.body.data;
1141
+ throw new Error(
1142
+ `Failed to merge or create wishlist: ${response.statusCode} ${response.statusMessage}`
1143
+ );
1144
+ }
1145
+ /**
1146
+ * @throws {Error} if the request fails
1147
+ */
1148
+ async removeProductFromWishlist(productId) {
1149
+ const response = await this.delete(
1150
+ `/customer/wishlist/delete/${productId}`,
1151
+ this.withContextToken()
1152
+ );
1153
+ if (response.statusCode === 200)
1154
+ return response.body.data;
1155
+ throw new Error(
1156
+ `Failed to remove product from wishlist: ${response.statusCode} ${response.statusMessage}`
1157
+ );
1158
+ }
1159
+ }
1160
+
1161
+ var __defProp = Object.defineProperty;
1162
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1163
+ var __publicField = (obj, key, value) => {
1164
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1165
+ return value;
1166
+ };
1167
+ class ShopwareClient {
1168
+ constructor(baseUrl, apiKey) {
1169
+ __publicField(this, "baseUrl");
1170
+ __publicField(this, "apiKey");
1171
+ __publicField(this, "authStore", new AuthenticationStore());
1172
+ __publicField(this, "cache", /* @__PURE__ */ new Map());
1173
+ this.baseUrl = baseUrl;
1174
+ this.apiKey = apiKey;
1175
+ }
1176
+ /**
1177
+ * Sends a request to the Shopware API.
1178
+ * @throws {import('ofetch').FetchError} if the request is invalid
1179
+ */
1180
+ doRequest(path, options) {
1181
+ const serializedBody = options?.body?.serialize() || void 0;
1182
+ let cacheKey = null;
1183
+ if (options?.maxAge && options.maxAge > 0) {
1184
+ cacheKey = `${options?.method || HTTPRequestMethod.GET}:${path}$` + crypto.createHash("md5").update(JSON.stringify({ ...options?.headers, body: serializedBody })).digest("hex");
1185
+ const cacheEntry = this.cache.get(cacheKey);
1186
+ if (cacheEntry && Date.now() - cacheEntry.cachedAt <= options.maxAge) {
1187
+ return Promise.resolve(cacheEntry.response);
1188
+ }
1189
+ }
1190
+ return new Promise(
1191
+ async (resolve, reject) => ofetch(this.baseUrl + path, {
1192
+ method: options?.method || HTTPRequestMethod.GET,
1193
+ headers: {
1194
+ "sw-access-key": this.apiKey,
1195
+ ...options?.body ? { "Content-Type": options.body.contentType() } : {},
1196
+ ...options?.headers
1197
+ },
1198
+ body: serializedBody,
1199
+ responseType: "stream",
1200
+ onResponse: async ({ response }) => {
1201
+ const clientResponse = {
1202
+ statusCode: response.status,
1203
+ statusMessage: response.statusText,
1204
+ headers: response.headers,
1205
+ body: await this.parseBody(response)
1206
+ };
1207
+ if (cacheKey) {
1208
+ this.cache.set(cacheKey, {
1209
+ cachedAt: Date.now(),
1210
+ response: clientResponse
1211
+ });
1212
+ }
1213
+ resolve(clientResponse);
1214
+ },
1215
+ onRequestError: ({ error }) => reject(error),
1216
+ onResponseError: async ({ response }) => {
1217
+ resolve({
1218
+ statusCode: response.status,
1219
+ statusMessage: response.statusText,
1220
+ headers: response.headers,
1221
+ body: await this.parseBody(response)
1222
+ });
1223
+ }
1224
+ })
1225
+ );
1226
+ }
1227
+ async parseBody(response) {
1228
+ let body = void 0;
1229
+ switch (response.headers.get("Content-Type")) {
1230
+ case BinaryPayload.CONTENT_TYPE:
1231
+ body = new BinaryPayload();
1232
+ break;
1233
+ case JsonPayload.CONTENT_TYPE:
1234
+ body = new JsonPayload();
1235
+ break;
1236
+ }
1237
+ if (body && response.body)
1238
+ await body.deserialize(await response.blob());
1239
+ return body;
1240
+ }
1241
+ withContextToken(options) {
1242
+ const entry = this.authStore.getEntry(
1243
+ AuthenticationType$1.CONTEXT_TOKEN
1244
+ );
1245
+ if (!entry)
1246
+ throw new Error("Not authenticated");
1247
+ return { ...options, ...entry.load() };
1248
+ }
1249
+ async withOAuth(options) {
1250
+ const entry = this.authStore.getEntry(
1251
+ AuthenticationType$1.OAUTH
1252
+ );
1253
+ if (!entry)
1254
+ throw new Error("Not authenticated");
1255
+ try {
1256
+ return { ...options, ...entry.load() };
1257
+ } catch (error) {
1258
+ if (error instanceof ExpiredError$1) {
1259
+ return { ...options, ...entry.load() };
1260
+ }
1261
+ throw error;
1262
+ }
1263
+ }
1264
+ forAccount() {
1265
+ return new AccountClient(this);
1266
+ }
1267
+ forAddress() {
1268
+ return new AddressClient(this);
1269
+ }
1270
+ forCart() {
1271
+ return new CartClient(this);
1272
+ }
1273
+ forCategory() {
1274
+ return new CategoryClient(this);
1275
+ }
1276
+ forContent() {
1277
+ return new ContentClient(this);
1278
+ }
1279
+ forContext() {
1280
+ return new ContextClient(this);
1281
+ }
1282
+ forCustomerAuthentication() {
1283
+ return new CustomerAuthenticationClient(this);
1284
+ }
1285
+ forDocument() {
1286
+ return new DocumentClient(this);
1287
+ }
1288
+ forGateway() {
1289
+ return new GatewayClient(this);
1290
+ }
1291
+ forNewsletter() {
1292
+ return new NewsletterClient(this);
1293
+ }
1294
+ forOrder() {
1295
+ return new OrderClient(this);
1296
+ }
1297
+ forPayment() {
1298
+ return new PaymentClient(this);
1299
+ }
1300
+ forProduct() {
1301
+ return new ProductClient(this);
1302
+ }
1303
+ forSeo() {
1304
+ return new SeoClient(this);
1305
+ }
1306
+ forSystem() {
1307
+ return new SystemClient(this);
1308
+ }
1309
+ forWishlist() {
1310
+ return new WishlistClient(this);
1311
+ }
1312
+ }
1313
+
1314
+ export { ShopwareClient };