@ikas/storefront 6.1.0-beta.272 → 6.1.0-beta.273

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 n}from'./../../../ext/tslib/tslib.es6.js';import*as e from"react";import{StorefrontWidgetSettingsStatusEnum as r,getStorefrontWidgetSettings as i,listEarningMethods as o,listLoyaltyProgramTiers as a,listSpendingMethodsByCartId as s,getLoyaltyCustomerInfo as u,listLoyaltyProgramPointHistory as c,useLoyaltyPoints as d,removeLoyaltyPointsFromCart as l}from"@ikas/storefront-api";import{IkasStorefrontConfig as f}from"@ikas/storefront-config";import{IkasBaseStore as v}from"../../../store/base.js";import"../../../store/customer/index.js";import"../../../store/cart/index.js";import g from"../../../store/product/index.js";import h from"../../../store/category/index.js";import m from"../../../store/brand/index.js";import{resolveStoreUrl as y}from"./common.js";import{formatCurrency as p}from"../../../utils/currency.js";import"lodash/get";function w(e){var r,y=this,w=v.getInstance(),S=function(){var t;return null===(t=w.cartStore.cart)||void 0===t?void 0:t.id},b=function(t){var n,e=null!==(n=null==t?void 0:t.themeSettingsJson)&&void 0!==n?n:t;if(!e)throw new Error("Loyalty widget settings not found");if("string"==typeof e)try{return JSON.parse(e)}catch(t){throw new Error("Loyalty widget settings format is invalid")}return e};return{getLoyaltyWidget:function(){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return e?[2,b(e)]:[4,i()];case 1:if((t=n.sent()).isSuccess&&t.data)return[2,b(t.data)];throw new Error("Loyalty widget settings not found")}}))}))},subscribeToMarketingNotifications:function(){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,v.getInstance().customerStore.createEmailSubscription((null===(t=v.getInstance().customerStore.customer)||void 0===t?void 0:t.email)||"")];case 1:return[2,n.sent()]}}))}))},listEarningMethods:function(){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,o()];case 1:return[2,t.sent().data||[]]}}))}))},listLoyaltyProgramTier:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,a()];case 1:return[2,t.sent().data||[]]}}))}))},listSpendingMethodsByCartId:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,s({cartId:e||S()})];case 1:return[2,t.sent().data||[]]}}))}))},getLoyaltyCustomerInfo:function(){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,u({cartId:S()||null})];case 1:return[2,t.sent().data||null]}}))}))},listLoyaltyProgramPointHistory:function(e){return t(y,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t={},(r=null==e?void 0:e.type)&&(t.type=Array.isArray(r)?{in:r}:{eq:r}),[4,c(t)];case 1:return[2,n.sent().data||[]]}}))}))},useLoyaltyPoints:function(e){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,d({input:e})];case 1:return(t=n.sent()).isSuccess?(r=e.loyaltySpendingMethodId,[4,w.cartStore.getCart()]):[3,3];case 2:n.sent(),n.label=3;case 3:return[2,!!t.isSuccess]}}))}))},removeLoyaltyPointsFromCart:function(){return t(y,void 0,void 0,(function(){var t,e,i,o,a;return n(this,(function(n){switch(n.label){case 0:return t=S(),e=r||(null===(a=null===(o=null===(i=w.cartStore.cart)||void 0===i?void 0:i.loyaltyLines)||void 0===o?void 0:o[0])||void 0===a?void 0:a.loyaltySpendingMethodId),t&&e?[4,l({cartId:t,loyaltySpendingMethodId:e})]:[2];case 1:return n.sent().isSuccess?[4,w.cartStore.getCart()]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},getProducts:function(e){return t(y,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?[4,g.searchProducts({input:{productIdList:e,page:1,perPage:e.length,priceListId:f.getPriceListId(),salesChannelId:f.getSalesChannelId()}},[])]:[2,[]];case 1:return t=n.sent(),[2,((null===(r=t.data)||void 0===r?void 0:r.data)||[]).map((function(t){var n,e,r,i,o,a;return{id:t.id,name:t.name,mainImageSrc:(null===(o=null===(i=null===(r=null===(e=null===(n=t.variants)||void 0===n?void 0:n[0])||void 0===e?void 0:e.images)||void 0===r?void 0:r.find((function(t){return t.isMain})))||void 0===i?void 0:i.image)||void 0===o?void 0:o.thumbnailSrc)||null,variants:(null===(a=t.variants)||void 0===a?void 0:a.map((function(t){var n,e,r,i;return{id:t.id,mainImageSrc:(null===(r=null===(e=null===(n=t.images)||void 0===n?void 0:n.find((function(t){return t.isMain})))||void 0===e?void 0:e.image)||void 0===r?void 0:r.thumbnailSrc)||null,variantText:(null===(i=t.variantValues)||void 0===i?void 0:i.map((function(t){return t.name})).join(" / "))||null}})))||[]}}))]}}))}))},getCategories:function(e){return t(y,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?(t={id:{in:e},pagination:{limit:e.length,page:1}},[4,h.listCategory(t)]):[2,[]];case 1:return r=n.sent(),[2,(null===(i=r.data)||void 0===i?void 0:i.data)||[]]}}))}))},getBrands:function(e){return t(y,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?(t={id:{in:e},pagination:{limit:e.length,page:1}},[4,m.listProductBrand(t)]):[2,[]];case 1:return r=n.sent(),[2,(null===(i=r.data)||void 0===i?void 0:i.data)||[]]}}))}))},getTags:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){return[2,[]]}))}))},formatCurrency:function(t){return p(t,f.getDefaultCurrencyCode()||"TRY",f.getDefaultCurrencySymbol()||"TRY")}}}var S=function(){e.useEffect((function(){if("undefined"!=typeof window&&"undefined"!=typeof document){var e=!1,o=function(t){if("function"==typeof window.startIkasLoyaltyWidget)try{window.startIkasLoyaltyWidget(t)}catch(t){console.error("[@ikas/storefront] Failed to start loyalty widget",t)}},a=function(t){var n=window.location.href.includes("http://localhost:3333/")?"http://localhost:3000/storefront-widget-script-injector.iife.js":"/sf/assets/popup/storefront-widget-script-injector.iife.js";if(n){var r=document.querySelector('script[data-ikas-loyalty-widget="true"]');if(r)"true"===r.dataset.loaded?o(t):r.addEventListener("load",(function(){return o(t)}),{once:!0});else{var i=document.createElement("script");i.src=n,i.defer=!0,i.setAttribute("data-ikas-loyalty-widget","true"),i.addEventListener("load",(function(){i.dataset.loaded="true",e||o(t)}),{once:!0}),i.addEventListener("error",(function(t){console.error("[@ikas/storefront] Failed to load loyalty widget script",n,t)}),{once:!0}),document.body.appendChild(i)}}};return t(void 0,void 0,void 0,(function(){var e,o,s,u,c,d;return n(this,(function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),(e=f.getLoyaltyPrograms()).length?(o=f.getStorefrontRoutingId(),s=[],e.forEach((function(t){var n;null===(n=t.salesChannels)||void 0===n||n.forEach((function(t){var n;null===(n=t.routingIds)||void 0===n||n.forEach((function(t){s.push(t)}))}))})),e.length>0&&o&&!s.some((function(t){return t===o}))?[2]:[4,i()]):[2];case 1:return(null==(u=l.sent())?void 0:u.isSuccess)&&u.data&&u.data.status===r.ACTIVE?[4,(g=u.data,t(void 0,void 0,void 0,(function(){var t,e,r,i;return n(this,(function(n){switch(n.label){case 0:return t={cdnURL:f.getCdnUrl()||"",merchantId:(null===(r=f.getMerchantSettings())||void 0===r?void 0:r.merchantId)||"",currency:f.getDefaultCurrencySymbol()||"TRY",callbacks:w(g),position:"fixed",storeURL:y()},[4,new Promise((function(t){var n=setInterval((function(){var e=f.getSessionId();e&&(clearInterval(n),t(e))}),100)}))];case 1:return n.sent(),(e=null===(i=v.getInstance().cartStore.cart)||void 0===i?void 0:i.id)&&(t.cartId=e),g&&(t.widgetSettings=g),[2,t]}}))})))]:[2];case 2:return c=l.sent(),window.ikasLoyaltyWidgetConfig=c,a(c),[3,4];case 3:return d=l.sent(),console.error("[@ikas/storefront] Failed to initialize loyalty widget",d),[3,4];case 4:return[2]}var g}))})),function(){e=!0}}}),[])};export{S as useLoyaltyWidget};
1
+ import{__awaiter as t,__generator as n}from'./../../../ext/tslib/tslib.es6.js';import*as e from"react";import{StorefrontWidgetSettingsStatusEnum as r,getStorefrontWidgetSettings as i,listEarningMethods as o,listLoyaltyProgramTiers as a,listSpendingMethodsByCartId as s,getLoyaltyCustomerInfo as u,listLoyaltyProgramPointHistory as c,useLoyaltyPoints as d,removeLoyaltyPointsFromCart as l}from"@ikas/storefront-api";import{IkasStorefrontConfig as f}from"@ikas/storefront-config";import{IkasBaseStore as v}from"../../../store/base.js";import"../../../store/customer/index.js";import"../../../store/cart/index.js";import g from"../../../store/product/index.js";import m from"../../../store/category/index.js";import h from"../../../store/brand/index.js";import{resolveStoreUrl as y}from"./common.js";import{formatCurrency as p}from"../../../utils/currency.js";import"lodash/get";function w(e){var r,y=this,w=v.getInstance(),S=function(){var t;return null===(t=w.cartStore.cart)||void 0===t?void 0:t.id},b=function(t){var n,e=null!==(n=null==t?void 0:t.themeSettingsJson)&&void 0!==n?n:t;if(!e)throw new Error("Loyalty widget settings not found");if("string"==typeof e)try{return JSON.parse(e)}catch(t){throw new Error("Loyalty widget settings format is invalid")}return e};return{getLoyaltyWidget:function(){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return e?[2,b(e)]:[4,i()];case 1:if((t=n.sent()).isSuccess&&t.data)return[2,b(t.data)];throw new Error("Loyalty widget settings not found")}}))}))},subscribeToMarketingNotifications:function(){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,v.getInstance().customerStore.createEmailSubscription((null===(t=v.getInstance().customerStore.customer)||void 0===t?void 0:t.email)||"")];case 1:return[2,n.sent()]}}))}))},listEarningMethods:function(){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,o()];case 1:return[2,t.sent().data||[]]}}))}))},listLoyaltyProgramTier:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,a()];case 1:return[2,t.sent().data||[]]}}))}))},listSpendingMethodsByCartId:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,s({cartId:e||S()})];case 1:return[2,t.sent().data||[]]}}))}))},getLoyaltyCustomerInfo:function(){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,u({cartId:S()||null})];case 1:return[2,t.sent().data||null]}}))}))},listLoyaltyProgramPointHistory:function(e){return t(y,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t={},(r=null==e?void 0:e.type)&&(t.type=Array.isArray(r)?{in:r}:{eq:r}),[4,c(t)];case 1:return[2,n.sent().data||[]]}}))}))},useLoyaltyPoints:function(e){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,d({input:e})];case 1:return(t=n.sent()).isSuccess?(r=e.loyaltySpendingMethodId,[4,w.cartStore.getCart()]):[3,3];case 2:n.sent(),n.label=3;case 3:return[2,!!t.isSuccess]}}))}))},removeLoyaltyPointsFromCart:function(){return t(y,void 0,void 0,(function(){var t,e,i,o,a;return n(this,(function(n){switch(n.label){case 0:return t=S(),e=r||(null===(a=null===(o=null===(i=w.cartStore.cart)||void 0===i?void 0:i.loyaltyLines)||void 0===o?void 0:o[0])||void 0===a?void 0:a.loyaltySpendingMethodId),t&&e?[4,l({cartId:t,loyaltySpendingMethodId:e})]:[2];case 1:return n.sent().isSuccess?[4,w.cartStore.getCart()]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},getProducts:function(e){return t(y,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?[4,g.searchProducts({input:{productIdList:e,page:1,perPage:e.length,priceListId:f.getPriceListId(),salesChannelId:f.getSalesChannelId()}},[])]:[2,[]];case 1:return t=n.sent(),[2,((null===(r=t.data)||void 0===r?void 0:r.data)||[]).map((function(t){var n,e,r,i,o,a,s;return{id:t.id,name:t.name,mainImageSrc:(null===(o=null===(i=null===(r=null===(e=null===(n=t.variants)||void 0===n?void 0:n[0])||void 0===e?void 0:e.images)||void 0===r?void 0:r.find((function(t){return t.isMain})))||void 0===i?void 0:i.image)||void 0===o?void 0:o.thumbnailSrc)||null,variants:(null===(a=t.variants)||void 0===a?void 0:a.map((function(t){var n,e,r,i;return{id:t.id,mainImageSrc:(null===(r=null===(e=null===(n=t.images)||void 0===n?void 0:n.find((function(t){return t.isMain})))||void 0===e?void 0:e.image)||void 0===r?void 0:r.thumbnailSrc)||null,variantText:(null===(i=t.variantValues)||void 0===i?void 0:i.map((function(t){return t.name})).join(" / "))||null}})))||[],url:null===(s=t.metaData)||void 0===s?void 0:s.slug}}))]}}))}))},getCategories:function(e){return t(y,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?(t={id:{in:e},pagination:{limit:e.length,page:1}},[4,m.listCategory(t)]):[2,[]];case 1:return r=n.sent(),[2,(null===(i=r.data)||void 0===i?void 0:i.data)||[]]}}))}))},getBrands:function(e){return t(y,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?(t={id:{in:e},pagination:{limit:e.length,page:1}},[4,h.listProductBrand(t)]):[2,[]];case 1:return r=n.sent(),[2,(null===(i=r.data)||void 0===i?void 0:i.data)||[]]}}))}))},getTags:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){return[2,[]]}))}))},formatCurrency:function(t){return p(t,f.getDefaultCurrencyCode()||"TRY",f.getDefaultCurrencySymbol()||"TRY")}}}var S=function(){e.useEffect((function(){if("undefined"!=typeof window&&"undefined"!=typeof document){var e=!1,o=function(t){if("function"==typeof window.startIkasLoyaltyWidget)try{window.startIkasLoyaltyWidget(t)}catch(t){console.error("[@ikas/storefront] Failed to start loyalty widget",t)}},a=function(t){var n=window.location.href.includes("http://localhost:3333/")?"http://localhost:3000/storefront-widget-script-injector.iife.js":"/sf/assets/popup/storefront-widget-script-injector.iife.js";if(n){var r=document.querySelector('script[data-ikas-loyalty-widget="true"]');if(r)"true"===r.dataset.loaded?o(t):r.addEventListener("load",(function(){return o(t)}),{once:!0});else{var i=document.createElement("script");i.src=n,i.defer=!0,i.setAttribute("data-ikas-loyalty-widget","true"),i.addEventListener("load",(function(){i.dataset.loaded="true",e||o(t)}),{once:!0}),i.addEventListener("error",(function(t){console.error("[@ikas/storefront] Failed to load loyalty widget script",n,t)}),{once:!0}),document.body.appendChild(i)}}};return t(void 0,void 0,void 0,(function(){var e,o,s,u,c,d;return n(this,(function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),(e=f.getLoyaltyPrograms()).length?(o=f.getStorefrontRoutingId(),s=[],e.forEach((function(t){var n;null===(n=t.salesChannels)||void 0===n||n.forEach((function(t){var n;null===(n=t.routingIds)||void 0===n||n.forEach((function(t){s.push(t)}))}))})),e.length>0&&o&&!s.some((function(t){return t===o}))?[2]:[4,i()]):[2];case 1:return(null==(u=l.sent())?void 0:u.isSuccess)&&u.data&&u.data.status===r.ACTIVE?[4,(g=u.data,t(void 0,void 0,void 0,(function(){var t,e,r,i;return n(this,(function(n){switch(n.label){case 0:return t={cdnURL:f.getCdnUrl()||"",merchantId:(null===(r=f.getMerchantSettings())||void 0===r?void 0:r.merchantId)||"",currency:f.getDefaultCurrencySymbol()||"TRY",callbacks:w(g),position:"fixed",storeURL:y()},[4,new Promise((function(t){var n=setInterval((function(){var e=f.getSessionId();e&&(clearInterval(n),t(e))}),100)}))];case 1:return n.sent(),(e=null===(i=v.getInstance().cartStore.cart)||void 0===i?void 0:i.id)&&(t.cartId=e),g&&(t.widgetSettings=g),[2,t]}}))})))]:[2];case 2:return c=l.sent(),window.ikasLoyaltyWidgetConfig=c,a(c),[3,4];case 3:return d=l.sent(),console.error("[@ikas/storefront] Failed to initialize loyalty widget",d),[3,4];case 4:return[2]}var g}))})),function(){e=!0}}}),[])};export{S as useLoyaltyWidget};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "6.1.0-beta.272",
3
+ "version": "6.1.0-beta.273",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -17,17 +17,17 @@
17
17
  "build": "rm -rf build && rollup -c"
18
18
  },
19
19
  "dependencies": {
20
- "@ikas/loyalty-widget-renderer": "1.0.0-alpha.83",
20
+ "@ikas/loyalty-widget-renderer": "1.0.0-alpha.84",
21
21
  "@ikas/popup-renderer": "1.0.227",
22
22
  "@ikas/popup-script-injector": "1.0.0-alpha.21",
23
23
  "swiper": "11.0.6"
24
24
  },
25
25
  "devDependencies": {
26
- "@ikas/storefront-api": "^6.1.0-beta.272",
27
- "@ikas/storefront-config": "^6.1.0-beta.272",
28
- "@ikas/storefront-model-functions": "^6.1.0-beta.272",
29
- "@ikas/storefront-models": "^6.1.0-beta.272",
30
- "@ikas/storefront-providers": "^6.1.0-beta.272",
26
+ "@ikas/storefront-api": "^6.1.0-beta.273",
27
+ "@ikas/storefront-config": "^6.1.0-beta.273",
28
+ "@ikas/storefront-model-functions": "^6.1.0-beta.273",
29
+ "@ikas/storefront-models": "^6.1.0-beta.273",
30
+ "@ikas/storefront-providers": "^6.1.0-beta.273",
31
31
  "@ikas/localized-address": "1.0.0-beta.6",
32
32
  "@adyen/adyen-web": "^5.57.0",
33
33
  "@rollup/plugin-commonjs": "^22.0.0",
@@ -62,11 +62,11 @@
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@ikas/localized-address": "1.0.0-beta.6",
65
- "@ikas/storefront-api": "^6.1.0-beta.272",
66
- "@ikas/storefront-config": "^6.1.0-beta.272",
67
- "@ikas/storefront-model-functions": "^6.1.0-beta.272",
68
- "@ikas/storefront-models": "^6.1.0-beta.272",
69
- "@ikas/storefront-providers": "^6.1.0-beta.272",
65
+ "@ikas/storefront-api": "^6.1.0-beta.273",
66
+ "@ikas/storefront-config": "^6.1.0-beta.273",
67
+ "@ikas/storefront-model-functions": "^6.1.0-beta.273",
68
+ "@ikas/storefront-models": "^6.1.0-beta.273",
69
+ "@ikas/storefront-providers": "^6.1.0-beta.273",
70
70
  "mobx": "^6.1.3",
71
71
  "mobx-react-lite": "^3.1.5",
72
72
  "next": "12.2.0",