@stigg/react-sdk 7.24.0 → 7.24.1

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/README.md CHANGED
@@ -171,25 +171,6 @@ API_KEY='<your-api-key>'
171
171
  yarn storybook
172
172
  ```
173
173
 
174
- ### Publish storybook
175
-
176
- When doing changes, it can be useful to let others play with it without publising the changes to npm.
177
- In order to do that we are uploading the storybook files to Chromatic:
178
-
179
- 1. Building storybook static files
180
-
181
- ```
182
- yarn build-storybook
183
- ```
184
-
185
- 2. Uploading storybook files to Chromatic:
186
-
187
- ```
188
- yarn publish-storybook
189
- ```
190
-
191
- **NOTE:** The `STORYBOOK_STIGG_BASE_URI` environment parameter in `.env.local` file controlling the API url that storybook is going to use.
192
-
193
174
  ### Link package
194
175
 
195
176
  1. Run `yarn link-sdk`
@@ -295,7 +295,7 @@
295
295
  display: flex;
296
296
  flex-direction: column;
297
297
  align-items: center;
298
- `,Fh=({plans:e,customer:t,currentSubscription:o,highlightedPlanId:n,selectedBillingPeriod:i,onBillingPeriodChanged:r,availableBillingPeriods:a,isCustomerOnTrial:s,onPlanSelected:l,paywallLocale:c,locale:d,shouldHidePlan:u,selectDefaultTierIndex:p,currentSubscriptionOverride:m,hideCompatibleAddons:h,showWatermark:f})=>{let g=Mh(e),y=e.some(L=>!!L.description),P=Rl(e,Xh.BillingPeriod.Monthly),T=Rl(e,Xh.BillingPeriod.Annually),k=Bh(e,i,u),w=xc.useCallback((L,E,O)=>l({plan:L,customer:t,subscription:o,intentionType:E,selectedBillingPeriod:i,billableFeatures:O}),[t,i,o,l]),v=!!o&&o.plan.pricingType===Xh.PricingType.Custom,A=xc.useMemo(()=>k.some(L=>{var N;let E=L.pricePoints.filter(F=>F.billingPeriod===i),O=(N=L.paywallCalculatedPricePoints)==null?void 0:N.find(F=>F.billingPeriod===i);return E.length>1&&!!(O!=null&&O.additionalChargesMayApply)}),[i,k]),M=xc.useMemo(()=>k.some(L=>!!Ar(L,i,c,d,P).unit),[i,P,d,c,k]),I=xc.useMemo(()=>!v&&k.some(L=>{let E=_r({plan:L,billingPeriod:i,currentSubscription:o,currentSubscriptionOverride:m});return Object.values(E).length>0}),[i,o,m,v,k]),B=k.some(L=>L.isCurrentCustomerPlan&&L.trialDaysLeft);return jsxRuntime.jsx(LP,{className:"stigg-paywall-container",children:jsxRuntime.jsxs(BP,{className:"stigg-paywall-layout",children:[jsxRuntime.jsx(kh,{onBillingPeriodChanged:r,selectedBillingPeriod:i,availableBillingPeriods:a,discountRate:g}),jsxRuntime.jsx(IP,{className:"stigg-paywall-plans-layout",children:k.map(L=>jsxRuntime.jsx(Sh,{withUnitPriceRow:M,withTiersRow:I,withTrialLeftRow:B,shouldShowDescriptionSection:y,hasMonthlyPrice:P,hasAnnuallyPrice:T,plan:L,withStartingAtRow:A,currentSubscription:o,currentSubscriptionOverride:m,billingPeriod:i,isHighlighted:L.id===n,isCustomerOnTrial:s,onPlanSelected:(E,O)=>w(L,E,O),paywallLocale:c,locale:d,customer:t,isCustomerInCustomPlan:v,selectDefaultTierIndex:p,hideCompatibleAddons:h},L.id))}),jsxRuntime.jsx(Jt,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:f})]})})};var Nl=class{error(t,o,...n){console.error(t,o||{},n);}log(t,o){console.log(t,o||{});}debug(t,o){console.debug(t,o||{});}},no=new Nl;function Rh(e,t,o){let n=e.flatMap(s=>s.pricePoints).map(s=>s.billingPeriod),i=lodash.countBy(n),r=lodash.uniq(n),a;if(o&&r.includes(o))a=o;else if(t){let s=t.find(l=>l.status===Xh.SubscriptionStatus.Active);s&&s.prices.length>0&&(a=s==null?void 0:s.prices[0].billingPeriod);}return a||(a=(i[Xh.BillingPeriod.Monthly]||0)>(i[Xh.BillingPeriod.Annually]||0)?Xh.BillingPeriod.Monthly:Xh.BillingPeriod.Annually),{defaultBillingPeriod:a,availableBillingPeriods:r}}function Nh(e){return Xc__default.default.utc(e).diff(Xc__default.default.utc(),"days",false)+1}var Br={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 io(e,t="px"){if(e)return `${e}${t}`}function Er(e){if(!e)return "normal";switch(e){case Xh.FontWeight.Normal:return "normal";case Xh.FontWeight.Bold:return "bold";default:return "normal"}}function Pi(e,t){var n,i,r,a,s,l,c,d;let o=t||{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:(e==null?void 0:e.fontFamily)||void 0,h1:{fontSize:io((n=e==null?void 0:e.h1)==null?void 0:n.fontSize)||o.h1.fontSize,fontWeight:Er((i=e==null?void 0:e.h1)==null?void 0:i.fontWeight)||o.h1.fontWeight,semanticElement:o.h1.semanticElement},h2:{fontSize:io((r=e==null?void 0:e.h2)==null?void 0:r.fontSize)||o.h2.fontSize,fontWeight:Er((a=e==null?void 0:e.h2)==null?void 0:a.fontWeight)||o.h2.fontWeight,semanticElement:o.h2.semanticElement},h3:{fontSize:io((s=e==null?void 0:e.h3)==null?void 0:s.fontSize)||o.h3.fontSize,fontWeight:Er((l=e==null?void 0:e.h3)==null?void 0:l.fontWeight)||o.h3.fontWeight,semanticElement:o.h3.semanticElement},body:{fontSize:io((c=e==null?void 0:e.body)==null?void 0:c.fontSize)||o.body.fontSize,fontWeight:Er((d=e==null?void 0:e.body)==null?void 0:d.fontWeight)||o.body.fontWeight,semanticElement:o.body.semanticElement}}}function Ul(e){if(e)switch(e){case Xh.Alignment.Left:return "left";case Xh.Alignment.Center:return "center";case Xh.Alignment.Right:return "right";default:return}}function Uh(e){let{palette:t,customCss:o,typography:n}=e;return {palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.paywallBackgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,backgroundHighlight:(t==null?void 0:t.currentPlanBackground)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0}},typography:Pi(n),customCss:o||void 0}}function zh(e){let{palette:t,layout:o,customCss:n,typography:i}=e;return {customCss:n||void 0,palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.backgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,backgroundHighlight:(t==null?void 0:t.currentPlanBackground)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0}},typography:Pi(i),layout:{ctaAlignment:Ul(o==null?void 0:o.alignment),headerAlignment:Ul(o==null?void 0:o.alignment),descriptionAlignment:Ul(o==null?void 0:o.alignment),planMaxWidth:io(o==null?void 0:o.planWidth),planMinWidth:io(o==null?void 0:o.planWidth),planMargin:io(o==null?void 0:o.planMargin),planPadding:io(o==null?void 0:o.planPadding)}}}function $h(e){let{palette:t,typography:o,customCss:n}=e;return {palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.backgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0},backgroundHighlight:(t==null?void 0:t.summaryBackgroundColor)||void 0},typography:Pi(o,Br),customCss:n||void 0}}function OP(e){let t=true,o=(e==null?void 0:e.find(r=>r.status===Xh.SubscriptionStatus.InTrial))||null,n=o==null?void 0:o.plan,i=o!=null&&o.trialEndDate?Nh(o.trialEndDate):void 0;return n||(t=false,o=(e==null?void 0:e.find(r=>r.status===Xh.SubscriptionStatus.Active))||null,n=o==null?void 0:o.plan),{currentSubscription:o,currentPlan:n,isCustomerOnTrial:t,trialDaysLeft:i}}function Gh(e,t,o){var k,w;let{plans:n,currency:i,configuration:r,customer:a,activeSubscriptions:s,paywallCalculatedPricePoints:l}=e||{},{currentSubscription:c,currentPlan:d,isCustomerOnTrial:u,trialDaysLeft:p}=OP(s),m=o==null?void 0:o({currentSubscription:c}),h=(c==null?void 0:c.scheduledUpdates)||[],f=(k=c==null?void 0:c.price)==null?void 0:k.billingPeriod,g=h.find(({subscriptionScheduleType:v})=>v===Xh.SubscriptionScheduleType.Downgrade),y=h.find(({subscriptionScheduleType:v})=>v===Xh.SubscriptionScheduleType.BillingPeriod),P=If__default.default(n,v=>v.order).map(v=>{var B;let A=(B=a==null?void 0:a.eligibleForTrial)==null?void 0:B.find(L=>L.productId===v.product.id),M=m!=null&&m.planId?(m==null?void 0:m.planId)===v.id:v.id===(d==null?void 0:d.id),I=L=>{var F;let E=g==null?void 0:g.scheduleVariables,O=y==null?void 0:y.scheduleVariables,N=v.pricePoints.some($=>$.billingPeriod===L);return g?((F=g.targetPackage)==null?void 0:F.refId)===v.id&&(!N||E.billingPeriod===L):y&&M?O.billingPeriod===L:false};return _(S({},v),{paywallCalculatedPricePoints:l==null?void 0:l.filter(L=>L.planId===v.id),isTriable:!vr__default.default(v.defaultTrialConfig)&&(!A||A.eligible),isCurrentCustomerPlan:M,currentCustomerPlanBillingPeriod:f,isUpcomingPlan:false,trialDaysLeft:p,isNextPlan:I,paywallCurrency:i,scheduledUpdate:g||y})});if(n&&d){let v=d&&((w=n==null?void 0:n.find(A=>A.id===(d==null?void 0:d.id)))==null?void 0:w.order);vr__default.default(v)||(P=P.map(A=>_(S({},A),{isLowerThanCurrentPlan:v>A.order})),t&&(P=P.filter(A=>A.order>=v)));}let T=r?zh(r):void 0;return {currentPlan:d,currentSubscription:c,currentSubscriptionOverride:m,isCustomerOnTrial:u,plans:P,paywallConfiguration:T}}var Yh="7.24.0";var Zh="@stigg/react-sdk";var Si=xc__default.default.createContext(null);Si.displayName="StiggContext";var HP="en-US",WP=({apiKey:e,baseUri:t,baseEdgeUri:o,enableEdge:n,customerId:i,customerToken:r,resourceId:a,theme:s,locale:l,cacheTtlMs:c,useEntitlementPolling:d,entitlementPollingInterval:u,entitlementsFallback:p,stiggClient:m,children:h,offline:f,clientName:g=Zh,clientVersion:y=Yh})=>{let P=xc.useRef(e),T={apiKey:e,customerId:i,customerToken:r,resourceId:a,baseUri:t,baseEdgeUri:o,enableEdge:n,entitlementsFallback:p,cacheTtlMs:c,useEntitlementPolling:d,entitlementPollingInterval:u,clientName:g,clientVersion:y,offline:f},[k,w]=xc.useState(()=>({stigg:m!=null?m:Xh__default.default.initialize(_(S({},T),{lazyLoad:true})),locale:l||HP,isInitialized:false,theme:s,refreshData:()=>R(null,null,function*(){w(v=>_(S({},v),{customerPortalUpdatedAt:new Date})),yield k.stigg.refresh();})}));return xc.useEffect(()=>{let v=true,A=L=>{v&&w(L);},M=()=>A(L=>_(S({},L),{updatedAt:new Date})),I=L=>A(E=>(E.stigg&&E.stigg.removeListener("entitlementsUpdated",M),L.addListener("entitlementsUpdated",M),_(S({},E),{stigg:L,isInitialized:true,updatedAt:new Date})));return R(null,null,function*(){let L=k.stigg;e!==P.current&&(no.log("Updating stigg client",{apiKey:e}),P.current=e,L=Xh__default.default.initialize(S({},T)),A(E=>_(S({},E),{isInitialized:false,updatedAt:new Date}))),yield L.waitForInitialization(),I(L);}),()=>{v=false,k.stigg.removeListener("entitlementsUpdated",M),k.stigg.clearCustomer();}},[e]),xc.useEffect(()=>{let v=k.stigg;i?v.setCustomerId(i,r,a):v.clearCustomer();},[i,r,a]),xc.useEffect(()=>{w(v=>_(S({},v),{theme:s}));},[s]),jsxRuntime.jsx(Si.Provider,{value:k,children:jsxRuntime.jsx(ro.SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:h})})};function D(e){let{optional:t}=e||{},o=xc.useContext(Si);if(!o&&!t)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return o}function qh({productId:e,resourceId:t,showOnlyEligiblePlans:o,billingCountryCode:n,preferredBillingPeriod:i,currentSubscriptionOverrideFn:r}){let{stigg:a,locale:s}=D(),[l,c]=xc.useState(Xh.BillingPeriod.Annually),[d,u]=xc.useState([]),[p,m]=xc.useState(null),[h,f]=xc.useState(true);xc.useEffect(()=>{R(null,null,function*(){try{f(!0),yield a.waitForInitialization();let P=yield a.getPaywall({productId:e,resourceId:t,billingCountryCode:n}),{availableBillingPeriods:T,defaultBillingPeriod:k}=Rh(P.plans,P.activeSubscriptions,i);m(P),u(T),c(k);}catch(P){no.error(`Failed to load paywall ${P==null?void 0:P.message}`,P);}finally{f(false);}});},[a,e,a.isCustomerLoaded,n,t,i]);let g=Gh(p,o,r);return S({customer:(p==null?void 0:p.customer)||null,isLoading:h,selectedBillingPeriod:l,setSelectedBillingPeriod:c,availableBillingPeriods:d,locale:s,configuration:g.paywallConfiguration,showWatermark:a.getShowWatermark()},g)}function Jh(e){return e2__default.default({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:o=>{var n;return `Start ${(n=o.defaultTrialConfig)==null?void 0:n.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:o=>o===Xh.BillingPeriod.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:o=>o===Xh.BillingPeriod.Monthly?"/ month":"/ year",free:o=>({price:`${o==null?void 0:o.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},e)}var XP=e=>jsxRuntime.jsx("svg",_(S({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),{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"})})),em=XP;var KP=x.div`
298
+ `,Fh=({plans:e,customer:t,currentSubscription:o,highlightedPlanId:n,selectedBillingPeriod:i,onBillingPeriodChanged:r,availableBillingPeriods:a,isCustomerOnTrial:s,onPlanSelected:l,paywallLocale:c,locale:d,shouldHidePlan:u,selectDefaultTierIndex:p,currentSubscriptionOverride:m,hideCompatibleAddons:h,showWatermark:f})=>{let g=Mh(e),y=e.some(L=>!!L.description),P=Rl(e,Xh.BillingPeriod.Monthly),T=Rl(e,Xh.BillingPeriod.Annually),k=Bh(e,i,u),w=xc.useCallback((L,E,O)=>l({plan:L,customer:t,subscription:o,intentionType:E,selectedBillingPeriod:i,billableFeatures:O}),[t,i,o,l]),v=!!o&&o.plan.pricingType===Xh.PricingType.Custom,A=xc.useMemo(()=>k.some(L=>{var N;let E=L.pricePoints.filter(F=>F.billingPeriod===i),O=(N=L.paywallCalculatedPricePoints)==null?void 0:N.find(F=>F.billingPeriod===i);return E.length>1&&!!(O!=null&&O.additionalChargesMayApply)}),[i,k]),M=xc.useMemo(()=>k.some(L=>!!Ar(L,i,c,d,P).unit),[i,P,d,c,k]),I=xc.useMemo(()=>!v&&k.some(L=>{let E=_r({plan:L,billingPeriod:i,currentSubscription:o,currentSubscriptionOverride:m});return Object.values(E).length>0}),[i,o,m,v,k]),B=k.some(L=>L.isCurrentCustomerPlan&&L.trialDaysLeft);return jsxRuntime.jsx(LP,{className:"stigg-paywall-container",children:jsxRuntime.jsxs(BP,{className:"stigg-paywall-layout",children:[jsxRuntime.jsx(kh,{onBillingPeriodChanged:r,selectedBillingPeriod:i,availableBillingPeriods:a,discountRate:g}),jsxRuntime.jsx(IP,{className:"stigg-paywall-plans-layout",children:k.map(L=>jsxRuntime.jsx(Sh,{withUnitPriceRow:M,withTiersRow:I,withTrialLeftRow:B,shouldShowDescriptionSection:y,hasMonthlyPrice:P,hasAnnuallyPrice:T,plan:L,withStartingAtRow:A,currentSubscription:o,currentSubscriptionOverride:m,billingPeriod:i,isHighlighted:L.id===n,isCustomerOnTrial:s,onPlanSelected:(E,O)=>w(L,E,O),paywallLocale:c,locale:d,customer:t,isCustomerInCustomPlan:v,selectDefaultTierIndex:p,hideCompatibleAddons:h},L.id))}),jsxRuntime.jsx(Jt,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:f})]})})};var Nl=class{error(t,o,...n){console.error(t,o||{},n);}log(t,o){console.log(t,o||{});}debug(t,o){console.debug(t,o||{});}},no=new Nl;function Rh(e,t,o){let n=e.flatMap(s=>s.pricePoints).map(s=>s.billingPeriod),i=lodash.countBy(n),r=lodash.uniq(n),a;if(o&&r.includes(o))a=o;else if(t){let s=t.find(l=>l.status===Xh.SubscriptionStatus.Active);s&&s.prices.length>0&&(a=s==null?void 0:s.prices[0].billingPeriod);}return a||(a=(i[Xh.BillingPeriod.Monthly]||0)>(i[Xh.BillingPeriod.Annually]||0)?Xh.BillingPeriod.Monthly:Xh.BillingPeriod.Annually),{defaultBillingPeriod:a,availableBillingPeriods:r}}function Nh(e){return Xc__default.default.utc(e).diff(Xc__default.default.utc(),"days",false)+1}var Br={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 io(e,t="px"){if(e)return `${e}${t}`}function Er(e){if(!e)return "normal";switch(e){case Xh.FontWeight.Normal:return "normal";case Xh.FontWeight.Bold:return "bold";default:return "normal"}}function Pi(e,t){var n,i,r,a,s,l,c,d;let o=t||{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:(e==null?void 0:e.fontFamily)||void 0,h1:{fontSize:io((n=e==null?void 0:e.h1)==null?void 0:n.fontSize)||o.h1.fontSize,fontWeight:Er((i=e==null?void 0:e.h1)==null?void 0:i.fontWeight)||o.h1.fontWeight,semanticElement:o.h1.semanticElement},h2:{fontSize:io((r=e==null?void 0:e.h2)==null?void 0:r.fontSize)||o.h2.fontSize,fontWeight:Er((a=e==null?void 0:e.h2)==null?void 0:a.fontWeight)||o.h2.fontWeight,semanticElement:o.h2.semanticElement},h3:{fontSize:io((s=e==null?void 0:e.h3)==null?void 0:s.fontSize)||o.h3.fontSize,fontWeight:Er((l=e==null?void 0:e.h3)==null?void 0:l.fontWeight)||o.h3.fontWeight,semanticElement:o.h3.semanticElement},body:{fontSize:io((c=e==null?void 0:e.body)==null?void 0:c.fontSize)||o.body.fontSize,fontWeight:Er((d=e==null?void 0:e.body)==null?void 0:d.fontWeight)||o.body.fontWeight,semanticElement:o.body.semanticElement}}}function Ul(e){if(e)switch(e){case Xh.Alignment.Left:return "left";case Xh.Alignment.Center:return "center";case Xh.Alignment.Right:return "right";default:return}}function Uh(e){let{palette:t,customCss:o,typography:n}=e;return {palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.paywallBackgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,backgroundHighlight:(t==null?void 0:t.currentPlanBackground)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0}},typography:Pi(n),customCss:o||void 0}}function zh(e){let{palette:t,layout:o,customCss:n,typography:i}=e;return {customCss:n||void 0,palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.backgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,backgroundHighlight:(t==null?void 0:t.currentPlanBackground)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0}},typography:Pi(i),layout:{ctaAlignment:Ul(o==null?void 0:o.alignment),headerAlignment:Ul(o==null?void 0:o.alignment),descriptionAlignment:Ul(o==null?void 0:o.alignment),planMaxWidth:io(o==null?void 0:o.planWidth),planMinWidth:io(o==null?void 0:o.planWidth),planMargin:io(o==null?void 0:o.planMargin),planPadding:io(o==null?void 0:o.planPadding)}}}function $h(e){let{palette:t,typography:o,customCss:n}=e;return {palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.backgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0},backgroundHighlight:(t==null?void 0:t.summaryBackgroundColor)||void 0},typography:Pi(o,Br),customCss:n||void 0}}function OP(e){let t=true,o=(e==null?void 0:e.find(r=>r.status===Xh.SubscriptionStatus.InTrial))||null,n=o==null?void 0:o.plan,i=o!=null&&o.trialEndDate?Nh(o.trialEndDate):void 0;return n||(t=false,o=(e==null?void 0:e.find(r=>r.status===Xh.SubscriptionStatus.Active))||null,n=o==null?void 0:o.plan),{currentSubscription:o,currentPlan:n,isCustomerOnTrial:t,trialDaysLeft:i}}function Gh(e,t,o){var k,w;let{plans:n,currency:i,configuration:r,customer:a,activeSubscriptions:s,paywallCalculatedPricePoints:l}=e||{},{currentSubscription:c,currentPlan:d,isCustomerOnTrial:u,trialDaysLeft:p}=OP(s),m=o==null?void 0:o({currentSubscription:c}),h=(c==null?void 0:c.scheduledUpdates)||[],f=(k=c==null?void 0:c.price)==null?void 0:k.billingPeriod,g=h.find(({subscriptionScheduleType:v})=>v===Xh.SubscriptionScheduleType.Downgrade),y=h.find(({subscriptionScheduleType:v})=>v===Xh.SubscriptionScheduleType.BillingPeriod),P=If__default.default(n,v=>v.order).map(v=>{var B;let A=(B=a==null?void 0:a.eligibleForTrial)==null?void 0:B.find(L=>L.productId===v.product.id),M=m!=null&&m.planId?(m==null?void 0:m.planId)===v.id:v.id===(d==null?void 0:d.id),I=L=>{var F;let E=g==null?void 0:g.scheduleVariables,O=y==null?void 0:y.scheduleVariables,N=v.pricePoints.some($=>$.billingPeriod===L);return g?((F=g.targetPackage)==null?void 0:F.refId)===v.id&&(!N||E.billingPeriod===L):y&&M?O.billingPeriod===L:false};return _(S({},v),{paywallCalculatedPricePoints:l==null?void 0:l.filter(L=>L.planId===v.id),isTriable:!vr__default.default(v.defaultTrialConfig)&&(!A||A.eligible),isCurrentCustomerPlan:M,currentCustomerPlanBillingPeriod:f,isUpcomingPlan:false,trialDaysLeft:p,isNextPlan:I,paywallCurrency:i,scheduledUpdate:g||y})});if(n&&d){let v=d&&((w=n==null?void 0:n.find(A=>A.id===(d==null?void 0:d.id)))==null?void 0:w.order);vr__default.default(v)||(P=P.map(A=>_(S({},A),{isLowerThanCurrentPlan:v>A.order})),t&&(P=P.filter(A=>A.order>=v)));}let T=r?zh(r):void 0;return {currentPlan:d,currentSubscription:c,currentSubscriptionOverride:m,isCustomerOnTrial:u,plans:P,paywallConfiguration:T}}var Yh="7.24.1";var Zh="@stigg/react-sdk";var Si=xc__default.default.createContext(null);Si.displayName="StiggContext";var HP="en-US",WP=({apiKey:e,baseUri:t,baseEdgeUri:o,enableEdge:n,customerId:i,customerToken:r,resourceId:a,theme:s,locale:l,cacheTtlMs:c,useEntitlementPolling:d,entitlementPollingInterval:u,entitlementsFallback:p,stiggClient:m,children:h,offline:f,clientName:g=Zh,clientVersion:y=Yh})=>{let P=xc.useRef(e),T={apiKey:e,customerId:i,customerToken:r,resourceId:a,baseUri:t,baseEdgeUri:o,enableEdge:n,entitlementsFallback:p,cacheTtlMs:c,useEntitlementPolling:d,entitlementPollingInterval:u,clientName:g,clientVersion:y,offline:f},[k,w]=xc.useState(()=>({stigg:m!=null?m:Xh__default.default.initialize(_(S({},T),{lazyLoad:true})),locale:l||HP,isInitialized:false,theme:s,refreshData:()=>R(null,null,function*(){w(v=>_(S({},v),{customerPortalUpdatedAt:new Date})),yield k.stigg.refresh();})}));return xc.useEffect(()=>{let v=true,A=L=>{v&&w(L);},M=()=>A(L=>_(S({},L),{updatedAt:new Date})),I=L=>A(E=>(E.stigg&&E.stigg.removeListener("entitlementsUpdated",M),L.addListener("entitlementsUpdated",M),_(S({},E),{stigg:L,isInitialized:true,updatedAt:new Date})));return R(null,null,function*(){let L=k.stigg;e!==P.current&&(no.log("Updating stigg client",{apiKey:e}),P.current=e,L=Xh__default.default.initialize(S({},T)),A(E=>_(S({},E),{isInitialized:false,updatedAt:new Date}))),yield L.waitForInitialization(),I(L);}),()=>{v=false,k.stigg.removeListener("entitlementsUpdated",M),k.stigg.clearCustomer();}},[e]),xc.useEffect(()=>{let v=k.stigg;i?v.setCustomerId(i,r,a):v.clearCustomer();},[i,r,a]),xc.useEffect(()=>{w(v=>_(S({},v),{theme:s}));},[s]),jsxRuntime.jsx(Si.Provider,{value:k,children:jsxRuntime.jsx(ro.SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:h})})};function D(e){let{optional:t}=e||{},o=xc.useContext(Si);if(!o&&!t)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return o}function qh({productId:e,resourceId:t,showOnlyEligiblePlans:o,billingCountryCode:n,preferredBillingPeriod:i,currentSubscriptionOverrideFn:r}){let{stigg:a,locale:s}=D(),[l,c]=xc.useState(Xh.BillingPeriod.Annually),[d,u]=xc.useState([]),[p,m]=xc.useState(null),[h,f]=xc.useState(true);xc.useEffect(()=>{R(null,null,function*(){try{f(!0),yield a.waitForInitialization();let P=yield a.getPaywall({productId:e,resourceId:t,billingCountryCode:n}),{availableBillingPeriods:T,defaultBillingPeriod:k}=Rh(P.plans,P.activeSubscriptions,i);m(P),u(T),c(k);}catch(P){no.error(`Failed to load paywall ${P==null?void 0:P.message}`,P);}finally{f(false);}});},[a,e,a.isCustomerLoaded,n,t,i]);let g=Gh(p,o,r);return S({customer:(p==null?void 0:p.customer)||null,isLoading:h,selectedBillingPeriod:l,setSelectedBillingPeriod:c,availableBillingPeriods:d,locale:s,configuration:g.paywallConfiguration,showWatermark:a.getShowWatermark()},g)}function Jh(e){return e2__default.default({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:o=>{var n;return `Start ${(n=o.defaultTrialConfig)==null?void 0:n.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:o=>o===Xh.BillingPeriod.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:o=>o===Xh.BillingPeriod.Monthly?"/ month":"/ year",free:o=>({price:`${o==null?void 0:o.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},e)}var XP=e=>jsxRuntime.jsx("svg",_(S({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),{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"})})),em=XP;var KP=x.div`
299
299
  display: flex;
300
300
  flex-direction: column;
301
301
  align-items: center;
@@ -295,7 +295,7 @@ import Xh__default,{BillingModel,PaymentCollection,CreditUsageTimeRange,Subscrip
295
295
  display: flex;
296
296
  flex-direction: column;
297
297
  align-items: center;
298
- `,Fh=({plans:e,customer:t,currentSubscription:o,highlightedPlanId:n,selectedBillingPeriod:i,onBillingPeriodChanged:r,availableBillingPeriods:a,isCustomerOnTrial:s,onPlanSelected:l,paywallLocale:c,locale:d,shouldHidePlan:u,selectDefaultTierIndex:p,currentSubscriptionOverride:m,hideCompatibleAddons:h,showWatermark:f})=>{let g=Mh(e),y=e.some(L=>!!L.description),P=Rl(e,BillingPeriod.Monthly),T=Rl(e,BillingPeriod.Annually),k=Bh(e,i,u),w=useCallback((L,E,O)=>l({plan:L,customer:t,subscription:o,intentionType:E,selectedBillingPeriod:i,billableFeatures:O}),[t,i,o,l]),v=!!o&&o.plan.pricingType===PricingType.Custom,A=useMemo(()=>k.some(L=>{var N;let E=L.pricePoints.filter(F=>F.billingPeriod===i),O=(N=L.paywallCalculatedPricePoints)==null?void 0:N.find(F=>F.billingPeriod===i);return E.length>1&&!!(O!=null&&O.additionalChargesMayApply)}),[i,k]),M=useMemo(()=>k.some(L=>!!Ar(L,i,c,d,P).unit),[i,P,d,c,k]),I=useMemo(()=>!v&&k.some(L=>{let E=_r({plan:L,billingPeriod:i,currentSubscription:o,currentSubscriptionOverride:m});return Object.values(E).length>0}),[i,o,m,v,k]),B=k.some(L=>L.isCurrentCustomerPlan&&L.trialDaysLeft);return jsx(LP,{className:"stigg-paywall-container",children:jsxs(BP,{className:"stigg-paywall-layout",children:[jsx(kh,{onBillingPeriodChanged:r,selectedBillingPeriod:i,availableBillingPeriods:a,discountRate:g}),jsx(IP,{className:"stigg-paywall-plans-layout",children:k.map(L=>jsx(Sh,{withUnitPriceRow:M,withTiersRow:I,withTrialLeftRow:B,shouldShowDescriptionSection:y,hasMonthlyPrice:P,hasAnnuallyPrice:T,plan:L,withStartingAtRow:A,currentSubscription:o,currentSubscriptionOverride:m,billingPeriod:i,isHighlighted:L.id===n,isCustomerOnTrial:s,onPlanSelected:(E,O)=>w(L,E,O),paywallLocale:c,locale:d,customer:t,isCustomerInCustomPlan:v,selectDefaultTierIndex:p,hideCompatibleAddons:h},L.id))}),jsx(Jt,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:f})]})})};var Nl=class{error(t,o,...n){console.error(t,o||{},n);}log(t,o){console.log(t,o||{});}debug(t,o){console.debug(t,o||{});}},no=new Nl;function Rh(e,t,o){let n=e.flatMap(s=>s.pricePoints).map(s=>s.billingPeriod),i=countBy(n),r=uniq(n),a;if(o&&r.includes(o))a=o;else if(t){let s=t.find(l=>l.status===SubscriptionStatus.Active);s&&s.prices.length>0&&(a=s==null?void 0:s.prices[0].billingPeriod);}return a||(a=(i[BillingPeriod.Monthly]||0)>(i[BillingPeriod.Annually]||0)?BillingPeriod.Monthly:BillingPeriod.Annually),{defaultBillingPeriod:a,availableBillingPeriods:r}}function Nh(e){return Xc.utc(e).diff(Xc.utc(),"days",false)+1}var Br={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 io(e,t="px"){if(e)return `${e}${t}`}function Er(e){if(!e)return "normal";switch(e){case FontWeight.Normal:return "normal";case FontWeight.Bold:return "bold";default:return "normal"}}function Pi(e,t){var n,i,r,a,s,l,c,d;let o=t||{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:(e==null?void 0:e.fontFamily)||void 0,h1:{fontSize:io((n=e==null?void 0:e.h1)==null?void 0:n.fontSize)||o.h1.fontSize,fontWeight:Er((i=e==null?void 0:e.h1)==null?void 0:i.fontWeight)||o.h1.fontWeight,semanticElement:o.h1.semanticElement},h2:{fontSize:io((r=e==null?void 0:e.h2)==null?void 0:r.fontSize)||o.h2.fontSize,fontWeight:Er((a=e==null?void 0:e.h2)==null?void 0:a.fontWeight)||o.h2.fontWeight,semanticElement:o.h2.semanticElement},h3:{fontSize:io((s=e==null?void 0:e.h3)==null?void 0:s.fontSize)||o.h3.fontSize,fontWeight:Er((l=e==null?void 0:e.h3)==null?void 0:l.fontWeight)||o.h3.fontWeight,semanticElement:o.h3.semanticElement},body:{fontSize:io((c=e==null?void 0:e.body)==null?void 0:c.fontSize)||o.body.fontSize,fontWeight:Er((d=e==null?void 0:e.body)==null?void 0:d.fontWeight)||o.body.fontWeight,semanticElement:o.body.semanticElement}}}function Ul(e){if(e)switch(e){case Alignment.Left:return "left";case Alignment.Center:return "center";case Alignment.Right:return "right";default:return}}function Uh(e){let{palette:t,customCss:o,typography:n}=e;return {palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.paywallBackgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,backgroundHighlight:(t==null?void 0:t.currentPlanBackground)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0}},typography:Pi(n),customCss:o||void 0}}function zh(e){let{palette:t,layout:o,customCss:n,typography:i}=e;return {customCss:n||void 0,palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.backgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,backgroundHighlight:(t==null?void 0:t.currentPlanBackground)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0}},typography:Pi(i),layout:{ctaAlignment:Ul(o==null?void 0:o.alignment),headerAlignment:Ul(o==null?void 0:o.alignment),descriptionAlignment:Ul(o==null?void 0:o.alignment),planMaxWidth:io(o==null?void 0:o.planWidth),planMinWidth:io(o==null?void 0:o.planWidth),planMargin:io(o==null?void 0:o.planMargin),planPadding:io(o==null?void 0:o.planPadding)}}}function $h(e){let{palette:t,typography:o,customCss:n}=e;return {palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.backgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0},backgroundHighlight:(t==null?void 0:t.summaryBackgroundColor)||void 0},typography:Pi(o,Br),customCss:n||void 0}}function OP(e){let t=true,o=(e==null?void 0:e.find(r=>r.status===SubscriptionStatus.InTrial))||null,n=o==null?void 0:o.plan,i=o!=null&&o.trialEndDate?Nh(o.trialEndDate):void 0;return n||(t=false,o=(e==null?void 0:e.find(r=>r.status===SubscriptionStatus.Active))||null,n=o==null?void 0:o.plan),{currentSubscription:o,currentPlan:n,isCustomerOnTrial:t,trialDaysLeft:i}}function Gh(e,t,o){var k,w;let{plans:n,currency:i,configuration:r,customer:a,activeSubscriptions:s,paywallCalculatedPricePoints:l}=e||{},{currentSubscription:c,currentPlan:d,isCustomerOnTrial:u,trialDaysLeft:p}=OP(s),m=o==null?void 0:o({currentSubscription:c}),h=(c==null?void 0:c.scheduledUpdates)||[],f=(k=c==null?void 0:c.price)==null?void 0:k.billingPeriod,g=h.find(({subscriptionScheduleType:v})=>v===SubscriptionScheduleType.Downgrade),y=h.find(({subscriptionScheduleType:v})=>v===SubscriptionScheduleType.BillingPeriod),P=If(n,v=>v.order).map(v=>{var B;let A=(B=a==null?void 0:a.eligibleForTrial)==null?void 0:B.find(L=>L.productId===v.product.id),M=m!=null&&m.planId?(m==null?void 0:m.planId)===v.id:v.id===(d==null?void 0:d.id),I=L=>{var F;let E=g==null?void 0:g.scheduleVariables,O=y==null?void 0:y.scheduleVariables,N=v.pricePoints.some($=>$.billingPeriod===L);return g?((F=g.targetPackage)==null?void 0:F.refId)===v.id&&(!N||E.billingPeriod===L):y&&M?O.billingPeriod===L:false};return _(S({},v),{paywallCalculatedPricePoints:l==null?void 0:l.filter(L=>L.planId===v.id),isTriable:!vr(v.defaultTrialConfig)&&(!A||A.eligible),isCurrentCustomerPlan:M,currentCustomerPlanBillingPeriod:f,isUpcomingPlan:false,trialDaysLeft:p,isNextPlan:I,paywallCurrency:i,scheduledUpdate:g||y})});if(n&&d){let v=d&&((w=n==null?void 0:n.find(A=>A.id===(d==null?void 0:d.id)))==null?void 0:w.order);vr(v)||(P=P.map(A=>_(S({},A),{isLowerThanCurrentPlan:v>A.order})),t&&(P=P.filter(A=>A.order>=v)));}let T=r?zh(r):void 0;return {currentPlan:d,currentSubscription:c,currentSubscriptionOverride:m,isCustomerOnTrial:u,plans:P,paywallConfiguration:T}}var Yh="7.24.0";var Zh="@stigg/react-sdk";var Si=xc.createContext(null);Si.displayName="StiggContext";var HP="en-US",WP=({apiKey:e,baseUri:t,baseEdgeUri:o,enableEdge:n,customerId:i,customerToken:r,resourceId:a,theme:s,locale:l,cacheTtlMs:c,useEntitlementPolling:d,entitlementPollingInterval:u,entitlementsFallback:p,stiggClient:m,children:h,offline:f,clientName:g=Zh,clientVersion:y=Yh})=>{let P=useRef(e),T={apiKey:e,customerId:i,customerToken:r,resourceId:a,baseUri:t,baseEdgeUri:o,enableEdge:n,entitlementsFallback:p,cacheTtlMs:c,useEntitlementPolling:d,entitlementPollingInterval:u,clientName:g,clientVersion:y,offline:f},[k,w]=useState(()=>({stigg:m!=null?m:Xh__default.initialize(_(S({},T),{lazyLoad:true})),locale:l||HP,isInitialized:false,theme:s,refreshData:()=>R(null,null,function*(){w(v=>_(S({},v),{customerPortalUpdatedAt:new Date})),yield k.stigg.refresh();})}));return useEffect(()=>{let v=true,A=L=>{v&&w(L);},M=()=>A(L=>_(S({},L),{updatedAt:new Date})),I=L=>A(E=>(E.stigg&&E.stigg.removeListener("entitlementsUpdated",M),L.addListener("entitlementsUpdated",M),_(S({},E),{stigg:L,isInitialized:true,updatedAt:new Date})));return R(null,null,function*(){let L=k.stigg;e!==P.current&&(no.log("Updating stigg client",{apiKey:e}),P.current=e,L=Xh__default.initialize(S({},T)),A(E=>_(S({},E),{isInitialized:false,updatedAt:new Date}))),yield L.waitForInitialization(),I(L);}),()=>{v=false,k.stigg.removeListener("entitlementsUpdated",M),k.stigg.clearCustomer();}},[e]),useEffect(()=>{let v=k.stigg;i?v.setCustomerId(i,r,a):v.clearCustomer();},[i,r,a]),useEffect(()=>{w(v=>_(S({},v),{theme:s}));},[s]),jsx(Si.Provider,{value:k,children:jsx(SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:h})})};function D(e){let{optional:t}=e||{},o=useContext(Si);if(!o&&!t)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return o}function qh({productId:e,resourceId:t,showOnlyEligiblePlans:o,billingCountryCode:n,preferredBillingPeriod:i,currentSubscriptionOverrideFn:r}){let{stigg:a,locale:s}=D(),[l,c]=useState(BillingPeriod.Annually),[d,u]=useState([]),[p,m]=useState(null),[h,f]=useState(true);useEffect(()=>{R(null,null,function*(){try{f(!0),yield a.waitForInitialization();let P=yield a.getPaywall({productId:e,resourceId:t,billingCountryCode:n}),{availableBillingPeriods:T,defaultBillingPeriod:k}=Rh(P.plans,P.activeSubscriptions,i);m(P),u(T),c(k);}catch(P){no.error(`Failed to load paywall ${P==null?void 0:P.message}`,P);}finally{f(false);}});},[a,e,a.isCustomerLoaded,n,t,i]);let g=Gh(p,o,r);return S({customer:(p==null?void 0:p.customer)||null,isLoading:h,selectedBillingPeriod:l,setSelectedBillingPeriod:c,availableBillingPeriods:d,locale:s,configuration:g.paywallConfiguration,showWatermark:a.getShowWatermark()},g)}function Jh(e){return e2({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:o=>{var n;return `Start ${(n=o.defaultTrialConfig)==null?void 0:n.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:o=>o===BillingPeriod.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:o=>o===BillingPeriod.Monthly?"/ month":"/ year",free:o=>({price:`${o==null?void 0:o.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},e)}var XP=e=>jsx("svg",_(S({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),{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"})})),em=XP;var KP=x.div`
298
+ `,Fh=({plans:e,customer:t,currentSubscription:o,highlightedPlanId:n,selectedBillingPeriod:i,onBillingPeriodChanged:r,availableBillingPeriods:a,isCustomerOnTrial:s,onPlanSelected:l,paywallLocale:c,locale:d,shouldHidePlan:u,selectDefaultTierIndex:p,currentSubscriptionOverride:m,hideCompatibleAddons:h,showWatermark:f})=>{let g=Mh(e),y=e.some(L=>!!L.description),P=Rl(e,BillingPeriod.Monthly),T=Rl(e,BillingPeriod.Annually),k=Bh(e,i,u),w=useCallback((L,E,O)=>l({plan:L,customer:t,subscription:o,intentionType:E,selectedBillingPeriod:i,billableFeatures:O}),[t,i,o,l]),v=!!o&&o.plan.pricingType===PricingType.Custom,A=useMemo(()=>k.some(L=>{var N;let E=L.pricePoints.filter(F=>F.billingPeriod===i),O=(N=L.paywallCalculatedPricePoints)==null?void 0:N.find(F=>F.billingPeriod===i);return E.length>1&&!!(O!=null&&O.additionalChargesMayApply)}),[i,k]),M=useMemo(()=>k.some(L=>!!Ar(L,i,c,d,P).unit),[i,P,d,c,k]),I=useMemo(()=>!v&&k.some(L=>{let E=_r({plan:L,billingPeriod:i,currentSubscription:o,currentSubscriptionOverride:m});return Object.values(E).length>0}),[i,o,m,v,k]),B=k.some(L=>L.isCurrentCustomerPlan&&L.trialDaysLeft);return jsx(LP,{className:"stigg-paywall-container",children:jsxs(BP,{className:"stigg-paywall-layout",children:[jsx(kh,{onBillingPeriodChanged:r,selectedBillingPeriod:i,availableBillingPeriods:a,discountRate:g}),jsx(IP,{className:"stigg-paywall-plans-layout",children:k.map(L=>jsx(Sh,{withUnitPriceRow:M,withTiersRow:I,withTrialLeftRow:B,shouldShowDescriptionSection:y,hasMonthlyPrice:P,hasAnnuallyPrice:T,plan:L,withStartingAtRow:A,currentSubscription:o,currentSubscriptionOverride:m,billingPeriod:i,isHighlighted:L.id===n,isCustomerOnTrial:s,onPlanSelected:(E,O)=>w(L,E,O),paywallLocale:c,locale:d,customer:t,isCustomerInCustomPlan:v,selectDefaultTierIndex:p,hideCompatibleAddons:h},L.id))}),jsx(Jt,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:f})]})})};var Nl=class{error(t,o,...n){console.error(t,o||{},n);}log(t,o){console.log(t,o||{});}debug(t,o){console.debug(t,o||{});}},no=new Nl;function Rh(e,t,o){let n=e.flatMap(s=>s.pricePoints).map(s=>s.billingPeriod),i=countBy(n),r=uniq(n),a;if(o&&r.includes(o))a=o;else if(t){let s=t.find(l=>l.status===SubscriptionStatus.Active);s&&s.prices.length>0&&(a=s==null?void 0:s.prices[0].billingPeriod);}return a||(a=(i[BillingPeriod.Monthly]||0)>(i[BillingPeriod.Annually]||0)?BillingPeriod.Monthly:BillingPeriod.Annually),{defaultBillingPeriod:a,availableBillingPeriods:r}}function Nh(e){return Xc.utc(e).diff(Xc.utc(),"days",false)+1}var Br={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 io(e,t="px"){if(e)return `${e}${t}`}function Er(e){if(!e)return "normal";switch(e){case FontWeight.Normal:return "normal";case FontWeight.Bold:return "bold";default:return "normal"}}function Pi(e,t){var n,i,r,a,s,l,c,d;let o=t||{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:(e==null?void 0:e.fontFamily)||void 0,h1:{fontSize:io((n=e==null?void 0:e.h1)==null?void 0:n.fontSize)||o.h1.fontSize,fontWeight:Er((i=e==null?void 0:e.h1)==null?void 0:i.fontWeight)||o.h1.fontWeight,semanticElement:o.h1.semanticElement},h2:{fontSize:io((r=e==null?void 0:e.h2)==null?void 0:r.fontSize)||o.h2.fontSize,fontWeight:Er((a=e==null?void 0:e.h2)==null?void 0:a.fontWeight)||o.h2.fontWeight,semanticElement:o.h2.semanticElement},h3:{fontSize:io((s=e==null?void 0:e.h3)==null?void 0:s.fontSize)||o.h3.fontSize,fontWeight:Er((l=e==null?void 0:e.h3)==null?void 0:l.fontWeight)||o.h3.fontWeight,semanticElement:o.h3.semanticElement},body:{fontSize:io((c=e==null?void 0:e.body)==null?void 0:c.fontSize)||o.body.fontSize,fontWeight:Er((d=e==null?void 0:e.body)==null?void 0:d.fontWeight)||o.body.fontWeight,semanticElement:o.body.semanticElement}}}function Ul(e){if(e)switch(e){case Alignment.Left:return "left";case Alignment.Center:return "center";case Alignment.Right:return "right";default:return}}function Uh(e){let{palette:t,customCss:o,typography:n}=e;return {palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.paywallBackgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,backgroundHighlight:(t==null?void 0:t.currentPlanBackground)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0}},typography:Pi(n),customCss:o||void 0}}function zh(e){let{palette:t,layout:o,customCss:n,typography:i}=e;return {customCss:n||void 0,palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.backgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,backgroundHighlight:(t==null?void 0:t.currentPlanBackground)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0}},typography:Pi(i),layout:{ctaAlignment:Ul(o==null?void 0:o.alignment),headerAlignment:Ul(o==null?void 0:o.alignment),descriptionAlignment:Ul(o==null?void 0:o.alignment),planMaxWidth:io(o==null?void 0:o.planWidth),planMinWidth:io(o==null?void 0:o.planWidth),planMargin:io(o==null?void 0:o.planMargin),planPadding:io(o==null?void 0:o.planPadding)}}}function $h(e){let{palette:t,typography:o,customCss:n}=e;return {palette:{primary:(t==null?void 0:t.primary)||void 0,backgroundPaper:(t==null?void 0:t.backgroundColor)||void 0,outlinedBorder:(t==null?void 0:t.borderColor)||void 0,text:{primary:(t==null?void 0:t.textColor)||void 0},backgroundHighlight:(t==null?void 0:t.summaryBackgroundColor)||void 0},typography:Pi(o,Br),customCss:n||void 0}}function OP(e){let t=true,o=(e==null?void 0:e.find(r=>r.status===SubscriptionStatus.InTrial))||null,n=o==null?void 0:o.plan,i=o!=null&&o.trialEndDate?Nh(o.trialEndDate):void 0;return n||(t=false,o=(e==null?void 0:e.find(r=>r.status===SubscriptionStatus.Active))||null,n=o==null?void 0:o.plan),{currentSubscription:o,currentPlan:n,isCustomerOnTrial:t,trialDaysLeft:i}}function Gh(e,t,o){var k,w;let{plans:n,currency:i,configuration:r,customer:a,activeSubscriptions:s,paywallCalculatedPricePoints:l}=e||{},{currentSubscription:c,currentPlan:d,isCustomerOnTrial:u,trialDaysLeft:p}=OP(s),m=o==null?void 0:o({currentSubscription:c}),h=(c==null?void 0:c.scheduledUpdates)||[],f=(k=c==null?void 0:c.price)==null?void 0:k.billingPeriod,g=h.find(({subscriptionScheduleType:v})=>v===SubscriptionScheduleType.Downgrade),y=h.find(({subscriptionScheduleType:v})=>v===SubscriptionScheduleType.BillingPeriod),P=If(n,v=>v.order).map(v=>{var B;let A=(B=a==null?void 0:a.eligibleForTrial)==null?void 0:B.find(L=>L.productId===v.product.id),M=m!=null&&m.planId?(m==null?void 0:m.planId)===v.id:v.id===(d==null?void 0:d.id),I=L=>{var F;let E=g==null?void 0:g.scheduleVariables,O=y==null?void 0:y.scheduleVariables,N=v.pricePoints.some($=>$.billingPeriod===L);return g?((F=g.targetPackage)==null?void 0:F.refId)===v.id&&(!N||E.billingPeriod===L):y&&M?O.billingPeriod===L:false};return _(S({},v),{paywallCalculatedPricePoints:l==null?void 0:l.filter(L=>L.planId===v.id),isTriable:!vr(v.defaultTrialConfig)&&(!A||A.eligible),isCurrentCustomerPlan:M,currentCustomerPlanBillingPeriod:f,isUpcomingPlan:false,trialDaysLeft:p,isNextPlan:I,paywallCurrency:i,scheduledUpdate:g||y})});if(n&&d){let v=d&&((w=n==null?void 0:n.find(A=>A.id===(d==null?void 0:d.id)))==null?void 0:w.order);vr(v)||(P=P.map(A=>_(S({},A),{isLowerThanCurrentPlan:v>A.order})),t&&(P=P.filter(A=>A.order>=v)));}let T=r?zh(r):void 0;return {currentPlan:d,currentSubscription:c,currentSubscriptionOverride:m,isCustomerOnTrial:u,plans:P,paywallConfiguration:T}}var Yh="7.24.1";var Zh="@stigg/react-sdk";var Si=xc.createContext(null);Si.displayName="StiggContext";var HP="en-US",WP=({apiKey:e,baseUri:t,baseEdgeUri:o,enableEdge:n,customerId:i,customerToken:r,resourceId:a,theme:s,locale:l,cacheTtlMs:c,useEntitlementPolling:d,entitlementPollingInterval:u,entitlementsFallback:p,stiggClient:m,children:h,offline:f,clientName:g=Zh,clientVersion:y=Yh})=>{let P=useRef(e),T={apiKey:e,customerId:i,customerToken:r,resourceId:a,baseUri:t,baseEdgeUri:o,enableEdge:n,entitlementsFallback:p,cacheTtlMs:c,useEntitlementPolling:d,entitlementPollingInterval:u,clientName:g,clientVersion:y,offline:f},[k,w]=useState(()=>({stigg:m!=null?m:Xh__default.initialize(_(S({},T),{lazyLoad:true})),locale:l||HP,isInitialized:false,theme:s,refreshData:()=>R(null,null,function*(){w(v=>_(S({},v),{customerPortalUpdatedAt:new Date})),yield k.stigg.refresh();})}));return useEffect(()=>{let v=true,A=L=>{v&&w(L);},M=()=>A(L=>_(S({},L),{updatedAt:new Date})),I=L=>A(E=>(E.stigg&&E.stigg.removeListener("entitlementsUpdated",M),L.addListener("entitlementsUpdated",M),_(S({},E),{stigg:L,isInitialized:true,updatedAt:new Date})));return R(null,null,function*(){let L=k.stigg;e!==P.current&&(no.log("Updating stigg client",{apiKey:e}),P.current=e,L=Xh__default.initialize(S({},T)),A(E=>_(S({},E),{isInitialized:false,updatedAt:new Date}))),yield L.waitForInitialization(),I(L);}),()=>{v=false,k.stigg.removeListener("entitlementsUpdated",M),k.stigg.clearCustomer();}},[e]),useEffect(()=>{let v=k.stigg;i?v.setCustomerId(i,r,a):v.clearCustomer();},[i,r,a]),useEffect(()=>{w(v=>_(S({},v),{theme:s}));},[s]),jsx(Si.Provider,{value:k,children:jsx(SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:h})})};function D(e){let{optional:t}=e||{},o=useContext(Si);if(!o&&!t)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return o}function qh({productId:e,resourceId:t,showOnlyEligiblePlans:o,billingCountryCode:n,preferredBillingPeriod:i,currentSubscriptionOverrideFn:r}){let{stigg:a,locale:s}=D(),[l,c]=useState(BillingPeriod.Annually),[d,u]=useState([]),[p,m]=useState(null),[h,f]=useState(true);useEffect(()=>{R(null,null,function*(){try{f(!0),yield a.waitForInitialization();let P=yield a.getPaywall({productId:e,resourceId:t,billingCountryCode:n}),{availableBillingPeriods:T,defaultBillingPeriod:k}=Rh(P.plans,P.activeSubscriptions,i);m(P),u(T),c(k);}catch(P){no.error(`Failed to load paywall ${P==null?void 0:P.message}`,P);}finally{f(false);}});},[a,e,a.isCustomerLoaded,n,t,i]);let g=Gh(p,o,r);return S({customer:(p==null?void 0:p.customer)||null,isLoading:h,selectedBillingPeriod:l,setSelectedBillingPeriod:c,availableBillingPeriods:d,locale:s,configuration:g.paywallConfiguration,showWatermark:a.getShowWatermark()},g)}function Jh(e){return e2({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:o=>{var n;return `Start ${(n=o.defaultTrialConfig)==null?void 0:n.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:o=>o===BillingPeriod.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:o=>o===BillingPeriod.Monthly?"/ month":"/ year",free:o=>({price:`${o==null?void 0:o.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},e)}var XP=e=>jsx("svg",_(S({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),{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"})})),em=XP;var KP=x.div`
299
299
  display: flex;
300
300
  flex-direction: column;
301
301
  align-items: center;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.24.0",
2
+ "version": "7.24.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/stigg-sdk.cjs.js",
5
5
  "types": "dist/index.d.ts",
@@ -26,7 +26,6 @@
26
26
  "prepare": "husky install",
27
27
  "docs": "typedoc",
28
28
  "link-sdk": "yarn link && cd node_modules/react && yarn link && cd ../../node_modules/react-dom && yarn link && cd ../../",
29
- "publish-storybook": "yarn build-storybook && npx chromatic --project-token=cbd1660d8132 --exit-once-uploaded",
30
29
  "type-check": "tsc --noEmit --skipLibCheck"
31
30
  },
32
31
  "peerDependencies": {
@@ -72,7 +71,6 @@
72
71
  "@types/react-lottie": "^1.2.10",
73
72
  "@vitejs/plugin-react": "^5.1.0",
74
73
  "autoprefixer": "^10.4.14",
75
- "chromatic": "^6.11.4",
76
74
  "esbuild-plugin-svgr": "^2.1.0",
77
75
  "eslint": "^9.0.0",
78
76
  "eslint-config-prettier": "^9.0.0",