@stigg/react-sdk 7.8.0-beta.0 → 7.8.0-beta.2
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/stigg-sdk.cjs.js +1 -1
- package/dist/stigg-sdk.esm.js +1 -1
- package/package.json +3 -2
package/dist/stigg-sdk.cjs.js
CHANGED
|
@@ -4967,7 +4967,7 @@ ${e.o5f}`,e.zBW=r.default`
|
|
|
4967
4967
|
display: flex;
|
|
4968
4968
|
flex-direction: column;
|
|
4969
4969
|
align-items: center;
|
|
4970
|
-
`,wS=({plans:t,customer:e,currentSubscription:n,highlightedPlanId:r,selectedBillingPeriod:i,onBillingPeriodChanged:o,availableBillingPeriods:s,isCustomerOnTrial:c,onPlanSelected:p,paywallLocale:h,locale:v,shouldHidePlan:P,selectDefaultTierIndex:x,currentSubscriptionOverride:T,hideCompatibleAddons:I,showWatermark:F})=>{let A=xS(t),O=t.some(Y=>!!Y.description),N=jb(t,be.Monthly),V=jb(t,be.Annually),G=TS(t,i,P),X=$v.useCallback((Y,at,pt)=>p({plan:Y,customer:e,subscription:n,intentionType:at,selectedBillingPeriod:i,billableFeatures:pt}),[e,i,n,p]),nt=!!n&&n.plan.pricingType===Rn.Custom,st=$v.useMemo(()=>G.some(Y=>{var ut;let at=Y.pricePoints.filter(mt=>mt.billingPeriod===i),pt=(ut=Y.paywallCalculatedPricePoints)==null?void 0:ut.find(mt=>mt.billingPeriod===i);return at.length>1&&!!(pt!=null&&pt.additionalChargesMayApply)}),[i,G]),U=$v.useMemo(()=>G.some(Y=>!!um(Y,i,h,v,N).unit),[i,N,v,h,G]),j=$v.useMemo(()=>!nt&&G.some(Y=>{let at=cm({plan:Y,billingPeriod:i,currentSubscription:n,currentSubscriptionOverride:T});return Object.values(at).length>0}),[i,n,T,nt,G]),dt=G.some(Y=>Y.isCurrentCustomerPlan&&Y.trialDaysLeft);return jsxRuntime.jsx(mA,{className:"stigg-paywall-container",children:jsxRuntime.jsxs(gA,{className:"stigg-paywall-layout",children:[jsxRuntime.jsx(vS,{onBillingPeriodChanged:o,selectedBillingPeriod:i,availableBillingPeriods:s,discountRate:A}),jsxRuntime.jsx(hA,{className:"stigg-paywall-plans-layout",children:G.map(Y=>jsxRuntime.jsx(yS,{withUnitPriceRow:U,withTiersRow:j,withTrialLeftRow:dt,shouldShowDescriptionSection:O,hasMonthlyPrice:N,hasAnnuallyPrice:V,plan:Y,withStartingAtRow:st,currentSubscription:n,currentSubscriptionOverride:T,billingPeriod:i,isHighlighted:Y.id===r,isCustomerOnTrial:c,onPlanSelected:(at,pt)=>X(Y,at,pt),paywallLocale:h,locale:v,customer:e,isCustomerInCustomPlan:nt,selectDefaultTierIndex:x,hideCompatibleAddons:I},Y.id))}),jsxRuntime.jsx(so,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:F})]})})};var zb=class{error(e,n,...r){console.error(e,n||{},r);}log(e,n){console.log(e,n||{});}debug(e,n){console.debug(e,n||{});}},tl=new zb;function IS(t,e,n){let r=t.flatMap(c=>c.pricePoints).map(c=>c.billingPeriod),i=lodash.countBy(r),o=lodash.uniq(r),s;if(n&&o.includes(n))s=n;else if(e){let c=e.find(p=>p.status===bi.Active);c&&c.prices.length>0&&(s=c==null?void 0:c.prices[0].billingPeriod);}return s||(s=(i[be.Monthly]||0)>(i[be.Annually]||0)?be.Monthly:be.Annually),{defaultBillingPeriod:s,availableBillingPeriods:o}}function DS(t){return j1__default.default.utc(t).diff(j1__default.default.utc(),"days",false)+1}var fm={h1:{fontSize:"24px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"16px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};function el(t,e="px"){if(t)return `${t}${e}`}function hm(t){if(!t)return "normal";switch(t){case gb.Normal:return "normal";case gb.Bold:return "bold";default:return "normal"}}function jp(t,e){var r,i,o,s,c,p,h,v;let n=e||{h1:{fontSize:"32px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"24px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};return {fontFamilyUrl:(t==null?void 0:t.fontFamily)||void 0,h1:{fontSize:el((r=t==null?void 0:t.h1)==null?void 0:r.fontSize)||n.h1.fontSize,fontWeight:hm((i=t==null?void 0:t.h1)==null?void 0:i.fontWeight)||n.h1.fontWeight,semanticElement:n.h1.semanticElement},h2:{fontSize:el((o=t==null?void 0:t.h2)==null?void 0:o.fontSize)||n.h2.fontSize,fontWeight:hm((s=t==null?void 0:t.h2)==null?void 0:s.fontWeight)||n.h2.fontWeight,semanticElement:n.h2.semanticElement},h3:{fontSize:el((c=t==null?void 0:t.h3)==null?void 0:c.fontSize)||n.h3.fontSize,fontWeight:hm((p=t==null?void 0:t.h3)==null?void 0:p.fontWeight)||n.h3.fontWeight,semanticElement:n.h3.semanticElement},body:{fontSize:el((h=t==null?void 0:t.body)==null?void 0:h.fontSize)||n.body.fontSize,fontWeight:hm((v=t==null?void 0:t.body)==null?void 0:v.fontWeight)||n.body.fontWeight,semanticElement:n.body.semanticElement}}}function Hb(t){if(t)switch(t){case Jh.Left:return "left";case Jh.Center:return "center";case Jh.Right:return "right";default:return}}function AS(t){let{palette:e,customCss:n,typography:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.paywallBackgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:jp(r),customCss:n||void 0}}function OS(t){let{palette:e,layout:n,customCss:r,typography:i}=t;return {customCss:r||void 0,palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:jp(i),layout:{ctaAlignment:Hb(n==null?void 0:n.alignment),headerAlignment:Hb(n==null?void 0:n.alignment),descriptionAlignment:Hb(n==null?void 0:n.alignment),planMaxWidth:el(n==null?void 0:n.planWidth),planMinWidth:el(n==null?void 0:n.planWidth),planMargin:el(n==null?void 0:n.planMargin),planPadding:el(n==null?void 0:n.planPadding)}}}function RS(t){let{palette:e,typography:n,customCss:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0},backgroundHighlight:(e==null?void 0:e.summaryBackgroundColor)||void 0},typography:jp(n,fm),customCss:r||void 0}}function SA(t){let e=true,n=(t==null?void 0:t.find(o=>o.status===bi.InTrial))||null,r=n==null?void 0:n.plan,i=n!=null&&n.trialEndDate?DS(n.trialEndDate):void 0;return r||(e=false,n=(t==null?void 0:t.find(o=>o.status===bi.Active))||null,r=n==null?void 0:n.plan),{currentSubscription:n,currentPlan:r,isCustomerOnTrial:e,trialDaysLeft:i}}function MS(t,e,n){var G,X;let{plans:r,currency:i,configuration:o,customer:s,activeSubscriptions:c,paywallCalculatedPricePoints:p}=t||{},{currentSubscription:h,currentPlan:v,isCustomerOnTrial:P,trialDaysLeft:x}=SA(c),T=n==null?void 0:n({currentSubscription:h}),I=(h==null?void 0:h.scheduledUpdates)||[],F=(G=h==null?void 0:h.price)==null?void 0:G.billingPeriod,A=I.find(({subscriptionScheduleType:nt})=>nt===Ui.Downgrade),O=I.find(({subscriptionScheduleType:nt})=>nt===Ui.BillingPeriod),N=hx__default.default(r,nt=>nt.order).map(nt=>{var dt;let st=(dt=s==null?void 0:s.eligibleForTrial)==null?void 0:dt.find(Y=>Y.productId===nt.product.id),U=T!=null&&T.planId?(T==null?void 0:T.planId)===nt.id:nt.id===(v==null?void 0:v.id),j=Y=>{var mt;let at=A==null?void 0:A.scheduleVariables,pt=O==null?void 0:O.scheduleVariables,ut=nt.pricePoints.some(Pt=>Pt.billingPeriod===Y);return A?((mt=A.targetPackage)==null?void 0:mt.refId)===nt.id&&(!ut||at.billingPeriod===Y):O&&U?pt.billingPeriod===Y:false};return Ct(W({},nt),{paywallCalculatedPricePoints:p==null?void 0:p.filter(Y=>Y.planId===nt.id),isTriable:!lm__default.default(nt.defaultTrialConfig)&&(!st||st.eligible),isCurrentCustomerPlan:U,currentCustomerPlanBillingPeriod:F,isUpcomingPlan:false,trialDaysLeft:x,isNextPlan:j,paywallCurrency:i,scheduledUpdate:A||O})});if(r&&v){let nt=v&&((X=r==null?void 0:r.find(st=>st.id===(v==null?void 0:v.id)))==null?void 0:X.order);lm__default.default(nt)||(N=N.map(st=>Ct(W({},st),{isLowerThanCurrentPlan:nt>st.order})),e&&(N=N.filter(st=>st.order>=nt)));}let V=o?OS(o):void 0;return {currentPlan:v,currentSubscription:h,currentSubscriptionOverride:T,isCustomerOnTrial:P,plans:N,paywallConfiguration:V}}var LS="7.8.0";var BS="@stigg/react-sdk";var Vp=$v__default.default.createContext(null);Vp.displayName="StiggContext";var TA="en-US",wA=({apiKey:t,baseUri:e,baseEdgeUri:n,enableEdge:r,customerId:i,customerToken:o,resourceId:s,theme:c,locale:p,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,entitlementsFallback:x,stiggClient:T,children:I,offline:F,clientName:A=BS,clientVersion:O=LS})=>{let N=$v.useRef(t),V={apiKey:t,customerId:i,customerToken:o,resourceId:s,baseUri:e,baseEdgeUri:n,enableEdge:r,entitlementsFallback:x,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,clientName:A,clientVersion:O,offline:F},[G,X]=$v.useState(()=>({stigg:T!=null?T:bb.initialize(Ct(W({},V),{lazyLoad:true})),locale:p||TA,isInitialized:false,theme:c,refreshData:()=>ce(null,null,function*(){X(nt=>Ct(W({},nt),{customerPortalUpdatedAt:new Date})),yield G.stigg.refresh();})}));return $v.useEffect(()=>{let nt=true,st=Y=>{nt&&X(Y);},U=()=>st(Y=>Ct(W({},Y),{updatedAt:new Date})),j=Y=>st(at=>(at.stigg&&at.stigg.removeListener("entitlementsUpdated",U),Y.addListener("entitlementsUpdated",U),Ct(W({},at),{stigg:Y,isInitialized:true,updatedAt:new Date})));return ce(null,null,function*(){let Y=G.stigg;t!==N.current&&(tl.log("Updating stigg client",{apiKey:t}),N.current=t,Y=bb.initialize(W({},V)),st(at=>Ct(W({},at),{isInitialized:false,updatedAt:new Date}))),yield Y.waitForInitialization(),j(Y);}),()=>{nt=false,G.stigg.removeListener("entitlementsUpdated",U),G.stigg.clearCustomer();}},[t]),$v.useEffect(()=>{let nt=G.stigg;i?nt.setCustomerId(i,o,s):nt.clearCustomer();},[i,o,s]),$v.useEffect(()=>{X(nt=>Ct(W({},nt),{theme:c}));},[c]),jsxRuntime.jsx(Vp.Provider,{value:G,children:jsxRuntime.jsx(nl.SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:I})})};function ve(t){let{optional:e}=t||{},n=$v.useContext(Vp);if(!n&&!e)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return n}function $S({productId:t,resourceId:e,showOnlyEligiblePlans:n,billingCountryCode:r,preferredBillingPeriod:i,currentSubscriptionOverrideFn:o}){let{stigg:s,locale:c}=ve(),[p,h]=$v.useState(be.Annually),[v,P]=$v.useState([]),[x,T]=$v.useState(null),[I,F]=$v.useState(true);$v.useEffect(()=>{ce(null,null,function*(){try{F(!0),yield s.waitForInitialization();let N=yield s.getPaywall({productId:t,resourceId:e,billingCountryCode:r}),{availableBillingPeriods:V,defaultBillingPeriod:G}=IS(N.plans,N.activeSubscriptions,i);T(N),P(V),h(G);}catch(N){tl.error(`Failed to load paywall ${N==null?void 0:N.message}`,N);}finally{F(false);}});},[s,t,s.isCustomerLoaded,r,e,i]);let A=MS(x,n,o);return W({customer:(x==null?void 0:x.customer)||null,isLoading:I,selectedBillingPeriod:p,setSelectedBillingPeriod:h,availableBillingPeriods:v,locale:c,configuration:A.paywallConfiguration,showWatermark:s.getShowWatermark()},A)}function GS(t){return HD__default.default({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:n=>{var r;return `Start ${(r=n.defaultTrialConfig)==null?void 0:r.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:n=>n===be.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:n=>n===be.Monthly?"/ month":"/ year",free:n=>({price:`${n==null?void 0:n.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},t)}var AA=t=>jsxRuntime.jsx("svg",Ct(W({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},t),{children:jsxRuntime.jsx("path",{d:"M5.59 7.9899L2.125 4.5249C1.73524 4.13514 1.10365 4.13402 0.712509 4.52241V4.52241C0.319409 4.91274 0.318286 5.54819 0.710005 5.9399L5.59 10.8199L14.2948 2.11513C14.6843 1.72565 14.6843 1.09417 14.2948 0.704691V0.704691C13.9055 0.315381 13.2743 0.315184 12.8848 0.70425L5.59 7.9899Z",fill:"#B2BBD3"})})),VS=AA;var OA=Q.div`
|
|
4970
|
+
`,wS=({plans:t,customer:e,currentSubscription:n,highlightedPlanId:r,selectedBillingPeriod:i,onBillingPeriodChanged:o,availableBillingPeriods:s,isCustomerOnTrial:c,onPlanSelected:p,paywallLocale:h,locale:v,shouldHidePlan:P,selectDefaultTierIndex:x,currentSubscriptionOverride:T,hideCompatibleAddons:I,showWatermark:F})=>{let A=xS(t),O=t.some(Y=>!!Y.description),N=jb(t,be.Monthly),V=jb(t,be.Annually),G=TS(t,i,P),X=$v.useCallback((Y,at,pt)=>p({plan:Y,customer:e,subscription:n,intentionType:at,selectedBillingPeriod:i,billableFeatures:pt}),[e,i,n,p]),nt=!!n&&n.plan.pricingType===Rn.Custom,st=$v.useMemo(()=>G.some(Y=>{var ut;let at=Y.pricePoints.filter(mt=>mt.billingPeriod===i),pt=(ut=Y.paywallCalculatedPricePoints)==null?void 0:ut.find(mt=>mt.billingPeriod===i);return at.length>1&&!!(pt!=null&&pt.additionalChargesMayApply)}),[i,G]),U=$v.useMemo(()=>G.some(Y=>!!um(Y,i,h,v,N).unit),[i,N,v,h,G]),j=$v.useMemo(()=>!nt&&G.some(Y=>{let at=cm({plan:Y,billingPeriod:i,currentSubscription:n,currentSubscriptionOverride:T});return Object.values(at).length>0}),[i,n,T,nt,G]),dt=G.some(Y=>Y.isCurrentCustomerPlan&&Y.trialDaysLeft);return jsxRuntime.jsx(mA,{className:"stigg-paywall-container",children:jsxRuntime.jsxs(gA,{className:"stigg-paywall-layout",children:[jsxRuntime.jsx(vS,{onBillingPeriodChanged:o,selectedBillingPeriod:i,availableBillingPeriods:s,discountRate:A}),jsxRuntime.jsx(hA,{className:"stigg-paywall-plans-layout",children:G.map(Y=>jsxRuntime.jsx(yS,{withUnitPriceRow:U,withTiersRow:j,withTrialLeftRow:dt,shouldShowDescriptionSection:O,hasMonthlyPrice:N,hasAnnuallyPrice:V,plan:Y,withStartingAtRow:st,currentSubscription:n,currentSubscriptionOverride:T,billingPeriod:i,isHighlighted:Y.id===r,isCustomerOnTrial:c,onPlanSelected:(at,pt)=>X(Y,at,pt),paywallLocale:h,locale:v,customer:e,isCustomerInCustomPlan:nt,selectDefaultTierIndex:x,hideCompatibleAddons:I},Y.id))}),jsxRuntime.jsx(so,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:F})]})})};var zb=class{error(e,n,...r){console.error(e,n||{},r);}log(e,n){console.log(e,n||{});}debug(e,n){console.debug(e,n||{});}},tl=new zb;function IS(t,e,n){let r=t.flatMap(c=>c.pricePoints).map(c=>c.billingPeriod),i=lodash.countBy(r),o=lodash.uniq(r),s;if(n&&o.includes(n))s=n;else if(e){let c=e.find(p=>p.status===bi.Active);c&&c.prices.length>0&&(s=c==null?void 0:c.prices[0].billingPeriod);}return s||(s=(i[be.Monthly]||0)>(i[be.Annually]||0)?be.Monthly:be.Annually),{defaultBillingPeriod:s,availableBillingPeriods:o}}function DS(t){return j1__default.default.utc(t).diff(j1__default.default.utc(),"days",false)+1}var fm={h1:{fontSize:"24px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"16px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};function el(t,e="px"){if(t)return `${t}${e}`}function hm(t){if(!t)return "normal";switch(t){case gb.Normal:return "normal";case gb.Bold:return "bold";default:return "normal"}}function jp(t,e){var r,i,o,s,c,p,h,v;let n=e||{h1:{fontSize:"32px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"24px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};return {fontFamilyUrl:(t==null?void 0:t.fontFamily)||void 0,h1:{fontSize:el((r=t==null?void 0:t.h1)==null?void 0:r.fontSize)||n.h1.fontSize,fontWeight:hm((i=t==null?void 0:t.h1)==null?void 0:i.fontWeight)||n.h1.fontWeight,semanticElement:n.h1.semanticElement},h2:{fontSize:el((o=t==null?void 0:t.h2)==null?void 0:o.fontSize)||n.h2.fontSize,fontWeight:hm((s=t==null?void 0:t.h2)==null?void 0:s.fontWeight)||n.h2.fontWeight,semanticElement:n.h2.semanticElement},h3:{fontSize:el((c=t==null?void 0:t.h3)==null?void 0:c.fontSize)||n.h3.fontSize,fontWeight:hm((p=t==null?void 0:t.h3)==null?void 0:p.fontWeight)||n.h3.fontWeight,semanticElement:n.h3.semanticElement},body:{fontSize:el((h=t==null?void 0:t.body)==null?void 0:h.fontSize)||n.body.fontSize,fontWeight:hm((v=t==null?void 0:t.body)==null?void 0:v.fontWeight)||n.body.fontWeight,semanticElement:n.body.semanticElement}}}function Hb(t){if(t)switch(t){case Jh.Left:return "left";case Jh.Center:return "center";case Jh.Right:return "right";default:return}}function AS(t){let{palette:e,customCss:n,typography:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.paywallBackgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:jp(r),customCss:n||void 0}}function OS(t){let{palette:e,layout:n,customCss:r,typography:i}=t;return {customCss:r||void 0,palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:jp(i),layout:{ctaAlignment:Hb(n==null?void 0:n.alignment),headerAlignment:Hb(n==null?void 0:n.alignment),descriptionAlignment:Hb(n==null?void 0:n.alignment),planMaxWidth:el(n==null?void 0:n.planWidth),planMinWidth:el(n==null?void 0:n.planWidth),planMargin:el(n==null?void 0:n.planMargin),planPadding:el(n==null?void 0:n.planPadding)}}}function RS(t){let{palette:e,typography:n,customCss:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0},backgroundHighlight:(e==null?void 0:e.summaryBackgroundColor)||void 0},typography:jp(n,fm),customCss:r||void 0}}function SA(t){let e=true,n=(t==null?void 0:t.find(o=>o.status===bi.InTrial))||null,r=n==null?void 0:n.plan,i=n!=null&&n.trialEndDate?DS(n.trialEndDate):void 0;return r||(e=false,n=(t==null?void 0:t.find(o=>o.status===bi.Active))||null,r=n==null?void 0:n.plan),{currentSubscription:n,currentPlan:r,isCustomerOnTrial:e,trialDaysLeft:i}}function MS(t,e,n){var G,X;let{plans:r,currency:i,configuration:o,customer:s,activeSubscriptions:c,paywallCalculatedPricePoints:p}=t||{},{currentSubscription:h,currentPlan:v,isCustomerOnTrial:P,trialDaysLeft:x}=SA(c),T=n==null?void 0:n({currentSubscription:h}),I=(h==null?void 0:h.scheduledUpdates)||[],F=(G=h==null?void 0:h.price)==null?void 0:G.billingPeriod,A=I.find(({subscriptionScheduleType:nt})=>nt===Ui.Downgrade),O=I.find(({subscriptionScheduleType:nt})=>nt===Ui.BillingPeriod),N=hx__default.default(r,nt=>nt.order).map(nt=>{var dt;let st=(dt=s==null?void 0:s.eligibleForTrial)==null?void 0:dt.find(Y=>Y.productId===nt.product.id),U=T!=null&&T.planId?(T==null?void 0:T.planId)===nt.id:nt.id===(v==null?void 0:v.id),j=Y=>{var mt;let at=A==null?void 0:A.scheduleVariables,pt=O==null?void 0:O.scheduleVariables,ut=nt.pricePoints.some(Pt=>Pt.billingPeriod===Y);return A?((mt=A.targetPackage)==null?void 0:mt.refId)===nt.id&&(!ut||at.billingPeriod===Y):O&&U?pt.billingPeriod===Y:false};return Ct(W({},nt),{paywallCalculatedPricePoints:p==null?void 0:p.filter(Y=>Y.planId===nt.id),isTriable:!lm__default.default(nt.defaultTrialConfig)&&(!st||st.eligible),isCurrentCustomerPlan:U,currentCustomerPlanBillingPeriod:F,isUpcomingPlan:false,trialDaysLeft:x,isNextPlan:j,paywallCurrency:i,scheduledUpdate:A||O})});if(r&&v){let nt=v&&((X=r==null?void 0:r.find(st=>st.id===(v==null?void 0:v.id)))==null?void 0:X.order);lm__default.default(nt)||(N=N.map(st=>Ct(W({},st),{isLowerThanCurrentPlan:nt>st.order})),e&&(N=N.filter(st=>st.order>=nt)));}let V=o?OS(o):void 0;return {currentPlan:v,currentSubscription:h,currentSubscriptionOverride:T,isCustomerOnTrial:P,plans:N,paywallConfiguration:V}}var LS="7.8.0-beta.1";var BS="@stigg/react-sdk";var Vp=$v__default.default.createContext(null);Vp.displayName="StiggContext";var TA="en-US",wA=({apiKey:t,baseUri:e,baseEdgeUri:n,enableEdge:r,customerId:i,customerToken:o,resourceId:s,theme:c,locale:p,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,entitlementsFallback:x,stiggClient:T,children:I,offline:F,clientName:A=BS,clientVersion:O=LS})=>{let N=$v.useRef(t),V={apiKey:t,customerId:i,customerToken:o,resourceId:s,baseUri:e,baseEdgeUri:n,enableEdge:r,entitlementsFallback:x,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,clientName:A,clientVersion:O,offline:F},[G,X]=$v.useState(()=>({stigg:T!=null?T:bb.initialize(Ct(W({},V),{lazyLoad:true})),locale:p||TA,isInitialized:false,theme:c,refreshData:()=>ce(null,null,function*(){X(nt=>Ct(W({},nt),{customerPortalUpdatedAt:new Date})),yield G.stigg.refresh();})}));return $v.useEffect(()=>{let nt=true,st=Y=>{nt&&X(Y);},U=()=>st(Y=>Ct(W({},Y),{updatedAt:new Date})),j=Y=>st(at=>(at.stigg&&at.stigg.removeListener("entitlementsUpdated",U),Y.addListener("entitlementsUpdated",U),Ct(W({},at),{stigg:Y,isInitialized:true,updatedAt:new Date})));return ce(null,null,function*(){let Y=G.stigg;t!==N.current&&(tl.log("Updating stigg client",{apiKey:t}),N.current=t,Y=bb.initialize(W({},V)),st(at=>Ct(W({},at),{isInitialized:false,updatedAt:new Date}))),yield Y.waitForInitialization(),j(Y);}),()=>{nt=false,G.stigg.removeListener("entitlementsUpdated",U),G.stigg.clearCustomer();}},[t]),$v.useEffect(()=>{let nt=G.stigg;i?nt.setCustomerId(i,o,s):nt.clearCustomer();},[i,o,s]),$v.useEffect(()=>{X(nt=>Ct(W({},nt),{theme:c}));},[c]),jsxRuntime.jsx(Vp.Provider,{value:G,children:jsxRuntime.jsx(nl.SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:I})})};function ve(t){let{optional:e}=t||{},n=$v.useContext(Vp);if(!n&&!e)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return n}function $S({productId:t,resourceId:e,showOnlyEligiblePlans:n,billingCountryCode:r,preferredBillingPeriod:i,currentSubscriptionOverrideFn:o}){let{stigg:s,locale:c}=ve(),[p,h]=$v.useState(be.Annually),[v,P]=$v.useState([]),[x,T]=$v.useState(null),[I,F]=$v.useState(true);$v.useEffect(()=>{ce(null,null,function*(){try{F(!0),yield s.waitForInitialization();let N=yield s.getPaywall({productId:t,resourceId:e,billingCountryCode:r}),{availableBillingPeriods:V,defaultBillingPeriod:G}=IS(N.plans,N.activeSubscriptions,i);T(N),P(V),h(G);}catch(N){tl.error(`Failed to load paywall ${N==null?void 0:N.message}`,N);}finally{F(false);}});},[s,t,s.isCustomerLoaded,r,e,i]);let A=MS(x,n,o);return W({customer:(x==null?void 0:x.customer)||null,isLoading:I,selectedBillingPeriod:p,setSelectedBillingPeriod:h,availableBillingPeriods:v,locale:c,configuration:A.paywallConfiguration,showWatermark:s.getShowWatermark()},A)}function GS(t){return HD__default.default({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:n=>{var r;return `Start ${(r=n.defaultTrialConfig)==null?void 0:r.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:n=>n===be.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:n=>n===be.Monthly?"/ month":"/ year",free:n=>({price:`${n==null?void 0:n.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},t)}var AA=t=>jsxRuntime.jsx("svg",Ct(W({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},t),{children:jsxRuntime.jsx("path",{d:"M5.59 7.9899L2.125 4.5249C1.73524 4.13514 1.10365 4.13402 0.712509 4.52241V4.52241C0.319409 4.91274 0.318286 5.54819 0.710005 5.9399L5.59 10.8199L14.2948 2.11513C14.6843 1.72565 14.6843 1.09417 14.2948 0.704691V0.704691C13.9055 0.315381 13.2743 0.315184 12.8848 0.70425L5.59 7.9899Z",fill:"#B2BBD3"})})),VS=AA;var OA=Q.div`
|
|
4971
4971
|
display: flex;
|
|
4972
4972
|
flex-direction: column;
|
|
4973
4973
|
align-items: center;
|
package/dist/stigg-sdk.esm.js
CHANGED
|
@@ -4967,7 +4967,7 @@ ${e.o5f}`,e.zBW=r.default`
|
|
|
4967
4967
|
display: flex;
|
|
4968
4968
|
flex-direction: column;
|
|
4969
4969
|
align-items: center;
|
|
4970
|
-
`,wS=({plans:t,customer:e,currentSubscription:n,highlightedPlanId:r,selectedBillingPeriod:i,onBillingPeriodChanged:o,availableBillingPeriods:s,isCustomerOnTrial:c,onPlanSelected:p,paywallLocale:h,locale:v,shouldHidePlan:P,selectDefaultTierIndex:x,currentSubscriptionOverride:T,hideCompatibleAddons:I,showWatermark:F})=>{let A=xS(t),O=t.some(Y=>!!Y.description),N=jb(t,be.Monthly),V=jb(t,be.Annually),G=TS(t,i,P),X=useCallback((Y,at,pt)=>p({plan:Y,customer:e,subscription:n,intentionType:at,selectedBillingPeriod:i,billableFeatures:pt}),[e,i,n,p]),nt=!!n&&n.plan.pricingType===Rn.Custom,st=useMemo(()=>G.some(Y=>{var ut;let at=Y.pricePoints.filter(mt=>mt.billingPeriod===i),pt=(ut=Y.paywallCalculatedPricePoints)==null?void 0:ut.find(mt=>mt.billingPeriod===i);return at.length>1&&!!(pt!=null&&pt.additionalChargesMayApply)}),[i,G]),U=useMemo(()=>G.some(Y=>!!um(Y,i,h,v,N).unit),[i,N,v,h,G]),j=useMemo(()=>!nt&&G.some(Y=>{let at=cm({plan:Y,billingPeriod:i,currentSubscription:n,currentSubscriptionOverride:T});return Object.values(at).length>0}),[i,n,T,nt,G]),dt=G.some(Y=>Y.isCurrentCustomerPlan&&Y.trialDaysLeft);return jsx(mA,{className:"stigg-paywall-container",children:jsxs(gA,{className:"stigg-paywall-layout",children:[jsx(vS,{onBillingPeriodChanged:o,selectedBillingPeriod:i,availableBillingPeriods:s,discountRate:A}),jsx(hA,{className:"stigg-paywall-plans-layout",children:G.map(Y=>jsx(yS,{withUnitPriceRow:U,withTiersRow:j,withTrialLeftRow:dt,shouldShowDescriptionSection:O,hasMonthlyPrice:N,hasAnnuallyPrice:V,plan:Y,withStartingAtRow:st,currentSubscription:n,currentSubscriptionOverride:T,billingPeriod:i,isHighlighted:Y.id===r,isCustomerOnTrial:c,onPlanSelected:(at,pt)=>X(Y,at,pt),paywallLocale:h,locale:v,customer:e,isCustomerInCustomPlan:nt,selectDefaultTierIndex:x,hideCompatibleAddons:I},Y.id))}),jsx(so,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:F})]})})};var zb=class{error(e,n,...r){console.error(e,n||{},r);}log(e,n){console.log(e,n||{});}debug(e,n){console.debug(e,n||{});}},tl=new zb;function IS(t,e,n){let r=t.flatMap(c=>c.pricePoints).map(c=>c.billingPeriod),i=countBy(r),o=uniq(r),s;if(n&&o.includes(n))s=n;else if(e){let c=e.find(p=>p.status===bi.Active);c&&c.prices.length>0&&(s=c==null?void 0:c.prices[0].billingPeriod);}return s||(s=(i[be.Monthly]||0)>(i[be.Annually]||0)?be.Monthly:be.Annually),{defaultBillingPeriod:s,availableBillingPeriods:o}}function DS(t){return j1.utc(t).diff(j1.utc(),"days",false)+1}var fm={h1:{fontSize:"24px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"16px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};function el(t,e="px"){if(t)return `${t}${e}`}function hm(t){if(!t)return "normal";switch(t){case gb.Normal:return "normal";case gb.Bold:return "bold";default:return "normal"}}function jp(t,e){var r,i,o,s,c,p,h,v;let n=e||{h1:{fontSize:"32px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"24px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};return {fontFamilyUrl:(t==null?void 0:t.fontFamily)||void 0,h1:{fontSize:el((r=t==null?void 0:t.h1)==null?void 0:r.fontSize)||n.h1.fontSize,fontWeight:hm((i=t==null?void 0:t.h1)==null?void 0:i.fontWeight)||n.h1.fontWeight,semanticElement:n.h1.semanticElement},h2:{fontSize:el((o=t==null?void 0:t.h2)==null?void 0:o.fontSize)||n.h2.fontSize,fontWeight:hm((s=t==null?void 0:t.h2)==null?void 0:s.fontWeight)||n.h2.fontWeight,semanticElement:n.h2.semanticElement},h3:{fontSize:el((c=t==null?void 0:t.h3)==null?void 0:c.fontSize)||n.h3.fontSize,fontWeight:hm((p=t==null?void 0:t.h3)==null?void 0:p.fontWeight)||n.h3.fontWeight,semanticElement:n.h3.semanticElement},body:{fontSize:el((h=t==null?void 0:t.body)==null?void 0:h.fontSize)||n.body.fontSize,fontWeight:hm((v=t==null?void 0:t.body)==null?void 0:v.fontWeight)||n.body.fontWeight,semanticElement:n.body.semanticElement}}}function Hb(t){if(t)switch(t){case Jh.Left:return "left";case Jh.Center:return "center";case Jh.Right:return "right";default:return}}function AS(t){let{palette:e,customCss:n,typography:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.paywallBackgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:jp(r),customCss:n||void 0}}function OS(t){let{palette:e,layout:n,customCss:r,typography:i}=t;return {customCss:r||void 0,palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:jp(i),layout:{ctaAlignment:Hb(n==null?void 0:n.alignment),headerAlignment:Hb(n==null?void 0:n.alignment),descriptionAlignment:Hb(n==null?void 0:n.alignment),planMaxWidth:el(n==null?void 0:n.planWidth),planMinWidth:el(n==null?void 0:n.planWidth),planMargin:el(n==null?void 0:n.planMargin),planPadding:el(n==null?void 0:n.planPadding)}}}function RS(t){let{palette:e,typography:n,customCss:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0},backgroundHighlight:(e==null?void 0:e.summaryBackgroundColor)||void 0},typography:jp(n,fm),customCss:r||void 0}}function SA(t){let e=true,n=(t==null?void 0:t.find(o=>o.status===bi.InTrial))||null,r=n==null?void 0:n.plan,i=n!=null&&n.trialEndDate?DS(n.trialEndDate):void 0;return r||(e=false,n=(t==null?void 0:t.find(o=>o.status===bi.Active))||null,r=n==null?void 0:n.plan),{currentSubscription:n,currentPlan:r,isCustomerOnTrial:e,trialDaysLeft:i}}function MS(t,e,n){var G,X;let{plans:r,currency:i,configuration:o,customer:s,activeSubscriptions:c,paywallCalculatedPricePoints:p}=t||{},{currentSubscription:h,currentPlan:v,isCustomerOnTrial:P,trialDaysLeft:x}=SA(c),T=n==null?void 0:n({currentSubscription:h}),I=(h==null?void 0:h.scheduledUpdates)||[],F=(G=h==null?void 0:h.price)==null?void 0:G.billingPeriod,A=I.find(({subscriptionScheduleType:nt})=>nt===Ui.Downgrade),O=I.find(({subscriptionScheduleType:nt})=>nt===Ui.BillingPeriod),N=hx(r,nt=>nt.order).map(nt=>{var dt;let st=(dt=s==null?void 0:s.eligibleForTrial)==null?void 0:dt.find(Y=>Y.productId===nt.product.id),U=T!=null&&T.planId?(T==null?void 0:T.planId)===nt.id:nt.id===(v==null?void 0:v.id),j=Y=>{var mt;let at=A==null?void 0:A.scheduleVariables,pt=O==null?void 0:O.scheduleVariables,ut=nt.pricePoints.some(Pt=>Pt.billingPeriod===Y);return A?((mt=A.targetPackage)==null?void 0:mt.refId)===nt.id&&(!ut||at.billingPeriod===Y):O&&U?pt.billingPeriod===Y:false};return Ct(W({},nt),{paywallCalculatedPricePoints:p==null?void 0:p.filter(Y=>Y.planId===nt.id),isTriable:!lm(nt.defaultTrialConfig)&&(!st||st.eligible),isCurrentCustomerPlan:U,currentCustomerPlanBillingPeriod:F,isUpcomingPlan:false,trialDaysLeft:x,isNextPlan:j,paywallCurrency:i,scheduledUpdate:A||O})});if(r&&v){let nt=v&&((X=r==null?void 0:r.find(st=>st.id===(v==null?void 0:v.id)))==null?void 0:X.order);lm(nt)||(N=N.map(st=>Ct(W({},st),{isLowerThanCurrentPlan:nt>st.order})),e&&(N=N.filter(st=>st.order>=nt)));}let V=o?OS(o):void 0;return {currentPlan:v,currentSubscription:h,currentSubscriptionOverride:T,isCustomerOnTrial:P,plans:N,paywallConfiguration:V}}var LS="7.8.0";var BS="@stigg/react-sdk";var Vp=$v.createContext(null);Vp.displayName="StiggContext";var TA="en-US",wA=({apiKey:t,baseUri:e,baseEdgeUri:n,enableEdge:r,customerId:i,customerToken:o,resourceId:s,theme:c,locale:p,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,entitlementsFallback:x,stiggClient:T,children:I,offline:F,clientName:A=BS,clientVersion:O=LS})=>{let N=useRef(t),V={apiKey:t,customerId:i,customerToken:o,resourceId:s,baseUri:e,baseEdgeUri:n,enableEdge:r,entitlementsFallback:x,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,clientName:A,clientVersion:O,offline:F},[G,X]=useState(()=>({stigg:T!=null?T:bb.initialize(Ct(W({},V),{lazyLoad:true})),locale:p||TA,isInitialized:false,theme:c,refreshData:()=>ce(null,null,function*(){X(nt=>Ct(W({},nt),{customerPortalUpdatedAt:new Date})),yield G.stigg.refresh();})}));return useEffect(()=>{let nt=true,st=Y=>{nt&&X(Y);},U=()=>st(Y=>Ct(W({},Y),{updatedAt:new Date})),j=Y=>st(at=>(at.stigg&&at.stigg.removeListener("entitlementsUpdated",U),Y.addListener("entitlementsUpdated",U),Ct(W({},at),{stigg:Y,isInitialized:true,updatedAt:new Date})));return ce(null,null,function*(){let Y=G.stigg;t!==N.current&&(tl.log("Updating stigg client",{apiKey:t}),N.current=t,Y=bb.initialize(W({},V)),st(at=>Ct(W({},at),{isInitialized:false,updatedAt:new Date}))),yield Y.waitForInitialization(),j(Y);}),()=>{nt=false,G.stigg.removeListener("entitlementsUpdated",U),G.stigg.clearCustomer();}},[t]),useEffect(()=>{let nt=G.stigg;i?nt.setCustomerId(i,o,s):nt.clearCustomer();},[i,o,s]),useEffect(()=>{X(nt=>Ct(W({},nt),{theme:c}));},[c]),jsx(Vp.Provider,{value:G,children:jsx(SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:I})})};function ve(t){let{optional:e}=t||{},n=useContext(Vp);if(!n&&!e)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return n}function $S({productId:t,resourceId:e,showOnlyEligiblePlans:n,billingCountryCode:r,preferredBillingPeriod:i,currentSubscriptionOverrideFn:o}){let{stigg:s,locale:c}=ve(),[p,h]=useState(be.Annually),[v,P]=useState([]),[x,T]=useState(null),[I,F]=useState(true);useEffect(()=>{ce(null,null,function*(){try{F(!0),yield s.waitForInitialization();let N=yield s.getPaywall({productId:t,resourceId:e,billingCountryCode:r}),{availableBillingPeriods:V,defaultBillingPeriod:G}=IS(N.plans,N.activeSubscriptions,i);T(N),P(V),h(G);}catch(N){tl.error(`Failed to load paywall ${N==null?void 0:N.message}`,N);}finally{F(false);}});},[s,t,s.isCustomerLoaded,r,e,i]);let A=MS(x,n,o);return W({customer:(x==null?void 0:x.customer)||null,isLoading:I,selectedBillingPeriod:p,setSelectedBillingPeriod:h,availableBillingPeriods:v,locale:c,configuration:A.paywallConfiguration,showWatermark:s.getShowWatermark()},A)}function GS(t){return HD({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:n=>{var r;return `Start ${(r=n.defaultTrialConfig)==null?void 0:r.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:n=>n===be.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:n=>n===be.Monthly?"/ month":"/ year",free:n=>({price:`${n==null?void 0:n.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},t)}var AA=t=>jsx("svg",Ct(W({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},t),{children:jsx("path",{d:"M5.59 7.9899L2.125 4.5249C1.73524 4.13514 1.10365 4.13402 0.712509 4.52241V4.52241C0.319409 4.91274 0.318286 5.54819 0.710005 5.9399L5.59 10.8199L14.2948 2.11513C14.6843 1.72565 14.6843 1.09417 14.2948 0.704691V0.704691C13.9055 0.315381 13.2743 0.315184 12.8848 0.70425L5.59 7.9899Z",fill:"#B2BBD3"})})),VS=AA;var OA=Q.div`
|
|
4970
|
+
`,wS=({plans:t,customer:e,currentSubscription:n,highlightedPlanId:r,selectedBillingPeriod:i,onBillingPeriodChanged:o,availableBillingPeriods:s,isCustomerOnTrial:c,onPlanSelected:p,paywallLocale:h,locale:v,shouldHidePlan:P,selectDefaultTierIndex:x,currentSubscriptionOverride:T,hideCompatibleAddons:I,showWatermark:F})=>{let A=xS(t),O=t.some(Y=>!!Y.description),N=jb(t,be.Monthly),V=jb(t,be.Annually),G=TS(t,i,P),X=useCallback((Y,at,pt)=>p({plan:Y,customer:e,subscription:n,intentionType:at,selectedBillingPeriod:i,billableFeatures:pt}),[e,i,n,p]),nt=!!n&&n.plan.pricingType===Rn.Custom,st=useMemo(()=>G.some(Y=>{var ut;let at=Y.pricePoints.filter(mt=>mt.billingPeriod===i),pt=(ut=Y.paywallCalculatedPricePoints)==null?void 0:ut.find(mt=>mt.billingPeriod===i);return at.length>1&&!!(pt!=null&&pt.additionalChargesMayApply)}),[i,G]),U=useMemo(()=>G.some(Y=>!!um(Y,i,h,v,N).unit),[i,N,v,h,G]),j=useMemo(()=>!nt&&G.some(Y=>{let at=cm({plan:Y,billingPeriod:i,currentSubscription:n,currentSubscriptionOverride:T});return Object.values(at).length>0}),[i,n,T,nt,G]),dt=G.some(Y=>Y.isCurrentCustomerPlan&&Y.trialDaysLeft);return jsx(mA,{className:"stigg-paywall-container",children:jsxs(gA,{className:"stigg-paywall-layout",children:[jsx(vS,{onBillingPeriodChanged:o,selectedBillingPeriod:i,availableBillingPeriods:s,discountRate:A}),jsx(hA,{className:"stigg-paywall-plans-layout",children:G.map(Y=>jsx(yS,{withUnitPriceRow:U,withTiersRow:j,withTrialLeftRow:dt,shouldShowDescriptionSection:O,hasMonthlyPrice:N,hasAnnuallyPrice:V,plan:Y,withStartingAtRow:st,currentSubscription:n,currentSubscriptionOverride:T,billingPeriod:i,isHighlighted:Y.id===r,isCustomerOnTrial:c,onPlanSelected:(at,pt)=>X(Y,at,pt),paywallLocale:h,locale:v,customer:e,isCustomerInCustomPlan:nt,selectDefaultTierIndex:x,hideCompatibleAddons:I},Y.id))}),jsx(so,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:F})]})})};var zb=class{error(e,n,...r){console.error(e,n||{},r);}log(e,n){console.log(e,n||{});}debug(e,n){console.debug(e,n||{});}},tl=new zb;function IS(t,e,n){let r=t.flatMap(c=>c.pricePoints).map(c=>c.billingPeriod),i=countBy(r),o=uniq(r),s;if(n&&o.includes(n))s=n;else if(e){let c=e.find(p=>p.status===bi.Active);c&&c.prices.length>0&&(s=c==null?void 0:c.prices[0].billingPeriod);}return s||(s=(i[be.Monthly]||0)>(i[be.Annually]||0)?be.Monthly:be.Annually),{defaultBillingPeriod:s,availableBillingPeriods:o}}function DS(t){return j1.utc(t).diff(j1.utc(),"days",false)+1}var fm={h1:{fontSize:"24px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"16px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};function el(t,e="px"){if(t)return `${t}${e}`}function hm(t){if(!t)return "normal";switch(t){case gb.Normal:return "normal";case gb.Bold:return "bold";default:return "normal"}}function jp(t,e){var r,i,o,s,c,p,h,v;let n=e||{h1:{fontSize:"32px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"24px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};return {fontFamilyUrl:(t==null?void 0:t.fontFamily)||void 0,h1:{fontSize:el((r=t==null?void 0:t.h1)==null?void 0:r.fontSize)||n.h1.fontSize,fontWeight:hm((i=t==null?void 0:t.h1)==null?void 0:i.fontWeight)||n.h1.fontWeight,semanticElement:n.h1.semanticElement},h2:{fontSize:el((o=t==null?void 0:t.h2)==null?void 0:o.fontSize)||n.h2.fontSize,fontWeight:hm((s=t==null?void 0:t.h2)==null?void 0:s.fontWeight)||n.h2.fontWeight,semanticElement:n.h2.semanticElement},h3:{fontSize:el((c=t==null?void 0:t.h3)==null?void 0:c.fontSize)||n.h3.fontSize,fontWeight:hm((p=t==null?void 0:t.h3)==null?void 0:p.fontWeight)||n.h3.fontWeight,semanticElement:n.h3.semanticElement},body:{fontSize:el((h=t==null?void 0:t.body)==null?void 0:h.fontSize)||n.body.fontSize,fontWeight:hm((v=t==null?void 0:t.body)==null?void 0:v.fontWeight)||n.body.fontWeight,semanticElement:n.body.semanticElement}}}function Hb(t){if(t)switch(t){case Jh.Left:return "left";case Jh.Center:return "center";case Jh.Right:return "right";default:return}}function AS(t){let{palette:e,customCss:n,typography:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.paywallBackgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:jp(r),customCss:n||void 0}}function OS(t){let{palette:e,layout:n,customCss:r,typography:i}=t;return {customCss:r||void 0,palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:jp(i),layout:{ctaAlignment:Hb(n==null?void 0:n.alignment),headerAlignment:Hb(n==null?void 0:n.alignment),descriptionAlignment:Hb(n==null?void 0:n.alignment),planMaxWidth:el(n==null?void 0:n.planWidth),planMinWidth:el(n==null?void 0:n.planWidth),planMargin:el(n==null?void 0:n.planMargin),planPadding:el(n==null?void 0:n.planPadding)}}}function RS(t){let{palette:e,typography:n,customCss:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0},backgroundHighlight:(e==null?void 0:e.summaryBackgroundColor)||void 0},typography:jp(n,fm),customCss:r||void 0}}function SA(t){let e=true,n=(t==null?void 0:t.find(o=>o.status===bi.InTrial))||null,r=n==null?void 0:n.plan,i=n!=null&&n.trialEndDate?DS(n.trialEndDate):void 0;return r||(e=false,n=(t==null?void 0:t.find(o=>o.status===bi.Active))||null,r=n==null?void 0:n.plan),{currentSubscription:n,currentPlan:r,isCustomerOnTrial:e,trialDaysLeft:i}}function MS(t,e,n){var G,X;let{plans:r,currency:i,configuration:o,customer:s,activeSubscriptions:c,paywallCalculatedPricePoints:p}=t||{},{currentSubscription:h,currentPlan:v,isCustomerOnTrial:P,trialDaysLeft:x}=SA(c),T=n==null?void 0:n({currentSubscription:h}),I=(h==null?void 0:h.scheduledUpdates)||[],F=(G=h==null?void 0:h.price)==null?void 0:G.billingPeriod,A=I.find(({subscriptionScheduleType:nt})=>nt===Ui.Downgrade),O=I.find(({subscriptionScheduleType:nt})=>nt===Ui.BillingPeriod),N=hx(r,nt=>nt.order).map(nt=>{var dt;let st=(dt=s==null?void 0:s.eligibleForTrial)==null?void 0:dt.find(Y=>Y.productId===nt.product.id),U=T!=null&&T.planId?(T==null?void 0:T.planId)===nt.id:nt.id===(v==null?void 0:v.id),j=Y=>{var mt;let at=A==null?void 0:A.scheduleVariables,pt=O==null?void 0:O.scheduleVariables,ut=nt.pricePoints.some(Pt=>Pt.billingPeriod===Y);return A?((mt=A.targetPackage)==null?void 0:mt.refId)===nt.id&&(!ut||at.billingPeriod===Y):O&&U?pt.billingPeriod===Y:false};return Ct(W({},nt),{paywallCalculatedPricePoints:p==null?void 0:p.filter(Y=>Y.planId===nt.id),isTriable:!lm(nt.defaultTrialConfig)&&(!st||st.eligible),isCurrentCustomerPlan:U,currentCustomerPlanBillingPeriod:F,isUpcomingPlan:false,trialDaysLeft:x,isNextPlan:j,paywallCurrency:i,scheduledUpdate:A||O})});if(r&&v){let nt=v&&((X=r==null?void 0:r.find(st=>st.id===(v==null?void 0:v.id)))==null?void 0:X.order);lm(nt)||(N=N.map(st=>Ct(W({},st),{isLowerThanCurrentPlan:nt>st.order})),e&&(N=N.filter(st=>st.order>=nt)));}let V=o?OS(o):void 0;return {currentPlan:v,currentSubscription:h,currentSubscriptionOverride:T,isCustomerOnTrial:P,plans:N,paywallConfiguration:V}}var LS="7.8.0-beta.1";var BS="@stigg/react-sdk";var Vp=$v.createContext(null);Vp.displayName="StiggContext";var TA="en-US",wA=({apiKey:t,baseUri:e,baseEdgeUri:n,enableEdge:r,customerId:i,customerToken:o,resourceId:s,theme:c,locale:p,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,entitlementsFallback:x,stiggClient:T,children:I,offline:F,clientName:A=BS,clientVersion:O=LS})=>{let N=useRef(t),V={apiKey:t,customerId:i,customerToken:o,resourceId:s,baseUri:e,baseEdgeUri:n,enableEdge:r,entitlementsFallback:x,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,clientName:A,clientVersion:O,offline:F},[G,X]=useState(()=>({stigg:T!=null?T:bb.initialize(Ct(W({},V),{lazyLoad:true})),locale:p||TA,isInitialized:false,theme:c,refreshData:()=>ce(null,null,function*(){X(nt=>Ct(W({},nt),{customerPortalUpdatedAt:new Date})),yield G.stigg.refresh();})}));return useEffect(()=>{let nt=true,st=Y=>{nt&&X(Y);},U=()=>st(Y=>Ct(W({},Y),{updatedAt:new Date})),j=Y=>st(at=>(at.stigg&&at.stigg.removeListener("entitlementsUpdated",U),Y.addListener("entitlementsUpdated",U),Ct(W({},at),{stigg:Y,isInitialized:true,updatedAt:new Date})));return ce(null,null,function*(){let Y=G.stigg;t!==N.current&&(tl.log("Updating stigg client",{apiKey:t}),N.current=t,Y=bb.initialize(W({},V)),st(at=>Ct(W({},at),{isInitialized:false,updatedAt:new Date}))),yield Y.waitForInitialization(),j(Y);}),()=>{nt=false,G.stigg.removeListener("entitlementsUpdated",U),G.stigg.clearCustomer();}},[t]),useEffect(()=>{let nt=G.stigg;i?nt.setCustomerId(i,o,s):nt.clearCustomer();},[i,o,s]),useEffect(()=>{X(nt=>Ct(W({},nt),{theme:c}));},[c]),jsx(Vp.Provider,{value:G,children:jsx(SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:I})})};function ve(t){let{optional:e}=t||{},n=useContext(Vp);if(!n&&!e)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return n}function $S({productId:t,resourceId:e,showOnlyEligiblePlans:n,billingCountryCode:r,preferredBillingPeriod:i,currentSubscriptionOverrideFn:o}){let{stigg:s,locale:c}=ve(),[p,h]=useState(be.Annually),[v,P]=useState([]),[x,T]=useState(null),[I,F]=useState(true);useEffect(()=>{ce(null,null,function*(){try{F(!0),yield s.waitForInitialization();let N=yield s.getPaywall({productId:t,resourceId:e,billingCountryCode:r}),{availableBillingPeriods:V,defaultBillingPeriod:G}=IS(N.plans,N.activeSubscriptions,i);T(N),P(V),h(G);}catch(N){tl.error(`Failed to load paywall ${N==null?void 0:N.message}`,N);}finally{F(false);}});},[s,t,s.isCustomerLoaded,r,e,i]);let A=MS(x,n,o);return W({customer:(x==null?void 0:x.customer)||null,isLoading:I,selectedBillingPeriod:p,setSelectedBillingPeriod:h,availableBillingPeriods:v,locale:c,configuration:A.paywallConfiguration,showWatermark:s.getShowWatermark()},A)}function GS(t){return HD({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:n=>{var r;return `Start ${(r=n.defaultTrialConfig)==null?void 0:r.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:n=>n===be.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:n=>n===be.Monthly?"/ month":"/ year",free:n=>({price:`${n==null?void 0:n.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},t)}var AA=t=>jsx("svg",Ct(W({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},t),{children:jsx("path",{d:"M5.59 7.9899L2.125 4.5249C1.73524 4.13514 1.10365 4.13402 0.712509 4.52241V4.52241C0.319409 4.91274 0.318286 5.54819 0.710005 5.9399L5.59 10.8199L14.2948 2.11513C14.6843 1.72565 14.6843 1.09417 14.2948 0.704691V0.704691C13.9055 0.315381 13.2743 0.315184 12.8848 0.70425L5.59 7.9899Z",fill:"#B2BBD3"})})),VS=AA;var OA=Q.div`
|
|
4971
4971
|
display: flex;
|
|
4972
4972
|
flex-direction: column;
|
|
4973
4973
|
align-items: center;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "7.8.0-beta.
|
|
2
|
+
"version": "7.8.0-beta.2",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/stigg-sdk.cjs.js",
|
|
5
|
-
"
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
6
7
|
"module": "dist/stigg-sdk.esm.js",
|
|
7
8
|
"files": [
|
|
8
9
|
"dist"
|