@ikas/bp-storefront 1.4.0-beta.167 → 1.4.0-beta.168

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.
@@ -85,6 +85,11 @@ export declare function addSelectedtedVariantToCart(product: IkasProduct, initia
85
85
  * Change the quantity of an item in the cart.
86
86
  * Use quantity=0 to remove the item.
87
87
  *
88
+ * Performs no client-side clamping or validation: a quantity above the sales channel's
89
+ * `maxQuantityPerCart` is rejected by the API with the `MAX_QUANTITY_PER_CART_LIMIT_REACHED`
90
+ * code in `result.response.errorCodes` (never as a `validationError`). Prevent violations in
91
+ * the stepper and treat the error code as the fallback.
92
+ *
88
93
  * @ai-category Cart
89
94
  * @ai-related removeItem, findExistingCartItem
90
95
  *
@@ -96,7 +101,7 @@ export declare function addSelectedtedVariantToCart(product: IkasProduct, initia
96
101
  *
97
102
  * @example
98
103
  * ```typescript
99
- * import { cartStore, changeItemQuantity } from "@ikas/bp-storefront";
104
+ * import { APIErrorCode, cartStore, changeItemQuantity } from "@ikas/bp-storefront";
100
105
  *
101
106
  * // Increment quantity
102
107
  * async function handleIncrement(itemId: string) {
@@ -104,7 +109,10 @@ export declare function addSelectedtedVariantToCart(product: IkasProduct, initia
104
109
  * if (item) {
105
110
  * const result = await changeItemQuantity(item, item.quantity + 1);
106
111
  * if (!result.success) {
107
- * showToast("Failed to update quantity");
112
+ * const limitHit = result.response?.errorCodes?.includes(
113
+ * APIErrorCode.MAX_QUANTITY_PER_CART_LIMIT_REACHED
114
+ * );
115
+ * showToast(limitHit ? "Per-cart quantity limit reached" : "Failed to update quantity");
108
116
  * }
109
117
  * }
110
118
  * }
package/dist/index.d.ts CHANGED
@@ -26,7 +26,7 @@ export * from "./utils/fetch";
26
26
  export * from "./utils/object-wrapper";
27
27
  export * from "./utils/pay-with-ikas";
28
28
  export * from "./utils/svg";
29
- export type { APIErrorCode, APIResponse } from "./storefront-api/src";
29
+ export type { APIResponse } from "./storefront-api/src";
30
30
  export * from "./storefront-api/src";
31
31
  export * from "./storefront-config/src";
32
32
  export * from "./storefront-models/src";
@@ -1 +1 @@
1
- var r;!function(r){r.ARGUMENT_VALIDATION_ERROR="ARGUMENT_VALIDATION_ERROR",r.UNAUTHENTICATED="UNAUTHENTICATED",r.UNAUTHORIZED="UNAUTHORIZED",r.INTERNAL_SERVER_ERROR="INTERNAL_SERVER_ERROR",r.LOGIN_REQUIRED="LOGIN_REQUIRED",r.NETWORK_ERROR="NETWORK_ERROR",r.REQUEST_CANCELLED="REQUEST_CANCELLED",r.DUPLICATE_KEY_ERROR="DUPLICATE_KEY_ERROR",r.CUSTOMER_ALREADY_SUBSCRIBED="CUSTOMER_ALREADY_SUBSCRIBED",r.UNKNOWN="UNKNOWN"}(r||(r={}));var e=function(){function e(e,o,n){this.errors=[],this.errorCodes=[];var t=[],E=[];null==o||o.forEach(function(e){var o;(null===(o=e.extensions)||void 0===o?void 0:o.code)?(t.push(e.message),E.push(e.extensions.code)):(t.push("Unknown error"),E.push(r.UNKNOWN))}),null==n||n.forEach(function(r){E.push(r)}),this.graphQLErrors=o,this.errors=t,this.errorCodes=E,this.data=e}return Object.defineProperty(e.prototype,"firstErrorMessage",{get:function(){return this.errors.length?this.errors[0]:""},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isUnAuthenticated",{get:function(){return this.errorCodes.some(function(e){return e===r.UNAUTHENTICATED})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isNetworkError",{get:function(){return this.errorCodes.some(function(e){return e===r.NETWORK_ERROR})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isSuccess",{get:function(){return 0===this.errorCodes.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isCancelled",{get:function(){return this.errorCodes.some(function(e){return e===r.REQUEST_CANCELLED})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isRecoverableError",{get:function(){var e=[r.UNAUTHENTICATED,r.INTERNAL_SERVER_ERROR,r.NETWORK_ERROR];return this.errorCodes.every(function(r){return e.includes(r)})},enumerable:!1,configurable:!0}),e.networkError=function(){var o=new e;return o.errors.push("Network error!"),o.errorCodes.push(r.NETWORK_ERROR),o},e.requestCancelled=function(){var o=new e;return o.errors.push("Request was cancelled"),o.errorCodes.push(r.REQUEST_CANCELLED),o},e.unknownError=function(){var o=new e;return o.errors.push("Unknown error!"),o.errorCodes.push(r.UNKNOWN),o},e.authError=function(){var o=new e;return o.errors.push("Authentication error!"),o.errorCodes.push(r.UNAUTHENTICATED),o},e.success=function(){return new e},e}();function o(r){var o,n;return console.error(r.toJSON?r.toJSON():r),"AbortError"===r.name||20===r.code||(null===(o=r.message)||void 0===o?void 0:o.includes("aborted"))?e.requestCancelled():r.networkError?e.networkError():r.graphQLErrors?new e(void 0,r.graphQLErrors):r instanceof TypeError&&(null===(n=r.message)||void 0===n?void 0:n.includes("fetch"))?e.networkError():e.unknownError()}export{r as APIErrorCode,e as APIResponse,o as handleAPIError};
1
+ var r;!function(r){r.ARGUMENT_VALIDATION_ERROR="ARGUMENT_VALIDATION_ERROR",r.UNAUTHENTICATED="UNAUTHENTICATED",r.UNAUTHORIZED="UNAUTHORIZED",r.INTERNAL_SERVER_ERROR="INTERNAL_SERVER_ERROR",r.LOGIN_REQUIRED="LOGIN_REQUIRED",r.NETWORK_ERROR="NETWORK_ERROR",r.REQUEST_CANCELLED="REQUEST_CANCELLED",r.DUPLICATE_KEY_ERROR="DUPLICATE_KEY_ERROR",r.CUSTOMER_ALREADY_SUBSCRIBED="CUSTOMER_ALREADY_SUBSCRIBED",r.MAX_QUANTITY_PER_CART_LIMIT_REACHED="MAX_QUANTITY_PER_CART_LIMIT_REACHED",r.UNKNOWN="UNKNOWN"}(r||(r={}));var e=function(){function e(e,o,n){this.errors=[],this.errorCodes=[];var t=[],E=[];null==o||o.forEach(function(e){var o;(null===(o=e.extensions)||void 0===o?void 0:o.code)?(t.push(e.message),E.push(e.extensions.code)):(t.push("Unknown error"),E.push(r.UNKNOWN))}),null==n||n.forEach(function(r){E.push(r)}),this.graphQLErrors=o,this.errors=t,this.errorCodes=E,this.data=e}return Object.defineProperty(e.prototype,"firstErrorMessage",{get:function(){return this.errors.length?this.errors[0]:""},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isUnAuthenticated",{get:function(){return this.errorCodes.some(function(e){return e===r.UNAUTHENTICATED})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isNetworkError",{get:function(){return this.errorCodes.some(function(e){return e===r.NETWORK_ERROR})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isSuccess",{get:function(){return 0===this.errorCodes.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isCancelled",{get:function(){return this.errorCodes.some(function(e){return e===r.REQUEST_CANCELLED})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isRecoverableError",{get:function(){var e=[r.UNAUTHENTICATED,r.INTERNAL_SERVER_ERROR,r.NETWORK_ERROR];return this.errorCodes.every(function(r){return e.includes(r)})},enumerable:!1,configurable:!0}),e.networkError=function(){var o=new e;return o.errors.push("Network error!"),o.errorCodes.push(r.NETWORK_ERROR),o},e.requestCancelled=function(){var o=new e;return o.errors.push("Request was cancelled"),o.errorCodes.push(r.REQUEST_CANCELLED),o},e.unknownError=function(){var o=new e;return o.errors.push("Unknown error!"),o.errorCodes.push(r.UNKNOWN),o},e.authError=function(){var o=new e;return o.errors.push("Authentication error!"),o.errorCodes.push(r.UNAUTHENTICATED),o},e.success=function(){return new e},e}();function o(r){var o,n;return console.error(r.toJSON?r.toJSON():r),"AbortError"===r.name||20===r.code||(null===(o=r.message)||void 0===o?void 0:o.includes("aborted"))?e.requestCancelled():r.networkError?e.networkError():r.graphQLErrors?new e(void 0,r.graphQLErrors):r instanceof TypeError&&(null===(n=r.message)||void 0===n?void 0:n.includes("fetch"))?e.networkError():e.unknownError()}export{r as APIErrorCode,e as APIResponse,o as handleAPIError};
@@ -15,6 +15,7 @@ export declare enum APIErrorCode {
15
15
  REQUEST_CANCELLED = "REQUEST_CANCELLED",
16
16
  DUPLICATE_KEY_ERROR = "DUPLICATE_KEY_ERROR",
17
17
  CUSTOMER_ALREADY_SUBSCRIBED = "CUSTOMER_ALREADY_SUBSCRIBED",
18
+ MAX_QUANTITY_PER_CART_LIMIT_REACHED = "MAX_QUANTITY_PER_CART_LIMIT_REACHED",
18
19
  UNKNOWN = "UNKNOWN"
19
20
  }
20
21
  export declare class APIResponse<T> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/bp-storefront",
3
- "version": "1.4.0-beta.167",
3
+ "version": "1.4.0-beta.168",
4
4
  "description": "A framework for the ikas blueprint storefronts.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",