@behio/storefront-sdk 1.9.0 → 1.18.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/README.md +11 -9
- package/dist/{chunk-CY6D2YEI.js → chunk-GAYYRRUL.js} +178 -27
- package/dist/{chunk-XMKY4RI5.mjs → chunk-W2P2D3EZ.mjs} +154 -3
- package/dist/{client-C635vSzU.d.mts → client-B29GktSJ.d.mts} +421 -7
- package/dist/{client-C635vSzU.d.ts → client-B29GktSJ.d.ts} +421 -7
- package/dist/index.d.mts +44 -3
- package/dist/index.d.ts +44 -3
- package/dist/index.js +743 -2
- package/dist/index.mjs +742 -1
- package/dist/next.d.mts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +2 -2
- package/dist/next.mjs +1 -1
- package/dist/react.d.mts +456 -13
- package/dist/react.d.ts +456 -13
- package/dist/react.js +339 -54
- package/dist/react.mjs +326 -46
- package/package.json +2 -2
|
@@ -33,6 +33,38 @@ var AddressTypes = {
|
|
|
33
33
|
SHIPPING: "SHIPPING",
|
|
34
34
|
BILLING: "BILLING"
|
|
35
35
|
};
|
|
36
|
+
var BE_CODE_TO_ERROR = {
|
|
37
|
+
"be.storefront.cartIsEmpty": "CART_EMPTY",
|
|
38
|
+
"be.storefront.productNotFound": "PRODUCT_NOT_FOUND",
|
|
39
|
+
"be.storefront.productNotAvailable": "PRODUCT_NOT_FOUND",
|
|
40
|
+
"be.storefront.invalidEmailOrPassword": "INVALID_CREDENTIALS",
|
|
41
|
+
"be.storefront.currentPasswordIncorrect": "INVALID_CREDENTIALS",
|
|
42
|
+
"be.storefront.discountExpired": "DISCOUNT_EXPIRED",
|
|
43
|
+
"be.storefront.discountExpiredOrLimit": "DISCOUNT_EXPIRED",
|
|
44
|
+
"be.storefront.invalidDiscountCode": "INVALID_DISCOUNT",
|
|
45
|
+
"be.storefront.discountInvalid": "INVALID_DISCOUNT",
|
|
46
|
+
"be.storefront.discountInactive": "INVALID_DISCOUNT",
|
|
47
|
+
"be.storefront.discountWrongCurrency": "INVALID_DISCOUNT",
|
|
48
|
+
"be.storefront.discountNotApplicable": "INVALID_DISCOUNT",
|
|
49
|
+
"be.storefront.discountNotYetValid": "INVALID_DISCOUNT",
|
|
50
|
+
"be.storefront.discountUsageLimitReached": "INVALID_DISCOUNT",
|
|
51
|
+
"be.storefront.discountLimitedToGroups": "INVALID_DISCOUNT",
|
|
52
|
+
"be.storefront.tokenInvalid": "TOKEN_INVALID",
|
|
53
|
+
"be.storefront.orderAccessTokenInvalid": "TOKEN_INVALID",
|
|
54
|
+
"be.storefront.resetTokenInvalid": "TOKEN_INVALID",
|
|
55
|
+
"be.storefront.invalidVerificationToken": "TOKEN_INVALID",
|
|
56
|
+
"be.storefront.invalidRefreshToken": "TOKEN_INVALID",
|
|
57
|
+
"be.storefront.refreshTokenExpired": "TOKEN_EXPIRED",
|
|
58
|
+
"be.storefront.apiKeyExpired": "TOKEN_EXPIRED",
|
|
59
|
+
"be.storefront.customerEmailTaken": "EMAIL_ALREADY_EXISTS",
|
|
60
|
+
"be.storefront.orderNotCancellable": "ORDER_NOT_CANCELLABLE",
|
|
61
|
+
"be.storefront.orderCancelledNotReturnable": "ORDER_NOT_CANCELLABLE",
|
|
62
|
+
"be.validation.failed": "VALIDATION_ERROR",
|
|
63
|
+
"be.forms.formNotFound": "NOT_FOUND",
|
|
64
|
+
"be.forms.validationFailed": "VALIDATION_ERROR",
|
|
65
|
+
"be.forms.consentRequired": "VALIDATION_ERROR",
|
|
66
|
+
"be.forms.tooLarge": "VALIDATION_ERROR"
|
|
67
|
+
};
|
|
36
68
|
var BehioApiError = class _BehioApiError extends Error {
|
|
37
69
|
constructor(status, body, message) {
|
|
38
70
|
super(message || `API Error ${status}`);
|
|
@@ -49,6 +81,11 @@ var BehioApiError = class _BehioApiError extends Error {
|
|
|
49
81
|
if (status === 409) return "EMAIL_ALREADY_EXISTS";
|
|
50
82
|
if (status === 429) return "RATE_LIMITED";
|
|
51
83
|
if (status >= 500) return "INTERNAL_ERROR";
|
|
84
|
+
const rawCode = body?.code;
|
|
85
|
+
if (typeof rawCode === "string") {
|
|
86
|
+
const mapped = BE_CODE_TO_ERROR[rawCode];
|
|
87
|
+
if (mapped) return mapped;
|
|
88
|
+
}
|
|
52
89
|
const msg = (body?.message || "").toLowerCase();
|
|
53
90
|
if (msg.includes("invalid") && msg.includes("password"))
|
|
54
91
|
return "INVALID_CREDENTIALS";
|
|
@@ -157,6 +194,8 @@ var BehioStorefront = class {
|
|
|
157
194
|
this.orders = new OrdersModule(this);
|
|
158
195
|
this.customer = new CustomerModule(this);
|
|
159
196
|
this.pages = new PagesModule(this);
|
|
197
|
+
this.blog = new BlogModule(this);
|
|
198
|
+
this.forms = new FormsModule(this);
|
|
160
199
|
this.wishlist = new WishlistModule(this);
|
|
161
200
|
this.reviews = new ReviewsModule(this);
|
|
162
201
|
this.returns = new ReturnsModule(this);
|
|
@@ -605,6 +644,7 @@ var CatalogModule = class {
|
|
|
605
644
|
if (query.priceMin) q.priceMin = query.priceMin;
|
|
606
645
|
if (query.priceMax) q.priceMax = query.priceMax;
|
|
607
646
|
if (query.currency) q.currency = query.currency;
|
|
647
|
+
if (query.country) q.country = query.country;
|
|
608
648
|
if (query.locale) q.locale = query.locale;
|
|
609
649
|
if (query.sort) q.sort = query.sort;
|
|
610
650
|
if (query.inStock !== void 0) q.inStock = query.inStock;
|
|
@@ -637,7 +677,7 @@ var CatalogModule = class {
|
|
|
637
677
|
"GET",
|
|
638
678
|
`/catalog/products/${slug}`,
|
|
639
679
|
{
|
|
640
|
-
query: { locale: options?.locale, currency: options?.currency }
|
|
680
|
+
query: { locale: options?.locale, currency: options?.currency, country: options?.country }
|
|
641
681
|
}
|
|
642
682
|
);
|
|
643
683
|
}
|
|
@@ -859,16 +899,27 @@ var CatalogModule = class {
|
|
|
859
899
|
{ body: input }
|
|
860
900
|
);
|
|
861
901
|
}
|
|
862
|
-
/**
|
|
902
|
+
/**
|
|
903
|
+
* List configured payment methods (filtered by currency). `locale` picks the
|
|
904
|
+
* language of `instruments[].label` / `swifts[].label` (SDK 1.14.0); pass the
|
|
905
|
+
* locale of the page so the instrument tiles read in the shopper's language.
|
|
906
|
+
*/
|
|
863
907
|
async listPaymentMethods(opts) {
|
|
864
908
|
const query = {};
|
|
865
909
|
if (opts?.currency) query.currency = opts.currency;
|
|
910
|
+
if (opts?.locale) query.locale = opts.locale;
|
|
911
|
+
if (opts?.country) query.country = opts.country;
|
|
912
|
+
if (opts?.shippingMethodId) query.shippingMethodId = opts.shippingMethodId;
|
|
866
913
|
return this.client.request(
|
|
867
914
|
"GET",
|
|
868
915
|
"/catalog/payment-methods",
|
|
869
916
|
{ query }
|
|
870
917
|
);
|
|
871
918
|
}
|
|
919
|
+
/** Alias of `listPaymentMethods` (SDK 1.14.0). */
|
|
920
|
+
paymentMethods(opts) {
|
|
921
|
+
return this.listPaymentMethods(opts);
|
|
922
|
+
}
|
|
872
923
|
};
|
|
873
924
|
var AuthModule = class {
|
|
874
925
|
constructor(client) {
|
|
@@ -1022,6 +1073,26 @@ var CartModule = class {
|
|
|
1022
1073
|
this.client.emit("cart:updated", res.data);
|
|
1023
1074
|
return res;
|
|
1024
1075
|
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Tell the cart where the order will ship (and, for B2B, the buyer's VAT
|
|
1078
|
+
* ID) so the VAT breakdown matches the checkout before the address form:
|
|
1079
|
+
* destination-country rate (OSS), 0 % export outside the EU, or reverse
|
|
1080
|
+
* charge for an EU business with a VIES-valid VAT ID. `cart.vatMode` says
|
|
1081
|
+
* which rule applied. SDK 1.17.0.
|
|
1082
|
+
*
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* await client.cart.setDestination({ country: "SK" });
|
|
1085
|
+
* await client.cart.setDestination({ vatId: "SK2020000001" }); // "" clears
|
|
1086
|
+
* ```
|
|
1087
|
+
*/
|
|
1088
|
+
async setDestination(input) {
|
|
1089
|
+
const res = await this.client.request("PUT", "/cart/destination", {
|
|
1090
|
+
body: input
|
|
1091
|
+
});
|
|
1092
|
+
if (res.error) return res;
|
|
1093
|
+
this.client.emit("cart:updated", res.data);
|
|
1094
|
+
return res;
|
|
1095
|
+
}
|
|
1025
1096
|
/** Update item quantity */
|
|
1026
1097
|
async updateQuantity(itemId, quantity) {
|
|
1027
1098
|
const res = await this.client.request(
|
|
@@ -1173,6 +1244,30 @@ var OrdersModule = class {
|
|
|
1173
1244
|
constructor(client) {
|
|
1174
1245
|
this.client = client;
|
|
1175
1246
|
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Ask the backend to re-check this order's payment with the gateway.
|
|
1249
|
+
*
|
|
1250
|
+
* Call it on the thank-you page the customer lands on after paying, BEFORE
|
|
1251
|
+
* you read the order. Some gateways (Tatrapay+) have no server-to-server
|
|
1252
|
+
* notification at all, so the customer's return is the only fast way the
|
|
1253
|
+
* payment gets confirmed; for the others it is a safety net for a lost
|
|
1254
|
+
* notification.
|
|
1255
|
+
*
|
|
1256
|
+
* The response is deliberately opaque (`{ok: true}` every time, even for an
|
|
1257
|
+
* order number that does not exist): order numbers are sequential, so
|
|
1258
|
+
* anything else would turn this into a probe for other people's orders.
|
|
1259
|
+
* Read the actual state afterwards through a path that proves entitlement
|
|
1260
|
+
* ({@link get}, {@link track} or the guest access-code flow).
|
|
1261
|
+
*
|
|
1262
|
+
* Never throws for a missing order and never blocks the page: treat a
|
|
1263
|
+
* failure as "not confirmed yet", the backend poller catches up on its own.
|
|
1264
|
+
*/
|
|
1265
|
+
async syncPaymentOnReturn(orderNumber) {
|
|
1266
|
+
return this.client.request(
|
|
1267
|
+
"POST",
|
|
1268
|
+
`/payments/return/${orderNumber}`
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1176
1271
|
/** List customer orders (requires auth) */
|
|
1177
1272
|
async list(options) {
|
|
1178
1273
|
return this.client.request(
|
|
@@ -1299,7 +1394,10 @@ var CustomerModule = class {
|
|
|
1299
1394
|
body: address
|
|
1300
1395
|
});
|
|
1301
1396
|
}
|
|
1302
|
-
/**
|
|
1397
|
+
/**
|
|
1398
|
+
* Update address. Partial: `{isDefault: true}` alone is a valid body. A
|
|
1399
|
+
* changed `vatId` or `country` re-runs the VIES check on the server.
|
|
1400
|
+
*/
|
|
1303
1401
|
async updateAddress(addressId, data) {
|
|
1304
1402
|
return this.client.request(
|
|
1305
1403
|
"PATCH",
|
|
@@ -1525,6 +1623,59 @@ var PagesModule = class {
|
|
|
1525
1623
|
});
|
|
1526
1624
|
}
|
|
1527
1625
|
};
|
|
1626
|
+
var BlogModule = class {
|
|
1627
|
+
constructor(client) {
|
|
1628
|
+
this.client = client;
|
|
1629
|
+
}
|
|
1630
|
+
/** List the site's blogs (active only). */
|
|
1631
|
+
async list(locale) {
|
|
1632
|
+
return this.client.request("GET", "/blogs", {
|
|
1633
|
+
query: { locale }
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
/** Published posts of one blog, newest first (featured first), paginated. */
|
|
1637
|
+
async posts(handle, query = {}) {
|
|
1638
|
+
return this.client.request("GET", `/blogs/${handle}/posts`, {
|
|
1639
|
+
query: {
|
|
1640
|
+
locale: query.locale,
|
|
1641
|
+
page: query.page,
|
|
1642
|
+
limit: query.limit,
|
|
1643
|
+
tag: query.tag
|
|
1644
|
+
}
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
/** One published post with sanitised HTML content and related posts. */
|
|
1648
|
+
async post(handle, slug, locale) {
|
|
1649
|
+
return this.client.request("GET", `/blogs/${handle}/posts/${slug}`, {
|
|
1650
|
+
query: { locale }
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
var FormsModule = class {
|
|
1655
|
+
constructor(client) {
|
|
1656
|
+
this.client = client;
|
|
1657
|
+
}
|
|
1658
|
+
/** Public definition of one form (fields + settings). 404 for an unknown or inactive slug. */
|
|
1659
|
+
async get(slug) {
|
|
1660
|
+
return this.client.request(
|
|
1661
|
+
"GET",
|
|
1662
|
+
`/forms/${encodeURIComponent(slug)}`
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Submit a response. On `be.forms.validationFailed` the returned error
|
|
1667
|
+
* carries per-field codes: read them with `formFieldErrors(error)`. Other
|
|
1668
|
+
* rejections: `be.forms.consentRequired`, `be.forms.tooLarge`,
|
|
1669
|
+
* `be.forms.formNotFound`; rate limit 10 submits per minute per visitor.
|
|
1670
|
+
*/
|
|
1671
|
+
async submit(slug, input) {
|
|
1672
|
+
return this.client.request(
|
|
1673
|
+
"POST",
|
|
1674
|
+
`/forms/${encodeURIComponent(slug)}/submit`,
|
|
1675
|
+
{ body: input, auth: false }
|
|
1676
|
+
);
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1528
1679
|
var WishlistModule = class {
|
|
1529
1680
|
constructor(client) {
|
|
1530
1681
|
this.client = client;
|