@ikas/bp-storefront 1.4.0-beta.22 → 1.4.0-beta.220
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/analytics/openai/addToCart.d.ts +2 -0
- package/dist/analytics/openai/addToCart.js +1 -0
- package/dist/analytics/openai/completeRegistration.d.ts +1 -0
- package/dist/analytics/openai/completeRegistration.js +1 -0
- package/dist/analytics/openai/contactForm.d.ts +1 -0
- package/dist/analytics/openai/contactForm.js +1 -0
- package/dist/analytics/openai/initAdvancedMatching.d.ts +12 -0
- package/dist/analytics/openai/initAdvancedMatching.js +1 -0
- package/dist/analytics/openai/pageView.d.ts +1 -0
- package/dist/analytics/openai/pageView.js +1 -0
- package/dist/analytics/openai/productView.d.ts +2 -0
- package/dist/analytics/openai/productView.js +1 -0
- package/dist/analytics/openai/utils.d.ts +26 -0
- package/dist/analytics/openai/utils.js +1 -0
- package/dist/analytics/utils.d.ts +1 -0
- package/dist/analytics/utils.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/api/customer/index.d.ts +10 -2
- package/dist/functions/api/customer/index.js +1 -1
- package/dist/functions/api/loyalty/index.d.ts +2 -1
- package/dist/functions/api/loyalty/index.js +1 -1
- package/dist/functions/api/product/index.js +1 -1
- package/dist/functions/models/attribute-detail/index.d.ts +3 -0
- package/dist/functions/models/attribute-list/index.d.ts +3 -0
- package/dist/functions/models/image/index.d.ts +71 -21
- package/dist/functions/models/image/index.js +1 -1
- package/dist/functions/models/index.d.ts +1 -0
- package/dist/functions/models/order/index.d.ts +139 -4
- package/dist/functions/models/order/index.js +1 -1
- package/dist/functions/models/product/attribute-value/index.d.ts +5 -0
- package/dist/functions/models/product/variant/index.d.ts +96 -6
- package/dist/functions/models/product/variant/index.js +1 -1
- package/dist/functions/models/product-list/index.js +1 -1
- package/dist/functions/models/validator/address/index.d.ts +70 -2
- 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 +322 -29
- package/dist/functions/stores/customer/index.js +1 -1
- package/dist/i18n/index.d.ts +14 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +1 -1
- package/dist/packages/storefront-api/src/__api/mutations/removeGiftCardFromCart.js +1 -0
- package/dist/packages/storefront-api/src/__api/mutations/unlinkExternalAccount.js +1 -0
- package/dist/packages/storefront-api/src/__api/queries/getExternalAccountLink.js +1 -0
- package/dist/packages/storefront-api/src/__api/queries/getLoyaltyProgram.js +1 -0
- package/dist/packages/storefront-api/src/__api/queries/getMilesSmilesDetails.js +1 -0
- package/dist/packages/storefront-api/src/__api/queries/getRefundableLines.js +1 -0
- package/dist/packages/storefront-api-client/src/utils/api.js +1 -1
- package/dist/packages/storefront-config/src/index.js +1 -1
- package/dist/packages/storefront-config/src/theme-globals.js +1 -0
- 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/mutations/unlinkExternalAccount.d.ts +6 -0
- package/dist/storefront-api/src/__api/queries/getExternalAccountLink.d.ts +6 -0
- package/dist/storefront-api/src/__api/queries/getLoyaltyProgram.d.ts +3 -0
- package/dist/storefront-api/src/__api/queries/getMilesSmilesDetails.d.ts +3 -0
- package/dist/storefront-api/src/__api/queries/getRefundableLines.d.ts +6 -0
- package/dist/storefront-api/src/__api/types/index.d.ts +101 -6
- package/dist/storefront-api-client/src/utils/api.d.ts +7 -0
- package/dist/storefront-config/src/index.d.ts +32 -0
- package/dist/storefront-config/src/theme-globals.d.ts +349 -0
- package/dist/storefront-models/src/index.d.ts +8 -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/color.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/loyalty-program/customer-info/index.d.ts +2 -0
- package/dist/storefront-models/src/models/loyalty-program/earning-method/index.d.ts +1 -0
- package/dist/storefront-models/src/models/loyalty-program/index.d.ts +1 -0
- package/dist/storefront-models/src/models/loyalty-program/point-history/index.d.ts +1 -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 +10 -0
- package/dist/storefront-models/src/models/order/line-item/index.d.ts +6 -1
- package/dist/storefront-models/src/models/order/package/index.d.ts +1 -1
- package/dist/storefront-models/src/models/order/refund/reason/index.d.ts +6 -0
- package/dist/storefront-models/src/models/order/refund/reason/translation/index.d.ts +4 -0
- package/dist/storefront-models/src/models/order/refund/refundable-line/index.d.ts +8 -0
- package/dist/storefront-models/src/models/order/refund/refundable-lines/index.d.ts +8 -0
- package/dist/storefront-models/src/models/order/refund/settings/translation/index.d.ts +4 -0
- package/dist/storefront-models/src/models/payment-gateway/index.d.ts +3 -1
- package/dist/storefront-models/src/models/product/attribute/index.d.ts +6 -1
- package/dist/storefront-models/src/models/product/campaign/data/index.d.ts +2 -0
- package/dist/storefront-models/src/models/product/campaign/filter/index.d.ts +1 -1
- package/dist/storefront-models/src/models/product/campaign/product-tiered-discount/index.d.ts +13 -0
- package/dist/storefront-models/src/models/product/image/index.d.ts +5 -0
- package/dist/storefront-models/src/models/product/variant/index.d.ts +17 -0
- package/dist/storefront-models/src/models/storefront/index.d.ts +1 -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/theme/settings/index.d.ts +51 -0
- package/dist/theme/settings/index.js +1 -0
- package/dist/utils/component-renderer.js +1 -1
- package/dist/utils/currency.d.ts +36 -3
- package/dist/utils/helper.d.ts +1 -0
- package/dist/utils/helper.js +1 -1
- package/dist/utils/pay-with-ikas.d.ts +552 -0
- package/dist/utils/pay-with-ikas.js +1 -0
- package/dist/utils/svg.d.ts +15 -0
- package/dist/utils/svg.js +1 -0
- package/package.json +1 -1
|
@@ -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";function v(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 p(a,s){return t(this,arguments,void 0,function(t,a,s,d){var v,p,m,I,g,y,b,C,L,_,j,w,P,T,x,k,U;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,E()]):[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=O(i.cart,t,a))){if(a.productOptionSet&&l(a.productOptionSet),!t.bundleSettings)return[2,h(p,p.quantity+s,a.offers,a)];if(!S())return[2,h(p,p.quantity+s,a.offers,a)]}n.label=3;case 3:return m=F(a),I=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&&(I=g.minQuantityPerCart),(null==g?void 0:g.maxQuantityPerCart)&&s>g.maxQuantityPerCart&&(I=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!==(x=null==p?void 0:p.id)&&void 0!==x?x:null,quantity:null!==(k=null==p?void 0:p.quantity)&&void 0!==k?k:I,variant:{id:t.id,name:a.name,bundleProducts:null===(U=t.bundleSettings)||void 0===U?void 0:U.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:q(a.offers),options:m.length?m:null,priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc")}}})];case 5:return b=n.sent(),v?[3,7]:b.isSuccess&&b.data?[4,A(b.data)]:[3,7];case 6:n.sent(),n.label=7;case 7:return(C=v?b.data:i.cart)?(L="".concat(C.id,"-").concat(C.updatedAt),(_=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)(_,s,L,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 m(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,p(u(t),t,r)];case 1:return[2,n.sent()]}})})}function h(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,E()];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?q(s):void 0,options:k(e),priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc")}}})];case 3:return(t=n.sent()).isSuccess&&t.data?[4,A(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 P(i),[2,{success:t.isSuccess,response:t}];case 10:return l=n.sent(),console.log(l),[2,{success:!1}];case 11:return[2]}})})}function I(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,h(e,i,a,o)];case 1:return[2,t.sent()]}})})}function g(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,h(r,0)];case 1:return[2,t.sent()]}})})}function b(t){localStorage.removeItem(e),t.cart=null}function C(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 S(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("editLineID")||""}function O(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=S();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=F(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(_(n,h))return h}}}else if(n.bundleSettings)for(var p=0,m=a;p<m.length;p++){var h=m[p];if(_(n,h))return h}}function L(t,n){return O(t,u(n),n)}function _(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 j(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 w(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,j(r,null)];case 1:return[2,t.sent()]}})})}function P(t){t.cart&&0===s(t.cart)&&b(t)}function T(){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,7,8,9]),i.isCartLoading=!0,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 2:return[4,(0,n.sent().apiGetCartById)({id:r})];case 3:return(o=n.sent()).isSuccess&&o.data?[4,A(o.data)]:[3,5];case 4:return n.sent(),[3,6];case 5:if(o.isCancelled||o.isNetworkError)return[2];b(i),n.label=6;case 6:return[3,9];case 7:return s=n.sent(),console.log(s),[3,9];case 8:return i.isCartLoading=!1,i.isCartInitialLoadFinished=!0,[7];case 9:return[2]}})})}function q(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 x(e,i){return t(this,arguments,void 0,function(t,e,i){var a,o,s,c,d,l,f,v,m,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,p(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===(m=null===(v=c.response)||void 0===v?void 0:v.data)||void 0===m?void 0:m.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 A(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 E(){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]:(b(i),[3,3]);case 1:return i.cart||!t?[3,3]:[4,T()];case 2:n.sent(),n.label=3;case 3:return[2]}})})}function k(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 F(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 U(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,E()];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")}}})];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,A(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 P(i),[2,{success:a.isSuccess,response:a}];case 10:return f=n.sent(),console.log(f),[2,{success:!1}];case 11:return[2]}})})}function Q(t){var n;return!!t.cart&&(null===(n=t.cart.orderLineItems)||void 0===n?void 0:n.length)>0}export{p as addItemToCart,m as addSelectedtedVariantToCart,I as changeCartItemQuantity,h as changeItemQuantity,x as createPayWithIkasSession,O as findExistingCartItem,L as findExistingCartItemWithProduct,q as getAcceptedOffers,T as getCart,v as getCheckoutUrlFromCartStore,Q as hasCart,g as isOrderLineItemAutoCreated,b as removeCart,w as removeCouponCode,y as removeItem,j as saveCouponCode,A as setCart,C as waitForCartStoreInit,U as windowAddToCart};
|
|
1
|
+
import{__awaiter as t,__generator as n,__assign as r}from'./../../../ext/tslib/tslib.es6.mjs.js';import{IkasStorefrontConfig as e}from"../../../packages/storefront-config/src/index.js";import{CART_LS_KEY as i,cartStore as a}from"../../../stores/cart/index.js";import{customerStore as o}from"../../../stores/customer/index.js";import{getCookieValue as s,getOpenAiAttributionMetadata as u}from"../../../utils/helper.js";import{getIkasOrderDistinctItemCount as c}from"../../models/order/index.js";import{getSelectedProductVariant as d,hasProductValidOptionValues as l}from"../../models/product/index.js";import{isProductOfferAccepted as f}from"../../models/product/campaign-offer/index.js";import{initProductOptionSetValues as v}from"../../models/product/option-set/index.js";import{hasProductVariantStock as p}from"../../models/product/variant/index.js";import{waitForCustomerStoreInit as m}from"../customer/index.js";function h(t){var n,r=null===(n=t.cart)||void 0===n?void 0:n.id;if(r){var i=e.getCurrentRouting();return"".concat((null==i?void 0:i.path)?"/".concat(i.path):"","/checkout?id=").concat(r,"&step=info")}return""}function I(o,c){return t(this,arguments,void 0,function(t,o,c,f){var m,h,I,g,y,C,S,O,_,w,x,P,T,q,A,E,F;return void 0===c&&(c=1),n(this,function(n){switch(n.label){case 0:m=null!==(P=null==f?void 0:f.isPayWithIkas)&&void 0!==P&&P,n.label=1;case 1:return n.trys.push([1,10,,11]),m||!o.productOptionSetId||o.productOptionSet?l(o)?p(t)||t.sellIfOutOfStock?(h=void 0,m?[3,3]:[4,Q()]):[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(),a.cart&&(h=j(a.cart,t,o))){if(o.productOptionSet&&v(o.productOptionSet),!t.bundleSettings)return[2,b(h,h.quantity+c,o.offers,o)];if(!L())return[2,b(h,h.quantity+c,o.offers,o)]}n.label=3;case 3:return I=D(o),g=c,(null==(y=null===(T=o.salesChannels)||void 0===T?void 0:T.find(function(t){return t.id===e.salesChannelId}))?void 0:y.minQuantityPerCart)&&c<y.minQuantityPerCart&&(g=y.minQuantityPerCart),(null==y?void 0:y.maxQuantityPerCart)&&c>y.maxQuantityPerCart&&(g=y.maxQuantityPerCart),C=m?null:(null===(q=a.cart)||void 0===q?void 0:q.id)||localStorage.getItem(i),[4,import("../../api/cart/index.js")];case 4:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:C,item:{id:null!==(A=null==h?void 0:h.id)&&void 0!==A?A:null,quantity:null!==(E=null==h?void 0:h.quantity)&&void 0!==E?E:g,variant:{id:t.id,name:o.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?d(t.product).id:"",quantity:t.quantity}})}},acceptedOffers:k(o.offers),options:I.length?I:null,priceListId:e.priceListId||null,salesChannelId:e.salesChannelId,storefrontThemeId:e.storefrontThemeId,metadata:r({_fbp:s("_fbp"),_fbc:s("_fbc"),_ga:s("_ga")},u())}})];case 5:return S=n.sent(),m?[3,7]:S.isSuccess&&S.data?[4,U(S.data)]:[3,7];case 6:n.sent(),n.label=7;case 7:return(O=m?S.data:a.cart)?(_="".concat(O.id,"-").concat(O.updatedAt),(w=O.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)(w,c,_,O,o),n.label=9;case 9:return o.productOptionSet&&v(o.productOptionSet),[2,{success:S.isSuccess,response:S}];case 10:return x=n.sent(),console.log(x),[2,{success:!1}];case 11:return[2]}})})}function g(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,I(d(t),t,r)];case 1:return[2,n.sent()]}})})}function b(i,o,c,d){return t(this,void 0,void 0,function(){var t,l,f,v,p,m;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,Q()];case 1:return n.sent(),[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(p=a.cart)||void 0===p?void 0:p.id)||null,item:{id:i.id,quantity:o,variant:{id:i.variant.id,name:i.variant.name,bundleProducts:null===(m=i.variant.bundleProducts)||void 0===m?void 0:m.map(function(t){return{id:t.id,productId:t.variant.productId||"",variantId:t.variant.id||"",quantity:t.quantity}})}},acceptedOffers:c?k(c):void 0,options:N(i),priceListId:e.priceListId||null,salesChannelId:e.salesChannelId,storefrontThemeId:e.storefrontThemeId,metadata:r({_fbp:s("_fbp"),_fbc:s("_fbc"),_ga:s("_ga")},u())}})];case 3:return(t=n.sent()).isSuccess&&t.data?[4,U(t.data)]:[3,5];case 4:n.sent(),n.label=5;case 5:return a.cart?(l="".concat(a.cart.id,"-").concat(a.cart.updatedAt),(f=i.quantity)>o?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(i,f-o,a.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(i,o-f,l,a.cart,d),n.label=9;case 9:return A(a),[2,{success:t.isSuccess,response:t}];case 10:return v=n.sent(),console.log(v),[2,{success:!1}];case 11:return[2]}})})}function y(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,b(e,i,a,o)];case 1:return[2,t.sent()]}})})}function C(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 S(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,b(r,0)];case 1:return[2,t.sent()]}})})}function O(t){localStorage.removeItem(i),t.cart=null}function _(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 L(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("editLineID")||""}function j(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=L();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=D(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(x(n,h))return h}}}else if(n.bundleSettings)for(var p=0,m=a;p<m.length;p++){var h=m[p];if(x(n,h))return h}}function w(t,n){return j(t,d(n),n)}function x(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===d(t.product).id}))})))}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().apiSaveCartCouponCode)({cartId:r.id,couponCode:e})];case 2:return(t=n.sent()).isSuccess&&t.data&&(a.cart=t.data),[2,{success:t.isSuccess,response:t}]}})})}function T(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,P(r,null)];case 1:return[2,t.sent()]}})})}function q(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&&(a.cart=t.data),[2,{success:t.isSuccess,response:t}]}})})}function A(t){t.cart&&0===c(t.cart)&&O(t)}function E(){return t(this,void 0,void 0,function(){var t,r,e,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]),a.isCartLoading=!0,[4,m(o)];case 2:return n.sent(),t=null===(u=o.customer)||void 0===u?void 0:u.id,(r=(null===(c=a.cart)||void 0===c?void 0:c.id)||localStorage.getItem(i))||t?[4,import("../../api/cart/index.js")]:[2];case 3:return[4,(0,n.sent().apiGetCartById)({id:r})];case 4:return(e=n.sent()).isSuccess&&e.data?[4,U(e.data)]:[3,6];case 5:return n.sent(),[3,7];case 6:if(e.isCancelled||e.isNetworkError)return[2];O(a),n.label=7;case 7:return[3,10];case 8:return s=n.sent(),console.log(s),[3,10];case 9:return a.isCartLoading=!1,a.isCartInitialLoadFinished=!0,[7];case 10:return[2]}})})}function k(t){var n=t.filter(function(t){return t.isSelected&&!f(t)}).map(function(t){return{campaignOfferId:t.campaignOfferId,campaignOfferProductId:t.campaignOfferProductId,productId:t.product.id,quantity:t.quantity,variantId:d(t.product).id}})||[];return n.length?n:void 0}function F(r,i){return t(this,arguments,void 0,function(t,r,i){var a,o,s,u,c,l,f,v,p,m,h,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=e.salesChannelId,o=e.storefrontThemeId,a&&o?(s=d(r))?[4,I(s,r,i,{isPayWithIkas:!0})]:[2,{success:!1,error:"No variant selected"}]:[2,{success:!1,error:"Missing storefront configuration"}];case 1:return(u=t.sent()).success&&(null===(p=null===(v=u.response)||void 0===v?void 0:v.data)||void 0===p?void 0:p.id)?(c=u.response.data.id,[4,import("../../api/cart/index.js")]):[2,{success:!1,error:(null===(g=null===(h=null===(m=u.response)||void 0===m?void 0:m.graphQLErrors)||void 0===h?void 0:h[0])||void 0===g?void 0:g.message)||"Failed to create cart"}];case 2:return[4,(0,t.sent().apiCreatePayWithIkasSessionUrl)({cartId:c})];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 U(r){return t(this,void 0,void 0,function(){return n(this,function(t){return localStorage.setItem(i,r.id),a.cart=r,[2]})})}function Q(){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return t=localStorage.getItem(i),!a.cart||t?[3,1]:(O(a),[3,3]);case 1:return a.cart||!t?[3,3]:[4,E()];case 2:n.sent(),n.label=3;case 3:return[2]}})})}function N(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 D(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 R(i){return t(this,void 0,void 0,function(){var t,o,c,d,l,f,v,p,m,h,I;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,Q()];case 1:return n.sent(),t=i.itemId?null===(m=a.cart)||void 0===m?void 0:m.orderLineItems.find(function(t){return t.id===i.itemId}):null,[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(h=a.cart)||void 0===h?void 0:h.id)||null,item:{id:i.itemId||null,quantity:i.quantity,variant:{id:i.variantId}},priceListId:e.priceListId||null,salesChannelId:e.salesChannelId,storefrontThemeId:e.storefrontThemeId,metadata:r({_fbp:s("_fbp"),_fbc:s("_fbc"),_ga:s("_ga")},u())}})];case 3:return(o=n.sent()).isSuccess&&o.data?(i.itemId||(c=(null===(I=a.cart)||void 0===I?void 0:I.orderLineItems.map(function(t){return t.id}))||[],d=o.data.orderLineItems.map(function(t){return t.id}),(l=d.find(function(t){return!c.includes(t)}))&&(t=o.data.orderLineItems.find(function(t){return t.id===l}))),[4,U(o.data)]):[3,5];case 4:n.sent(),n.label=5;case 5:return a.cart&&t?(f="".concat(a.cart.id,"-").concat(a.cart.updatedAt),(v=i.quantity)>i.quantity?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(t,v-i.quantity,a.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(t,i.quantity-v,f,a.cart),n.label=9;case 9:return A(a),[2,{success:o.isSuccess,response:o}];case 10:return p=n.sent(),console.log(p),[2,{success:!1}];case 11:return[2]}})})}function V(t){var n;return!!t.cart&&(null===(n=t.cart.orderLineItems)||void 0===n?void 0:n.length)>0}export{I as addItemToCart,g as addSelectedtedVariantToCart,y as changeCartItemQuantity,b as changeItemQuantity,F as createPayWithIkasSession,j as findExistingCartItem,w as findExistingCartItemWithProduct,k as getAcceptedOffers,E as getCart,h as getCheckoutUrlFromCartStore,V as hasCart,C as isOrderLineItemAutoCreated,O as removeCart,T as removeCouponCode,q as removeGiftCardLine,S as removeItem,P as saveCouponCode,U as setCart,_ as waitForCartStoreInit,R as windowAddToCart};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ListLoyaltyProgramPointHistoryQueryParams, SaveCustomerFormDataInput, UseLoyaltyPointsQueryParams } from "../../../storefront-api/src";
|
|
1
|
+
import type { ExternalAccountLink, ListLoyaltyProgramPointHistoryQueryParams, MilesSmilesDetailsResponse, 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
|
-
import { IkasLoginError, IkasRegisterError } from "../../api/customer";
|
|
6
|
-
export type SocialLoginProvider = "facebook" | "google" | "twitch"
|
|
5
|
+
import { IkasLoginError, IkasRefundRequestError, IkasRegisterError } from "../../api/customer";
|
|
6
|
+
export type SocialLoginProvider = "facebook" | "google" | "twitch";
|
|
7
7
|
/**
|
|
8
8
|
* Initialize the customer store by loading tokens, refreshing authentication, and fetching customer data.
|
|
9
9
|
*
|
|
@@ -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
|
*
|
|
@@ -156,6 +192,143 @@ export declare function handleSocialLogin(customerStore: IkasCustomerStore): Pro
|
|
|
156
192
|
* ```
|
|
157
193
|
*/
|
|
158
194
|
export declare function socialLoginToken(customerStore: IkasCustomerStore, token: string): Promise<boolean>;
|
|
195
|
+
/** Provider segment of the customer-service external-account endpoints (`/ms/miles_smiles/bind/*`). */
|
|
196
|
+
export declare const MILES_SMILES_PROVIDER: string;
|
|
197
|
+
/** Synthetic gateway code a Miles&Smiles SALE is written on. Never selectable at checkout. */
|
|
198
|
+
export declare const MILES_SMILES_PAYMENT_GATEWAY_CODE: string;
|
|
199
|
+
/** Synthetic gateway id of the Miles&Smiles SALE. Never send it as `paymentGatewayId`. */
|
|
200
|
+
export declare const MILES_SMILES_PAYMENT_GATEWAY_ID: string;
|
|
201
|
+
/**
|
|
202
|
+
* Start the Turkish Airlines Miles&Smiles account bind flow for the logged-in customer.
|
|
203
|
+
* Opens the THY login page in a popup; once THY confirms, the browser is sent to the
|
|
204
|
+
* ikas bind callback and lands back on `redirect` with `milesSmilesStatus` query params
|
|
205
|
+
* (see handleMilesSmilesBind). Binding is required before miles can be spent at checkout.
|
|
206
|
+
*
|
|
207
|
+
* @ai-category Customer, Miles&Smiles
|
|
208
|
+
* @ai-related handleMilesSmilesBind, getMilesSmilesLink, unlinkMilesSmiles, getMilesSmilesDetails
|
|
209
|
+
*
|
|
210
|
+
* @param customerStore - The customer store instance (customer must be logged in)
|
|
211
|
+
* @param redirect - Relative store path to land on after bind, e.g. "/account" or "/checkout?id=...&step=payment"
|
|
212
|
+
* @returns `isSuccess: true` when the bind hand-off started; otherwise an `errorCode`
|
|
213
|
+
* such as "AUTHORIZATION_REQUIRED" or "MILES_SMILES_LOGIN_CANCELLED_OR_FAILED"
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* import { customerStore, milesSmilesBind } from "@ikas/bp-storefront";
|
|
218
|
+
*
|
|
219
|
+
* async function onLinkClick() {
|
|
220
|
+
* const result = await milesSmilesBind(customerStore, "/account");
|
|
221
|
+
* if (!result.isSuccess) showToast(result.errorCode || "UNEXPECTED_ERROR");
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export declare function milesSmilesBind(customerStore: IkasCustomerStore, redirect?: string | null): Promise<MilesSmilesBindResult>;
|
|
226
|
+
/**
|
|
227
|
+
* Read the Miles&Smiles bind result from the current URL after THY redirects back
|
|
228
|
+
* (`?milesSmilesStatus=success` or `?milesSmilesStatus=fail&milesSmilesError=CODE`).
|
|
229
|
+
* Call this on the landing page (account or checkout). The params are removed from the
|
|
230
|
+
* URL so a refresh does not repeat the same message.
|
|
231
|
+
*
|
|
232
|
+
* @ai-category Customer, Miles&Smiles
|
|
233
|
+
* @ai-related milesSmilesBind, getMilesSmilesLink
|
|
234
|
+
*
|
|
235
|
+
* @param clear - Remove the params from the URL with history.replaceState (default: true)
|
|
236
|
+
* @returns The landing result, or null when the URL carries no bind result
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* import { handleMilesSmilesBind } from "@ikas/bp-storefront";
|
|
241
|
+
*
|
|
242
|
+
* useEffect(() => {
|
|
243
|
+
* const result = handleMilesSmilesBind();
|
|
244
|
+
* if (result?.status === "success") showToast("Miles&Smiles account linked");
|
|
245
|
+
* if (result?.status === "fail") showToast(result.errorCode || "Bind failed");
|
|
246
|
+
* }, []);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
export declare function handleMilesSmilesBind(clear?: boolean): HandleMilesSmilesBindReturnType | null;
|
|
250
|
+
/**
|
|
251
|
+
* Get the customer's durable Miles&Smiles link (TK membership number and link date).
|
|
252
|
+
* A link does not guarantee a live checkout session; when getMilesSmilesDetails returns
|
|
253
|
+
* MILES_SMILES_LOGIN_REQUIRED, run milesSmilesBind again.
|
|
254
|
+
*
|
|
255
|
+
* @ai-category Customer, Miles&Smiles
|
|
256
|
+
* @ai-related milesSmilesBind, unlinkMilesSmiles
|
|
257
|
+
*
|
|
258
|
+
* @param customerStore - The customer store instance
|
|
259
|
+
* @returns API response whose data is the link, or null when not linked
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* import { customerStore, getMilesSmilesLink } from "@ikas/bp-storefront";
|
|
264
|
+
*
|
|
265
|
+
* const response = await getMilesSmilesLink(customerStore);
|
|
266
|
+
* const tkNumber = response.data?.externalId;
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
export declare function getMilesSmilesLink(customerStore: IkasCustomerStore): Promise<APIResponse<ExternalAccountLink | null>>;
|
|
270
|
+
/**
|
|
271
|
+
* Remove the customer's Miles&Smiles link. Also clears the server-side checkout
|
|
272
|
+
* session token, so miles cannot be spent until the customer binds again.
|
|
273
|
+
*
|
|
274
|
+
* @ai-category Customer, Miles&Smiles
|
|
275
|
+
* @ai-related milesSmilesBind, getMilesSmilesLink
|
|
276
|
+
*
|
|
277
|
+
* @param customerStore - The customer store instance
|
|
278
|
+
* @returns API response whose data is true on success
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* import { customerStore, unlinkMilesSmiles } from "@ikas/bp-storefront";
|
|
283
|
+
*
|
|
284
|
+
* const response = await unlinkMilesSmiles(customerStore);
|
|
285
|
+
* if (response.isSuccess) showToast("Miles&Smiles link removed");
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
export declare function unlinkMilesSmiles(customerStore: IkasCustomerStore): Promise<APIResponse<boolean>>;
|
|
289
|
+
/**
|
|
290
|
+
* Get the Miles&Smiles balance and member details for the payment step.
|
|
291
|
+
* Requires a recent bind; MILES_SMILES_LOGIN_REQUIRED means the short-lived session
|
|
292
|
+
* expired and milesSmilesBind should be run again. MILES_SMILES_NOT_ENABLED and
|
|
293
|
+
* PAYMENT_GATEWAY_NOT_FOUND mean the Miles UI should be hidden.
|
|
294
|
+
*
|
|
295
|
+
* @ai-category Customer, Miles&Smiles
|
|
296
|
+
* @ai-related milesSmilesBind, getMilesSmilesLink
|
|
297
|
+
*
|
|
298
|
+
* @param customerStore - The customer store instance
|
|
299
|
+
* @returns API response whose data holds availableMiles, memberId, firstName and lastName
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* import { customerStore, getMilesSmilesDetails } from "@ikas/bp-storefront";
|
|
304
|
+
*
|
|
305
|
+
* const response = await getMilesSmilesDetails(customerStore);
|
|
306
|
+
* if (response.errorCodes.includes("MILES_SMILES_LOGIN_REQUIRED")) {
|
|
307
|
+
* await milesSmilesBind(customerStore, window.location.pathname + window.location.search);
|
|
308
|
+
* } else if (response.data) {
|
|
309
|
+
* console.log("Available miles:", response.data.availableMiles);
|
|
310
|
+
* }
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
export declare function getMilesSmilesDetails(customerStore: IkasCustomerStore): Promise<APIResponse<MilesSmilesDetailsResponse | undefined>>;
|
|
314
|
+
/**
|
|
315
|
+
* Check whether an order transaction is the Miles&Smiles leg of a multi-tender payment.
|
|
316
|
+
* Such rows are written on the synthetic MILES_SMILES gateway and are not refundable from the storefront.
|
|
317
|
+
*
|
|
318
|
+
* @ai-category Customer, Orders, Miles&Smiles
|
|
319
|
+
* @ai-related getOrderTransactions
|
|
320
|
+
*
|
|
321
|
+
* @param transaction - The order transaction to check
|
|
322
|
+
* @returns True when the transaction is a Miles&Smiles SALE
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* import { isMilesSmilesTransaction } from "@ikas/bp-storefront";
|
|
327
|
+
*
|
|
328
|
+
* const label = isMilesSmilesTransaction(tx) ? "Miles&Smiles" : tx.paymentGatewayName;
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export declare function isMilesSmilesTransaction(transaction: IkasOrderTransaction): boolean;
|
|
159
332
|
/**
|
|
160
333
|
* Delete a customer address from their address list.
|
|
161
334
|
*
|
|
@@ -182,11 +355,43 @@ export declare function socialLoginToken(customerStore: IkasCustomerStore, token
|
|
|
182
355
|
* ```
|
|
183
356
|
*/
|
|
184
357
|
export declare function deleteCustomerAddress(customerStore: IkasCustomerStore, address: IkasCustomerAddress): Promise<boolean>;
|
|
358
|
+
/**
|
|
359
|
+
* Submit a refund request for an order based on the refund quantities set on each line item,
|
|
360
|
+
* along with the selected refund reason id and refund reason note set on the order.
|
|
361
|
+
*
|
|
362
|
+
* @ai-category Customer
|
|
363
|
+
* @ai-related refundOrder, getOrder, setIkasOrderRefundReasonId, setIkasOrderRefundReason
|
|
364
|
+
*
|
|
365
|
+
* @param customerStore - The customer store instance
|
|
366
|
+
* @param order - The order to request a refund for
|
|
367
|
+
* @param email - Optional email address for guest order refunds
|
|
368
|
+
* @returns Object with isSuccess flag, errorCode on failure and the not allowed lines for REFUND_NOT_ALLOWED
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```typescript
|
|
372
|
+
* import { customerStore, createRefundRequest, getOrder } from "@ikas/bp-storefront";
|
|
373
|
+
*
|
|
374
|
+
* async function handleRefundRequest(orderId: string) {
|
|
375
|
+
* const order = await getOrder(customerStore, orderId);
|
|
376
|
+
* if (!order) return;
|
|
377
|
+
*
|
|
378
|
+
* const result = await createRefundRequest(customerStore, order);
|
|
379
|
+
* if (result.isSuccess) {
|
|
380
|
+
* showToast("Refund request submitted");
|
|
381
|
+
* } else if (result.errorCode === "REFUND_REASON_REQUIRED") {
|
|
382
|
+
* showToast("Please select a refund reason");
|
|
383
|
+
* } else {
|
|
384
|
+
* showToast("Refund request failed");
|
|
385
|
+
* }
|
|
386
|
+
* }
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
export declare function createRefundRequest(customerStore: IkasCustomerStore, order: IkasOrder, email?: string | null): Promise<IkasRefundRequestResult>;
|
|
185
390
|
/**
|
|
186
391
|
* Submit a refund request for an order based on the refund quantities set on each line item.
|
|
187
392
|
*
|
|
188
393
|
* @ai-category Customer
|
|
189
|
-
* @ai-related getOrder, getOrders, getOrderRefundSettings
|
|
394
|
+
* @ai-related createRefundRequest, getOrder, getOrders, getOrderRefundSettings
|
|
190
395
|
*
|
|
191
396
|
* @param customerStore - The customer store instance
|
|
192
397
|
* @param order - The order to request a refund for
|
|
@@ -908,7 +1113,7 @@ export declare function sendReview(customerStore: IkasCustomerStore, input: Ikas
|
|
|
908
1113
|
* Deactivate (delete) the current customer's account after password verification.
|
|
909
1114
|
*
|
|
910
1115
|
* @ai-category Customer, Account
|
|
911
|
-
* @ai-related hasCustomer, logout
|
|
1116
|
+
* @ai-related hasCustomer, logout, getDeactivateCustomerForm
|
|
912
1117
|
*
|
|
913
1118
|
* @param customerStore - The customer store instance
|
|
914
1119
|
* @param password - The customer's current password for verification
|
|
@@ -1276,6 +1481,26 @@ type HandleSocialLoginReturnType = {
|
|
|
1276
1481
|
status?: "fail" | "success";
|
|
1277
1482
|
message?: string;
|
|
1278
1483
|
};
|
|
1484
|
+
export type MilesSmilesBindResult = {
|
|
1485
|
+
isSuccess: boolean;
|
|
1486
|
+
/** Bind error code, e.g. AUTHORIZATION_REQUIRED, MILES_SMILES_LOGIN_CANCELLED_OR_FAILED, UNEXPECTED_ERROR. */
|
|
1487
|
+
errorCode?: string | null;
|
|
1488
|
+
};
|
|
1489
|
+
export type IkasRefundNotAllowedLine = {
|
|
1490
|
+
orderLineItemId: string;
|
|
1491
|
+
reason: string;
|
|
1492
|
+
};
|
|
1493
|
+
export type IkasRefundRequestResult = {
|
|
1494
|
+
isSuccess: boolean;
|
|
1495
|
+
errorCode?: IkasRefundRequestError;
|
|
1496
|
+
/** Lines that can not be refunded, only set when errorCode is REFUND_NOT_ALLOWED. */
|
|
1497
|
+
lines?: IkasRefundNotAllowedLine[];
|
|
1498
|
+
};
|
|
1499
|
+
export type HandleMilesSmilesBindReturnType = {
|
|
1500
|
+
status: "success" | "fail";
|
|
1501
|
+
/** milesSmilesError from the redirect, e.g. EXTERNAL_ACCOUNT_ALREADY_LINKED. */
|
|
1502
|
+
errorCode: string | null;
|
|
1503
|
+
};
|
|
1279
1504
|
/**
|
|
1280
1505
|
* Get or initialize the account info form with validation for updating customer profile details.
|
|
1281
1506
|
*
|
|
@@ -1421,6 +1646,68 @@ export declare function getCouponCodeForm(customerStore: IkasCustomerStore): Cou
|
|
|
1421
1646
|
* ```
|
|
1422
1647
|
*/
|
|
1423
1648
|
export declare function clearCouponCodeForm(customerStore: IkasCustomerStore): void;
|
|
1649
|
+
/**
|
|
1650
|
+
* Get or initialize the deactivate customer form with validation for deleting the current customer's account.
|
|
1651
|
+
*
|
|
1652
|
+
* @ai-category Customer, Account
|
|
1653
|
+
* @ai-related clearDeactivateCustomerForm, deactivateCustomer
|
|
1654
|
+
*
|
|
1655
|
+
* @param customerStore - The customer store instance
|
|
1656
|
+
* @returns The deactivate customer form object with validated fields
|
|
1657
|
+
*
|
|
1658
|
+
* @example
|
|
1659
|
+
* ```typescript
|
|
1660
|
+
* import {
|
|
1661
|
+
* customerStore,
|
|
1662
|
+
* getDeactivateCustomerForm,
|
|
1663
|
+
* setDeactivateCustomerFormPassword,
|
|
1664
|
+
* submitDeactivateCustomerForm,
|
|
1665
|
+
* logout,
|
|
1666
|
+
* } from "@ikas/bp-storefront";
|
|
1667
|
+
*
|
|
1668
|
+
* function DeleteAccountPage() {
|
|
1669
|
+
* const form = getDeactivateCustomerForm(customerStore);
|
|
1670
|
+
*
|
|
1671
|
+
* const handleSubmit = async () => {
|
|
1672
|
+
* const isSuccess = await submitDeactivateCustomerForm(form);
|
|
1673
|
+
* if (isSuccess) {
|
|
1674
|
+
* await logout(customerStore);
|
|
1675
|
+
* Router.navigateToPage("INDEX");
|
|
1676
|
+
* }
|
|
1677
|
+
* };
|
|
1678
|
+
*
|
|
1679
|
+
* return (
|
|
1680
|
+
* <form>
|
|
1681
|
+
* <input
|
|
1682
|
+
* type="password"
|
|
1683
|
+
* value={form.password.value}
|
|
1684
|
+
* onChange={e => setDeactivateCustomerFormPassword(form, e.target.value)}
|
|
1685
|
+
* />
|
|
1686
|
+
* <button onClick={handleSubmit}>Delete Account</button>
|
|
1687
|
+
* </form>
|
|
1688
|
+
* );
|
|
1689
|
+
* }
|
|
1690
|
+
* ```
|
|
1691
|
+
*/
|
|
1692
|
+
export declare function getDeactivateCustomerForm(customerStore: IkasCustomerStore): DeactivateCustomerForm;
|
|
1693
|
+
/**
|
|
1694
|
+
* Clear the cached deactivate customer form, forcing a fresh form on next retrieval.
|
|
1695
|
+
*
|
|
1696
|
+
* @ai-category Customer, Account
|
|
1697
|
+
* @ai-related getDeactivateCustomerForm
|
|
1698
|
+
*
|
|
1699
|
+
* @param customerStore - The customer store instance
|
|
1700
|
+
*
|
|
1701
|
+
* @example
|
|
1702
|
+
* ```typescript
|
|
1703
|
+
* import { customerStore, clearDeactivateCustomerForm } from "@ikas/bp-storefront";
|
|
1704
|
+
*
|
|
1705
|
+
* function handleDeactivateCustomerReset() {
|
|
1706
|
+
* clearDeactivateCustomerForm(customerStore);
|
|
1707
|
+
* }
|
|
1708
|
+
* ```
|
|
1709
|
+
*/
|
|
1710
|
+
export declare function clearDeactivateCustomerForm(customerStore: IkasCustomerStore): void;
|
|
1424
1711
|
/**
|
|
1425
1712
|
* Get or initialize the forgot password form with validation for requesting a password reset.
|
|
1426
1713
|
*
|
|
@@ -1868,35 +2155,41 @@ export declare function clearRegisterForm(customerStore: IkasCustomerStore): voi
|
|
|
1868
2155
|
/**
|
|
1869
2156
|
* Create and return a new, empty address form with validation, wrapped in MobX observability.
|
|
1870
2157
|
*
|
|
2158
|
+
* Use this to create an address; use `getIkasCustomerAddressForm(address)` to edit an existing
|
|
2159
|
+
* one. It starts `initAddressForm` internally but does not await it, so await `initAddressForm`
|
|
2160
|
+
* yourself when you need to know that the country layout (`addressFormat`) and the country/state/
|
|
2161
|
+
* city lists are ready to render.
|
|
2162
|
+
*
|
|
1871
2163
|
* @ai-category Customer, Address
|
|
1872
|
-
* @ai-related
|
|
2164
|
+
* @ai-related initAddressForm, submitAddressForm, getIkasCustomerAddressForm, deleteCustomerAddress
|
|
1873
2165
|
*
|
|
1874
2166
|
* @param customerStore - The customer store instance
|
|
1875
2167
|
* @returns A new observable address form object with validated fields
|
|
1876
2168
|
*
|
|
1877
2169
|
* @example
|
|
1878
|
-
* ```
|
|
1879
|
-
* import {
|
|
1880
|
-
*
|
|
1881
|
-
*
|
|
1882
|
-
*
|
|
1883
|
-
*
|
|
1884
|
-
*
|
|
1885
|
-
*
|
|
1886
|
-
*
|
|
1887
|
-
*
|
|
1888
|
-
*
|
|
1889
|
-
*
|
|
1890
|
-
*
|
|
1891
|
-
*
|
|
1892
|
-
*
|
|
1893
|
-
*
|
|
1894
|
-
*
|
|
1895
|
-
*
|
|
1896
|
-
*
|
|
1897
|
-
*
|
|
1898
|
-
*
|
|
1899
|
-
*
|
|
2170
|
+
* ```tsx
|
|
2171
|
+
* import {
|
|
2172
|
+
* customerStore,
|
|
2173
|
+
* getEmptyAddressForm,
|
|
2174
|
+
* initAddressForm,
|
|
2175
|
+
* setAddressFormAddressLine1,
|
|
2176
|
+
* submitAddressForm,
|
|
2177
|
+
* } from "@ikas/bp-storefront";
|
|
2178
|
+
*
|
|
2179
|
+
* // Create the form once, then await init before rendering the country-driven layout.
|
|
2180
|
+
* const [form] = useState(() => getEmptyAddressForm(customerStore));
|
|
2181
|
+
* const [isLoading, setIsLoading] = useState(true);
|
|
2182
|
+
* useEffect(() => {
|
|
2183
|
+
* initAddressForm(form).then(() => setIsLoading(false));
|
|
2184
|
+
* }, []);
|
|
2185
|
+
*
|
|
2186
|
+
* // Always go through the setters. Assigning `form.addressLine1.value` directly skips
|
|
2187
|
+
* // re-validation and the dependent-field resets the location setters perform.
|
|
2188
|
+
* setAddressFormAddressLine1(form, "123 Main Street");
|
|
2189
|
+
*
|
|
2190
|
+
* // submitAddressForm validates and saves the address onto the customer itself --
|
|
2191
|
+
* // do not hand-build a customer object and call saveCustomer for this.
|
|
2192
|
+
* const ok = await submitAddressForm(form);
|
|
1900
2193
|
* ```
|
|
1901
2194
|
*/
|
|
1902
2195
|
export declare function getEmptyAddressForm(customerStore: IkasCustomerStore): AddressForm;
|