@ikas/bp-storefront 2.8.0 → 2.9.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/dist/analytics/analytics-functions/addToCart.js +1 -1
- package/dist/analytics/analytics-functions/addToWishlist.js +1 -1
- package/dist/analytics/analytics-functions/completeRegistration.js +1 -1
- package/dist/analytics/analytics-functions/contactForm.js +1 -1
- package/dist/analytics/analytics-functions/createEmailSubscription.js +1 -1
- package/dist/analytics/analytics-functions/customerLogin.js +1 -1
- package/dist/analytics/analytics-functions/customerLogout.js +1 -1
- package/dist/analytics/analytics-functions/customerVisit.js +1 -1
- package/dist/analytics/analytics-functions/pageView.js +1 -1
- package/dist/analytics/analytics-functions/productView.js +1 -1
- package/dist/analytics/analytics-functions/removeFromCart.js +1 -1
- package/dist/analytics/analytics-functions/search.js +1 -1
- package/dist/analytics/analytics-functions/viewBrand.js +1 -1
- package/dist/analytics/analytics-functions/viewCart.js +1 -1
- package/dist/analytics/analytics-functions/viewCategory.js +1 -1
- package/dist/analytics/analytics-functions/viewListing.js +1 -1
- package/dist/analytics/analytics-functions/viewSearchResults.js +1 -1
- package/dist/analytics/analytics-functions/viewStorefrontPopup.js +1 -1
- package/dist/analytics/events.d.ts +8 -0
- package/dist/analytics/events.js +1 -1
- package/dist/analytics/ikas/analytics.js +1 -1
- package/dist/functions/api/cart/index.d.ts +2 -0
- package/dist/functions/api/cart/index.js +1 -1
- package/dist/functions/models/image/index.d.ts +13 -8
- package/dist/functions/models/index.d.ts +1 -0
- package/dist/functions/models/order/index.d.ts +21 -0
- package/dist/functions/models/order/index.js +1 -1
- package/dist/functions/models/product-list/index.js +1 -1
- package/dist/functions/models/validator/deactivate-customer/index.d.ts +54 -0
- package/dist/functions/models/validator/deactivate-customer/index.js +1 -0
- package/dist/functions/stores/base/index.d.ts +67 -0
- package/dist/functions/stores/base/index.js +1 -1
- package/dist/functions/stores/cart/index.d.ts +46 -2
- package/dist/functions/stores/cart/index.js +1 -1
- package/dist/functions/stores/customer/index.d.ts +100 -2
- package/dist/functions/stores/customer/index.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/packages/storefront-api/src/__api/mutations/removeGiftCardFromCart.js +1 -0
- package/dist/packages/storefront-api-client/src/utils/api.js +1 -1
- package/dist/packages/storefront-config/src/theme-globals.js +1 -1
- package/dist/router/index.d.ts +28 -0
- package/dist/router/index.js +1 -1
- package/dist/storefront-api/src/__api/mutations/removeGiftCardFromCart.d.ts +7 -0
- package/dist/storefront-api/src/__api/types/index.d.ts +32 -4
- package/dist/storefront-api-client/src/utils/api.d.ts +7 -0
- package/dist/storefront-config/src/theme-globals.d.ts +1 -1
- package/dist/storefront-models/src/index.d.ts +2 -0
- package/dist/storefront-models/src/models/blueprint/prop-value/attribute-list.d.ts +2 -0
- package/dist/storefront-models/src/models/blueprint/prop-value/attribute.d.ts +2 -0
- package/dist/storefront-models/src/models/blueprint/prop-value/index.d.ts +1 -0
- package/dist/storefront-models/src/models/blueprint/prop-value/variable-binding.d.ts +16 -0
- package/dist/storefront-models/src/models/image/index.d.ts +7 -0
- package/dist/storefront-models/src/models/order/gift-card-line/index.d.ts +15 -0
- package/dist/storefront-models/src/models/order/index.d.ts +2 -0
- package/dist/storefront-models/src/models/order/line-item/index.d.ts +1 -1
- package/dist/storefront-models/src/models/order/package/index.d.ts +1 -1
- package/dist/storefront-models/src/models/payment-gateway/index.d.ts +1 -1
- package/dist/storefront-models/src/models/product/image/index.d.ts +5 -0
- package/dist/storefront-models/src/models/validator/deactivate-customer/index.d.ts +4 -0
- package/dist/stores/customer/index.d.ts +2 -1
- package/dist/stores/customer/index.js +1 -1
- package/dist/utils/currency.d.ts +36 -3
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DeactivateCustomerForm } from "../../../../storefront-models/src";
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the deactivate customer form with default password field values, labels, and placeholders.
|
|
4
|
+
*
|
|
5
|
+
* @ai-category Validation, DeactivateCustomer, Form
|
|
6
|
+
* @ai-related setDeactivateCustomerFormPassword, submitDeactivateCustomerForm
|
|
7
|
+
*
|
|
8
|
+
* @param deactivateCustomerForm - The deactivate customer form model to initialize
|
|
9
|
+
* @returns void
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { initDeactivateCustomerForm } from "@ikas/bp-storefront";
|
|
14
|
+
* initDeactivateCustomerForm(deactivateCustomerForm);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function initDeactivateCustomerForm(deactivateCustomerForm: DeactivateCustomerForm): void;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the password value on the deactivate customer form and re-validates if the form has already been submitted.
|
|
20
|
+
*
|
|
21
|
+
* @ai-category Validation, DeactivateCustomer, Form
|
|
22
|
+
* @ai-related initDeactivateCustomerForm, submitDeactivateCustomerForm
|
|
23
|
+
*
|
|
24
|
+
* @param deactivateCustomerForm - The deactivate customer form model to update
|
|
25
|
+
* @param value - The new password string to set
|
|
26
|
+
* @returns void
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { setDeactivateCustomerFormPassword } from "@ikas/bp-storefront";
|
|
31
|
+
* setDeactivateCustomerFormPassword(deactivateCustomerForm, "mySecurePassword123");
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function setDeactivateCustomerFormPassword(deactivateCustomerForm: DeactivateCustomerForm, value: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Validates and submits the deactivate customer form, deleting the current customer's account after password verification.
|
|
37
|
+
* The customer session is not cleared automatically, call `logout` after a successful submission.
|
|
38
|
+
*
|
|
39
|
+
* @ai-category Validation, DeactivateCustomer, Form
|
|
40
|
+
* @ai-related initDeactivateCustomerForm, setDeactivateCustomerFormPassword
|
|
41
|
+
*
|
|
42
|
+
* @param deactivateCustomerForm - The deactivate customer form model to submit
|
|
43
|
+
* @returns A promise that resolves to true if the account was deactivated successfully, or false on validation error or API failure
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { customerStore, logout, submitDeactivateCustomerForm } from "@ikas/bp-storefront";
|
|
48
|
+
* const success = await submitDeactivateCustomerForm(deactivateCustomerForm);
|
|
49
|
+
* if (success) {
|
|
50
|
+
* await logout(customerStore);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function submitDeactivateCustomerForm(deactivateCustomerForm: DeactivateCustomerForm): Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__assign as s,__awaiter as e,__generator as i}from'./../../../../ext/tslib/tslib.es6.mjs.js';import{I18n as r}from"../../../../i18n/index.js";import{customerStore as o}from"../../../../stores/customer/index.js";import"../../../../packages/storefront-config/src/index.js";import'./../../../../ext/lodash/_isFlattenable.js';import'./../../../../ext/lodash/sortBy.js';import"../../../../stores/base/index.js";import"../../../../stores/cart/index.js";import'./../../../../ext/mobx/dist/mobx.esm.js';import"../../../../router/index.js";import{deactivateCustomer as t}from"../../../stores/customer/index.js";import{FORM_ITEM_DEFAULT_VALUE as a,validateValue as n}from"../index.js";function d(e){e.password=s(s({},a),{isRequired:!0,label:r.translate("label.password"),placeholder:r.translate("placeholder.password")}),e.isSubmitted=!1,e.isSubmitting=!1,e.isSuccess=void 0,e.isFailure=void 0,e.responseMessage=void 0}function u(s,e){s.password.value=e,s.isSubmitted&&m(s)}function l(s){return e(this,void 0,void 0,function(){var e,a,n,d;return i(this,function(i){switch(i.label){case 0:return s.isSubmitted=!0,s.isSuccess=void 0,s.isFailure=void 0,s.responseMessage=void 0,m(s)?[2,!1]:(s.isSubmitting=!0,[4,t(o,s.password.value)]);case 1:return e=i.sent(),s.isSubmitting=!1,(null==e?void 0:e.isSuccess)?(s.isSuccess=!0,s.responseMessage=r.translate("notification.success.deactivate_customer"),[2,!0]):(s.isFailure=!0,a=null!==(d=null===(n=null==e?void 0:e.errors)||void 0===n?void 0:n[0])&&void 0!==d?d:"",s.responseMessage=a.includes("customer_deactivation_request_already_exists")?r.translate("notification.failure.deactivate_customer_request_already_exists"):r.translate("notification.failure.deactivate_customer"),[2,!1])}})})}function m(s){var e=n(s.password.value,{required:!0});return e.hasError?(s.password.hasError=!0,s.password.message=e.message):(s.password.hasError=!1,s.password.message=void 0),e.hasError}export{d as initDeactivateCustomerForm,u as setDeactivateCustomerFormPassword,l as submitDeactivateCustomerForm};
|
|
@@ -92,12 +92,79 @@ export declare function setLocalization(baseStore: BaseStore, localeOption: Ikas
|
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
94
|
export declare function setLanguage(baseStore: BaseStore, language: IkasLanguageOption): void;
|
|
95
|
+
/**
|
|
96
|
+
* Fetches a single product by id and returns it as a full `IkasProduct`.
|
|
97
|
+
*
|
|
98
|
+
* Use this when a lightweight reference (e.g. a cart line's `IkasOrderLineVariant`, which carries
|
|
99
|
+
* neither `salesChannels` nor `stock`) needs product-level data: the returned product includes
|
|
100
|
+
* `salesChannels` filtered to the active sales channel (with `minQuantityPerCart` /
|
|
101
|
+
* `maxQuantityPerCart`) and per-variant `stock` (summed over the sales channel's configured
|
|
102
|
+
* stock locations). `selectedVariantValues` is seeded from the first active variant (or the
|
|
103
|
+
* first variant when none is active). For multiple ids, prefer `bs_searchProductsById` — one
|
|
104
|
+
* batched request.
|
|
105
|
+
*
|
|
106
|
+
* @ai-category Product, Search
|
|
107
|
+
* @ai-related bs_searchProductsById
|
|
108
|
+
*
|
|
109
|
+
* @param baseStore - The base store instance
|
|
110
|
+
* @param params - `{ productId }` — id of the product to fetch
|
|
111
|
+
* @returns `{ isSuccess, product }` — `product` is null when not found or on failure
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* import { baseStore, bs_searchProductById, IkasStorefrontConfig } from "@ikas/bp-storefront";
|
|
116
|
+
*
|
|
117
|
+
* const { isSuccess, product } = await bs_searchProductById(baseStore, { productId });
|
|
118
|
+
* if (isSuccess && product) {
|
|
119
|
+
* const channel = product.salesChannels?.find(sc => sc.id === IkasStorefrontConfig.salesChannelId);
|
|
120
|
+
* console.log(channel?.maxQuantityPerCart);
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
95
124
|
export declare function bs_searchProductById(baseStore: BaseStore, params: {
|
|
96
125
|
productId: string;
|
|
97
126
|
}): Promise<{
|
|
98
127
|
isSuccess: boolean;
|
|
99
128
|
product: IkasProduct | null;
|
|
100
129
|
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Batch-fetches products by id in a single request and returns them as full `IkasProduct` objects.
|
|
132
|
+
*
|
|
133
|
+
* The go-to function when cart lines (or any lightweight reference) need product-level data they
|
|
134
|
+
* do not carry: `IkasOrderLineVariant` has neither `salesChannels` nor `stock`, while the products
|
|
135
|
+
* returned here include `salesChannels` filtered to the active sales channel (with
|
|
136
|
+
* `minQuantityPerCart` / `maxQuantityPerCart`) and per-variant `stock` (summed over the sales
|
|
137
|
+
* channel's configured stock locations). Collect the distinct `productId`s of the lines and
|
|
138
|
+
* fetch them in ONE call instead of one request per line. Called with an empty `productIds`,
|
|
139
|
+
* it returns `{ isSuccess: true, products: [] }` without a network request.
|
|
140
|
+
*
|
|
141
|
+
* @ai-category Product, Cart, Search
|
|
142
|
+
* @ai-related bs_searchProductById, changeItemQuantity
|
|
143
|
+
*
|
|
144
|
+
* @param baseStore - The base store instance
|
|
145
|
+
* @param params - `{ productIds }` — product ids to fetch (deduplicate before calling)
|
|
146
|
+
* @returns `{ isSuccess, products }` — `products` is null on failure
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```tsx
|
|
150
|
+
* import { baseStore, bs_searchProductsById, cartStore, IkasStorefrontConfig } from "@ikas/bp-storefront";
|
|
151
|
+
*
|
|
152
|
+
* // Enforce per-cart quantity limits on cart lines:
|
|
153
|
+
* const productIds = [
|
|
154
|
+
* ...new Set(
|
|
155
|
+
* (cartStore.cart?.orderLineItems ?? [])
|
|
156
|
+
* .map(item => item.variant.productId)
|
|
157
|
+
* .filter((id): id is string => !!id)
|
|
158
|
+
* ),
|
|
159
|
+
* ];
|
|
160
|
+
* const { products } = await bs_searchProductsById(baseStore, { productIds });
|
|
161
|
+
* const maxByProductId = new Map<string, number | null>();
|
|
162
|
+
* for (const p of products ?? []) {
|
|
163
|
+
* const channel = p.salesChannels?.find(sc => sc.id === IkasStorefrontConfig.salesChannelId);
|
|
164
|
+
* maxByProductId.set(p.id, channel?.maxQuantityPerCart ?? null);
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
101
168
|
export declare function bs_searchProductsById(baseStore: BaseStore, params: {
|
|
102
169
|
productIds: string[];
|
|
103
170
|
}): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as n,__generator as
|
|
1
|
+
import{__awaiter as n,__generator as o}from'./../../../ext/tslib/tslib.es6.mjs.js';import{IkasStorefrontConfig as i}from"../../../packages/storefront-config/src/index.js";import t from'./../../../ext/lodash/flatten.js';import e from'./../../../ext/lodash/sortBy.js';import{baseStore as r}from"../../../stores/base/index.js";function c(c){r.currentPageType=c,function(){n(this,void 0,void 0,function(){var n,c,a,u,s,d,l,v;return o(this,function(o){switch(o.label){case 0:return[4,import("../../api/location/index.js")];case 1:return[4,(0,o.sent().apiGetMyCountry)()];case 2:return n=o.sent(),c=n.data,n.isSuccess&&c?(a=i.routings.filter(function(n){var o;return null===(o=n.countryCodes)||void 0===o?void 0:o.includes(c)}),a.length?(u=t(i.routings.map(function(n){return n.countryCodes||[]})),[4,import("../../api/location/index.js")]):[2]):[2];case 3:return[4,(0,o.sent().apiListCountry)({iso2:{in:u}})];case 4:return(s=o.sent()).isSuccess?(d=s.data||[],l=[],v=[],i.routings.forEach(function(n){var o;if(null===(o=n.countryCodes)||void 0===o?void 0:o.length)n.countryCodes.forEach(function(o){var i=d.find(function(n){return n.iso2===o});if(!v.some(function(n){return n.iso2===(null==i?void 0:i.iso2)})){var t={id:(null==i?void 0:i.iso2)||(null==i?void 0:i.iso3)||Date.now()+"",countryName:(null==i?void 0:i.native)||(null==i?void 0:i.name)||"",iso2:(null==i?void 0:i.iso2)||void 0,iso3:(null==i?void 0:i.iso3)||void 0,routing:n,isRecommended:o===c};v.push(t)}});else{var t={id:n.id,routing:n,isRecommended:!i.routings.some(function(n){var o;return null===(o=n.countryCodes)||void 0===o?void 0:o.includes(c)})};v.push(t)}}),i.routings.forEach(function(n){var o;if(a.some(function(o){return o.id===n.id})){var t={id:n.id,currencyCode:n.currencyCode,currencySymbol:n.currencySymbol,language:"undefined"!=typeof Intl&&void 0!==Intl.DisplayNames&&new Intl.DisplayNames([],{type:"language"}).of(n.locale)||n.locale,locale:n.locale,isSelected:n.id===(null===(o=i.getCurrentRouting())||void 0===o?void 0:o.id)||!1};l.push(t)}}),r.languageOptions=e(l,"language"),r.localeOptions=e(v,"countryName"),[2]):[2]}})})}()}function a(n,o){var i=s(o.routing);window.location.replace(i)}function u(n,o){var t=i.routings.find(function(n){return n.id===o.id});if(t){var e=s(t);window.location.replace(e)}}function s(n){var o,t,e,c;if(n.domain)return"https://".concat(n.domain);var a=window.location,u=a.origin,s=a.pathname,d=a.search,l=a.hash,v=n.path?"/".concat(n.path):"",f=r.currentPageType;if("CATEGORY"===f||"BRAND"===f||"PRODUCT"===f){var p=null===(o=window.__IKAS_DATA__)||void 0===o?void 0:o.pageSpecificData,m=null===(e=null===(t=null==p?void 0:p.metaData)||void 0===t?void 0:t.translations)||void 0===e?void 0:e.find(function(o){return o.locale===n.locale});if(null==m?void 0:m.slug)return"".concat(u).concat(v,"/").concat(m.slug).concat(d).concat(l)}var g=null===(c=i.getCurrentRouting())||void 0===c?void 0:c.path,h=s;if(g){var y="/".concat(g);s===y?h="/":s.startsWith("".concat(y,"/"))&&(h=s.slice(y.length))}return"".concat(u).concat(v).concat(h).concat(d).concat(l)}function d(i,t){return n(this,void 0,void 0,function(){var n,i,e,r;return o(this,function(o){switch(o.label){case 0:return[4,import("../../api/product/index.js")];case 1:return[4,(0,o.sent().apiSearchProducts)({input:{productIdList:[t.productId]}})];case 2:return n=o.sent(),(i=(null===(r=null===(e=n.data)||void 0===e?void 0:e.data)||void 0===r?void 0:r[0])||null)&&l(i),[2,{isSuccess:n.isSuccess,product:i}]}})})}function l(n){var o=n.variants.find(function(n){return n.isActive})||n.variants[0];o&&(n.selectedVariantValues=o.variantValues)}function v(i,t){return n(this,void 0,void 0,function(){var n,i,e;return o(this,function(o){switch(o.label){case 0:return t.productIds.length?[4,import("../../api/product/index.js")]:[2,{isSuccess:!0,products:[]}];case 1:return[4,(0,o.sent().apiSearchProducts)({input:{productIdList:t.productIds}})];case 2:return n=o.sent(),(i=(null===(e=n.data)||void 0===e?void 0:e.data)||null)&&i.forEach(l),[2,{isSuccess:n.isSuccess,products:i}]}})})}export{d as bs_searchProductById,v as bs_searchProductsById,c as initBaseStore,u as setLanguage,a as setLocalization};
|
|
@@ -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
|
-
*
|
|
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
|
* }
|
|
@@ -353,6 +368,35 @@ export declare function saveCouponCode(cart: IkasCart, couponCode?: string | nul
|
|
|
353
368
|
* ```
|
|
354
369
|
*/
|
|
355
370
|
export declare function removeCouponCode(cart: IkasCart): Promise<IkasCartOperationResult>;
|
|
371
|
+
/**
|
|
372
|
+
* Remove a gift card (or store credit) line from the cart.
|
|
373
|
+
*
|
|
374
|
+
* Gift cards are applied through `saveCouponCode` with the gift card code, and the applied
|
|
375
|
+
* cards are listed on `cart.giftCardLines`. Pass the `giftCardId` of the line to remove; when
|
|
376
|
+
* omitted, every gift card line is removed from the cart.
|
|
377
|
+
*
|
|
378
|
+
* @ai-category Cart
|
|
379
|
+
* @ai-related saveCouponCode, getIkasOrderGiftCardTotalPrice
|
|
380
|
+
*
|
|
381
|
+
* @param cart - The cart object
|
|
382
|
+
* @param giftCardId - The gift card to remove, or null/undefined to remove all of them
|
|
383
|
+
* @returns Result with success flag
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```typescript
|
|
387
|
+
* import { cartStore, removeGiftCardLine } from "@ikas/bp-storefront";
|
|
388
|
+
*
|
|
389
|
+
* async function handleRemoveGiftCard(giftCardId: string) {
|
|
390
|
+
* if (!cartStore.cart) return;
|
|
391
|
+
*
|
|
392
|
+
* const result = await removeGiftCardLine(cartStore.cart, giftCardId);
|
|
393
|
+
* if (result.success) {
|
|
394
|
+
* showToast("Gift card removed");
|
|
395
|
+
* }
|
|
396
|
+
* }
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
export declare function removeGiftCardLine(cart: IkasCart, giftCardId?: string | null): Promise<IkasCartOperationResult>;
|
|
356
400
|
/**
|
|
357
401
|
* Fetch the cart from the API and persist it to the cart store.
|
|
358
402
|
* Resolves the cart using the localStorage cart ID or the logged-in customer ID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__generator as n}from'./../../../ext/tslib/tslib.es6.mjs.js';import{IkasStorefrontConfig as r}from"../../../packages/storefront-config/src/index.js";import{CART_LS_KEY as e,cartStore as i}from"../../../stores/cart/index.js";import{customerStore as a}from"../../../stores/customer/index.js";import{getCookieValue as o}from"../../../utils/helper.js";import{getIkasOrderDistinctItemCount as s}from"../../models/order/index.js";import{getSelectedProductVariant as u,hasProductValidOptionValues as c}from"../../models/product/index.js";import{isProductOfferAccepted as d}from"../../models/product/campaign-offer/index.js";import{initProductOptionSetValues as l}from"../../models/product/option-set/index.js";import{hasProductVariantStock as f}from"../../models/product/variant/index.js";import{waitForCustomerStoreInit as v}from"../customer/index.js";function p(t){var n,e=null===(n=t.cart)||void 0===n?void 0:n.id;if(e){var i=r.getCurrentRouting();return"".concat((null==i?void 0:i.path)?"/".concat(i.path):"","/checkout?id=").concat(e,"&step=info")}return""}function m(a,s){return t(this,arguments,void 0,function(t,a,s,d){var v,p,m,h,g,y,b,C,S,L,j,w,P,T,q,A,F;return void 0===s&&(s=1),n(this,function(n){switch(n.label){case 0:v=null!==(w=null==d?void 0:d.isPayWithIkas)&&void 0!==w&&w,n.label=1;case 1:return n.trys.push([1,10,,11]),v||!a.productOptionSetId||a.productOptionSet?c(a)?f(t)||t.sellIfOutOfStock?(p=void 0,v?[3,3]:[4,k()]):[2,{success:!1,validationError:"INSUFFICIENT_STOCK"}]:[2,{success:!1,validationError:"INVALID_PRODUCT_OPTION_VALUES"}]:[2,{success:!1,validationError:"INVALID_PRODUCT_OPTION_VALUES"}];case 2:if(n.sent(),i.cart&&(p=_(i.cart,t,a))){if(a.productOptionSet&&l(a.productOptionSet),!t.bundleSettings)return[2,I(p,p.quantity+s,a.offers,a)];if(!O())return[2,I(p,p.quantity+s,a.offers,a)]}n.label=3;case 3:return m=U(a),h=s,(null==(g=null===(P=a.salesChannels)||void 0===P?void 0:P.find(function(t){return t.id===r.salesChannelId}))?void 0:g.minQuantityPerCart)&&s<g.minQuantityPerCart&&(h=g.minQuantityPerCart),(null==g?void 0:g.maxQuantityPerCart)&&s>g.maxQuantityPerCart&&(h=g.maxQuantityPerCart),y=v?null:(null===(T=i.cart)||void 0===T?void 0:T.id)||localStorage.getItem(e),[4,import("../../api/cart/index.js")];case 4:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:y,item:{id:null!==(q=null==p?void 0:p.id)&&void 0!==q?q:null,quantity:null!==(A=null==p?void 0:p.quantity)&&void 0!==A?A:h,variant:{id:t.id,name:a.name,bundleProducts:null===(F=t.bundleSettings)||void 0===F?void 0:F.products.map(function(t){var n;return{id:t.id,productId:(null===(n=t.product)||void 0===n?void 0:n.id)||"",variantId:t.product?u(t.product).id:"",quantity:t.quantity}})}},acceptedOffers:x(a.offers),options:m.length?m:null,priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc"),_ga:o("_ga")}}})];case 5:return b=n.sent(),v?[3,7]:b.isSuccess&&b.data?[4,E(b.data)]:[3,7];case 6:n.sent(),n.label=7;case 7:return(C=v?b.data:i.cart)?(S="".concat(C.id,"-").concat(C.updatedAt),(L=C.orderLineItems.find(function(n){return n.variant.id===t.id}))?[4,import("../../../analytics/analytics-functions/addToCart.js")]:[3,9]):[3,9];case 8:(0,n.sent().anl_addToCart)(L,s,S,C,a),n.label=9;case 9:return a.productOptionSet&&l(a.productOptionSet),[2,{success:b.isSuccess,response:b}];case 10:return j=n.sent(),console.log(j),[2,{success:!1}];case 11:return[2]}})})}function h(r){return t(this,arguments,void 0,function(t,r){return void 0===r&&(r=1),n(this,function(n){switch(n.label){case 0:return[4,m(u(t),t,r)];case 1:return[2,n.sent()]}})})}function I(e,a,s,u){return t(this,void 0,void 0,function(){var t,c,d,l,f,v;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,k()];case 1:return n.sent(),[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(f=i.cart)||void 0===f?void 0:f.id)||null,item:{id:e.id,quantity:a,variant:{id:e.variant.id,name:e.variant.name,bundleProducts:null===(v=e.variant.bundleProducts)||void 0===v?void 0:v.map(function(t){return{id:t.id,productId:t.variant.productId||"",variantId:t.variant.id||"",quantity:t.quantity}})}},acceptedOffers:s?x(s):void 0,options:F(e),priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc"),_ga:o("_ga")}}})];case 3:return(t=n.sent()).isSuccess&&t.data?[4,E(t.data)]:[3,5];case 4:n.sent(),n.label=5;case 5:return i.cart?(c="".concat(i.cart.id,"-").concat(i.cart.updatedAt),(d=e.quantity)>a?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(e,d-a,i.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(e,a-d,c,i.cart,u),n.label=9;case 9:return T(i),[2,{success:t.isSuccess,response:t}];case 10:return l=n.sent(),console.log(l),[2,{success:!1}];case 11:return[2]}})})}function g(r,e,i,a,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,I(e,i,a,o)];case 1:return[2,t.sent()]}})})}function y(t,n){for(var r=0,e=(null==t?void 0:t.orderAdjustments)||[];r<e.length;r++)for(var i=0,a=e[r].appliedOrderLines||[];i<a.length;i++){var o=a[i];if(o.orderLineId===n.id)return o.isAutoCreated||!1}return!1}function b(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,I(r,0)];case 1:return[2,t.sent()]}})})}function C(t){localStorage.removeItem(e),t.cart=null}function S(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,new Promise(function(t){var n=setInterval(function(){r.isCartInitialLoadFinished&&(clearInterval(n),t(null))},100)})];case 1:return[2,t.sent()]}})})}function O(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("editLineID")||""}function _(t,n,r){var e;if(!r.productOptionSetId&&!n.bundleSettings)return t.orderLineItems.find(function(t){return t.variant.id===n.id});if(n.bundleSettings){var i=O();if(i)if(h=t.orderLineItems.find(function(t){return t.id===i}))return h}var a=t.orderLineItems.filter(function(t){return t.variant.id===n.id})||[];if(r.productOptionSetId)for(var o=U(r),s=a.filter(function(t){var n;return(null===(n=t.options)||void 0===n?void 0:n.length)===o.length})||[],u=0,c=s;u<c.length;u++){if((h=c[u]).options){for(var d=!0,l=function(t){var n=t.values.map(function(t){return t.value}),r=null===(e=o.find(function(n){return n.productOptionId===t.productOptionId}))||void 0===e?void 0:e.values;if(!(d=d&&n.length===(null==r?void 0:r.length)&&n.every(function(t){return null==r?void 0:r.includes(t)})))return"break"},f=0,v=h.options;f<v.length;f++){if("break"===l(v[f]))break}if(d){if(!n.bundleSettings)return h;if(j(n,h))return h}}}else if(n.bundleSettings)for(var p=0,m=a;p<m.length;p++){var h=m[p];if(j(n,h))return h}}function L(t,n){return _(t,u(n),n)}function j(t,n){var r,e=null===(r=t.bundleSettings)||void 0===r?void 0:r.products,i=n.variant.bundleProducts;return!!e&&((null==e?void 0:e.length)===(null==i?void 0:i.length)&&(null==e?void 0:e.every(function(t){return!!(null==i?void 0:i.find(function(n){return n.id===t.id&&n.quantity===t.quantity&&t.product&&n.variant.id===u(t.product).id}))})))}function w(r,e){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return[4,import("../../api/cart/index.js")];case 1:return[4,(0,n.sent().apiSaveCartCouponCode)({cartId:r.id,couponCode:e})];case 2:return(t=n.sent()).isSuccess&&t.data&&(i.cart=t.data),[2,{success:t.isSuccess,response:t}]}})})}function P(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,w(r,null)];case 1:return[2,t.sent()]}})})}function T(t){t.cart&&0===s(t.cart)&&C(t)}function q(){return t(this,void 0,void 0,function(){var t,r,o,s,u,c;return n(this,function(n){switch(n.label){case 0:if(!("undefined"!=typeof localStorage))return[2];n.label=1;case 1:return n.trys.push([1,8,9,10]),i.isCartLoading=!0,[4,v(a)];case 2:return n.sent(),t=null===(u=a.customer)||void 0===u?void 0:u.id,(r=(null===(c=i.cart)||void 0===c?void 0:c.id)||localStorage.getItem(e))||t?[4,import("../../api/cart/index.js")]:[2];case 3:return[4,(0,n.sent().apiGetCartById)({id:r})];case 4:return(o=n.sent()).isSuccess&&o.data?[4,E(o.data)]:[3,6];case 5:return n.sent(),[3,7];case 6:if(o.isCancelled||o.isNetworkError)return[2];C(i),n.label=7;case 7:return[3,10];case 8:return s=n.sent(),console.log(s),[3,10];case 9:return i.isCartLoading=!1,i.isCartInitialLoadFinished=!0,[7];case 10:return[2]}})})}function x(t){var n=t.filter(function(t){return t.isSelected&&!d(t)}).map(function(t){return{campaignOfferId:t.campaignOfferId,campaignOfferProductId:t.campaignOfferProductId,productId:t.product.id,quantity:t.quantity,variantId:u(t.product).id}})||[];return n.length?n:void 0}function A(e,i){return t(this,arguments,void 0,function(t,e,i){var a,o,s,c,d,l,f,v,p,h,I,g,y,b,C;return void 0===i&&(i=1),n(this,function(t){switch(t.label){case 0:return t.trys.push([0,4,,5]),a=r.salesChannelId,o=r.storefrontThemeId,a&&o?(s=u(e))?[4,m(s,e,i,{isPayWithIkas:!0})]:[2,{success:!1,error:"No variant selected"}]:[2,{success:!1,error:"Missing storefront configuration"}];case 1:return(c=t.sent()).success&&(null===(p=null===(v=c.response)||void 0===v?void 0:v.data)||void 0===p?void 0:p.id)?(d=c.response.data.id,[4,import("../../api/cart/index.js")]):[2,{success:!1,error:(null===(g=null===(I=null===(h=c.response)||void 0===h?void 0:h.graphQLErrors)||void 0===I?void 0:I[0])||void 0===g?void 0:g.message)||"Failed to create cart"}];case 2:return[4,(0,t.sent().apiCreatePayWithIkasSessionUrl)({cartId:d})];case 3:return!(l=t.sent()).data||(null===(y=l.graphQLErrors)||void 0===y?void 0:y.length)?[2,{success:!1,error:(null===(C=null===(b=l.graphQLErrors)||void 0===b?void 0:b[0])||void 0===C?void 0:C.message)||"Failed to create Pay with ikas session"}]:[2,{success:!0,payUrl:l.data.payUrl,expiresAt:l.data.expiresAt}];case 4:return f=t.sent(),console.log("error",f),[2,{success:!1,error:f instanceof Error?f.message:"Unknown error occurred"}];case 5:return[2]}})})}function E(r){return t(this,void 0,void 0,function(){return n(this,function(t){return localStorage.setItem(e,r.id),i.cart=r,[2]})})}function k(){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return t=localStorage.getItem(e),!i.cart||t?[3,1]:(C(i),[3,3]);case 1:return i.cart||!t?[3,3]:[4,q()];case 2:n.sent(),n.label=3;case 3:return[2]}})})}function F(t){if(t&&t.options){for(var n=[],r=0,e=t.options;r<e.length;r++){var i=e[r],a={productOptionId:i.productOptionId,productOptionsSetId:i.productOptionsSetId,values:i.values.map(function(t){return t.value})};n.push(a)}return n}return null}function U(t){var n,r=[],e=new Set,i=function(t){var n;e.has(t.id)||(e.add(t.id),t.values.length&&r.push({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values}),null===(n=t.childOptions)||void 0===n||n.forEach(i))};return null===(n=t.productOptionSet)||void 0===n||n.options.filter(function(t){return!t.requiredOptionId}).forEach(i),r}function Q(e){return t(this,void 0,void 0,function(){var t,a,s,u,c,d,l,f,v,p,m;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,k()];case 1:return n.sent(),t=e.itemId?null===(v=i.cart)||void 0===v?void 0:v.orderLineItems.find(function(t){return t.id===e.itemId}):null,[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(p=i.cart)||void 0===p?void 0:p.id)||null,item:{id:e.itemId||null,quantity:e.quantity,variant:{id:e.variantId}},priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc"),_ga:o("_ga")}}})];case 3:return(a=n.sent()).isSuccess&&a.data?(e.itemId||(s=(null===(m=i.cart)||void 0===m?void 0:m.orderLineItems.map(function(t){return t.id}))||[],u=a.data.orderLineItems.map(function(t){return t.id}),(c=u.find(function(t){return!s.includes(t)}))&&(t=a.data.orderLineItems.find(function(t){return t.id===c}))),[4,E(a.data)]):[3,5];case 4:n.sent(),n.label=5;case 5:return i.cart&&t?(d="".concat(i.cart.id,"-").concat(i.cart.updatedAt),(l=e.quantity)>e.quantity?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(t,l-e.quantity,i.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(t,e.quantity-l,d,i.cart),n.label=9;case 9:return T(i),[2,{success:a.isSuccess,response:a}];case 10:return f=n.sent(),console.log(f),[2,{success:!1}];case 11:return[2]}})})}function N(t){var n;return!!t.cart&&(null===(n=t.cart.orderLineItems)||void 0===n?void 0:n.length)>0}export{m as addItemToCart,h as addSelectedtedVariantToCart,g as changeCartItemQuantity,I as changeItemQuantity,A as createPayWithIkasSession,_ as findExistingCartItem,L as findExistingCartItemWithProduct,x as getAcceptedOffers,q as getCart,p as getCheckoutUrlFromCartStore,N as hasCart,y as isOrderLineItemAutoCreated,C as removeCart,P as removeCouponCode,b as removeItem,w as saveCouponCode,E as setCart,S as waitForCartStoreInit,Q as windowAddToCart};
|
|
1
|
+
import{__awaiter as t,__generator as n}from'./../../../ext/tslib/tslib.es6.mjs.js';import{IkasStorefrontConfig as r}from"../../../packages/storefront-config/src/index.js";import{CART_LS_KEY as e,cartStore as i}from"../../../stores/cart/index.js";import{customerStore as a}from"../../../stores/customer/index.js";import{getCookieValue as o}from"../../../utils/helper.js";import{getIkasOrderDistinctItemCount as s}from"../../models/order/index.js";import{getSelectedProductVariant as u,hasProductValidOptionValues as c}from"../../models/product/index.js";import{isProductOfferAccepted as d}from"../../models/product/campaign-offer/index.js";import{initProductOptionSetValues as l}from"../../models/product/option-set/index.js";import{hasProductVariantStock as f}from"../../models/product/variant/index.js";import{waitForCustomerStoreInit as v}from"../customer/index.js";function p(t){var n,e=null===(n=t.cart)||void 0===n?void 0:n.id;if(e){var i=r.getCurrentRouting();return"".concat((null==i?void 0:i.path)?"/".concat(i.path):"","/checkout?id=").concat(e,"&step=info")}return""}function m(a,s){return t(this,arguments,void 0,function(t,a,s,d){var v,p,m,h,g,b,y,C,S,L,j,w,x,P,T,q,E;return void 0===s&&(s=1),n(this,function(n){switch(n.label){case 0:v=null!==(w=null==d?void 0:d.isPayWithIkas)&&void 0!==w&&w,n.label=1;case 1:return n.trys.push([1,10,,11]),v||!a.productOptionSetId||a.productOptionSet?c(a)?f(t)||t.sellIfOutOfStock?(p=void 0,v?[3,3]:[4,F()]):[2,{success:!1,validationError:"INSUFFICIENT_STOCK"}]:[2,{success:!1,validationError:"INVALID_PRODUCT_OPTION_VALUES"}]:[2,{success:!1,validationError:"INVALID_PRODUCT_OPTION_VALUES"}];case 2:if(n.sent(),i.cart&&(p=_(i.cart,t,a))){if(a.productOptionSet&&l(a.productOptionSet),!t.bundleSettings)return[2,I(p,p.quantity+s,a.offers,a)];if(!O())return[2,I(p,p.quantity+s,a.offers,a)]}n.label=3;case 3:return m=Q(a),h=s,(null==(g=null===(x=a.salesChannels)||void 0===x?void 0:x.find(function(t){return t.id===r.salesChannelId}))?void 0:g.minQuantityPerCart)&&s<g.minQuantityPerCart&&(h=g.minQuantityPerCart),(null==g?void 0:g.maxQuantityPerCart)&&s>g.maxQuantityPerCart&&(h=g.maxQuantityPerCart),b=v?null:(null===(P=i.cart)||void 0===P?void 0:P.id)||localStorage.getItem(e),[4,import("../../api/cart/index.js")];case 4:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:b,item:{id:null!==(T=null==p?void 0:p.id)&&void 0!==T?T:null,quantity:null!==(q=null==p?void 0:p.quantity)&&void 0!==q?q:h,variant:{id:t.id,name:a.name,bundleProducts:null===(E=t.bundleSettings)||void 0===E?void 0:E.products.map(function(t){var n;return{id:t.id,productId:(null===(n=t.product)||void 0===n?void 0:n.id)||"",variantId:t.product?u(t.product).id:"",quantity:t.quantity}})}},acceptedOffers:A(a.offers),options:m.length?m:null,priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc"),_ga:o("_ga")}}})];case 5:return y=n.sent(),v?[3,7]:y.isSuccess&&y.data?[4,k(y.data)]:[3,7];case 6:n.sent(),n.label=7;case 7:return(C=v?y.data:i.cart)?(S="".concat(C.id,"-").concat(C.updatedAt),(L=C.orderLineItems.find(function(n){return n.variant.id===t.id}))?[4,import("../../../analytics/analytics-functions/addToCart.js")]:[3,9]):[3,9];case 8:(0,n.sent().anl_addToCart)(L,s,S,C,a),n.label=9;case 9:return a.productOptionSet&&l(a.productOptionSet),[2,{success:y.isSuccess,response:y}];case 10:return j=n.sent(),console.log(j),[2,{success:!1}];case 11:return[2]}})})}function h(r){return t(this,arguments,void 0,function(t,r){return void 0===r&&(r=1),n(this,function(n){switch(n.label){case 0:return[4,m(u(t),t,r)];case 1:return[2,n.sent()]}})})}function I(e,a,s,u){return t(this,void 0,void 0,function(){var t,c,d,l,f,v;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,F()];case 1:return n.sent(),[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(f=i.cart)||void 0===f?void 0:f.id)||null,item:{id:e.id,quantity:a,variant:{id:e.variant.id,name:e.variant.name,bundleProducts:null===(v=e.variant.bundleProducts)||void 0===v?void 0:v.map(function(t){return{id:t.id,productId:t.variant.productId||"",variantId:t.variant.id||"",quantity:t.quantity}})}},acceptedOffers:s?A(s):void 0,options:U(e),priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc"),_ga:o("_ga")}}})];case 3:return(t=n.sent()).isSuccess&&t.data?[4,k(t.data)]:[3,5];case 4:n.sent(),n.label=5;case 5:return i.cart?(c="".concat(i.cart.id,"-").concat(i.cart.updatedAt),(d=e.quantity)>a?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(e,d-a,i.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(e,a-d,c,i.cart,u),n.label=9;case 9:return T(i),[2,{success:t.isSuccess,response:t}];case 10:return l=n.sent(),console.log(l),[2,{success:!1}];case 11:return[2]}})})}function g(r,e,i,a,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,I(e,i,a,o)];case 1:return[2,t.sent()]}})})}function b(t,n){for(var r=0,e=(null==t?void 0:t.orderAdjustments)||[];r<e.length;r++)for(var i=0,a=e[r].appliedOrderLines||[];i<a.length;i++){var o=a[i];if(o.orderLineId===n.id)return o.isAutoCreated||!1}return!1}function y(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,I(r,0)];case 1:return[2,t.sent()]}})})}function C(t){localStorage.removeItem(e),t.cart=null}function S(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,new Promise(function(t){var n=setInterval(function(){r.isCartInitialLoadFinished&&(clearInterval(n),t(null))},100)})];case 1:return[2,t.sent()]}})})}function O(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("editLineID")||""}function _(t,n,r){var e;if(!r.productOptionSetId&&!n.bundleSettings)return t.orderLineItems.find(function(t){return t.variant.id===n.id});if(n.bundleSettings){var i=O();if(i)if(h=t.orderLineItems.find(function(t){return t.id===i}))return h}var a=t.orderLineItems.filter(function(t){return t.variant.id===n.id})||[];if(r.productOptionSetId)for(var o=Q(r),s=a.filter(function(t){var n;return(null===(n=t.options)||void 0===n?void 0:n.length)===o.length})||[],u=0,c=s;u<c.length;u++){if((h=c[u]).options){for(var d=!0,l=function(t){var n=t.values.map(function(t){return t.value}),r=null===(e=o.find(function(n){return n.productOptionId===t.productOptionId}))||void 0===e?void 0:e.values;if(!(d=d&&n.length===(null==r?void 0:r.length)&&n.every(function(t){return null==r?void 0:r.includes(t)})))return"break"},f=0,v=h.options;f<v.length;f++){if("break"===l(v[f]))break}if(d){if(!n.bundleSettings)return h;if(j(n,h))return h}}}else if(n.bundleSettings)for(var p=0,m=a;p<m.length;p++){var h=m[p];if(j(n,h))return h}}function L(t,n){return _(t,u(n),n)}function j(t,n){var r,e=null===(r=t.bundleSettings)||void 0===r?void 0:r.products,i=n.variant.bundleProducts;return!!e&&((null==e?void 0:e.length)===(null==i?void 0:i.length)&&(null==e?void 0:e.every(function(t){return!!(null==i?void 0:i.find(function(n){return n.id===t.id&&n.quantity===t.quantity&&t.product&&n.variant.id===u(t.product).id}))})))}function w(r,e){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return[4,import("../../api/cart/index.js")];case 1:return[4,(0,n.sent().apiSaveCartCouponCode)({cartId:r.id,couponCode:e})];case 2:return(t=n.sent()).isSuccess&&t.data&&(i.cart=t.data),[2,{success:t.isSuccess,response:t}]}})})}function x(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,w(r,null)];case 1:return[2,t.sent()]}})})}function P(r,e){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return[4,import("../../api/cart/index.js")];case 1:return[4,(0,n.sent().apiRemoveGiftCardFromCart)({cartId:r.id,giftCardId:e})];case 2:return(t=n.sent()).isSuccess&&t.data&&(i.cart=t.data),[2,{success:t.isSuccess,response:t}]}})})}function T(t){t.cart&&0===s(t.cart)&&C(t)}function q(){return t(this,void 0,void 0,function(){var t,r,o,s,u,c;return n(this,function(n){switch(n.label){case 0:if(!("undefined"!=typeof localStorage))return[2];n.label=1;case 1:return n.trys.push([1,8,9,10]),i.isCartLoading=!0,[4,v(a)];case 2:return n.sent(),t=null===(u=a.customer)||void 0===u?void 0:u.id,(r=(null===(c=i.cart)||void 0===c?void 0:c.id)||localStorage.getItem(e))||t?[4,import("../../api/cart/index.js")]:[2];case 3:return[4,(0,n.sent().apiGetCartById)({id:r})];case 4:return(o=n.sent()).isSuccess&&o.data?[4,k(o.data)]:[3,6];case 5:return n.sent(),[3,7];case 6:if(o.isCancelled||o.isNetworkError)return[2];C(i),n.label=7;case 7:return[3,10];case 8:return s=n.sent(),console.log(s),[3,10];case 9:return i.isCartLoading=!1,i.isCartInitialLoadFinished=!0,[7];case 10:return[2]}})})}function A(t){var n=t.filter(function(t){return t.isSelected&&!d(t)}).map(function(t){return{campaignOfferId:t.campaignOfferId,campaignOfferProductId:t.campaignOfferProductId,productId:t.product.id,quantity:t.quantity,variantId:u(t.product).id}})||[];return n.length?n:void 0}function E(e,i){return t(this,arguments,void 0,function(t,e,i){var a,o,s,c,d,l,f,v,p,h,I,g,b,y,C;return void 0===i&&(i=1),n(this,function(t){switch(t.label){case 0:return t.trys.push([0,4,,5]),a=r.salesChannelId,o=r.storefrontThemeId,a&&o?(s=u(e))?[4,m(s,e,i,{isPayWithIkas:!0})]:[2,{success:!1,error:"No variant selected"}]:[2,{success:!1,error:"Missing storefront configuration"}];case 1:return(c=t.sent()).success&&(null===(p=null===(v=c.response)||void 0===v?void 0:v.data)||void 0===p?void 0:p.id)?(d=c.response.data.id,[4,import("../../api/cart/index.js")]):[2,{success:!1,error:(null===(g=null===(I=null===(h=c.response)||void 0===h?void 0:h.graphQLErrors)||void 0===I?void 0:I[0])||void 0===g?void 0:g.message)||"Failed to create cart"}];case 2:return[4,(0,t.sent().apiCreatePayWithIkasSessionUrl)({cartId:d})];case 3:return!(l=t.sent()).data||(null===(b=l.graphQLErrors)||void 0===b?void 0:b.length)?[2,{success:!1,error:(null===(C=null===(y=l.graphQLErrors)||void 0===y?void 0:y[0])||void 0===C?void 0:C.message)||"Failed to create Pay with ikas session"}]:[2,{success:!0,payUrl:l.data.payUrl,expiresAt:l.data.expiresAt}];case 4:return f=t.sent(),console.log("error",f),[2,{success:!1,error:f instanceof Error?f.message:"Unknown error occurred"}];case 5:return[2]}})})}function k(r){return t(this,void 0,void 0,function(){return n(this,function(t){return localStorage.setItem(e,r.id),i.cart=r,[2]})})}function F(){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return t=localStorage.getItem(e),!i.cart||t?[3,1]:(C(i),[3,3]);case 1:return i.cart||!t?[3,3]:[4,q()];case 2:n.sent(),n.label=3;case 3:return[2]}})})}function U(t){if(t&&t.options){for(var n=[],r=0,e=t.options;r<e.length;r++){var i=e[r],a={productOptionId:i.productOptionId,productOptionsSetId:i.productOptionsSetId,values:i.values.map(function(t){return t.value})};n.push(a)}return n}return null}function Q(t){var n,r=[],e=new Set,i=function(t){var n;e.has(t.id)||(e.add(t.id),t.values.length&&r.push({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values}),null===(n=t.childOptions)||void 0===n||n.forEach(i))};return null===(n=t.productOptionSet)||void 0===n||n.options.filter(function(t){return!t.requiredOptionId}).forEach(i),r}function N(e){return t(this,void 0,void 0,function(){var t,a,s,u,c,d,l,f,v,p,m;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,F()];case 1:return n.sent(),t=e.itemId?null===(v=i.cart)||void 0===v?void 0:v.orderLineItems.find(function(t){return t.id===e.itemId}):null,[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(p=i.cart)||void 0===p?void 0:p.id)||null,item:{id:e.itemId||null,quantity:e.quantity,variant:{id:e.variantId}},priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc"),_ga:o("_ga")}}})];case 3:return(a=n.sent()).isSuccess&&a.data?(e.itemId||(s=(null===(m=i.cart)||void 0===m?void 0:m.orderLineItems.map(function(t){return t.id}))||[],u=a.data.orderLineItems.map(function(t){return t.id}),(c=u.find(function(t){return!s.includes(t)}))&&(t=a.data.orderLineItems.find(function(t){return t.id===c}))),[4,k(a.data)]):[3,5];case 4:n.sent(),n.label=5;case 5:return i.cart&&t?(d="".concat(i.cart.id,"-").concat(i.cart.updatedAt),(l=e.quantity)>e.quantity?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(t,l-e.quantity,i.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(t,e.quantity-l,d,i.cart),n.label=9;case 9:return T(i),[2,{success:a.isSuccess,response:a}];case 10:return f=n.sent(),console.log(f),[2,{success:!1}];case 11:return[2]}})})}function D(t){var n;return!!t.cart&&(null===(n=t.cart.orderLineItems)||void 0===n?void 0:n.length)>0}export{m as addItemToCart,h as addSelectedtedVariantToCart,g as changeCartItemQuantity,I as changeItemQuantity,E as createPayWithIkasSession,_ as findExistingCartItem,L as findExistingCartItemWithProduct,A as getAcceptedOffers,q as getCart,p as getCheckoutUrlFromCartStore,D as hasCart,b as isOrderLineItemAutoCreated,C as removeCart,x as removeCouponCode,P as removeGiftCardLine,y as removeItem,w as saveCouponCode,k as setCart,S as waitForCartStoreInit,N as windowAddToCart};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ListLoyaltyProgramPointHistoryQueryParams, SaveCustomerFormDataInput, UseLoyaltyPointsQueryParams } from "../../../storefront-api/src";
|
|
2
2
|
import { APIResponse } from "../../../storefront-api-client/src";
|
|
3
|
-
import { AccountInfoForm, AddressForm, ContactForm, CouponCodeForm, ForgotPasswordForm, IkasContactForm, IkasCustomer, IkasCustomerAddress, IkasCustomerAttributeValue, IkasCustomerReviewForm, IkasFavoriteProduct, IkasOrder, IkasOrderTransaction, IkasProduct, IkasProductFile, LoginForm, NewsletterSubscriptionForm, OrderTrackingForm, RecoverPasswordForm, RegisterForm, SmsLoginForm, VerifyPhoneNumberForm } from "../../../storefront-models/src";
|
|
3
|
+
import { AccountInfoForm, AddressForm, ContactForm, CouponCodeForm, DeactivateCustomerForm, ForgotPasswordForm, IkasContactForm, IkasCustomer, IkasCustomerAddress, IkasCustomerAttributeValue, IkasCustomerReviewForm, IkasFavoriteProduct, IkasOrder, IkasOrderTransaction, IkasProduct, IkasProductFile, LoginForm, NewsletterSubscriptionForm, OrderTrackingForm, RecoverPasswordForm, RegisterForm, SmsLoginForm, VerifyPhoneNumberForm } from "../../../storefront-models/src";
|
|
4
4
|
import { IkasCustomerStore } from "../../../stores/customer";
|
|
5
5
|
import { IkasLoginError, IkasRegisterError } from "../../api/customer";
|
|
6
6
|
export type SocialLoginProvider = "facebook" | "google" | "twitch" | "miles_smiles";
|
|
@@ -24,6 +24,42 @@ export type SocialLoginProvider = "facebook" | "google" | "twitch" | "miles_smil
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export declare function initCustomerStore(customerStore: IkasCustomerStore): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* The already-restored session of another store instance, as plain data. `null` means that
|
|
29
|
+
* instance settled as a guest (or failed) — the seeded store then settles as a guest too.
|
|
30
|
+
*/
|
|
31
|
+
export type CustomerSessionSnapshot = {
|
|
32
|
+
customer: IkasCustomer;
|
|
33
|
+
favoriteProducts?: IkasFavoriteProduct[];
|
|
34
|
+
} | null;
|
|
35
|
+
/**
|
|
36
|
+
* Initialize the customer store from a session another store instance already restored, instead
|
|
37
|
+
* of restoring it again. A page can run two copies of this SDK (a host theme and an embedded
|
|
38
|
+
* component bundle); both share one localStorage session, so letting each copy run
|
|
39
|
+
* `initCustomerStore` duplicates the refresh-token and get-customer requests and double-counts
|
|
40
|
+
* the visit analytics event. The copy that restored the session hands its result over as plain
|
|
41
|
+
* data; this seeds the other copy with no network traffic at all.
|
|
42
|
+
*
|
|
43
|
+
* The token is still read from localStorage rather than taken from the snapshot: the restoring
|
|
44
|
+
* copy's refresh already persisted the rotated token there, and `loadToken` also wires it into
|
|
45
|
+
* this copy's API client config.
|
|
46
|
+
*
|
|
47
|
+
* `requiredCustomerFields` is the version-skew escape hatch. The snapshot's customer was fetched
|
|
48
|
+
* by the OTHER copy's get-customer query, which froze when that copy was built — so a snapshot
|
|
49
|
+
* from a much older copy can lack fields this copy's components rely on. Keys are checked for
|
|
50
|
+
* PRESENCE (`in`), not truthiness: a field the query asked for arrives even when null. When one
|
|
51
|
+
* is missing, this copy runs its own customer fetch — one request, and only against stale peers;
|
|
52
|
+
* an up-to-date peer's snapshot carries every key and stays at zero. If that fetch fails, the
|
|
53
|
+
* partially seeded customer is kept: stale data a page can render beats none.
|
|
54
|
+
*/
|
|
55
|
+
export declare function seedCustomerSession(customerStore: IkasCustomerStore, snapshot: CustomerSessionSnapshot, requiredCustomerFields?: string[]): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Reset this store's session state locally — no network, no analytics, no cart mutation. This is
|
|
58
|
+
* NOT `logout` (which revokes the session and fires the logout side effects); it is for the other
|
|
59
|
+
* SDK copy on the page, whose `logout` already did all of that, to bring this copy in line.
|
|
60
|
+
* Idempotent, and safe to call on a store that never held a session.
|
|
61
|
+
*/
|
|
62
|
+
export declare function clearCustomerSession(customerStore: IkasCustomerStore): void;
|
|
27
63
|
/**
|
|
28
64
|
* Check whether a customer is eligible to create an email subscription.
|
|
29
65
|
*
|
|
@@ -908,7 +944,7 @@ export declare function sendReview(customerStore: IkasCustomerStore, input: Ikas
|
|
|
908
944
|
* Deactivate (delete) the current customer's account after password verification.
|
|
909
945
|
*
|
|
910
946
|
* @ai-category Customer, Account
|
|
911
|
-
* @ai-related hasCustomer, logout
|
|
947
|
+
* @ai-related hasCustomer, logout, getDeactivateCustomerForm
|
|
912
948
|
*
|
|
913
949
|
* @param customerStore - The customer store instance
|
|
914
950
|
* @param password - The customer's current password for verification
|
|
@@ -1421,6 +1457,68 @@ export declare function getCouponCodeForm(customerStore: IkasCustomerStore): Cou
|
|
|
1421
1457
|
* ```
|
|
1422
1458
|
*/
|
|
1423
1459
|
export declare function clearCouponCodeForm(customerStore: IkasCustomerStore): void;
|
|
1460
|
+
/**
|
|
1461
|
+
* Get or initialize the deactivate customer form with validation for deleting the current customer's account.
|
|
1462
|
+
*
|
|
1463
|
+
* @ai-category Customer, Account
|
|
1464
|
+
* @ai-related clearDeactivateCustomerForm, deactivateCustomer
|
|
1465
|
+
*
|
|
1466
|
+
* @param customerStore - The customer store instance
|
|
1467
|
+
* @returns The deactivate customer form object with validated fields
|
|
1468
|
+
*
|
|
1469
|
+
* @example
|
|
1470
|
+
* ```typescript
|
|
1471
|
+
* import {
|
|
1472
|
+
* customerStore,
|
|
1473
|
+
* getDeactivateCustomerForm,
|
|
1474
|
+
* setDeactivateCustomerFormPassword,
|
|
1475
|
+
* submitDeactivateCustomerForm,
|
|
1476
|
+
* logout,
|
|
1477
|
+
* } from "@ikas/bp-storefront";
|
|
1478
|
+
*
|
|
1479
|
+
* function DeleteAccountPage() {
|
|
1480
|
+
* const form = getDeactivateCustomerForm(customerStore);
|
|
1481
|
+
*
|
|
1482
|
+
* const handleSubmit = async () => {
|
|
1483
|
+
* const isSuccess = await submitDeactivateCustomerForm(form);
|
|
1484
|
+
* if (isSuccess) {
|
|
1485
|
+
* await logout(customerStore);
|
|
1486
|
+
* Router.navigateToPage("INDEX");
|
|
1487
|
+
* }
|
|
1488
|
+
* };
|
|
1489
|
+
*
|
|
1490
|
+
* return (
|
|
1491
|
+
* <form>
|
|
1492
|
+
* <input
|
|
1493
|
+
* type="password"
|
|
1494
|
+
* value={form.password.value}
|
|
1495
|
+
* onChange={e => setDeactivateCustomerFormPassword(form, e.target.value)}
|
|
1496
|
+
* />
|
|
1497
|
+
* <button onClick={handleSubmit}>Delete Account</button>
|
|
1498
|
+
* </form>
|
|
1499
|
+
* );
|
|
1500
|
+
* }
|
|
1501
|
+
* ```
|
|
1502
|
+
*/
|
|
1503
|
+
export declare function getDeactivateCustomerForm(customerStore: IkasCustomerStore): DeactivateCustomerForm;
|
|
1504
|
+
/**
|
|
1505
|
+
* Clear the cached deactivate customer form, forcing a fresh form on next retrieval.
|
|
1506
|
+
*
|
|
1507
|
+
* @ai-category Customer, Account
|
|
1508
|
+
* @ai-related getDeactivateCustomerForm
|
|
1509
|
+
*
|
|
1510
|
+
* @param customerStore - The customer store instance
|
|
1511
|
+
*
|
|
1512
|
+
* @example
|
|
1513
|
+
* ```typescript
|
|
1514
|
+
* import { customerStore, clearDeactivateCustomerForm } from "@ikas/bp-storefront";
|
|
1515
|
+
*
|
|
1516
|
+
* function handleDeactivateCustomerReset() {
|
|
1517
|
+
* clearDeactivateCustomerForm(customerStore);
|
|
1518
|
+
* }
|
|
1519
|
+
* ```
|
|
1520
|
+
*/
|
|
1521
|
+
export declare function clearDeactivateCustomerForm(customerStore: IkasCustomerStore): void;
|
|
1424
1522
|
/**
|
|
1425
1523
|
* Get or initialize the forgot password form with validation for requesting a password reset.
|
|
1426
1524
|
*
|