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

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.
@@ -26,6 +26,13 @@ export declare function getCheckoutUrlFromCartStore(cartStore: IkasCartStore): s
26
26
  /**
27
27
  * Add a product variant to the shopping cart.
28
28
  *
29
+ * Clamps the quantity to the sales channel's `minQuantityPerCart`/`maxQuantityPerCart` only
30
+ * when it creates a new cart line. When the variant already has a line in the cart, the add
31
+ * is delegated to `changeItemQuantity` (existing quantity + `initialQuantity`) with no
32
+ * client-side clamp — a quantity past `maxQuantityPerCart` is then rejected by the API with
33
+ * the `MAX_QUANTITY_PER_CART_LIMIT_REACHED` code in `result.response.errorCodes`, never as a
34
+ * `validationError`. See `changeItemQuantity` for the handling pattern.
35
+ *
29
36
  * @ai-category ProductDetail, Cart
30
37
  * @ai-related getSelectedProductVariant, findExistingCartItem, hasProductVariantStock
31
38
  *
@@ -85,6 +92,11 @@ export declare function addSelectedtedVariantToCart(product: IkasProduct, initia
85
92
  * Change the quantity of an item in the cart.
86
93
  * Use quantity=0 to remove the item.
87
94
  *
95
+ * Performs no client-side clamping or validation: a quantity above the sales channel's
96
+ * `maxQuantityPerCart` is rejected by the API with the `MAX_QUANTITY_PER_CART_LIMIT_REACHED`
97
+ * code in `result.response.errorCodes` (never as a `validationError`). Prevent violations in
98
+ * the stepper and treat the error code as the fallback.
99
+ *
88
100
  * @ai-category Cart
89
101
  * @ai-related removeItem, findExistingCartItem
90
102
  *
@@ -96,7 +108,7 @@ export declare function addSelectedtedVariantToCart(product: IkasProduct, initia
96
108
  *
97
109
  * @example
98
110
  * ```typescript
99
- * import { cartStore, changeItemQuantity } from "@ikas/bp-storefront";
111
+ * import { APIErrorCode, cartStore, changeItemQuantity } from "@ikas/bp-storefront";
100
112
  *
101
113
  * // Increment quantity
102
114
  * async function handleIncrement(itemId: string) {
@@ -104,7 +116,10 @@ export declare function addSelectedtedVariantToCart(product: IkasProduct, initia
104
116
  * if (item) {
105
117
  * const result = await changeItemQuantity(item, item.quantity + 1);
106
118
  * if (!result.success) {
107
- * showToast("Failed to update quantity");
119
+ * const limitHit = result.response?.errorCodes?.includes(
120
+ * APIErrorCode.MAX_QUANTITY_PER_CART_LIMIT_REACHED
121
+ * );
122
+ * showToast(limitHit ? "Per-cart quantity limit reached" : "Failed to update quantity");
108
123
  * }
109
124
  * }
110
125
  * }
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};
@@ -5,6 +5,12 @@ export default interface API<T> {
5
5
  saveBulk?: (models: T[]) => Promise<APIResponse<any>>;
6
6
  delete?: (idList: string[]) => Promise<APIResponse<any>>;
7
7
  }
8
+ /**
9
+ * Error codes the SDK itself distinguishes. NOT exhaustive: the APIResponse
10
+ * constructor copies `extensions.code` from GraphQL errors verbatim, so
11
+ * `errorCodes` can carry backend codes that are not listed here (e.g.
12
+ * VARIANT_NOT_FOUND). Never build an exhaustive switch over this enum.
13
+ */
8
14
  export declare enum APIErrorCode {
9
15
  ARGUMENT_VALIDATION_ERROR = "ARGUMENT_VALIDATION_ERROR",
10
16
  UNAUTHENTICATED = "UNAUTHENTICATED",
@@ -15,6 +21,7 @@ export declare enum APIErrorCode {
15
21
  REQUEST_CANCELLED = "REQUEST_CANCELLED",
16
22
  DUPLICATE_KEY_ERROR = "DUPLICATE_KEY_ERROR",
17
23
  CUSTOMER_ALREADY_SUBSCRIBED = "CUSTOMER_ALREADY_SUBSCRIBED",
24
+ MAX_QUANTITY_PER_CART_LIMIT_REACHED = "MAX_QUANTITY_PER_CART_LIMIT_REACHED",
18
25
  UNKNOWN = "UNKNOWN"
19
26
  }
20
27
  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.169",
4
4
  "description": "A framework for the ikas blueprint storefronts.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",