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