@ikas/loyalty-widget-renderer 1.0.0-alpha.54 → 1.0.0-alpha.56

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 e,__generator as t,__spreadArray as n}from'./../ext/tslib/tslib.es6.mjs.js';import{observer as r}from"mobx-react";import i,{useState as o,useEffect as s}from"react";import'./../ext/react-i18next/dist/es/context.js';import{I18nextProvider as a}from'./../ext/react-i18next/dist/es/I18nextProvider.js';import{LoyaltyWidgetViewModel as c}from"../models/index.js";import{LoyaltyCustomerInfo as l}from"../models/loyalty-customer-info/index.js";import{LoyaltyProgramEarningMethod as d}from"../models/loyalty-program-earning-method/index.js";import{LoyaltyProgramPointHistory as u}from"../models/loyalty-program-point-history/index.js";import{LoyaltyProgramSpendingMethod as f}from"../models/loyalty-program-spending-method/index.js";import{LoyaltyWidget as m}from"../models/loyalty-widget/index.js";import{WidgetPositionEnum as v,LoyaltyWidgetLayoutTypeEnum as E}from"../models/loyalty-widget/types/index.js";import{WidgetMode as g,LoyaltyWidgetScreenTypeEnum as p,EarningMethodTypeEnum as y,LoyaltyProgramFilterTypeEnum as h,LoyaltyProgramMethodSpendingTypeEnum as R}from"../models/types/index.js";import w from"./components/mini-mode-button/index.js";import T from"./components/mini-mode-description/index.js";import b from"./screens/credit-earning-methods-screen/index.js";import M from"./screens/credit-history-screen/index.js";import I from"./screens/credit-spending-methods-screen/index.js";import k from"./screens/loyalty-level-screen/index.js";import C from"./screens/main-screen/index.js";import _ from"./utils/i18n.js";import{Container as S,MiniModeWrapper as A,Panel as N,ScreenWrapper as D}from"./style.js";var O=r(function(r){var O,P,L=r.config,x=o(function(){var e=L||window.ikasLoyaltyWidgetConfig;return new c({cartId:(null==e?void 0:e.cartId)||null,ikasEventUser:(null==e?void 0:e.userId)?{id:e.userId}:null},(null==e?void 0:e.cdnURL)||"",(null==e?void 0:e.merchantId)||"",(null==e?void 0:e.currency)||"",(null==e?void 0:e.locale)||"",(null==e?void 0:e.storeURL)||null,null==e?void 0:e.isPreviewMode,null==e?void 0:e.callbacks)})[0],j=o(!1),U=j[0],W=j[1];s(function(){var e=L||window.ikasLoyaltyWidgetConfig;(null==e?void 0:e.onViewModelInitialized)&&e.onViewModelInitialized(x)},[x,L]);var G=function(){return e(void 0,void 0,void 0,function(){var e,r,i,o,s;return t(this,function(t){switch(t.label){case 0:return x.callbacks?(e=new Set,r=new Set,i=new Set,o=new Set,x.earningMethods.forEach(function(t){var s,a;t.methodType===y.ORDER_CREATE&&n(n([],(null===(s=t.orderSettings)||void 0===s?void 0:s.productFilters)||[],!0),(null===(a=t.productSettings)||void 0===a?void 0:a.productFilters)||[],!0).forEach(function(t){t.type===h.PRODUCT_AND_VARIANT?t.idList.forEach(function(t){return e.add(t)}):t.type===h.CATEGORY?t.idList.forEach(function(e){return r.add(e)}):t.type===h.PRODUCT_BRAND?t.idList.forEach(function(e){return i.add(e)}):t.type===h.PRODUCT_TAG&&t.idList.forEach(function(e){return o.add(e)})})}),x.spendingMethods&&x.spendingMethods.forEach(function(t){var n,s;t.type===R.FREE_PRODUCT&&(null===(n=t.discountSettings)||void 0===n?void 0:n.freeProductId)&&e.add(t.discountSettings.freeProductId),null===(s=t.productFilters)||void 0===s||s.forEach(function(t){t.type===h.PRODUCT_AND_VARIANT?t.idList.forEach(function(t){return e.add(t)}):t.type===h.CATEGORY?t.idList.forEach(function(e){return r.add(e)}):t.type===h.PRODUCT_BRAND?t.idList.forEach(function(e){return i.add(e)}):t.type===h.PRODUCT_TAG&&t.idList.forEach(function(e){return o.add(e)})})}),s=[],e.size>0&&x.callbacks.getProducts&&s.push(x.callbacks.getProducts(Array.from(e)).then(function(e){return x.products=e})),r.size>0&&x.callbacks.getCategories&&s.push(x.callbacks.getCategories(Array.from(r)).then(function(e){return x.categories=e})),i.size>0&&x.callbacks.getBrands&&s.push(x.callbacks.getBrands(Array.from(i)).then(function(e){return x.brands=e})),o.size>0&&x.callbacks.getTags&&s.push(x.callbacks.getTags(Array.from(o)).then(function(e){return x.tags=e})),[4,Promise.all(s)]):[2];case 1:return t.sent(),[2]}})})};s(function(){e(void 0,void 0,void 0,function(){var e,n,r,i,o,s;return t(this,function(t){switch(t.label){case 0:if(!x.callbacks)return[3,6];t.label=1;case 1:return t.trys.push([1,4,5,6]),e=[x.callbacks.getLoyaltyWidget(),x.callbacks.listEarningMethods(),x.callbacks.listLoyaltyProgramTier({})],[4,Promise.all(e)];case 2:return n=t.sent(),r=n[0],i=n[1],o=n[2],x.loyaltyWidget=r instanceof m?r:new m(r||{}),x.earningMethods=i.map(function(e){return new d(e)}),x.tiers=o||[],[4,G()];case 3:return t.sent(),[3,6];case 4:return s=t.sent(),console.error("Failed to initialize loyalty data",s),[3,6];case 5:return W(!0),[7];case 6:return[2]}})})},[]),s(function(){if(window.IkasEvents){var e=function(e){var t,n=null===(t=e.data)||void 0===t?void 0:t.customer;n&&(x.ikasEventUser=n),x.userRefreshTrigger++,x.cartRefreshTrigger++},t=function(e){var t,n,r=null===(n=null===(t=e.data)||void 0===t?void 0:t.cart)||void 0===n?void 0:n.id;r&&(x.cartId=r),x.cartRefreshTrigger++},n={CUSTOMER_LOGIN:e,CUSTOMER_VISIT:e,CUSTOMER_LOGOUT:function(){x.ikasEventUser=null,x.userRefreshTrigger++,x.cartRefreshTrigger++},ADD_TO_CART:t,REMOVE_FROM_CART:t,PAGE_VIEW:function(e){var t,n,r=null===(t=e.data)||void 0===t?void 0:t.customer;if(r){var i=!x.ikasEventUser,o=(null===(n=x.ikasEventUser)||void 0===n?void 0:n.subscriptionStatus)!==r.subscriptionStatus;(i||o)&&(x.ikasEventUser=r,x.userRefreshTrigger++,x.cartRefreshTrigger++)}}},r="ikas-loyalty-widget-subscriber";try{window.IkasEvents.subscribe({id:r,callback:function(e){var t=n[e.type];t&&t(e)}})}catch(e){console.error("Failed to subscribe to IkasEvents",e)}return function(){var e;(null===(e=window.IkasEvents)||void 0===e?void 0:e.unsubscribe)&&window.IkasEvents.unsubscribe(r)}}},[x]),s(function(){e(void 0,void 0,void 0,function(){var e,n,r,i,o;return t(this,function(t){switch(t.label){case 0:if(!x.callbacks||!(null===(o=x.ikasEventUser)||void 0===o?void 0:o.id))return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,Promise.all([x.callbacks.getLoyaltyCustomerInfo(),x.callbacks.listLoyaltyProgramPointHistory({})])];case 2:return e=t.sent(),n=e[0],r=e[1],x.user=n?new l(n):null,x.pointHistory=r?r.map(function(e){return new u(e)}):[],[3,4];case 3:return i=t.sent(),console.error("Failed to fetch user data",i),[3,4];case 4:return[2]}})})},[null===(O=x.ikasEventUser)||void 0===O?void 0:O.id,x.userRefreshTrigger]),s(function(){e(void 0,void 0,void 0,function(){var e,n;return t(this,function(t){switch(t.label){case 0:if(!x.callbacks)return[3,5];t.label=1;case 1:return t.trys.push([1,4,,5]),[4,x.callbacks.listSpendingMethodsByCartId(x.cartId)];case 2:return e=t.sent(),x.spendingMethods=e.map(function(e){return new f(e)}),[4,G()];case 3:return t.sent(),[3,5];case 4:return n=t.sent(),console.error("Failed to fetch cart data",n),[3,5];case 5:return[2]}})})},[x.cartId,x.cartRefreshTrigger]);var $=function(e){x.selectedScreen=e},B=function(){x.setWidgetMode(g.MINI_MODE),setTimeout(function(){x.selectedScreen=p.MAIN_SCREEN},300)};s(function(){return x.currentWidgetMode===g.WIDGET_MODE?document.body.style.overflow="hidden":document.body.style.overflow="",function(){document.body.style.overflow=""}},[x.currentWidgetMode]);var F=x.selectedScreen===p.MAIN_SCREEN,V=o(null),z=V[0],H=V[1];s(function(){x.selectedScreen!==p.MAIN_SCREEN&&H(x.selectedScreen)},[x.selectedScreen]);var Y=F?z:x.selectedScreen,q=x.loyaltyWidget.settings.position||v.RIGHT,J=x.loyaltyWidget.settings.type||E.DRAWER;if(!U)return null;var K=(null==L?void 0:L.position)||(null===(P=window.ikasLoyaltyWidgetConfig)||void 0===P?void 0:P.position)||"fixed";return i.createElement(a,{i18n:_},i.createElement(S,{$layoutType:J,$widgetPosition:q,$widgetMode:x.currentWidgetMode,$position:K,onClick:function(){x.currentWidgetMode===g.WIDGET_MODE&&B()}},i.createElement(A,{$isVisible:x.currentWidgetMode===g.MINI_MODE,$widgetPosition:q},i.createElement(T,{viewModel:x}),i.createElement(w,{viewModel:x})),i.createElement(N,{$layoutType:J,$isOpen:x.currentWidgetMode===g.WIDGET_MODE,$widgetPosition:q,onClick:function(e){return e.stopPropagation()}},i.createElement(D,{$isActive:F,$isMain:!0},i.createElement(C,{viewModel:x,onClose:B,onNavigate:$})),i.createElement(D,{$isActive:!F,$isMain:!1},function(){switch(Y){case p.CREDIT_SPENDING_METHODS_SCREEN:return i.createElement(I,{viewModel:x,onBack:function(){return $(p.MAIN_SCREEN)},onClose:B});case p.CREDIT_EARNING_METHODS_SCREEN:return i.createElement(b,{viewModel:x,onBack:function(){return $(p.MAIN_SCREEN)},onClose:B});case p.CREDIT_HISTORY_SCREEN:return i.createElement(M,{viewModel:x,onBack:function(){return $(p.MAIN_SCREEN)},onClose:B});case p.LOYALTY_LEVEL_SCREEN:return i.createElement(k,{viewModel:x,onBack:function(){return $(p.MAIN_SCREEN)},onClose:B});default:return null}}()))))});export{O as default};
1
+ import{__awaiter as e,__generator as t,__spreadArray as n}from'./../ext/tslib/tslib.es6.mjs.js';import{observer as r}from"mobx-react";import i,{useState as o,useEffect as s}from"react";import'./../ext/react-i18next/dist/es/context.js';import{I18nextProvider as a}from'./../ext/react-i18next/dist/es/I18nextProvider.js';import{LoyaltyWidgetViewModel as c}from"../models/index.js";import{LoyaltyCustomerInfo as l}from"../models/loyalty-customer-info/index.js";import{LoyaltyProgramEarningMethod as d}from"../models/loyalty-program-earning-method/index.js";import{LoyaltyProgramPointHistory as u}from"../models/loyalty-program-point-history/index.js";import{LoyaltyProgramSpendingMethod as f}from"../models/loyalty-program-spending-method/index.js";import{LoyaltyWidget as m}from"../models/loyalty-widget/index.js";import{WidgetPositionEnum as v,LoyaltyWidgetLayoutTypeEnum as E}from"../models/loyalty-widget/types/index.js";import{WidgetMode as g,LoyaltyWidgetScreenTypeEnum as p,EarningMethodTypeEnum as y,LoyaltyProgramFilterTypeEnum as h,LoyaltyProgramMethodSpendingTypeEnum as R}from"../models/types/index.js";import w from"./components/mini-mode-button/index.js";import T from"./components/mini-mode-description/index.js";import b from"./screens/credit-earning-methods-screen/index.js";import M from"./screens/credit-history-screen/index.js";import I from"./screens/credit-spending-methods-screen/index.js";import k from"./screens/loyalty-level-screen/index.js";import C from"./screens/main-screen/index.js";import _ from"./utils/i18n.js";import{Container as S,MiniModeWrapper as A,Panel as N,ScreenWrapper as D}from"./style.js";var O=r(function(r){var O,P,L=r.config,x=o(function(){var e=L||window.ikasLoyaltyWidgetConfig;return new c({cartId:(null==e?void 0:e.cartId)||null,ikasEventUser:(null==e?void 0:e.userId)?{id:e.userId}:null},(null==e?void 0:e.cdnURL)||"",(null==e?void 0:e.merchantId)||"",(null==e?void 0:e.currency)||"",(null==e?void 0:e.locale)||"",(null==e?void 0:e.storeURL)||null,null==e?void 0:e.isPreviewMode,null==e?void 0:e.callbacks)})[0],j=o(!1),U=j[0],W=j[1];s(function(){var e=L||window.ikasLoyaltyWidgetConfig;(null==e?void 0:e.onViewModelInitialized)&&e.onViewModelInitialized(x)},[x,L]);var G=function(){return e(void 0,void 0,void 0,function(){var e,r,i,o,s;return t(this,function(t){switch(t.label){case 0:return x.callbacks?(e=new Set,r=new Set,i=new Set,o=new Set,x.earningMethods.forEach(function(t){var s,a;t.methodType===y.ORDER_CREATE&&n(n([],(null===(s=t.orderSettings)||void 0===s?void 0:s.productFilters)||[],!0),(null===(a=t.productSettings)||void 0===a?void 0:a.productFilters)||[],!0).forEach(function(t){t.type===h.PRODUCT_AND_VARIANT?t.idList.forEach(function(t){return e.add(t)}):t.type===h.CATEGORY?t.idList.forEach(function(e){return r.add(e)}):t.type===h.PRODUCT_BRAND?t.idList.forEach(function(e){return i.add(e)}):t.type===h.PRODUCT_TAG&&t.idList.forEach(function(e){return o.add(e)})})}),x.spendingMethods&&x.spendingMethods.forEach(function(t){var n,s;t.type===R.FREE_PRODUCT&&(null===(n=t.discountSettings)||void 0===n?void 0:n.freeProductId)&&e.add(t.discountSettings.freeProductId),null===(s=t.productFilters)||void 0===s||s.forEach(function(t){t.type===h.PRODUCT_AND_VARIANT?t.idList.forEach(function(t){return e.add(t)}):t.type===h.CATEGORY?t.idList.forEach(function(e){return r.add(e)}):t.type===h.PRODUCT_BRAND?t.idList.forEach(function(e){return i.add(e)}):t.type===h.PRODUCT_TAG&&t.idList.forEach(function(e){return o.add(e)})})}),s=[],e.size>0&&x.callbacks.getProducts&&s.push(x.callbacks.getProducts(Array.from(e)).then(function(e){return x.products=e})),r.size>0&&x.callbacks.getCategories&&s.push(x.callbacks.getCategories(Array.from(r)).then(function(e){return x.categories=e})),i.size>0&&x.callbacks.getBrands&&s.push(x.callbacks.getBrands(Array.from(i)).then(function(e){return x.brands=e})),o.size>0&&x.callbacks.getTags&&s.push(x.callbacks.getTags(Array.from(o)).then(function(e){return x.tags=e})),[4,Promise.all(s)]):[2];case 1:return t.sent(),[2]}})})};s(function(){e(void 0,void 0,void 0,function(){var e,n,r,i,o,s;return t(this,function(t){switch(t.label){case 0:if(!x.callbacks)return[3,6];t.label=1;case 1:return t.trys.push([1,4,5,6]),e=[x.callbacks.getLoyaltyWidget(),x.callbacks.listEarningMethods(),x.callbacks.listLoyaltyProgramTier({})],[4,Promise.all(e)];case 2:return n=t.sent(),r=n[0],i=n[1],o=n[2],x.loyaltyWidget=r instanceof m?r:new m(r||{}),x.earningMethods=i.map(function(e){return new d(e)}),x.tiers=o||[],[4,G()];case 3:return t.sent(),[3,6];case 4:return s=t.sent(),console.error("Failed to initialize loyalty data",s),[3,6];case 5:return W(!0),[7];case 6:return[2]}})})},[]),s(function(){if(window.IkasEvents){var e=function(e){var t,n=null===(t=e.data)||void 0===t?void 0:t.customer;n&&(x.ikasEventUser=n),x.userRefreshTrigger++,x.cartRefreshTrigger++},t=function(e){var t,n,r=null===(n=null===(t=e.data)||void 0===t?void 0:t.cart)||void 0===n?void 0:n.id;r&&(x.cartId=r),x.cartRefreshTrigger++},n={CUSTOMER_LOGIN:e,CUSTOMER_VISIT:e,CUSTOMER_LOGOUT:function(){x.ikasEventUser=null,x.userRefreshTrigger++,x.cartRefreshTrigger++},ADD_TO_CART:t,REMOVE_FROM_CART:t,PAGE_VIEW:function(e){var t,n,r=null===(t=e.data)||void 0===t?void 0:t.customer;if(r){var i=!x.ikasEventUser,o=(null===(n=x.ikasEventUser)||void 0===n?void 0:n.subscriptionStatus)!==r.subscriptionStatus;(i||o)&&(x.ikasEventUser=r,x.userRefreshTrigger++,x.cartRefreshTrigger++)}}},r="ikas-loyalty-widget-subscriber";try{window.IkasEvents.subscribe({id:r,callback:function(e){var t=n[e.type];t&&t(e)}})}catch(e){console.error("Failed to subscribe to IkasEvents",e)}return function(){var e;(null===(e=window.IkasEvents)||void 0===e?void 0:e.unsubscribe)&&window.IkasEvents.unsubscribe(r)}}},[x]),s(function(){e(void 0,void 0,void 0,function(){var e,n,r,i,o;return t(this,function(t){switch(t.label){case 0:if(!x.callbacks||!(null===(o=x.ikasEventUser)||void 0===o?void 0:o.id))return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,Promise.all([x.callbacks.getLoyaltyCustomerInfo(),x.callbacks.listLoyaltyProgramPointHistory({})])];case 2:return e=t.sent(),n=e[0],r=e[1],x.user=n?new l(n):null,x.pointHistory=r?r.map(function(e){return new u(e)}):[],[3,4];case 3:return i=t.sent(),console.error("Failed to fetch user data",i),[3,4];case 4:return[2]}})})},[null===(O=x.ikasEventUser)||void 0===O?void 0:O.id,x.userRefreshTrigger]),s(function(){e(void 0,void 0,void 0,function(){var e,n;return t(this,function(t){switch(t.label){case 0:if(!x.callbacks)return[3,5];t.label=1;case 1:return t.trys.push([1,4,,5]),[4,x.callbacks.listSpendingMethodsByCartId(x.cartId)];case 2:return e=t.sent(),x.spendingMethods=e.map(function(e){return new f(e)}),[4,G()];case 3:return t.sent(),[3,5];case 4:return n=t.sent(),console.error("Failed to fetch cart data",n),[3,5];case 5:return[2]}})})},[x.cartId,x.cartRefreshTrigger]);var $=function(e){x.selectedScreen=e},B=function(){x.setWidgetMode(g.MINI_MODE),setTimeout(function(){x.selectedScreen=p.MAIN_SCREEN},300)};s(function(){return x.currentWidgetMode===g.WIDGET_MODE?document.body.style.overflow="hidden":document.body.style.overflow="",function(){document.body.style.overflow=""}},[x.currentWidgetMode]);var F=x.selectedScreen===p.MAIN_SCREEN,V=o(null),z=V[0],H=V[1];s(function(){x.selectedScreen!==p.MAIN_SCREEN&&H(x.selectedScreen)},[x.selectedScreen]);var Y=F?z:x.selectedScreen,q=x.loyaltyWidget.settings.position||v.RIGHT,J=x.loyaltyWidget.settings.type||E.DRAWER;if(!U)return null;var K=(null==L?void 0:L.position)||(null===(P=window.ikasLoyaltyWidgetConfig)||void 0===P?void 0:P.position)||"fixed";return i.createElement(a,{i18n:_},i.createElement(S,{$layoutType:J,$widgetPosition:q,$widgetMode:x.currentWidgetMode,$position:K,onClick:function(){x.currentWidgetMode===g.WIDGET_MODE&&B()},className:"ikas-storefront-widget"},i.createElement(A,{$isVisible:x.currentWidgetMode===g.MINI_MODE,$widgetPosition:q},i.createElement(T,{viewModel:x}),i.createElement(w,{viewModel:x})),i.createElement(N,{$layoutType:J,$isOpen:x.currentWidgetMode===g.WIDGET_MODE,$widgetPosition:q,onClick:function(e){return e.stopPropagation()}},i.createElement(D,{$isActive:F,$isMain:!0},i.createElement(C,{viewModel:x,onClose:B,onNavigate:$})),i.createElement(D,{$isActive:!F,$isMain:!1},function(){switch(Y){case p.CREDIT_SPENDING_METHODS_SCREEN:return i.createElement(I,{viewModel:x,onBack:function(){return $(p.MAIN_SCREEN)},onClose:B});case p.CREDIT_EARNING_METHODS_SCREEN:return i.createElement(b,{viewModel:x,onBack:function(){return $(p.MAIN_SCREEN)},onClose:B});case p.CREDIT_HISTORY_SCREEN:return i.createElement(M,{viewModel:x,onBack:function(){return $(p.MAIN_SCREEN)},onClose:B});case p.LOYALTY_LEVEL_SCREEN:return i.createElement(k,{viewModel:x,onBack:function(){return $(p.MAIN_SCREEN)},onClose:B});default:return null}}()))))});export{O as default};