@ikas/storefront 4.0.0-beta.3 → 4.0.0-beta.5

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{__awaiter as t,__generator as e}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import n from"./api.js";import{IkasStorefrontConfig as r}from"@ikas/storefront-config";import{Analytics as o}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{SaveCartInput as s}from"@ikas/storefront-api";var a,c="cartId",u=function(){function c(c){var u=this;this.cart=null,this._isLoadingCart=!1,this._isCartLoadFinished=!1,this.addItem=function(i,s,c){return void 0===c&&(c=1),t(u,void 0,void 0,(function(){var t,u,d,l,h,v,f,p,I,m;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),s.hasValidProductOptionValues?i.hasStock||i.sellIfOutOfStock?[4,this.beforeCartOperationCheck()]:[2,{success:!1,validationError:a.INSUFFICIENT_STOCK}]:[2,{success:!1,validationError:a.INVALID_PRODUCT_OPTION_VALUES}];case 1:return e.sent(),this.cart&&(t=this.findExistingItem(i,s))?(null===(p=s.productOptionSet)||void 0===p||p.initOptionValues(),[2,this.changeItemQuantity(t,t.quantity+1)]):(u=this.getOptionValues(s),d=(null===(I=this.cart)||void 0===I?void 0:I.id)||localStorage.getItem("cartId"),[4,n.addItemToCart({input:{cartId:d,item:{id:null,quantity:c,variant:{id:i.id,name:s.name}},options:u.length?u:null,priceListId:r.getPriceListId()||null,salesChannelId:r.getSalesChannelId(),storefrontThemeId:r.getStorefrontThemeId()}})]);case 2:return(l=e.sent()).isSuccess&&l.data?[4,this.setCart(l.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(h="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(v=this.cart.items.find((function(t){return t.variant.id===i.id})))&&o.addToCart(v,c,h,this.cart)),null===(m=s.productOptionSet)||void 0===m||m.initOptionValues(),[2,{success:l.isSuccess,response:l}];case 5:return f=e.sent(),console.log(f),[2,{success:!1}];case 6:return[2]}}))}))},this.changeItemQuantity=function(i,s){return t(u,void 0,void 0,(function(){var t,a,c,u,d;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(),[4,n.addItemToCart({input:{cartId:(null===(d=this.cart)||void 0===d?void 0:d.id)||null,item:{id:i.id,quantity:s,variant:{id:i.variant.id,name:i.variant.name}},options:this.createCartLineOptions(i),priceListId:r.getPriceListId()||null,salesChannelId:r.getSalesChannelId(),storefrontThemeId:r.getStorefrontThemeId()}})];case 2:return(t=e.sent()).isSuccess&&t.data?[4,this.setCart(t.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.removeCardIfEmpty(),this.cart&&(a="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(c=i.quantity)>s?o.removeFromCart(i,c-s,this.cart):o.addToCart(i,s-c,a,this.cart)),[2,{success:t.isSuccess}];case 5:return u=e.sent(),console.log(u),[2,{success:!1}];case 6:return[2]}}))}))},this.removeItem=function(i){return t(u,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return[2,t.sent()]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),u.cart=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){u.isCartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.findExistingItem=function(t,e){var i,n,r,o,s;if(!e.productOptionSetId)return null===(i=u.cart)||void 0===i?void 0:i.orderLineItems.find((function(e){return e.variant.id===t.id}));for(var a=u.getOptionValues(e),c=(null===(n=u.cart)||void 0===n?void 0:n.orderLineItems.filter((function(e){var i;return e.variant.id===t.id&&(null===(i=e.options)||void 0===i?void 0:i.length)===a.length})))||[],d=0,l=c;d<l.length;d++){var h=l[d];if(h.options){for(var v=!0,f=function(t){var i=t.values.map((function(t){return t.value})),n=null===(s=null===(o=null===(r=e.productOptionSet)||void 0===r?void 0:r.options)||void 0===o?void 0:o.find((function(e){return e.id===t.productOptionId})))||void 0===s?void 0:s.values;if(!(v=v&&i.length===(null==n?void 0:n.length)&&i.every((function(t){return null==n?void 0:n.includes(t)}))))return"break"},p=0,I=h.options;p<I.length;p++){if("break"===f(I[p]))break}if(v)return h}}},this.saveCouponCode=function(i){return t(u,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,n.saveCartCouponCode({cartId:this.cart.id,couponCode:i})]:[2,{success:!1,validationError:a.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeCouponCode=function(){return t(u,void 0,void 0,(function(){return e(this,(function(t){return[2,this.saveCouponCode(null)]}))}))},this.saveCart=function(i){return t(u,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return t=new s(i),[4,n.saveCart({input:t})];case 1:return[2,{success:(r=e.sent()).isSuccess,response:r}]}}))}))},this.removeCardIfEmpty=function(){var t;0===(null===(t=u.cart)||void 0===t?void 0:t.itemCount)&&u.removeCart()},this.getCart=function(){return t(u,void 0,void 0,(function(){var t,i,r,o,s,a;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===(s=this.baseStore.customerStore.customer)||void 0===s?void 0:s.id,(i=(null===(a=this.cart)||void 0===a?void 0:a.id)||localStorage.getItem("cartId"))||t?[4,n.getCartById({id:i})]:[2];case 2:return(r=e.sent()).isSuccess&&r.data?[4,this.setCart(r.data)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return o=e.sent(),console.log(o),[3,8];case 7:return this._isLoadingCart=!1,this._isCartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(u,void 0,void 0,(function(){return e(this,(function(t){return localStorage.setItem("cartId",i.id),this.cart=i,[2]}))}))},this.beforeCartOperationCheck=function(){return t(u,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,n=t.options;i<n.length;i++){var r=n[i],o={productOptionId:r.productOptionId,productOptionsSetId:r.productOptionsSetId,values:r.values.map((function(t){return t.value}))};e.push(o)}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({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values})})),i},this.baseStore=c,i(this)}return Object.defineProperty(c.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"isCartLoadFinished",{get:function(){return this._isCartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"checkoutId",{get:function(){var t;return null===(t=this.cart)||void 0===t?void 0:t.id},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"checkoutUrl",{get:function(){if(this.checkoutId)return"/checkout?id=".concat(this.checkoutId,"&step=info")},enumerable:!1,configurable:!0}),c}();!function(t){t.INSUFFICIENT_STOCK="INSUFFICIENT_STOCK",t.INVALID_PRODUCT_OPTION_VALUES="INVALID_PRODUCT_OPTION_VALUES",t.EMPTY_CART="EMPTY_CART"}(a||(a={}));export{c as CART_LS_KEY,a as IkasCartOperationValidationError,u as IkasCartStore};
1
+ import{__awaiter as t,__generator as e}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import n from"./api.js";import{IkasStorefrontConfig as r}from"@ikas/storefront-config";import{Analytics as o}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{SaveCartInput as s}from"@ikas/storefront-api";var a,c="cartId",u=function(){function c(c){var u=this;this.cart=null,this._isLoadingCart=!1,this._isCartLoadFinished=!1,this.addItem=function(i,s,c){return void 0===c&&(c=1),t(u,void 0,void 0,(function(){var t,u,d,l,h,v,f,p,I,m;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),s.hasValidProductOptionValues?i.hasStock||i.sellIfOutOfStock?[4,this.beforeCartOperationCheck()]:[2,{success:!1,validationError:a.INSUFFICIENT_STOCK}]:[2,{success:!1,validationError:a.INVALID_PRODUCT_OPTION_VALUES}];case 1:return e.sent(),this.cart&&(t=this.findExistingItem(i,s))?(null===(p=s.productOptionSet)||void 0===p||p.initOptionValues(),[2,this.changeItemQuantity(t,t.quantity+1)]):(u=this.getOptionValues(s),d=(null===(I=this.cart)||void 0===I?void 0:I.id)||localStorage.getItem("cartId"),[4,n.addItemToCart({input:{cartId:d,item:{id:null,quantity:c,variant:{id:i.id,name:s.name}},options:u.length?u:null,priceListId:r.getPriceListId()||null,salesChannelId:r.getSalesChannelId(),storefrontThemeId:r.getStorefrontThemeId()}})]);case 2:return(l=e.sent()).isSuccess&&l.data?[4,this.setCart(l.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(h="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(v=this.cart.items.find((function(t){return t.variant.id===i.id})))&&o.addToCart(v,c,h,this.cart)),null===(m=s.productOptionSet)||void 0===m||m.initOptionValues(),[2,{success:l.isSuccess,response:l}];case 5:return f=e.sent(),console.log(f),[2,{success:!1}];case 6:return[2]}}))}))},this.changeItemQuantity=function(i,s){return t(u,void 0,void 0,(function(){var t,a,c,u,d;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(),[4,n.addItemToCart({input:{cartId:(null===(d=this.cart)||void 0===d?void 0:d.id)||null,item:{id:i.id,quantity:s,variant:{id:i.variant.id,name:i.variant.name}},options:this.createCartLineOptions(i),priceListId:r.getPriceListId()||null,salesChannelId:r.getSalesChannelId(),storefrontThemeId:r.getStorefrontThemeId()}})];case 2:return(t=e.sent()).isSuccess&&t.data?[4,this.setCart(t.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.removeCardIfEmpty(),this.cart&&(a="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(c=i.quantity)>s?o.removeFromCart(i,c-s,this.cart):o.addToCart(i,s-c,a,this.cart)),[2,{success:t.isSuccess,response:t}];case 5:return u=e.sent(),console.log(u),[2,{success:!1}];case 6:return[2]}}))}))},this.removeItem=function(i){return t(u,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return[2,t.sent()]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),u.cart=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){u.isCartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.findExistingItem=function(t,e){var i,n,r,o,s;if(!e.productOptionSetId)return null===(i=u.cart)||void 0===i?void 0:i.orderLineItems.find((function(e){return e.variant.id===t.id}));for(var a=u.getOptionValues(e),c=(null===(n=u.cart)||void 0===n?void 0:n.orderLineItems.filter((function(e){var i;return e.variant.id===t.id&&(null===(i=e.options)||void 0===i?void 0:i.length)===a.length})))||[],d=0,l=c;d<l.length;d++){var h=l[d];if(h.options){for(var v=!0,f=function(t){var i=t.values.map((function(t){return t.value})),n=null===(s=null===(o=null===(r=e.productOptionSet)||void 0===r?void 0:r.options)||void 0===o?void 0:o.find((function(e){return e.id===t.productOptionId})))||void 0===s?void 0:s.values;if(!(v=v&&i.length===(null==n?void 0:n.length)&&i.every((function(t){return null==n?void 0:n.includes(t)}))))return"break"},p=0,I=h.options;p<I.length;p++){if("break"===f(I[p]))break}if(v)return h}}},this.saveCouponCode=function(i){return t(u,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,n.saveCartCouponCode({cartId:this.cart.id,couponCode:i})]:[2,{success:!1,validationError:a.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeCouponCode=function(){return t(u,void 0,void 0,(function(){return e(this,(function(t){return[2,this.saveCouponCode(null)]}))}))},this.saveCart=function(i){return t(u,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return t=new s(i),[4,n.saveCart({input:t})];case 1:return[2,{success:(r=e.sent()).isSuccess,response:r}]}}))}))},this.removeCardIfEmpty=function(){var t;0===(null===(t=u.cart)||void 0===t?void 0:t.itemCount)&&u.removeCart()},this.getCart=function(){return t(u,void 0,void 0,(function(){var t,i,r,o,s,a;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===(s=this.baseStore.customerStore.customer)||void 0===s?void 0:s.id,(i=(null===(a=this.cart)||void 0===a?void 0:a.id)||localStorage.getItem("cartId"))||t?[4,n.getCartById({id:i})]:[2];case 2:return(r=e.sent()).isSuccess&&r.data?[4,this.setCart(r.data)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return o=e.sent(),console.log(o),[3,8];case 7:return this._isLoadingCart=!1,this._isCartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(u,void 0,void 0,(function(){return e(this,(function(t){return localStorage.setItem("cartId",i.id),this.cart=i,[2]}))}))},this.beforeCartOperationCheck=function(){return t(u,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,n=t.options;i<n.length;i++){var r=n[i],o={productOptionId:r.productOptionId,productOptionsSetId:r.productOptionsSetId,values:r.values.map((function(t){return t.value}))};e.push(o)}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({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values})})),i},this.baseStore=c,i(this)}return Object.defineProperty(c.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"isCartLoadFinished",{get:function(){return this._isCartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"checkoutId",{get:function(){var t;return null===(t=this.cart)||void 0===t?void 0:t.id},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"checkoutUrl",{get:function(){if(this.checkoutId)return"/checkout?id=".concat(this.checkoutId,"&step=info")},enumerable:!1,configurable:!0}),c}();!function(t){t.INSUFFICIENT_STOCK="INSUFFICIENT_STOCK",t.INVALID_PRODUCT_OPTION_VALUES="INVALID_PRODUCT_OPTION_VALUES",t.EMPTY_CART="EMPTY_CART"}(a||(a={}));export{c as CART_LS_KEY,a as IkasCartOperationValidationError,u as IkasCartStore};
@@ -46,7 +46,7 @@ export declare class IkasCustomerStore {
46
46
  waitUntilInitialized: () => Promise<unknown>;
47
47
  waitUntilCaptchaTokenInitialized: () => Promise<unknown>;
48
48
  setCaptchaToken: (token: string) => void;
49
- getCaptcha(): Promise<void>;
49
+ private getCaptcha;
50
50
  getRaffles: () => Promise<import("@ikas/fe-api-client").APIResponse<import("../../models/data").IkasRaffleParticipant[]>>;
51
51
  getCustomerAttributes: () => Promise<import("../../models/data").IkasCustomerAttribute[]>;
52
52
  getOrderByEmail: (email: string, orderNumber: string) => Promise<IkasOrder | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "4.0.0-beta.3",
3
+ "version": "4.0.0-beta.5",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -23,11 +23,11 @@
23
23
  "libphonenumber-js": "^1.10.6"
24
24
  },
25
25
  "devDependencies": {
26
- "@ikas/storefront-api": "^4.0.0-beta.3",
27
- "@ikas/storefront-config": "^4.0.0-beta.3",
28
- "@ikas/storefront-model-functions": "^4.0.0-beta.3",
29
- "@ikas/storefront-models": "^4.0.0-beta.3",
30
- "@ikas/storefront-providers": "^4.0.0-beta.3",
26
+ "@ikas/storefront-api": "^4.0.0-beta.5",
27
+ "@ikas/storefront-config": "^4.0.0-beta.5",
28
+ "@ikas/storefront-model-functions": "^4.0.0-beta.5",
29
+ "@ikas/storefront-models": "^4.0.0-beta.5",
30
+ "@ikas/storefront-providers": "^4.0.0-beta.5",
31
31
  "@rollup/plugin-commonjs": "^22.0.0",
32
32
  "@rollup/plugin-json": "^4.1.0",
33
33
  "@rollup/plugin-node-resolve": "^13.3.0",
@@ -48,22 +48,22 @@
48
48
  "ttypescript": "^1.5.12",
49
49
  "typescript": "^4.7.2",
50
50
  "typescript-transform-paths": "^2.2.2",
51
- "lodash": "^4.17.20",
51
+ "lodash": "^4.17.21",
52
52
  "html-react-parser": "^1.4.0",
53
53
  "query-string": "^6.13.8"
54
54
  },
55
55
  "peerDependencies": {
56
- "@ikas/storefront-api": "^4.0.0-beta.3",
57
- "@ikas/storefront-config": "^4.0.0-beta.3",
58
- "@ikas/storefront-model-functions": "^4.0.0-beta.3",
59
- "@ikas/storefront-models": "^4.0.0-beta.3",
60
- "@ikas/storefront-providers": "^4.0.0-beta.3",
56
+ "@ikas/storefront-api": "^4.0.0-beta.5",
57
+ "@ikas/storefront-config": "^4.0.0-beta.5",
58
+ "@ikas/storefront-model-functions": "^4.0.0-beta.5",
59
+ "@ikas/storefront-models": "^4.0.0-beta.5",
60
+ "@ikas/storefront-providers": "^4.0.0-beta.5",
61
61
  "mobx": "^6.1.3",
62
62
  "mobx-react-lite": "^3.1.5",
63
63
  "next": "12.2.0",
64
64
  "react": "17.0.2",
65
65
  "react-dom": "17.0.2",
66
- "lodash": "^4.17.20",
66
+ "lodash": "^4.17.21",
67
67
  "html-react-parser": "^1.4.0",
68
68
  "query-string": "^6.13.8"
69
69
  }