@ikas/storefront 2.0.68-alpha.1 → 2.0.68

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.
@@ -1 +1 @@
1
- import e from'../ext/strict-uri-encode/index.js';export{default}from"../node_modules/strict-uri-encode/index.js";
1
+ import o from'../ext/split-on-first/index.js';export{default}from"../node_modules/split-on-first/index.js";
@@ -1 +1 @@
1
- import o from'../ext/split-on-first/index.js';export{default}from"../node_modules/split-on-first/index.js";
1
+ import e from'../ext/strict-uri-encode/index.js';export{default}from"../node_modules/strict-uri-encode/index.js";
@@ -1,7 +1,5 @@
1
1
  import { IkasSaveItemToCartInput, IkasCart } from "../../models/data/cart";
2
- import { GraphQLError } from "graphql";
3
- export declare type SaveItemToCartCallbackType = (errors?: readonly GraphQLError[]) => void;
4
2
  export declare class IkasCartAPI {
5
- static saveItemToCart(input: IkasSaveItemToCartInput, callback?: SaveItemToCartCallbackType): Promise<IkasCart | undefined>;
3
+ static saveItemToCart(input: IkasSaveItemToCartInput): Promise<IkasCart | undefined>;
6
4
  static getCart(cartId?: string, customerId?: string): Promise<IkasCart | undefined>;
7
5
  }
@@ -1 +1 @@
1
- import{__awaiter as n,__generator as t,__makeTemplateObject as e}from'../../ext/tslib/tslib.es6.js';import{IkasCart as r}from"../../models/data/cart/index.js";import a from'../../ext/graphql-tag/src/index.js';import{apollo as o}from"../apollo.js";import{IkasStorefrontConfig as i}from"../../storefront/index.js";var d,u,s=function(){function s(){}return s.saveItemToCart=function(i,u){return n(this,void 0,void 0,(function(){var n,s,c,I,m,l;return t(this,(function(t){switch(t.label){case 0:n=a(d||(d=e(["\n mutation saveItemToCart($input: SaveItemToCartInput!) {\n saveItemToCart(input: $input) {\n id\n createdAt\n updatedAt\n dueDate\n currencyCode\n customerId\n merchantId\n itemCount\n totalPrice\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n taxLines {\n price\n rate\n }\n items {\n createdAt\n currencyCode\n deleted\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionsSetId\n productOptionId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n id\n name\n sku\n slug\n barcodeList\n mainImageId\n productId\n prices {\n buyPrice\n currency\n discountPrice\n sellPrice\n }\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n }\n }\n "],["\n mutation saveItemToCart($input: SaveItemToCartInput!) {\n saveItemToCart(input: $input) {\n id\n createdAt\n updatedAt\n dueDate\n currencyCode\n customerId\n merchantId\n itemCount\n totalPrice\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n taxLines {\n price\n rate\n }\n items {\n createdAt\n currencyCode\n deleted\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionsSetId\n productOptionId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n id\n name\n sku\n slug\n barcodeList\n mainImageId\n productId\n prices {\n buyPrice\n currency\n discountPrice\n sellPrice\n }\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n }\n }\n "]))),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.getClient().mutate({mutation:n,variables:{input:i}})];case 2:return s=t.sent(),c=s.data,(I=s.errors)&&I.length&&console.log(I),u&&u(I),c?[2,new r(c.saveItemToCart)]:[3,4];case 3:return m=t.sent(),console.log(m),u&&(l=null==m?void 0:m.graphQLErrors,u(l)),[3,4];case 4:return[2]}}))}))},s.getCart=function(d,s){return n(this,void 0,void 0,(function(){var n,c,I,m,l;return t(this,(function(t){switch(t.label){case 0:n=a(u||(u=e(["\n query getCart(\n $cartId: String\n $customerId: String\n $storefrontRoutingId: String\n ) {\n getCart(\n id: $cartId\n customerId: $customerId\n storefrontRoutingId: $storefrontRoutingId\n ) {\n createdAt\n currencyCode\n customerId\n dueDate\n id\n itemCount\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n items {\n createdAt\n currencyCode\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionId\n productOptionsSetId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n deleted\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n slug\n barcodeList\n id\n mainImageId\n name\n productId\n sku\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n merchantId\n status\n totalPrice\n updatedAt\n }\n }\n "],["\n query getCart(\n $cartId: String\n $customerId: String\n $storefrontRoutingId: String\n ) {\n getCart(\n id: $cartId\n customerId: $customerId\n storefrontRoutingId: $storefrontRoutingId\n ) {\n createdAt\n currencyCode\n customerId\n dueDate\n id\n itemCount\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n items {\n createdAt\n currencyCode\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionId\n productOptionsSetId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n deleted\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n slug\n barcodeList\n id\n mainImageId\n name\n productId\n sku\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n merchantId\n status\n totalPrice\n updatedAt\n }\n }\n "]))),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.getClient().query({query:n,variables:{cartId:d,customerId:s,storefrontRoutingId:i.storefrontRoutingId}})];case 2:return c=t.sent(),I=c.data,(m=c.errors)&&m.length&&console.log(m),I&&I.getCart?[2,new r(I.getCart)]:[3,4];case 3:return l=t.sent(),console.log(l),[3,4];case 4:return[2]}}))}))},s}();export{s as IkasCartAPI};
1
+ import{__awaiter as n,__generator as t,__makeTemplateObject as e}from'../../ext/tslib/tslib.es6.js';import{IkasCart as r}from"../../models/data/cart/index.js";import a from'../../ext/graphql-tag/src/index.js';import{apollo as o}from"../apollo.js";import{IkasStorefrontConfig as i}from"../../storefront/index.js";var d,u,s=function(){function s(){}return s.saveItemToCart=function(i){return n(this,void 0,void 0,(function(){var n,u,s,c,I;return t(this,(function(t){switch(t.label){case 0:n=a(d||(d=e(["\n mutation saveItemToCart($input: SaveItemToCartInput!) {\n saveItemToCart(input: $input) {\n id\n createdAt\n updatedAt\n dueDate\n currencyCode\n customerId\n merchantId\n itemCount\n totalPrice\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n taxLines {\n price\n rate\n }\n items {\n createdAt\n currencyCode\n deleted\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionsSetId\n productOptionId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n id\n name\n sku\n slug\n barcodeList\n mainImageId\n productId\n prices {\n buyPrice\n currency\n discountPrice\n sellPrice\n }\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n }\n }\n "],["\n mutation saveItemToCart($input: SaveItemToCartInput!) {\n saveItemToCart(input: $input) {\n id\n createdAt\n updatedAt\n dueDate\n currencyCode\n customerId\n merchantId\n itemCount\n totalPrice\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n taxLines {\n price\n rate\n }\n items {\n createdAt\n currencyCode\n deleted\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionsSetId\n productOptionId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n id\n name\n sku\n slug\n barcodeList\n mainImageId\n productId\n prices {\n buyPrice\n currency\n discountPrice\n sellPrice\n }\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n }\n }\n "]))),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.getClient().mutate({mutation:n,variables:{input:i}})];case 2:return u=t.sent(),s=u.data,(c=u.errors)&&c.length&&console.log(c),s?[2,new r(s.saveItemToCart)]:[3,4];case 3:return I=t.sent(),console.log(I),[3,4];case 4:return[2]}}))}))},s.getCart=function(d,s){return n(this,void 0,void 0,(function(){var n,c,I,m,l;return t(this,(function(t){switch(t.label){case 0:n=a(u||(u=e(["\n query getCart(\n $cartId: String\n $customerId: String\n $storefrontRoutingId: String\n ) {\n getCart(\n id: $cartId\n customerId: $customerId\n storefrontRoutingId: $storefrontRoutingId\n ) {\n createdAt\n currencyCode\n customerId\n dueDate\n id\n itemCount\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n items {\n createdAt\n currencyCode\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionId\n productOptionsSetId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n deleted\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n slug\n barcodeList\n id\n mainImageId\n name\n productId\n sku\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n merchantId\n status\n totalPrice\n updatedAt\n }\n }\n "],["\n query getCart(\n $cartId: String\n $customerId: String\n $storefrontRoutingId: String\n ) {\n getCart(\n id: $cartId\n customerId: $customerId\n storefrontRoutingId: $storefrontRoutingId\n ) {\n createdAt\n currencyCode\n customerId\n dueDate\n id\n itemCount\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n items {\n createdAt\n currencyCode\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionId\n productOptionsSetId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n deleted\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n slug\n barcodeList\n id\n mainImageId\n name\n productId\n sku\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n merchantId\n status\n totalPrice\n updatedAt\n }\n }\n "]))),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.getClient().query({query:n,variables:{cartId:d,customerId:s,storefrontRoutingId:i.storefrontRoutingId}})];case 2:return c=t.sent(),I=c.data,(m=c.errors)&&m.length&&console.log(m),I&&I.getCart?[2,new r(I.getCart)]:[3,4];case 3:return l=t.sent(),console.log(l),[3,4];case 4:return[2]}}))}))},s}();export{s as IkasCartAPI};
@@ -1,7 +1,6 @@
1
1
  import { IkasCart } from "../models/data/cart";
2
2
  import { IkasProductVariant, IkasOrderLineItem, IkasProduct } from "../models";
3
3
  import { IkasBaseStore } from "./base";
4
- import { SaveItemToCartCallbackType } from "src/api/cart";
5
4
  export declare const CART_LS_KEY = "cartId";
6
5
  export declare const CHECKOUT_LS_KEY = "checkoutId";
7
6
  export declare class IkasCartStore {
@@ -15,29 +14,8 @@ export declare class IkasCartStore {
15
14
  get cartLoadFinished(): boolean;
16
15
  get checkoutId(): string | null | undefined;
17
16
  get checkoutUrl(): string | undefined;
18
- /**
19
- * @async
20
- * @function addItem
21
- * @param variant
22
- * @param product
23
- * @param initialQuantity
24
- * @param {Function=} callback BREAKING CHANGE ALERT. will be deprecated in v3.0 -
25
- * you can use when you want catch and handle api errors.
26
- * for example max_quantity_per_cart_limit_reached
27
- * @returns {Promise<boolean>}
28
- */
29
- addItem: (variant: IkasProductVariant, product: IkasProduct, initialQuantity?: number, callback?: SaveItemToCartCallbackType | undefined) => Promise<boolean>;
30
- /**
31
- * @async
32
- * @function changeItemQuantity
33
- * @param item
34
- * @param quantity
35
- * @param {Function=} callback BREAKING CHANGE ALERT. will be deprecated in v3.0 -
36
- * you can use when you want catch and handle api errors.
37
- * for example max_quantity_per_cart_limit_reached
38
- * @returns {Promise<boolean>}
39
- */
40
- changeItemQuantity: (item: IkasOrderLineItem, quantity: number, callback?: SaveItemToCartCallbackType | undefined) => Promise<boolean>;
17
+ addItem: (variant: IkasProductVariant, product: IkasProduct, initialQuantity?: number) => Promise<boolean>;
18
+ changeItemQuantity: (item: IkasOrderLineItem, quantity: number) => Promise<boolean>;
41
19
  removeItem: (item: IkasOrderLineItem) => Promise<void>;
42
20
  removeCart: () => void;
43
21
  waitUntilInitialized: () => Promise<unknown>;
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e}from'../ext/tslib/tslib.es6.js';import"../api/blog/index.js";import"../api/brand/index.js";import{IkasCartAPI as i}from"../api/cart/index.js";import"../api/category/index.js";import{IkasCheckoutAPI as o}from"../api/checkout/index.js";import"../api/city/index.js";import"../api/country/index.js";import"../api/customer/index.js";import"../api/customer-review/index.js";import"../api/customer-review-summary/index.js";import"../api/district/index.js";import"../api/html-meta-data/index.js";import"../api/merchant/index.js";import"../api/product-search/index.js";import"../models/data/blog/index.js";import"../models/data/brand/index.js";import"../models/data/category/index.js";import"../models/data/checkout/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/index.js";import"../models/data/customer-review/index.js";import{makeAutoObservable as r}from"mobx";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/installment-info/index.js";import"../models/data/merchant-settings/index.js";import"../models/data/order/index.js";import"../models/data/order/line-item/index.js";import"../api/product-option-file/index.js";import"../models/data/product/index.js";import"../models/data/variant-type/index.js";import"../models/data/product/variant/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product-attribute/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product-filter/index.js";import"../models/data/variant-type/variant-value/index.js";import"../models/data/order-transaction/index.js";import"../models/data/product-option-set/index.js";import"../models/data/raffle/index.js";import"../models/data/product-campaing/campaign/index.js";import"../models/data/customer-attribute/index.js";import"../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import"../models/theme/theme.js";import"../models/theme/page/index.js";import"../models/theme/component/prop/index.js";import"../models/theme/page/component/prop-value/link.js";import"../models/ui/brand-list/index.js";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-detail/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/customer-review-summary-list/index.js";import"../models/ui/validator/index.js";import"../models/ui/validator/rules/index.js";import"../models/ui/validator/form/login.js";import"../models/ui/validator/form/address.js";import"../models/ui/validator/form/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import"../models/theme/settings/index.js";import"../models/theme/custom-data/index.js";import"../api/apollo.js";import"../api/favorite-product/index.js";import"../api/contact-form/index.js";import"../api/state/index.js";import"../api/product-option-set/index.js";import"../api/raffle/index.js";import"../api/back-in-stock-reminder/index.js";import"../api/product-campaign/index.js";import{Analytics as n}from"../analytics/analytics.js";import"../analytics/head/index.js";import{IkasStorefrontConfig as a}from"../storefront/index.js";import{IkasProductCartLineOption as s}from"../models/data/product-cart-item-options/index.js";var d="cartId",c="checkoutId",u=function(){function d(d){var c=this;this.cart=null,this._checkoutId=null,this._isLoadingCart=!1,this._cartLoadFinished=!1,this.addItem=function(o,r,s,d){return void 0===s&&(s=1),t(c,void 0,void 0,(function(){var t,c,u,l,m,p,h,v,f,j,I,g,x;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),r.canAddToCart?[4,this.beforeCartOperationCheck()]:[2,!1];case 1:return e.sent(),this.cart&&(t=this.findExistingItem(o,r))?(null===(f=r.productOptionSet)||void 0===f||f.initOptionValues(),[2,this.changeItemQuantity(t,t.quantity+1,d)]):(c=this.getOptionValues(r),u=(null===(j=this.cart)||void 0===j?void 0:j.id)||localStorage.getItem("cartId"),l={cartId:u,customerId:(null===(I=this.cart)||void 0===I?void 0:I.customerId)||(null===(g=this.baseStore.customerStore.customer)||void 0===g?void 0:g.id)||null,item:{id:null,quantity:s,variant:{id:o.id,name:r.name}},options:c.length?c:null,priceListId:a.priceListId||null,salesChannelId:a.salesChannelId,storefrontId:a.storefrontId,storefrontRoutingId:a.storefrontRoutingId,storefrontThemeId:a.storefrontThemeId},[4,i.saveItemToCart(l,d)]);case 2:return(m=e.sent())?[4,this.setCart(m)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(p="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(h=this.cart.items.find((function(t){return t.variant.id===o.id})))&&n.addToCart(h,s,p,this.cart)),null===(x=r.productOptionSet)||void 0===x||x.initOptionValues(),[2,!0];case 5:return v=e.sent(),console.log(v),[2,!1];case 6:return[2]}}))}))},this.changeItemQuantity=function(o,r,s){return t(c,void 0,void 0,(function(){var t,d,c,u,l,m,p,h;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,this.beforeCartOperationCheck()];case 1:return e.sent(),t={cartId:(null===(m=this.cart)||void 0===m?void 0:m.id)||null,customerId:(null===(p=this.cart)||void 0===p?void 0:p.customerId)||(null===(h=this.baseStore.customerStore.customer)||void 0===h?void 0:h.id)||null,item:{id:o.id,quantity:r,variant:{id:o.variant.id,name:o.variant.name}},options:this.createCartLineOptions(o),priceListId:a.priceListId||null,salesChannelId:a.salesChannelId,storefrontId:a.storefrontId,storefrontRoutingId:a.storefrontRoutingId,storefrontThemeId:a.storefrontThemeId},[4,i.saveItemToCart(t,s)];case 2:return(d=e.sent())?[4,this.setCart(d)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.removeCardIfEmpty(),this.cart&&(c="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(u=o.quantity)>r?n.removeFromCart(o,u-r,this.cart):n.addToCart(o,r-u,c,this.cart)),[2,!0];case 5:return l=e.sent(),console.log(l),[2,!1];case 6:return[2]}}))}))},this.removeItem=function(i){return t(c,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return t.sent(),[2]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),localStorage.removeItem("checkoutId"),c.cart=void 0,c._checkoutId=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){c.cartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.findExistingItem=function(t,e){var i,o,r,n,a;if(!e.productOptionSetId)return null===(i=c.cart)||void 0===i?void 0:i.items.find((function(e){return e.variant.id===t.id}));for(var s=c.getOptionValues(e),d=(null===(o=c.cart)||void 0===o?void 0:o.items.filter((function(e){var i;return e.variant.id===t.id&&(null===(i=e.options)||void 0===i?void 0:i.length)===s.length})))||[],u=0,l=d;u<l.length;u++){var m=l[u];if(m.options){for(var p=!0,h=function(t){var i=t.values.map((function(t){return t.value})),o=null===(a=null===(n=null===(r=e.productOptionSet)||void 0===r?void 0:r.options)||void 0===n?void 0:n.find((function(e){return e.id===t.productOptionId})))||void 0===a?void 0:a.values;if(!(p=p&&i.length===(null==o?void 0:o.length)&&i.every((function(t){return null==o?void 0:o.includes(t)}))))return"break"},v=0,f=m.options;v<f.length;v++){if("break"===h(f[v]))break}if(p)return m}}},this.removeCardIfEmpty=function(){var t;0===(null===(t=c.cart)||void 0===t?void 0:t.itemCount)&&c.removeCart()},this.getCart=function(){return t(c,void 0,void 0,(function(){var t,o,r,n,a,s;return e(this,(function(e){switch(e.label){case 0:if(!("undefined"!=typeof localStorage))return[2];e.label=1;case 1:return e.trys.push([1,6,7,8]),this._isLoadingCart=!0,t=null===(a=this.baseStore.customerStore.customer)||void 0===a?void 0:a.id,(o=(null===(s=this.cart)||void 0===s?void 0:s.id)||localStorage.getItem("cartId"))||t?[4,i.getCart(o||void 0)]:[2];case 2:return(r=e.sent())?[4,this.setCart(r)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return n=e.sent(),console.log(n),[3,8];case 7:return this._isLoadingCart=!1,this._cartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(c,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return localStorage.setItem("cartId",i.id),this.cart=i,this._checkoutId||(this._checkoutId=localStorage.getItem("checkoutId")||void 0),this._checkoutId?[3,2]:[4,o.getCheckoutId(i.id)];case 1:t=e.sent(),this._checkoutId=t,t&&localStorage.setItem("checkoutId",t),e.label=2;case 2:return[2]}}))}))},this.beforeCartOperationCheck=function(){return t(c,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return t=localStorage.getItem("cartId"),!this.cart||t?[3,1]:(this.removeCart(),[3,3]);case 1:return this.cart||!t?[3,3]:[4,this.getCart()];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},this.createCartLineOptions=function(t){if(t&&t.options){for(var e=[],i=0,o=t.options;i<o.length;i++){var r=o[i],n=new s({});n.productOptionId=r.productOptionId,n.productOptionsSetId=r.productOptionsSetId,n.values=r.values.map((function(t){return t.value})),e.push(n)}return e}return null},this.getOptionValues=function(t){var e,i=[];return null===(e=t.productOptionSet)||void 0===e||e.options.forEach((function(t){t.values.length&&i.push(new s({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values}))})),i},this.baseStore=d,r(this)}return Object.defineProperty(d.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"cartLoadFinished",{get:function(){return this._cartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"checkoutId",{get:function(){return this._checkoutId},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"checkoutUrl",{get:function(){if(this._checkoutId)return"/checkout?id=".concat(this._checkoutId,"&step=info")},enumerable:!1,configurable:!0}),d}();export{d as CART_LS_KEY,c as CHECKOUT_LS_KEY,u as IkasCartStore};
1
+ import{__awaiter as t,__generator as e}from'../ext/tslib/tslib.es6.js';import"../api/blog/index.js";import"../api/brand/index.js";import{IkasCartAPI as i}from"../api/cart/index.js";import"../api/category/index.js";import{IkasCheckoutAPI as o}from"../api/checkout/index.js";import"../api/city/index.js";import"../api/country/index.js";import"../api/customer/index.js";import"../api/customer-review/index.js";import"../api/customer-review-summary/index.js";import"../api/district/index.js";import"../api/html-meta-data/index.js";import"../api/merchant/index.js";import"../api/product-search/index.js";import"../models/data/blog/index.js";import"../models/data/brand/index.js";import"../models/data/category/index.js";import"../models/data/checkout/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/index.js";import"../models/data/customer-review/index.js";import{makeAutoObservable as r}from"mobx";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/installment-info/index.js";import"../models/data/merchant-settings/index.js";import"../models/data/order/index.js";import"../models/data/order/line-item/index.js";import"../api/product-option-file/index.js";import"../models/data/product/index.js";import"../models/data/variant-type/index.js";import"../models/data/product/variant/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product-attribute/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product-filter/index.js";import"../models/data/variant-type/variant-value/index.js";import"../models/data/order-transaction/index.js";import"../models/data/product-option-set/index.js";import"../models/data/raffle/index.js";import"../models/data/product-campaing/campaign/index.js";import"../models/data/customer-attribute/index.js";import"../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import"../models/theme/theme.js";import"../models/theme/page/index.js";import"../models/theme/component/prop/index.js";import"../models/theme/page/component/prop-value/link.js";import"../models/ui/brand-list/index.js";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-detail/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/customer-review-summary-list/index.js";import"../models/ui/validator/index.js";import"../models/ui/validator/rules/index.js";import"../models/ui/validator/form/login.js";import"../models/ui/validator/form/address.js";import"../models/ui/validator/form/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import"../models/theme/settings/index.js";import"../models/theme/custom-data/index.js";import"../api/apollo.js";import"../api/favorite-product/index.js";import"../api/contact-form/index.js";import"../api/state/index.js";import"../api/product-option-set/index.js";import"../api/raffle/index.js";import"../api/back-in-stock-reminder/index.js";import"../api/product-campaign/index.js";import{Analytics as n}from"../analytics/analytics.js";import"../analytics/head/index.js";import{IkasStorefrontConfig as a}from"../storefront/index.js";import{IkasProductCartLineOption as s}from"../models/data/product-cart-item-options/index.js";var d="cartId",c="checkoutId",u=function(){function d(d){var c=this;this.cart=null,this._checkoutId=null,this._isLoadingCart=!1,this._cartLoadFinished=!1,this.addItem=function(o,r,s){return void 0===s&&(s=1),t(c,void 0,void 0,(function(){var t,d,c,u,l,m,p,h,v,f,j,I,g;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),r.canAddToCart?[4,this.beforeCartOperationCheck()]:[2,!1];case 1:return e.sent(),this.cart&&(t=this.findExistingItem(o,r))?(null===(v=r.productOptionSet)||void 0===v||v.initOptionValues(),[2,this.changeItemQuantity(t,t.quantity+1)]):(d=this.getOptionValues(r),c=(null===(f=this.cart)||void 0===f?void 0:f.id)||localStorage.getItem("cartId"),u={cartId:c,customerId:(null===(j=this.cart)||void 0===j?void 0:j.customerId)||(null===(I=this.baseStore.customerStore.customer)||void 0===I?void 0:I.id)||null,item:{id:null,quantity:s,variant:{id:o.id,name:r.name}},options:d.length?d:null,priceListId:a.priceListId||null,salesChannelId:a.salesChannelId,storefrontId:a.storefrontId,storefrontRoutingId:a.storefrontRoutingId,storefrontThemeId:a.storefrontThemeId},[4,i.saveItemToCart(u)]);case 2:return(l=e.sent())?[4,this.setCart(l)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(m="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(p=this.cart.items.find((function(t){return t.variant.id===o.id})))&&n.addToCart(p,s,m,this.cart)),null===(g=r.productOptionSet)||void 0===g||g.initOptionValues(),[2,!0];case 5:return h=e.sent(),console.log(h),[2,!1];case 6:return[2]}}))}))},this.changeItemQuantity=function(o,r){return t(c,void 0,void 0,(function(){var t,s,d,c,u,l,m,p;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,this.beforeCartOperationCheck()];case 1:return e.sent(),t={cartId:(null===(l=this.cart)||void 0===l?void 0:l.id)||null,customerId:(null===(m=this.cart)||void 0===m?void 0:m.customerId)||(null===(p=this.baseStore.customerStore.customer)||void 0===p?void 0:p.id)||null,item:{id:o.id,quantity:r,variant:{id:o.variant.id,name:o.variant.name}},options:this.createCartLineOptions(o),priceListId:a.priceListId||null,salesChannelId:a.salesChannelId,storefrontId:a.storefrontId,storefrontRoutingId:a.storefrontRoutingId,storefrontThemeId:a.storefrontThemeId},[4,i.saveItemToCart(t)];case 2:return(s=e.sent())?[4,this.setCart(s)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.removeCardIfEmpty(),this.cart&&(d="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(c=o.quantity)>r?n.removeFromCart(o,c-r,this.cart):n.addToCart(o,r-c,d,this.cart)),[2,!0];case 5:return u=e.sent(),console.log(u),[2,!1];case 6:return[2]}}))}))},this.removeItem=function(i){return t(c,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return t.sent(),[2]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),localStorage.removeItem("checkoutId"),c.cart=void 0,c._checkoutId=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){c.cartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.findExistingItem=function(t,e){var i,o,r,n,a;if(!e.productOptionSetId)return null===(i=c.cart)||void 0===i?void 0:i.items.find((function(e){return e.variant.id===t.id}));for(var s=c.getOptionValues(e),d=(null===(o=c.cart)||void 0===o?void 0:o.items.filter((function(e){var i;return e.variant.id===t.id&&(null===(i=e.options)||void 0===i?void 0:i.length)===s.length})))||[],u=0,l=d;u<l.length;u++){var m=l[u];if(m.options){for(var p=!0,h=function(t){var i=t.values.map((function(t){return t.value})),o=null===(a=null===(n=null===(r=e.productOptionSet)||void 0===r?void 0:r.options)||void 0===n?void 0:n.find((function(e){return e.id===t.productOptionId})))||void 0===a?void 0:a.values;if(!(p=p&&i.length===(null==o?void 0:o.length)&&i.every((function(t){return null==o?void 0:o.includes(t)}))))return"break"},v=0,f=m.options;v<f.length;v++){if("break"===h(f[v]))break}if(p)return m}}},this.removeCardIfEmpty=function(){var t;0===(null===(t=c.cart)||void 0===t?void 0:t.itemCount)&&c.removeCart()},this.getCart=function(){return t(c,void 0,void 0,(function(){var t,o,r,n,a,s;return e(this,(function(e){switch(e.label){case 0:if(!("undefined"!=typeof localStorage))return[2];e.label=1;case 1:return e.trys.push([1,6,7,8]),this._isLoadingCart=!0,t=null===(a=this.baseStore.customerStore.customer)||void 0===a?void 0:a.id,(o=(null===(s=this.cart)||void 0===s?void 0:s.id)||localStorage.getItem("cartId"))||t?[4,i.getCart(o||void 0)]:[2];case 2:return(r=e.sent())?[4,this.setCart(r)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return n=e.sent(),console.log(n),[3,8];case 7:return this._isLoadingCart=!1,this._cartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(c,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return localStorage.setItem("cartId",i.id),this.cart=i,this._checkoutId||(this._checkoutId=localStorage.getItem("checkoutId")||void 0),this._checkoutId?[3,2]:[4,o.getCheckoutId(i.id)];case 1:t=e.sent(),this._checkoutId=t,t&&localStorage.setItem("checkoutId",t),e.label=2;case 2:return[2]}}))}))},this.beforeCartOperationCheck=function(){return t(c,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return t=localStorage.getItem("cartId"),!this.cart||t?[3,1]:(this.removeCart(),[3,3]);case 1:return this.cart||!t?[3,3]:[4,this.getCart()];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},this.createCartLineOptions=function(t){if(t&&t.options){for(var e=[],i=0,o=t.options;i<o.length;i++){var r=o[i],n=new s({});n.productOptionId=r.productOptionId,n.productOptionsSetId=r.productOptionsSetId,n.values=r.values.map((function(t){return t.value})),e.push(n)}return e}return null},this.getOptionValues=function(t){var e,i=[];return null===(e=t.productOptionSet)||void 0===e||e.options.forEach((function(t){t.values.length&&i.push(new s({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values}))})),i},this.baseStore=d,r(this)}return Object.defineProperty(d.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"cartLoadFinished",{get:function(){return this._cartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"checkoutId",{get:function(){return this._checkoutId},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"checkoutUrl",{get:function(){if(this._checkoutId)return"/checkout?id=".concat(this._checkoutId,"&step=info")},enumerable:!1,configurable:!0}),d}();export{d as CART_LS_KEY,c as CHECKOUT_LS_KEY,u as IkasCartStore};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "2.0.68-alpha.1",
3
+ "version": "2.0.68",
4
4
  "main": "./build/index.js",
5
5
  "module": "./build/index.js",
6
6
  "author": "Umut Ozan Yıldırım",