@capitalos/react 1.1.0-rc.1 → 1.1.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/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/_tsup-dts-rollup.d.mts +0 -915
- package/dist/_tsup-dts-rollup.d.ts +0 -915
- package/dist/src/index.d.mts +0 -23
- package/dist/src/index.d.ts +0 -23
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";var ie=Object.defineProperty,se=Object.defineProperties;var ae=Object.getOwnPropertyDescriptors;var
|
|
1
|
+
"use client";var ie=Object.defineProperty,se=Object.defineProperties;var ae=Object.getOwnPropertyDescriptors;var H=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var V=(e,t,o)=>t in e?ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,a=(e,t)=>{for(var o in t||(t={}))J.call(t,o)&&V(e,o,t[o]);if(H)for(var o of H(t))$.call(t,o)&&V(e,o,t[o]);return e},p=(e,t)=>se(e,ae(t));var f=(e,t)=>{var o={};for(var n in e)J.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&H)for(var n of H(e))t.indexOf(n)<0&&$.call(e,n)&&(o[n]=e[n]);return o};var q=(e,t,o)=>new Promise((n,r)=>{var i=u=>{try{d(o.next(u))}catch(g){r(g)}},s=u=>{try{d(o.throw(u))}catch(g){r(g)}},d=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,s);d((o=o.apply(e,t)).next())});import m,{useMemo as l}from"react";import L,{useEffect as te,useMemo as Fe,useRef as oe,useState as He,useCallback as Re}from"react";import _,{createContext as Se,useContext as we,useState as O,useMemo as Me,useCallback as j,useEffect as Ae}from"react";import De,{useMemo as Oe,useRef as Le}from"react";var C=class extends Error{constructor({message:t,code:o}){super(t),this.name="CapitalOSError",this.code=o}},E={unauthorized:"unauthorized",invalid_account_status:"invalid_account_status",unsupported_entry_point:"unsupported_entry_point",internal_error:"internal_error"},b=class extends C{constructor(t){super({message:`Invalid token ${t!=null?t:""}`,code:E.unauthorized}),this.name="CapitalOSInvalidTokenError"}};import{connectToChild as fe}from"penpal";import{useEffect as ge,useMemo as Ce,useRef as Q}from"react";var Z="1.1.1";function le(e){let t=JSON.stringify(e),o=btoa(t);return encodeURIComponent(o)}function W(e){try{let t=decodeURIComponent(e),o=atob(t);return JSON.parse(o)}catch(t){throw new b}}function ue(e){try{return decodeURIComponent(e)}catch(t){return e}}function G({tokenData:e,renderingContext:t,theme:o,onError:n}){try{let r=t?p(a({},t),{referer:window.location.href}):null,i=r?le(r):null,s=new URL(e.baseUrl),d=ue(e.token);return e.paramLocation==="search"?s.searchParams.set(e.paramKey,d):e.paramLocation==="hash"&&(s.hash=e.paramKey+"="+encodeURIComponent(d)),s.searchParams.set("sdkVersion",Z),i&&s.searchParams.set("renderingContext",i),o&&s.searchParams.set("theme",o),s.toString()}catch(r){n==null||n(new b);return}}function R(e){let o=W(e).path;if(!o||typeof o!="string")throw new b;return{token:e,tokenType:"oneTime",baseUrl:o,paramKey:"token",paramLocation:"search"}}var he=1e4;function B({iframeRef:e,token:t,onError:o,methods:n}){ge(()=>{if(!e.current)return;let r=fe({iframe:e.current,childOrigin:"*",debug:!0,timeout:he,methods:n});return r.promise.catch(i=>{o==null||o(i)}),()=>{r.destroy()}},[t,e])}function U({tokenData:e,renderingContext:t,theme:o,onError:n}){let r=Q(n),i=Q(t);return Ce(()=>{if(e)return G({tokenData:e,renderingContext:i.current,theme:o,onError:r.current})},[e,o,r,i])}import{iframeResizer as xe}from"iframe-resizer";import ye,{forwardRef as Pe,useEffect as Te,useImperativeHandle as ke,useRef as ve}from"react";var D=Pe((e,t)=>{let o=e.title||"iframe",{iframeHTMLAttributes:n,resizerOptions:r}=Ee(e),i=ve(null);return Te(()=>{let s=i.current;return xe(a({},r),s),()=>s.iFrameResizer&&s.iFrameResizer.removeListeners()}),ke(t,()=>i.current),ye.createElement("iframe",p(a({},n),{title:o,ref:i}))});D.displayName="IframeResizer";var be=["autoResize","bodyBackground","bodyMargin","bodyPadding","checkOrigin","inPageLinks","heightCalculationMethod","interval","log","maxHeight","maxWidth","minHeight","minWidth","resizeFrom","scrolling","sizeHeight","sizeWidth","warningTimeout","tolerance","widthCalculationMethod","onClosed","onInit","onMessage","onResized","onScroll"],Ie=new Set(be);function Ee(e){return Object.keys(e).reduce((o,n)=>{let r=e[n];return Ie.has(n)?r!==void 0&&(o.resizerOptions[n]=e[n]):o.iframeHTMLAttributes[n]=e[n],o},{resizerOptions:{},iframeHTMLAttributes:{}})}function X(e){let{oneTimeToken:t,enableLogging:o,onExchangeComplete:n,onExchangeError:r}=e,i=Le(null),s=Oe(()=>R(t),[t]),u=U({tokenData:s,onError:r,renderingContext:{entryPoint:"tokenExchange"}});return B({iframeRef:i,token:t,onError:r,methods:{onLoad:()=>{},onError:g=>{r==null||r(new C(g))},tokenExchange:{onLongLivedToken:n}}}),De.createElement(D,{src:u,checkOrigin:!1,style:{display:"none"},log:!!o,ref:i})}var Y=Se({isLoading:!1,invalidateToken:()=>{}}),ze=({getToken:e,enableLogging:t,children:o})=>{let[n,r]=O(void 0),[i,s]=O(void 0),[d,u]=O(void 0),[g,x]=O(!1),[M,y]=O(void 0),I=j(()=>q(void 0,null,function*(){x(!0);try{let h=yield e();r(h),y(void 0);let z=W(h),F=new URL(z.path);F.pathname="",s(F.toString())}catch(h){y(h)}finally{x(!1)}}),[e]),k=j(()=>{u(void 0)},[]);Ae(()=>{d||I()},[d,I]);let A=j(h=>{u(h),r(void 0),y(void 0)},[]),P=Me(()=>{if(d&&!i)throw new C({message:"baseUrl is required for long lived tokens",code:E.unauthorized});return{tokenData:d?{token:d,tokenType:"longLived",baseUrl:i,paramKey:"access_token",paramLocation:"hash"}:void 0,isLoading:g,error:M,invalidateToken:k}},[d,g,M,k,i]);return _.createElement(_.Fragment,null,_.createElement(Y.Provider,{value:P},o),n&&!d&&_.createElement(X,{oneTimeToken:n,onExchangeComplete:A,enableLogging:t,onExchangeError:y}))},ee=()=>we(Y);function c(e){let{token:t,className:o,enableLogging:n,onError:r,loadingComponent:i,renderingContext:s,methods:d,theme:u,sizeWidth:g}=e,{tokenData:x,error:M,invalidateToken:y}=ee(),[I,k]=He(!1),A=oe(null);Be(M,r);let P=Fe(()=>t?R(t):x,[t,x]),h=Re(()=>{if(n&&console.log("CapitalOS: Token expired, invalidating..."),t){r==null||r(new C({message:"Token expired. Cannot automatically refresh when using token prop.",code:E.unauthorized}));return}y(),k(!1)},[t,y,n,r]);te(()=>{t&&x&&n&&console.warn("CapitalOS: token was provided both from provider and from the token prop. the prop will take precedence")},[t,x,n]);let z=U({tokenData:P,renderingContext:s,theme:u,onError:r});if(B({iframeRef:A,token:P==null?void 0:P.token,onError:v=>{r==null||r(v),k(!0)},methods:a({onLoad:()=>{k(!0)},onError:v=>{let N=new C(v);r==null||r(N)},onTokenExpired:h},d)}),!P||!z)return L.createElement(L.Fragment,null,i||null);let F=s.entryPoint!=="insightsWidget";return L.createElement(L.Fragment,null,!I&&i,L.createElement(D,{src:z,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:o,log:!!n,ref:A,hidden:!I,onResized:v=>{if(!F)return;let N=`${parseInt(v.height)+12}px`;v.iframe.style.height=N},sizeWidth:g}))}function Be(e,t){let o=oe(!1);te(()=>{e&&!o.current&&(t==null||t(e),o.current=!0)},[e,t])}import w,{useMemo as Ue}from"react";import{useState as _e}from"react";import T,{useState as ne}from"react";var S={bugButton:{position:"fixed",left:"12px",bottom:"12px",margin:"12px",padding:"4px",display:"inline-flex",alignItems:"center",borderRadius:"9999px",border:"1px solid transparent",backgroundColor:"#2563eb",color:"white",opacity:.4,boxShadow:"0 1px 3px 0 rgb(0 0 0 / 0.1)",cursor:"pointer",zIndex:50,transition:"opacity 0.3s ease-in-out"},bugButtonHover:{backgroundColor:"#1d4ed8",opacity:1},bugButtonFocus:{outline:"none",boxShadow:"0 0 0 2px white, 0 0 0 4px #3b82f6"},bugIcon:{width:"20px",height:"20px"},loadingButton:{cursor:"default",opacity:1,animation:"pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},re=()=>T.createElement("svg",{style:S.bugIcon,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor"},T.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0 1 12 12.75Zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 0 1-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 0 0 2.248-2.354M12 12.75a2.25 2.25 0 0 1-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 0 0-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 0 1 .4-2.253M12 8.25a2.25 2.25 0 0 0-2.248 2.146M12 8.25a2.25 2.25 0 0 1 2.248 2.146M8.683 5a6.032 6.032 0 0 1-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0 1 15.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 0 0-.575-1.752M4.921 6a24.048 24.048 0 0 0-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 0 1-5.223 1.082"}));function K({onClick:e,isLoading:t=!1}){let[o,n]=ne(!1),[r,i]=ne(!1),s=a(a(a(a({},S.bugButton),t&&S.loadingButton),!t&&o&&S.bugButtonHover),!t&&r&&S.bugButtonFocus);return t?T.createElement("div",{style:s},T.createElement("style",null,`
|
|
2
2
|
@keyframes pulse {
|
|
3
3
|
0%, 100% {
|
|
4
4
|
opacity: 1;
|
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
opacity: 0.4;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
`),T.createElement(re,null)):T.createElement("button",{id:"dev-tools-button",onClick:e,type:"button",style:s,onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),onFocus:()=>i(!0),onBlur:()=>i(!1)},T.createElement(re,null))}var Ne={panel:{position:"fixed",bottom:"20px",left:"20px",zIndex:50}};function We(e){let t="devTools",o=Ue(()=>({entryPoint:t}),[t]),[n,r]=_e(!1);return
|
|
10
|
+
`),T.createElement(re,null)):T.createElement("button",{id:"dev-tools-button",onClick:e,type:"button",style:s,onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),onFocus:()=>i(!0),onBlur:()=>i(!1)},T.createElement(re,null))}var Ne={panel:{position:"fixed",bottom:"20px",left:"20px",zIndex:50}};function We(e){let t="devTools",o=Ue(()=>({entryPoint:t}),[t]),[n,r]=_e(!1);return w.createElement("aside",{"aria-label":"CapitalOS dev tools"},!n&&w.createElement(K,{onClick:()=>r(!n)}),n&&w.createElement("div",{style:Ne.panel},w.createElement(c,p(a({},e),{renderingContext:o,methods:{devTools:{onClose:()=>r(!1)}},enableLogging:!0,sizeWidth:!0,loadingComponent:w.createElement(K,{isLoading:!0})}))))}function je(e){let t="cardsApp",o=l(()=>({entryPoint:t}),[t]);return m.createElement(c,p(a({},e),{renderingContext:o}))}var Xt=je;function Yt(r){var i=r,{cardholder:e,onDone:t,onCancel:o}=i,n=f(i,["cardholder","onDone","onCancel"]);let s="createCard",d=l(()=>({entryPoint:s,cardholder:e}),[e]);return m.createElement(c,p(a({},n),{renderingContext:d,methods:{createCard:{onDone:t,onCancel:o}}}))}function eo(r){var i=r,{transactionId:e,onDone:t,onCancel:o}=i,n=f(i,["transactionId","onDone","onCancel"]);let s="createDispute",d=l(()=>({entryPoint:s,transactionId:e}),[e]);return m.createElement(c,p(a({},n),{renderingContext:d,methods:{createDispute:{onDone:t,onCancel:o}}}))}function to(e){let t="billPayApp",o=l(()=>({entryPoint:t}),[t]);return m.createElement(c,p(a({},e),{renderingContext:o}))}function oo(e){let i=e,{onCardCanceled:t}=i,o=f(i,["onCardCanceled"]),n="cardDetails",r=l(()=>({entryPoint:n,cardId:e.cardId,cardOnly:e.cardOnly,hideAddress:e.hideAddress}),[n,e.cardId,e.cardOnly]);return m.createElement(c,p(a({},o),{renderingContext:r,methods:{cardDetails:{onCardCanceled:t!=null?t:()=>{}}}}))}function no(e){let t="accountDetails",o=l(()=>({entryPoint:t}),[t]);return m.createElement(c,p(a({},e),{renderingContext:o}))}function ro(e){let t="accountActions",o=l(()=>({entryPoint:t}),[t]);return m.createElement(c,p(a({},e),{renderingContext:o}))}function io(e){let t="insightsDashboard",o=l(()=>({entryPoint:t}),[t]);return m.createElement(c,p(a({},e),{renderingContext:o}))}function so(e){let t="insightsWidget",{widget:o,hideTitle:n,height:r,width:i}=e,s=l(()=>({entryPoint:t,widget:o,hideTitle:n,height:r,width:i}),[t,o,n,r,i]);return m.createElement(c,p(a({},e),{renderingContext:s}))}function ao(r){var i=r,{onDone:e,entryPoint:t,exitPoint:o}=i,n=f(i,["onDone","entryPoint","exitPoint"]);let s="onboarding",d=l(()=>({entryPoint:s,onboardingEntryPoint:t,onboardingExitPoint:o}),[s,t,o]);return m.createElement(c,p(a({},n),{renderingContext:d,methods:{onboarding:{onDone:e}}}))}function po(o){var n=o,{onDone:e}=n,t=f(n,["onDone"]);let r="makePayment",i=l(()=>({entryPoint:r}),[r]);return m.createElement(c,p(a({},t),{renderingContext:i,methods:{makePayment:{onDone:e}}}))}function co(n){var r=n,{onDone:e,onCancel:t}=r,o=f(r,["onDone","onCancel"]);let i="contactSupport",s=l(()=>({entryPoint:i}),[i]);return m.createElement(c,p(a({},o),{renderingContext:s,methods:{contactSupport:{onDone:e,onCancel:t}}}))}function mo(o){var n=o,{onDone:e}=n,t=f(n,["onDone"]);let r="statements",i=l(()=>({entryPoint:r}),[r]);return m.createElement(c,p(a({},t),{renderingContext:i,methods:{statements:{onDone:e}}}))}function lo(o){var n=o,{onDone:e}=n,t=f(n,["onDone"]);let r="legalDocuments",i=l(()=>({entryPoint:r}),[r]);return m.createElement(c,p(a({},t),{renderingContext:i,methods:{legalDocuments:{onDone:e}}}))}function uo(r){var i=r,{cardId:e,onDone:t,onClose:o}=i,n=f(i,["cardId","onDone","onClose"]);let s="replaceCard",d=l(()=>({entryPoint:s,cardId:e}),[e]);return m.createElement(c,p(a({},n),{renderingContext:d,methods:{replaceCard:{onDone:t,onClose:o}}}))}function fo(r){var i=r,{cardId:e,onDone:t,onClose:o}=i,n=f(i,["cardId","onDone","onClose"]);let s="terminateCard",d=l(()=>({entryPoint:s,cardId:e}),[e]);return m.createElement(c,p(a({},n),{renderingContext:d,methods:{terminateCard:{onDone:t,onClose:o}}}))}export{ro as AccountActions,no as AccountDetails,Xt as App,to as BillPayApp,ze as CapitalOsAuthenticationProvider,oo as CardDetails,je as CardsApp,co as ContactSupport,We as DevTools,eo as DisputeTransaction,io as InsightsDashboard,so as InsightsWidget,Yt as IssueCard,lo as LegalDocuments,po as MakePayment,ao as Onboarding,uo as ReplaceCard,mo as Statements,fo as TerminateCard};
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.tsx","../../src/capital-os.tsx","../../src/context/capital-os-authentication-context.tsx","../../src/common/token-exchange-iframe.tsx","../../src/error.ts","../../src/hooks.ts","../../package.json","../../src/utils.ts","../../src/iframe-resizer.tsx","../../src/dev-tools.tsx","../../src/components/dev-tools-button.tsx"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport { CapitalOsAuthenticationProvider } from './context/capital-os-authentication-context'\nimport { DevTools } from './dev-tools'\nimport type { EntryPoint, IssueCardDefaultValues } from './external-types'\nimport type { Account, CommonProps } from './types'\n\n// #region App\n/**\n * Renders the CapitalOS CardsApp.\n */\nexport function CardsApp(props: CommonProps) {\n const entryPoint: EntryPoint = 'cardsApp'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// maintain backwards compatibility\n\n/** @deprecated Use {@link CardsApp} instead */\nconst App = CardsApp\n\nexport { App }\n\n// #region Issue Card\nexport type IssueCardProps = CommonProps & {\n /**\n * Default values to prefill the form with.\n *\n * Either provide a userId, in which case the default values will be taken from that user's profile, or provide the cardholder's details directly.\n */\n cardholder?: IssueCardDefaultValues\n\n /**\n * Callback to invoke when the card was created successfully.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the card creation was cancelled by the user.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Issue Card experience.\n */\nexport function IssueCard({ cardholder, onDone, onCancel, ...restOfProps }: IssueCardProps) {\n const entryPoint: EntryPoint = 'createCard'\n const renderingContext = useMemo(\n () => ({\n entryPoint,\n cardholder,\n }),\n [cardholder],\n )\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createCard: { onDone, onCancel } }} />\n )\n}\n// #endregion\n\n// #region Dispute Transaction\nexport type DisputeTransactionProps = CommonProps & {\n /**\n * The ID of the transaction to dispute.\n */\n transactionId: string\n\n /**\n * Callback to invoke when the dispute was successfully submitted.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the user cancels the dispute submission.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Dispute Transaction experience.\n */\nexport function DisputeTransaction({ transactionId, onDone, onCancel, ...restOfProps }: DisputeTransactionProps) {\n const entryPoint: EntryPoint = 'createDispute'\n const renderingContext = useMemo(() => ({ entryPoint, transactionId }), [transactionId])\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createDispute: { onDone, onCancel } }} />\n )\n}\n// #endregion\n\n// #region Bill Payment Dashboard\nexport type BillPayAppProps = CommonProps\n\n/**\n * Renders the CapitalOS Bill Payment Dashboard experience.\n */\nexport function BillPayApp(props: BillPayAppProps) {\n const entryPoint: EntryPoint = 'billPayApp'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Card Details\nexport type CardDetailsProps = CommonProps & {\n /**\n * The ID of the card to manage.\n */\n cardId: string\n cardOnly?: boolean | undefined\n hideAddress?: boolean | undefined\n onCardCanceled?: () => void\n}\n\n/**\n * Renders the CapitalOS Manage Card experience.\n */\nexport function CardDetails(props: CardDetailsProps) {\n const { onCardCanceled, ...restOfProps } = props\n const entryPoint: EntryPoint = 'cardDetails'\n const renderingContext = useMemo(\n () => ({ entryPoint, cardId: props.cardId, cardOnly: props.cardOnly, hideAddress: props.hideAddress }),\n [entryPoint, props.cardId, props.cardOnly],\n )\n\n return (\n <CapitalOS\n {...restOfProps}\n renderingContext={renderingContext}\n methods={{ cardDetails: { onCardCanceled: onCardCanceled ?? (() => {}) } }}\n />\n )\n}\n// #endregion\n\n// #region Account Details\nexport type AccountDetailsProps = CommonProps\n\n/**\n * Renders the CapitalOS Account Details experience.\n */\nexport function AccountDetails(props: AccountDetailsProps) {\n const entryPoint: EntryPoint = 'accountDetails'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Account Actions\nexport type AccountActionsProps = CommonProps\n\n/**\n * Renders the CapitalOS Account Actions experience.\n */\nexport function AccountActions(props: AccountActionsProps) {\n const entryPoint: EntryPoint = 'accountActions'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Insights Dashboard\nexport type InsightsDashboardProps = CommonProps\n\n/**\n * Renders the CapitalOS Insights Dashboard experience\n */\nexport function InsightsDashboard(props: InsightsDashboardProps) {\n const entryPoint: EntryPoint = 'insightsDashboard'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Insights Widget\nexport type InsightsWidgetProps = CommonProps & {\n /**\n * The specific widget to render.\n * naming convention:\n * 1. Over-time Widgets\n * over-time-{metric}-by-{dimension}-per-{time-granularity}\n * 2. Top/Ranking Widgets\n * top-{entities}-by-{metric}-{timeframe}\n * 3. Comparison Widgets\n * comparison-{metric}-{primary-timeframe}-vs-{secondary-timeframe}\n */\n widget:\n | 'over-time-spend-by-card-per-month'\n | 'over-time-spend-by-category-per-month'\n | 'top-cards-by-spend-this-month'\n | 'top-categories-by-spend-this-month'\n | 'top-transactions-by-amount-this-month'\n | 'comparison-spend-this-month-vs-last-month'\n /**\n * Whether to hide the title of the widget.\n */\n hideTitle?: boolean | undefined\n /**\n * The height of the widget.\n */\n height?: number | undefined\n /**\n * The width of the widget.\n */\n width?: number | undefined\n}\n\n/**\n * Renders a specific CapitalOS Insights Widget\n */\nexport function InsightsWidget(props: InsightsWidgetProps) {\n const entryPoint: EntryPoint = 'insightsWidget'\n const { widget, hideTitle, height, width } = props\n const renderingContext = useMemo(\n () => ({ entryPoint, widget, hideTitle, height, width }),\n [entryPoint, widget, hideTitle, height, width],\n )\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Onboarding\ntype AllowedExitPoints = {\n welcome: 'application' | 'activation'\n application: 'application' | 'activation'\n}\n\ntype OnboardingEntryPoint = keyof AllowedExitPoints\ntype OnboardingProps<T extends keyof AllowedExitPoints> = CommonProps & {\n entryPoint?: T\n exitPoint?: AllowedExitPoints[T]\n onDone: (account: Account) => void\n}\n\nexport function Onboarding<T extends OnboardingEntryPoint>({\n onDone,\n entryPoint: onboardingEntryPoint,\n exitPoint: onboardingExitPoint,\n ...restOfProps\n}: OnboardingProps<T>) {\n // This component uses 'entryPoint' in two distinct ways:\n // 1. As a prop to control the user's starting/ending stages of onboarding\n // 2. For internal rendering context to determine which client component to display\n const entryPoint: EntryPoint = 'onboarding'\n const renderingContext = useMemo(\n () => ({ entryPoint, onboardingEntryPoint, onboardingExitPoint }),\n [entryPoint, onboardingEntryPoint, onboardingExitPoint],\n )\n\n return <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ onboarding: { onDone } }} />\n}\n// #endregion\n\n// #region Make a payment\nexport type MakePaymentProps = CommonProps & {\n /**\n * Callback to invoke when the payment was made successfully.\n */\n onDone: () => void\n}\n\n/**\n * Renders the CapitalOS Make a Payment experience.\n */\nexport function MakePayment({ onDone, ...restOfProps }: MakePaymentProps) {\n const entryPoint: EntryPoint = 'makePayment'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ makePayment: { onDone } }} />\n}\n// #endregion\n\n// #region Dev Tools\nexport { DevTools }\n// #endregion\n\n// #region Authentication provider\nexport { CapitalOsAuthenticationProvider }\n// #endregion\n","import React, { useEffect, useMemo, useRef, useState, useCallback } from 'react'\n\nimport { useCapitalOsAuthContext } from './context/capital-os-authentication-context'\nimport { CapitalOSError, ErrorCode } from './error'\nimport { IframeConnectionMethods, useIframeConnection, useIframeUrl } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps, CapitalOsRenderingContext, TokenData } from './types'\nimport { tokenDataFromOneTimeToken } from './utils'\n\ntype CapitalOsProps<T extends CapitalOsRenderingContext> = CommonProps & {\n renderingContext: T\n methods?: Partial<IframeConnectionMethods>\n sizeWidth?: boolean\n}\n\n/**\n * The internal component that handles all the heavy lifting of connecting to the iframe and rendering the app.\n * all user facing components are basically a syntactic sugar on top of this.\n */\nexport function CapitalOS<T extends CapitalOsRenderingContext>(props: CapitalOsProps<T>) {\n const {\n token: tokenProp,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n theme,\n sizeWidth,\n } = props\n const { tokenData: contextTokenData, error, invalidateToken } = useCapitalOsAuthContext()\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n useErrorHandling(error, onError)\n\n const tokenData: TokenData | undefined = useMemo(\n () => (tokenProp ? tokenDataFromOneTimeToken(tokenProp) : contextTokenData),\n [tokenProp, contextTokenData],\n )\n\n // Handle token expiration by invalidating the token\n // The context's useEffect will automatically handle the refresh\n const handleTokenExpired = useCallback(() => {\n if (enableLogging) {\n // eslint-disable-next-line no-console\n console.log('CapitalOS: Token expired, invalidating...')\n }\n\n // If we're using tokenProp, we can't refresh automatically\n if (tokenProp) {\n onError?.(\n new CapitalOSError({\n message: 'Token expired. Cannot automatically refresh when using token prop.',\n code: ErrorCode.unauthorized,\n }),\n )\n return\n }\n\n // Use the invalidateToken function from the context\n // This will clear the token and the authentication context's useEffect will handle the refresh\n invalidateToken()\n\n // The iframe will be reloaded automatically when tokenData changes\n setIsLoaded(false)\n }, [tokenProp, invalidateToken, enableLogging, onError])\n\n useEffect(() => {\n if (tokenProp && contextTokenData && enableLogging) {\n // eslint-disable-next-line no-console\n console.warn(\n 'CapitalOS: token was provided both from provider and from the token prop. the prop will take precedence',\n )\n }\n }, [tokenProp, contextTokenData, enableLogging])\n\n const url = useIframeUrl({ tokenData, renderingContext, theme, onError })\n\n useIframeConnection({\n iframeRef,\n token: tokenData?.token,\n onError: (error) => {\n onError?.(error)\n // when connection fails it's probably a handshake timeout with the iframe. we will stop showing the loader\n // since the fact we failed communication doesn't necessarily mean the iframe didn't load\n setIsLoaded(true)\n },\n methods: {\n onLoad: () => {\n setIsLoaded(true)\n },\n onError: (error) => {\n const err = new CapitalOSError(error)\n onError?.(err)\n },\n onTokenExpired: handleTokenExpired,\n ...methods,\n },\n })\n\n if (!tokenData || !url) {\n return <>{LoadingComponent || null}</>\n }\n\n // insightsWidget does not need additional padding. also - it supports a height property that needs to be respected.\n const shouldAddPaddingBottom = renderingContext.entryPoint !== 'insightsWidget'\n\n return (\n <>\n {/* show loader as long as we're not loaded */}\n {!isLoaded && LoadingComponent}\n {/* hide the iframe as long as we're not loaded */}\n <IframeResizer\n src={url}\n allow=\"clipboard-write\"\n checkOrigin={false}\n style={{ width: '1px', height: '0px', minWidth: '100%' }}\n className={className}\n log={!!enableLogging}\n ref={iframeRef}\n hidden={!isLoaded}\n // Add a constant offset to the height of the iframe to account for css shadows.\n // This is useful for tooltips that are rendered with shadows below them that extend beyond the bottom of the tooltip.\n onResized={(data) => {\n if (!shouldAddPaddingBottom) {\n return\n }\n\n // typing is wrong here. this is a string.\n const newHeight = `${parseInt(data.height as unknown as string) + 12}px`\n data.iframe.style.height = newHeight\n }}\n sizeWidth={sizeWidth}\n />\n </>\n )\n}\n\n/**\n * Makes sure component only fires the error event once.\n * @param error - The error to handle.\n * @param onError - The function to call when the error occurs.\n */\nfunction useErrorHandling(error: Error | null | undefined, onError?: (error: Error) => void) {\n const errorFired = useRef(false)\n\n useEffect(() => {\n if (error && !errorFired.current) {\n onError?.(error)\n errorFired.current = true\n }\n }, [error, onError])\n}\n","'use client'\n\nimport React, { createContext, useContext, useState, useMemo, useCallback, useEffect } from 'react'\n\nimport { TokenExchangeIframe } from '../common/token-exchange-iframe'\nimport { CapitalOSError, ErrorCode } from '../error'\nimport { TokenData, TokenParamKey, TokenParamLocation, TokenType } from '../types'\nimport { decodeOneTimeToken } from '../utils'\n\ntype CapitalOsAuthenticationContextType = {\n tokenData?: TokenData | undefined\n isLoading: boolean\n error?: Error | undefined\n /**\n * Invalidates the current token..\n * This is used when the iframe signals that the token has expired.\n * The authentication flow will automatically refresh the token after invalidation.\n */\n invalidateToken: () => void\n}\n\ntype ProviderProps = {\n getToken: () => Promise<string>\n enableLogging?: boolean | undefined\n children: React.ReactNode\n}\n\nconst CapitalOsAuthenticationContext = createContext<CapitalOsAuthenticationContextType>({\n isLoading: false,\n invalidateToken: () => {},\n})\n\nexport const CapitalOsAuthenticationProvider: React.FC<ProviderProps> = ({ getToken, enableLogging, children }) => {\n const [oneTimeToken, setOneTimeToken] = useState<string | undefined>(undefined)\n const [baseUrl, setBaseUrl] = useState<string | undefined>(undefined)\n const [longLivedToken, setLongLivedToken] = useState<string | undefined>(undefined)\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<Error | undefined>(undefined)\n\n const refreshOneTimeToken = useCallback(async () => {\n setIsLoading(true)\n try {\n const newToken = await getToken()\n setOneTimeToken(newToken)\n setError(undefined)\n const tokenObject = decodeOneTimeToken(newToken)\n const url = new URL(tokenObject.path)\n // we don't need the /login part of the path since long lived tokens don't go through the login flow.\n url.pathname = ''\n setBaseUrl(url.toString())\n } catch (error) {\n setError(error as Error)\n } finally {\n setIsLoading(false)\n }\n }, [getToken])\n\n // Add invalidateToken method\n const invalidateToken = useCallback(() => {\n setLongLivedToken(undefined)\n }, [])\n\n // On mount, if no long-lived token is available, refresh to get a one-time token.\n useEffect(() => {\n if (!longLivedToken) {\n refreshOneTimeToken()\n }\n }, [longLivedToken, refreshOneTimeToken])\n\n const onExchangeComplete = useCallback((jwtToken: string) => {\n setLongLivedToken(jwtToken)\n setOneTimeToken(undefined)\n setError(undefined)\n }, [])\n\n const contextValue: CapitalOsAuthenticationContextType = useMemo(() => {\n if (longLivedToken && !baseUrl) {\n throw new CapitalOSError({\n message: 'baseUrl is required for long lived tokens',\n code: ErrorCode.unauthorized,\n })\n }\n const tokenData: TokenData | undefined = longLivedToken\n ? ({\n token: longLivedToken,\n tokenType: TokenType.longLived,\n baseUrl: baseUrl!,\n paramKey: TokenParamKey.accessToken,\n paramLocation: TokenParamLocation.hash,\n } as const)\n : undefined\n\n return {\n tokenData,\n isLoading,\n error,\n invalidateToken,\n }\n }, [longLivedToken, isLoading, error, invalidateToken, baseUrl])\n\n return (\n <>\n <CapitalOsAuthenticationContext.Provider value={contextValue}>{children}</CapitalOsAuthenticationContext.Provider>\n {oneTimeToken && !longLivedToken && (\n <TokenExchangeIframe\n oneTimeToken={oneTimeToken}\n onExchangeComplete={onExchangeComplete}\n enableLogging={enableLogging}\n onExchangeError={setError}\n />\n )}\n </>\n )\n}\n\nexport const useCapitalOsAuthContext = () => useContext(CapitalOsAuthenticationContext)\n","import React, { useMemo, useRef } from 'react'\n\nimport { CapitalOSError } from '../error'\nimport { useIframeConnection, useIframeUrl } from '../hooks'\nimport { IframeResizer } from '../iframe-resizer'\nimport { tokenDataFromOneTimeToken } from '../utils'\n\nexport interface TokenExchangeIframeProps {\n oneTimeToken: string\n enableLogging?: boolean | undefined\n onExchangeComplete: (jwtToken: string) => void\n onExchangeError?: (error: Error) => void\n}\n\n/**\n * The component is hidden from the user and is only used to exchange a one-time token for a JWT in the authentication context.\n *\n * The token exchange process works as follows:\n * 1. Component renders a hidden iframe with the one-time token in the URL\n * 2. The iframe loads with the long-lived token as part of its url redirect response and establishes a secure connection with the parent window\n * 3. The iframe passes the long-lived token to the parent via postMessage\n * 4. onExchangeComplete callback is triggered with the new JWT\n *\n * If any errors occur during this process, they are passed to onExchangeError.\n */\nexport function TokenExchangeIframe(props: TokenExchangeIframeProps) {\n const { oneTimeToken, enableLogging, onExchangeComplete, onExchangeError } = props\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n const tokenData = useMemo(() => tokenDataFromOneTimeToken(oneTimeToken), [oneTimeToken])\n\n const renderingContext = {\n entryPoint: 'tokenExchange',\n } as const\n\n const url = useIframeUrl({\n tokenData,\n onError: onExchangeError,\n renderingContext,\n })\n\n useIframeConnection({\n iframeRef,\n token: oneTimeToken,\n onError: onExchangeError,\n methods: {\n onLoad: () => {},\n onError: (error) => {\n onExchangeError?.(new CapitalOSError(error))\n },\n tokenExchange: {\n onLongLivedToken: onExchangeComplete,\n },\n },\n })\n\n // Render the hidden iframe.\n return (\n <IframeResizer\n src={url}\n checkOrigin={false}\n style={{ display: 'none' }} // Hidden from view\n log={!!enableLogging}\n ref={iframeRef}\n />\n )\n}\n","/**\n * Base class for all SDK errors\n */\nexport class CapitalOSError extends Error {\n code: ErrorCode\n constructor({ message, code }: { message: string; code: ErrorCode }) {\n super(message)\n this.name = 'CapitalOSError'\n this.code = code\n }\n}\n\nexport const ErrorCode = {\n unauthorized: 'unauthorized',\n invalid_account_status: 'invalid_account_status',\n unsupported_entry_point: 'unsupported_entry_point',\n internal_error: 'internal_error',\n} as const\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode]\n\n/**\n * Represents an error that occurs when an invalid token is encountered.\n */\nexport class InvalidTokenError extends CapitalOSError {\n constructor(message?: string) {\n super({ message: `Invalid token ${message ?? ''}`, code: ErrorCode.unauthorized })\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n\nexport class TokenRefreshError extends CapitalOSError {\n constructor(originalError?: Error) {\n super({\n message: `Failed to refresh token: ${originalError?.message}`,\n code: ErrorCode.unauthorized,\n })\n this.name = 'CapitalOSTokenRefreshError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect, useMemo, useRef } from 'react'\n\nimport { ErrorCode } from './error'\nimport { Account, ThemeColorScheme, CapitalOsRenderingContext, TokenData } from './types'\nimport { buildIframeUrl } from './utils'\n\nconst IFRAME_CONNECTION_TIMEOUT_MILLISECONDS = 10_000\n\n/**\n * An error type providing a reason code and message.\n * Penpal only passes plain objects, so this does not inherit from Error.\n */\nexport type RawErrorDetails = {\n code: ErrorCode\n message: string\n}\n\nexport type IframeConnectionMethods = {\n onLoad: () => void\n onError: (error: RawErrorDetails) => void\n /**\n * Called when the iframe detects that the JWT token has expired.\n * This triggers the token refresh flow, which will obtain a new token\n * and reload the iframe with the fresh token.\n */\n onTokenExpired?: () => void\n createCard?: {\n onDone?: () => void\n onCancel?: () => void\n }\n createDispute?: {\n onDone?: () => void\n onCancel?: () => void\n }\n onboarding?: {\n onDone?: (account: Account) => void\n }\n tokenExchange?: {\n onLongLivedToken?: (jwtToken: string) => void\n }\n makePayment?: {\n onDone?: () => void\n }\n devTools?: {\n onClose?: () => void\n }\n cardDetails?: {\n onCardCanceled?: () => void\n }\n}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n * token was added to the list of dependencies to make sure that the connection is re-established when the token changes.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string | undefined\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\n if (!iframeRef.current) {\n return\n }\n\n const connection = connectToChild({\n iframe: iframeRef.current,\n childOrigin: '*',\n debug: true,\n timeout: IFRAME_CONNECTION_TIMEOUT_MILLISECONDS,\n methods,\n })\n\n connection.promise.catch((error) => {\n onError?.(error)\n })\n\n return () => {\n connection.destroy()\n }\n }, [token, iframeRef])\n}\n\nexport function useIframeUrl({\n tokenData,\n renderingContext,\n theme,\n onError,\n}: {\n tokenData: TokenData | undefined\n renderingContext: CapitalOsRenderingContext\n theme?: ThemeColorScheme | undefined\n onError?: ((error: Error) => void) | undefined\n}) {\n // We assume that onError and renderingContext do not change over the lifetime of the component.\n // We put it in a ref to avoid causing unnecessary re-renders.\n const onErrorRef = useRef(onError)\n const renderingContextRef = useRef(renderingContext)\n\n return useMemo(() => {\n if (!tokenData) {\n return undefined\n }\n return buildIframeUrl({\n tokenData,\n renderingContext: renderingContextRef.current,\n theme,\n onError: onErrorRef.current,\n })\n // wrapped rendering context in a ref since we do not want to reload the iframe unless the token changes.\n }, [tokenData, theme, onErrorRef, renderingContextRef])\n}\n","{\n \"name\": \"@capitalos/react\",\n \"version\": \"1.1.0-rc.1\",\n \"description\": \"integrate CapitalOS into your react app\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/esm/index.js\",\n \"types\": \"dist/_tsup-dts-rollup.d.ts\",\n \"scripts\": {\n \"build\": \" pnpm lint && tsup src/index.tsx --experimental-dts --minify --format esm,cjs --clean --no-splitting --sourcemap --legacy-output --out-dir dist\",\n \"dev\": \"pnpm build --watch\",\n \"prepublishOnly\": \"pnpm build\",\n \"lint\": \"eslint . --ext .ts,.tsx --fix\",\n \"lint-ci\": \"eslint . --ext .ts,.tsx\"\n },\n \"keywords\": [\n \"capitalos\",\n \"react\"\n ],\n \"homepage\": \"https://docs.capitalos.com/docs/using-react-client-library\",\n \"author\": \"CapitalOS\",\n \"license\": \"MIT\",\n \"files\": [\n \"dist\",\n \"package.json\"\n ],\n \"devDependencies\": {\n \"@changesets/cli\": \"^2.27.12\",\n \"@microsoft/api-extractor\": \"^7.39.5\",\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\n \"@types/iframe-resizer\": \"^3.5.13\",\n \"@types/react\": \"18.0.20\",\n \"@typescript-eslint/eslint-plugin\": \"^7.2.0\",\n \"@typescript-eslint/parser\": \"^7.2.0\",\n \"eslint\": \"^8.57.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"eslint-plugin-prettier\": \"^5.1.3\",\n \"eslint-plugin-react\": \"^7.34.0\",\n \"prettier\": \"^3.2.5\",\n \"react\": \"16.8.0\",\n \"tsup\": \"^8.1.0\",\n \"typescript\": \"^5.6.2\"\n },\n \"dependencies\": {\n \"iframe-resizer\": \"^4.3.9\",\n \"penpal\": \"^6.2.2\"\n },\n \"peerDependencies\": {\n \"react\": \">=16.8.0\"\n }\n}\n","import { version as sdkVersion } from '../package.json'\nimport { InvalidTokenError } from './error'\nimport {\n ThemeColorScheme,\n CapitalOsRenderingContext,\n TokenData,\n TokenType,\n TokenParamKey,\n TokenParamLocation,\n} from './types'\n\n/**\n * Encodes the rendering context as base64 and then URI encodes it.\n */\nexport function encodeRenderingContext<T>(renderingContext: NonNullable<T>) {\n const renderingContextJson = JSON.stringify(renderingContext)\n const renderingContextBase64 = btoa(renderingContextJson)\n const renderingContextEncoded = encodeURIComponent(renderingContextBase64)\n\n return renderingContextEncoded\n}\n\nexport function decodeOneTimeToken(token: string) {\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n return JSON.parse(base64DecodedToken)\n } catch (error) {\n throw new InvalidTokenError()\n }\n}\n\n/**\n * Safely decodes a URL component, handling potential errors\n */\nexport function safeDecodeURIComponent(str: string): string {\n try {\n return decodeURIComponent(str)\n } catch (e) {\n // If decoding fails, it might not have been encoded, so return original\n return str\n }\n}\n\n/**\n * Builds the iframe url from token data, rendering context, and theme.\n */\nexport function buildIframeUrl({\n tokenData,\n renderingContext,\n theme,\n onError,\n}: {\n tokenData: TokenData\n renderingContext: CapitalOsRenderingContext\n theme?: ThemeColorScheme | undefined\n onError?: ((error: Error) => void) | undefined\n}) {\n try {\n const enrichedRenderingContext = renderingContext\n ? {\n ...renderingContext,\n referer: window.location.href,\n }\n : null\n\n const encodedRenderingContext = enrichedRenderingContext ? encodeRenderingContext(enrichedRenderingContext) : null\n\n const url = new URL(tokenData.baseUrl)\n\n // Always safely decode the token before setting it since search params url encode the token and we do not want to double encode it.\n // in dev, since we're using 2 separate server for client and server, we have a redirect which prevents the double encoding.\n const decodedToken = safeDecodeURIComponent(tokenData.token)\n\n if (tokenData.paramLocation === 'search') {\n url.searchParams.set(tokenData.paramKey, decodedToken)\n } else if (tokenData.paramLocation === 'hash') {\n url.hash = tokenData.paramKey + '=' + encodeURIComponent(decodedToken)\n }\n\n url.searchParams.set('sdkVersion', sdkVersion)\n\n if (encodedRenderingContext) {\n url.searchParams.set('renderingContext', encodedRenderingContext)\n }\n\n if (theme) {\n url.searchParams.set('theme', theme)\n }\n\n const urlString = url.toString()\n return urlString\n } catch (error) {\n // communicate a general error about the token being invalid to the parent component, no matter which internal error we encountered during token parsing.\n onError?.(new InvalidTokenError())\n return undefined\n }\n}\n\nexport function tokenDataFromOneTimeToken(oneTimeToken: string): TokenData {\n const tokenObject = decodeOneTimeToken(oneTimeToken)\n const path = tokenObject.path\n if (!path || typeof path !== 'string') {\n throw new InvalidTokenError()\n }\n\n const tokenData: TokenData = {\n token: oneTimeToken,\n tokenType: TokenType.oneTime,\n baseUrl: path,\n paramKey: TokenParamKey.token,\n paramLocation: TokenParamLocation.search,\n }\n\n return tokenData\n}\n","import {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react'\n\n// the events were renamed but package maintainers didn't update the types.\ntype IFrameOptions = Omit<\n BrokenIframeOptions,\n 'closedCallback' | 'scrollCallback' | 'resizedCallback' | 'messageCallback' | 'initCallback'\n> & {\n onClosed?(iframeId: string): void\n onInit?(iframe: IFrameComponent): void\n onMessage?(data: IFrameMessageData): void\n onResized?(data: IFrameResizedData): void\n onScroll?(data: IFrameScrollData): boolean\n}\n\ntype IframeResizerProps = IFrameOptions & IframeHTMLAttributes<HTMLIFrameElement>\ntype EnrichedHtmlIframeElement = HTMLIFrameElement & { iFrameResizer: { removeListeners: () => void } }\n\nexport const IframeResizer = forwardRef((props: IframeResizerProps, ref: React.Ref<HTMLIFrameElement>) => {\n const title = props.title || 'iframe'\n const { iframeHTMLAttributes, resizerOptions } = splitProps(props)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n useEffect(() => {\n // effects run after render, so the ref is guaranteed to be set (unless the component conditionally renders the iframe, which is not the case)\n const iframe = iframeRef.current as EnrichedHtmlIframeElement\n\n iframeResizer({ ...resizerOptions }, iframe)\n\n return () => iframe.iFrameResizer && iframe.iFrameResizer.removeListeners()\n })\n\n // make the ref provided as a prop point to the same place as the internal iframe ref.\n useImperativeHandle(ref, () => iframeRef.current as HTMLIFrameElement)\n\n return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n})\n\nIframeResizer.displayName = 'IframeResizer'\n\nconst resizerOptions = [\n 'autoResize',\n 'bodyBackground',\n 'bodyMargin',\n 'bodyPadding',\n 'checkOrigin',\n 'inPageLinks',\n 'heightCalculationMethod',\n 'interval',\n 'log',\n 'maxHeight',\n 'maxWidth',\n 'minHeight',\n 'minWidth',\n 'resizeFrom',\n 'scrolling',\n 'sizeHeight',\n 'sizeWidth',\n 'warningTimeout',\n 'tolerance',\n 'widthCalculationMethod',\n 'onClosed',\n 'onInit',\n 'onMessage',\n 'onResized',\n 'onScroll',\n]\n\nconst resizerOptionsSet = new Set(resizerOptions)\n\n/**\n * split props into the resizer library options and the native iframe attributes.\n * the code is contains many type assertions because typescript doesn't handle reduce well.\n */\nfunction splitProps(props: IframeResizerProps) {\n const split = (Object.keys(props) as Array<keyof IframeResizerProps>).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n const value = props[key]\n if (resizerOptionsSet.has(key)) {\n if (value !== undefined) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\n }\n } else {\n acc.iframeHTMLAttributes[key as keyof IframeHTMLAttributes<HTMLIFrameElement>] =\n props[key as keyof typeof props]\n }\n return acc\n },\n { resizerOptions: {}, iframeHTMLAttributes: {} },\n )\n\n return split\n}\n","import React, { useMemo } from 'react'\nimport { useState } from 'react'\nimport { CSSProperties } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport { DevToolsButton } from './components/dev-tools-button'\nimport { EntryPoint } from './external-types'\nimport { CommonProps } from './types'\n\nconst styles: Record<string, CSSProperties> = {\n panel: {\n position: 'fixed',\n bottom: '20px',\n left: '20px',\n zIndex: 50,\n },\n}\n\n// #region Dev Tools\nexport type DevToolsProps = CommonProps\n\n/**\n * Renders the CapitalOS Dev Tools experience.\n * Allows for simulating transactions, etc.\n */\nexport function DevTools(props: DevToolsProps) {\n const entryPoint: EntryPoint = 'devTools'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n const [isOpen, setIsOpen] = useState(false)\n\n return (\n <aside aria-label=\"CapitalOS dev tools\">\n {!isOpen && <DevToolsButton onClick={() => setIsOpen(!isOpen)} />}\n {isOpen && (\n <div style={styles['panel']}>\n <CapitalOS\n {...props}\n renderingContext={renderingContext}\n methods={{ devTools: { onClose: () => setIsOpen(false) } }}\n enableLogging={true}\n sizeWidth={true}\n loadingComponent={<DevToolsButton isLoading />}\n />\n </div>\n )}\n </aside>\n )\n}\n","import React, { useState } from 'react'\nimport { CSSProperties } from 'react'\n\nconst styles: Record<string, CSSProperties> = {\n bugButton: {\n position: 'fixed',\n left: '12px',\n bottom: '12px',\n margin: '12px',\n padding: '4px',\n display: 'inline-flex',\n alignItems: 'center',\n borderRadius: '9999px',\n border: '1px solid transparent',\n backgroundColor: '#2563eb',\n color: 'white',\n opacity: 0.4,\n boxShadow: '0 1px 3px 0 rgb(0 0 0 / 0.1)',\n cursor: 'pointer',\n zIndex: 50,\n transition: 'opacity 0.3s ease-in-out',\n },\n bugButtonHover: {\n backgroundColor: '#1d4ed8',\n opacity: 1,\n },\n bugButtonFocus: {\n outline: 'none',\n boxShadow: '0 0 0 2px white, 0 0 0 4px #3b82f6',\n },\n bugIcon: {\n width: '20px',\n height: '20px',\n },\n loadingButton: {\n cursor: 'default',\n opacity: 1,\n animation: 'pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite',\n },\n}\n\nconst BugIcon = () => (\n <svg\n style={styles['bugIcon']}\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n strokeWidth=\"1.5\"\n stroke=\"currentColor\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0 1 12 12.75Zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 0 1-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 0 0 2.248-2.354M12 12.75a2.25 2.25 0 0 1-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 0 0-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 0 1 .4-2.253M12 8.25a2.25 2.25 0 0 0-2.248 2.146M12 8.25a2.25 2.25 0 0 1 2.248 2.146M8.683 5a6.032 6.032 0 0 1-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0 1 15.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 0 0-.575-1.752M4.921 6a24.048 24.048 0 0 0-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 0 1-5.223 1.082\"\n />\n </svg>\n)\n\ninterface DevToolsButtonProps {\n onClick?: () => void\n isLoading?: boolean\n}\n\nexport function DevToolsButton({ onClick, isLoading = false }: DevToolsButtonProps) {\n const [isHovered, setIsHovered] = useState(false)\n const [isFocused, setIsFocused] = useState(false)\n\n const buttonStyle = {\n ...styles['bugButton'],\n ...(isLoading && styles['loadingButton']),\n ...(!isLoading && isHovered && styles['bugButtonHover']),\n ...(!isLoading && isFocused && styles['bugButtonFocus']),\n }\n\n if (isLoading) {\n return (\n <div style={buttonStyle}>\n <style>\n {`\n @keyframes pulse {\n 0%, 100% {\n opacity: 1;\n }\n 50% {\n opacity: 0.4;\n }\n }\n `}\n </style>\n <BugIcon />\n </div>\n )\n }\n\n return (\n <button\n id=\"dev-tools-button\"\n onClick={onClick}\n type=\"button\"\n style={buttonStyle}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n onFocus={() => setIsFocused(true)}\n onBlur={() => setIsFocused(false)}\n >\n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EAAaI,EAAAC,EAAbL,EAAa,CAAX,WAC5B,IAAMM,EAAyB,cACzBC,EAAmBC,EAAQ,KAAO,CAAE,WAAAF,CAAW,GAAI,CAACA,CAAU,CAAC,EAErE,OAAOG,EAAA,cAACC,EAAAC,EAAAC,EAAA,GAAcR,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,YAAa,CAAE,OAAAL,CAAO,CAAE,GAAG,CAC/G","names":["React","useMemo","React","useEffect","useMemo","useRef","useState","useCallback","React","createContext","useContext","useState","useMemo","useCallback","useEffect","React","useMemo","useRef","CapitalOSError","message","code","ErrorCode","InvalidTokenError","connectToChild","useEffect","useMemo","useRef","version","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeOneTimeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","safeDecodeURIComponent","str","e","buildIframeUrl","tokenData","theme","onError","enrichedRenderingContext","__spreadProps","__spreadValues","encodedRenderingContext","url","decodedToken","version","tokenDataFromOneTimeToken","oneTimeToken","path","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","useEffect","connection","connectToChild","error","useIframeUrl","tokenData","renderingContext","theme","onErrorRef","useRef","renderingContextRef","useMemo","buildIframeUrl","iframeResizer","React","forwardRef","useEffect","useImperativeHandle","useRef","IframeResizer","forwardRef","props","ref","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","useRef","useEffect","iframe","iframeResizer","__spreadValues","useImperativeHandle","React","__spreadProps","resizerOptionsSet","acc","key","value","TokenExchangeIframe","props","oneTimeToken","enableLogging","onExchangeComplete","onExchangeError","iframeRef","useRef","tokenData","useMemo","tokenDataFromOneTimeToken","url","useIframeUrl","useIframeConnection","error","CapitalOSError","React","IframeResizer","CapitalOsAuthenticationContext","createContext","CapitalOsAuthenticationProvider","getToken","enableLogging","children","oneTimeToken","setOneTimeToken","useState","baseUrl","setBaseUrl","longLivedToken","setLongLivedToken","isLoading","setIsLoading","error","setError","refreshOneTimeToken","useCallback","__async","newToken","tokenObject","decodeOneTimeToken","url","invalidateToken","useEffect","onExchangeComplete","jwtToken","contextValue","useMemo","CapitalOSError","ErrorCode","React","TokenExchangeIframe","useCapitalOsAuthContext","useContext","CapitalOS","props","tokenProp","className","enableLogging","onError","LoadingComponent","renderingContext","methods","theme","sizeWidth","contextTokenData","error","invalidateToken","useCapitalOsAuthContext","isLoaded","setIsLoaded","useState","iframeRef","useRef","useErrorHandling","tokenData","useMemo","tokenDataFromOneTimeToken","handleTokenExpired","useCallback","CapitalOSError","ErrorCode","useEffect","url","useIframeUrl","useIframeConnection","__spreadValues","err","React","shouldAddPaddingBottom","IframeResizer","data","newHeight","errorFired","React","useMemo","useState","React","useState","styles","BugIcon","React","DevToolsButton","onClick","isLoading","isHovered","setIsHovered","useState","isFocused","setIsFocused","buttonStyle","__spreadValues","styles","DevTools","props","entryPoint","renderingContext","useMemo","isOpen","setIsOpen","useState","React","DevToolsButton","CapitalOS","__spreadProps","__spreadValues","CardsApp","props","entryPoint","renderingContext","useMemo","React","CapitalOS","__spreadProps","__spreadValues","App","IssueCard","_a","_b","cardholder","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","useMemo","React","CapitalOS","__spreadProps","__spreadValues","DisputeTransaction","transactionId","BillPayApp","props","CardDetails","onCardCanceled","AccountDetails","AccountActions","InsightsDashboard","InsightsWidget","widget","hideTitle","height","width","Onboarding","onboardingEntryPoint","onboardingExitPoint","MakePayment"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.tsx","../../src/capital-os.tsx","../../src/context/capital-os-authentication-context.tsx","../../src/common/token-exchange-iframe.tsx","../../src/error.ts","../../src/hooks.ts","../../package.json","../../src/utils.ts","../../src/iframe-resizer.tsx","../../src/dev-tools.tsx","../../src/components/dev-tools-button.tsx"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport { CapitalOsAuthenticationProvider } from './context/capital-os-authentication-context'\nimport { DevTools } from './dev-tools'\nimport type { EntryPoint, IssueCardDefaultValues } from './external-types'\nimport type { Account, CommonProps } from './types'\n\n// #region App\n/**\n * Renders the CapitalOS CardsApp.\n */\nexport function CardsApp(props: CommonProps) {\n const entryPoint: EntryPoint = 'cardsApp'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// maintain backwards compatibility\n\n/** @deprecated Use {@link CardsApp} instead */\nconst App = CardsApp\n\nexport { App }\n\n// #region Issue Card\nexport type IssueCardProps = CommonProps & {\n /**\n * Default values to prefill the form with.\n *\n * Either provide a userId, in which case the default values will be taken from that user's profile, or provide the cardholder's details directly.\n */\n cardholder?: IssueCardDefaultValues\n\n /**\n * Callback to invoke when the card was created successfully.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the card creation was cancelled by the user.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Issue Card experience.\n */\nexport function IssueCard({ cardholder, onDone, onCancel, ...restOfProps }: IssueCardProps) {\n const entryPoint: EntryPoint = 'createCard'\n const renderingContext = useMemo(\n () => ({\n entryPoint,\n cardholder,\n }),\n [cardholder],\n )\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createCard: { onDone, onCancel } }} />\n )\n}\n// #endregion\n\n// #region Dispute Transaction\nexport type DisputeTransactionProps = CommonProps & {\n /**\n * The ID of the transaction to dispute.\n */\n transactionId: string\n\n /**\n * Callback to invoke when the dispute was successfully submitted.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the user cancels the dispute submission.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Dispute Transaction experience.\n */\nexport function DisputeTransaction({ transactionId, onDone, onCancel, ...restOfProps }: DisputeTransactionProps) {\n const entryPoint: EntryPoint = 'createDispute'\n const renderingContext = useMemo(() => ({ entryPoint, transactionId }), [transactionId])\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createDispute: { onDone, onCancel } }} />\n )\n}\n// #endregion\n\n// #region Bill Payment Dashboard\nexport type BillPayAppProps = CommonProps\n\n/**\n * Renders the CapitalOS Bill Payment Dashboard experience.\n */\nexport function BillPayApp(props: BillPayAppProps) {\n const entryPoint: EntryPoint = 'billPayApp'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Card Details\nexport type CardDetailsProps = CommonProps & {\n /**\n * The ID of the card to manage.\n */\n cardId: string\n cardOnly?: boolean | undefined\n hideAddress?: boolean | undefined\n onCardCanceled?: () => void\n}\n\n/**\n * Renders the CapitalOS Manage Card experience.\n */\nexport function CardDetails(props: CardDetailsProps) {\n const { onCardCanceled, ...restOfProps } = props\n const entryPoint: EntryPoint = 'cardDetails'\n const renderingContext = useMemo(\n () => ({ entryPoint, cardId: props.cardId, cardOnly: props.cardOnly, hideAddress: props.hideAddress }),\n [entryPoint, props.cardId, props.cardOnly],\n )\n\n return (\n <CapitalOS\n {...restOfProps}\n renderingContext={renderingContext}\n methods={{ cardDetails: { onCardCanceled: onCardCanceled ?? (() => {}) } }}\n />\n )\n}\n// #endregion\n\n// #region Account Details\nexport type AccountDetailsProps = CommonProps\n\n/**\n * Renders the CapitalOS Account Details experience.\n */\nexport function AccountDetails(props: AccountDetailsProps) {\n const entryPoint: EntryPoint = 'accountDetails'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Account Actions\nexport type AccountActionsProps = CommonProps\n\n/**\n * Renders the CapitalOS Account Actions experience.\n */\nexport function AccountActions(props: AccountActionsProps) {\n const entryPoint: EntryPoint = 'accountActions'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Insights Dashboard\nexport type InsightsDashboardProps = CommonProps\n\n/**\n * Renders the CapitalOS Insights Dashboard experience\n */\nexport function InsightsDashboard(props: InsightsDashboardProps) {\n const entryPoint: EntryPoint = 'insightsDashboard'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Insights Widget\nexport type InsightsWidgetProps = CommonProps & {\n /**\n * The specific widget to render.\n * naming convention:\n * 1. Over-time Widgets\n * over-time-{metric}-by-{dimension}-per-{time-granularity}\n * 2. Top/Ranking Widgets\n * top-{entities}-by-{metric}-{timeframe}\n * 3. Comparison Widgets\n * comparison-{metric}-{primary-timeframe}-vs-{secondary-timeframe}\n */\n widget:\n | 'over-time-spend-by-card-per-month'\n | 'over-time-spend-by-category-per-month'\n | 'top-cards-by-spend-this-month'\n | 'top-categories-by-spend-this-month'\n | 'top-transactions-by-amount-this-month'\n | 'comparison-spend-this-month-vs-last-month'\n /**\n * Whether to hide the title of the widget.\n */\n hideTitle?: boolean | undefined\n /**\n * The height of the widget.\n */\n height?: number | undefined\n /**\n * The width of the widget.\n */\n width?: number | undefined\n}\n\n/**\n * Renders a specific CapitalOS Insights Widget\n */\nexport function InsightsWidget(props: InsightsWidgetProps) {\n const entryPoint: EntryPoint = 'insightsWidget'\n const { widget, hideTitle, height, width } = props\n const renderingContext = useMemo(\n () => ({ entryPoint, widget, hideTitle, height, width }),\n [entryPoint, widget, hideTitle, height, width],\n )\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\n}\n// #endregion\n\n// #region Onboarding\ntype AllowedExitPoints = {\n welcome: 'application' | 'activation'\n application: 'application' | 'activation'\n}\n\ntype OnboardingEntryPoint = keyof AllowedExitPoints\ntype OnboardingProps<T extends keyof AllowedExitPoints> = CommonProps & {\n entryPoint?: T\n exitPoint?: AllowedExitPoints[T]\n onDone: (account: Account) => void\n}\n\nexport function Onboarding<T extends OnboardingEntryPoint>({\n onDone,\n entryPoint: onboardingEntryPoint,\n exitPoint: onboardingExitPoint,\n ...restOfProps\n}: OnboardingProps<T>) {\n // This component uses 'entryPoint' in two distinct ways:\n // 1. As a prop to control the user's starting/ending stages of onboarding\n // 2. For internal rendering context to determine which client component to display\n const entryPoint: EntryPoint = 'onboarding'\n const renderingContext = useMemo(\n () => ({ entryPoint, onboardingEntryPoint, onboardingExitPoint }),\n [entryPoint, onboardingEntryPoint, onboardingExitPoint],\n )\n\n return <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ onboarding: { onDone } }} />\n}\n// #endregion\n\n// #region Make a payment\nexport type MakePaymentProps = CommonProps & {\n /**\n * Callback to invoke when the payment was made successfully.\n */\n onDone: () => void\n}\n\n/**\n * Renders the CapitalOS Make a Payment experience.\n */\nexport function MakePayment({ onDone, ...restOfProps }: MakePaymentProps) {\n const entryPoint: EntryPoint = 'makePayment'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ makePayment: { onDone } }} />\n}\n// #endregion\n\n// #region Dev Tools\nexport { DevTools }\n// #endregion\n\n// #region Contact Support\nexport type ContactSupportProps = CommonProps & {\n onDone: () => void\n onCancel: () => void\n}\n\nexport function ContactSupport({ onDone, onCancel, ...restOfProps }: ContactSupportProps) {\n const entryPoint: EntryPoint = 'contactSupport'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return (\n <CapitalOS\n {...restOfProps}\n renderingContext={renderingContext}\n methods={{ contactSupport: { onDone, onCancel } }}\n />\n )\n}\n\n// #endregion\n\n// #region Statements\nexport type StatementsProps = CommonProps & {\n onDone: () => void\n}\n\nexport function Statements({ onDone, ...restOfProps }: StatementsProps) {\n const entryPoint: EntryPoint = 'statements'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ statements: { onDone } }} />\n}\n// #endregion\n\n// #region Legal Documents\nexport type LegalDocumentsProps = CommonProps & {\n onDone: () => void\n}\n\nexport function LegalDocuments({ onDone, ...restOfProps }: LegalDocumentsProps) {\n const entryPoint: EntryPoint = 'legalDocuments'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n return <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ legalDocuments: { onDone } }} />\n}\n// #endregion\n\n// #region Replace Card\nexport type ReplaceCardProps = CommonProps & {\n cardId: string\n onDone: () => void\n onClose: () => void\n}\n\nexport function ReplaceCard({ cardId, onDone, onClose, ...restOfProps }: ReplaceCardProps) {\n const entryPoint: EntryPoint = 'replaceCard'\n const renderingContext = useMemo(() => ({ entryPoint, cardId }), [cardId])\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ replaceCard: { onDone, onClose } }} />\n )\n}\n// #endregion\n\n// #region Terminate Card\nexport type TerminateCardProps = CommonProps & {\n cardId: string\n onDone: () => void\n onClose: () => void\n}\n\nexport function TerminateCard({ cardId, onDone, onClose, ...restOfProps }: TerminateCardProps) {\n const entryPoint: EntryPoint = 'terminateCard'\n const renderingContext = useMemo(() => ({ entryPoint, cardId }), [cardId])\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ terminateCard: { onDone, onClose } }} />\n )\n}\n// #endregion\n\n// #region Authentication provider\nexport { CapitalOsAuthenticationProvider }\n// #endregion\n","import React, { useEffect, useMemo, useRef, useState, useCallback } from 'react'\n\nimport { useCapitalOsAuthContext } from './context/capital-os-authentication-context'\nimport { CapitalOSError, ErrorCode } from './error'\nimport { IframeConnectionMethods, useIframeConnection, useIframeUrl } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps, CapitalOsRenderingContext, TokenData } from './types'\nimport { tokenDataFromOneTimeToken } from './utils'\n\ntype CapitalOsProps<T extends CapitalOsRenderingContext> = CommonProps & {\n renderingContext: T\n methods?: Partial<IframeConnectionMethods>\n sizeWidth?: boolean\n}\n\n/**\n * The internal component that handles all the heavy lifting of connecting to the iframe and rendering the app.\n * all user facing components are basically a syntactic sugar on top of this.\n */\nexport function CapitalOS<T extends CapitalOsRenderingContext>(props: CapitalOsProps<T>) {\n const {\n token: tokenProp,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n theme,\n sizeWidth,\n } = props\n const { tokenData: contextTokenData, error, invalidateToken } = useCapitalOsAuthContext()\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n useErrorHandling(error, onError)\n\n const tokenData: TokenData | undefined = useMemo(\n () => (tokenProp ? tokenDataFromOneTimeToken(tokenProp) : contextTokenData),\n [tokenProp, contextTokenData],\n )\n\n // Handle token expiration by invalidating the token\n // The context's useEffect will automatically handle the refresh\n const handleTokenExpired = useCallback(() => {\n if (enableLogging) {\n // eslint-disable-next-line no-console\n console.log('CapitalOS: Token expired, invalidating...')\n }\n\n // If we're using tokenProp, we can't refresh automatically\n if (tokenProp) {\n onError?.(\n new CapitalOSError({\n message: 'Token expired. Cannot automatically refresh when using token prop.',\n code: ErrorCode.unauthorized,\n }),\n )\n return\n }\n\n // Use the invalidateToken function from the context\n // This will clear the token and the authentication context's useEffect will handle the refresh\n invalidateToken()\n\n // The iframe will be reloaded automatically when tokenData changes\n setIsLoaded(false)\n }, [tokenProp, invalidateToken, enableLogging, onError])\n\n useEffect(() => {\n if (tokenProp && contextTokenData && enableLogging) {\n // eslint-disable-next-line no-console\n console.warn(\n 'CapitalOS: token was provided both from provider and from the token prop. the prop will take precedence',\n )\n }\n }, [tokenProp, contextTokenData, enableLogging])\n\n const url = useIframeUrl({ tokenData, renderingContext, theme, onError })\n\n useIframeConnection({\n iframeRef,\n token: tokenData?.token,\n onError: (error) => {\n onError?.(error)\n // when connection fails it's probably a handshake timeout with the iframe. we will stop showing the loader\n // since the fact we failed communication doesn't necessarily mean the iframe didn't load\n setIsLoaded(true)\n },\n methods: {\n onLoad: () => {\n setIsLoaded(true)\n },\n onError: (error) => {\n const err = new CapitalOSError(error)\n onError?.(err)\n },\n onTokenExpired: handleTokenExpired,\n ...methods,\n },\n })\n\n if (!tokenData || !url) {\n return <>{LoadingComponent || null}</>\n }\n\n // insightsWidget does not need additional padding. also - it supports a height property that needs to be respected.\n const shouldAddPaddingBottom = renderingContext.entryPoint !== 'insightsWidget'\n\n return (\n <>\n {/* show loader as long as we're not loaded */}\n {!isLoaded && LoadingComponent}\n {/* hide the iframe as long as we're not loaded */}\n <IframeResizer\n src={url}\n allow=\"clipboard-write\"\n checkOrigin={false}\n style={{ width: '1px', height: '0px', minWidth: '100%' }}\n className={className}\n log={!!enableLogging}\n ref={iframeRef}\n hidden={!isLoaded}\n // Add a constant offset to the height of the iframe to account for css shadows.\n // This is useful for tooltips that are rendered with shadows below them that extend beyond the bottom of the tooltip.\n onResized={(data) => {\n if (!shouldAddPaddingBottom) {\n return\n }\n\n // typing is wrong here. this is a string.\n const newHeight = `${parseInt(data.height as unknown as string) + 12}px`\n data.iframe.style.height = newHeight\n }}\n sizeWidth={sizeWidth}\n />\n </>\n )\n}\n\n/**\n * Makes sure component only fires the error event once.\n * @param error - The error to handle.\n * @param onError - The function to call when the error occurs.\n */\nfunction useErrorHandling(error: Error | null | undefined, onError?: (error: Error) => void) {\n const errorFired = useRef(false)\n\n useEffect(() => {\n if (error && !errorFired.current) {\n onError?.(error)\n errorFired.current = true\n }\n }, [error, onError])\n}\n","'use client'\n\nimport React, { createContext, useContext, useState, useMemo, useCallback, useEffect } from 'react'\n\nimport { TokenExchangeIframe } from '../common/token-exchange-iframe'\nimport { CapitalOSError, ErrorCode } from '../error'\nimport { TokenData, TokenParamKey, TokenParamLocation, TokenType } from '../types'\nimport { decodeOneTimeToken } from '../utils'\n\ntype CapitalOsAuthenticationContextType = {\n tokenData?: TokenData | undefined\n isLoading: boolean\n error?: Error | undefined\n /**\n * Invalidates the current token..\n * This is used when the iframe signals that the token has expired.\n * The authentication flow will automatically refresh the token after invalidation.\n */\n invalidateToken: () => void\n}\n\ntype ProviderProps = {\n getToken: () => Promise<string>\n enableLogging?: boolean | undefined\n children: React.ReactNode\n}\n\nconst CapitalOsAuthenticationContext = createContext<CapitalOsAuthenticationContextType>({\n isLoading: false,\n invalidateToken: () => {},\n})\n\nexport const CapitalOsAuthenticationProvider: React.FC<ProviderProps> = ({ getToken, enableLogging, children }) => {\n const [oneTimeToken, setOneTimeToken] = useState<string | undefined>(undefined)\n const [baseUrl, setBaseUrl] = useState<string | undefined>(undefined)\n const [longLivedToken, setLongLivedToken] = useState<string | undefined>(undefined)\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<Error | undefined>(undefined)\n\n const refreshOneTimeToken = useCallback(async () => {\n setIsLoading(true)\n try {\n const newToken = await getToken()\n setOneTimeToken(newToken)\n setError(undefined)\n const tokenObject = decodeOneTimeToken(newToken)\n const url = new URL(tokenObject.path)\n // we don't need the /login part of the path since long lived tokens don't go through the login flow.\n url.pathname = ''\n setBaseUrl(url.toString())\n } catch (error) {\n setError(error as Error)\n } finally {\n setIsLoading(false)\n }\n }, [getToken])\n\n // Add invalidateToken method\n const invalidateToken = useCallback(() => {\n setLongLivedToken(undefined)\n }, [])\n\n // On mount, if no long-lived token is available, refresh to get a one-time token.\n useEffect(() => {\n if (!longLivedToken) {\n refreshOneTimeToken()\n }\n }, [longLivedToken, refreshOneTimeToken])\n\n const onExchangeComplete = useCallback((jwtToken: string) => {\n setLongLivedToken(jwtToken)\n setOneTimeToken(undefined)\n setError(undefined)\n }, [])\n\n const contextValue: CapitalOsAuthenticationContextType = useMemo(() => {\n if (longLivedToken && !baseUrl) {\n throw new CapitalOSError({\n message: 'baseUrl is required for long lived tokens',\n code: ErrorCode.unauthorized,\n })\n }\n const tokenData: TokenData | undefined = longLivedToken\n ? ({\n token: longLivedToken,\n tokenType: TokenType.longLived,\n baseUrl: baseUrl!,\n paramKey: TokenParamKey.accessToken,\n paramLocation: TokenParamLocation.hash,\n } as const)\n : undefined\n\n return {\n tokenData,\n isLoading,\n error,\n invalidateToken,\n }\n }, [longLivedToken, isLoading, error, invalidateToken, baseUrl])\n\n return (\n <>\n <CapitalOsAuthenticationContext.Provider value={contextValue}>{children}</CapitalOsAuthenticationContext.Provider>\n {oneTimeToken && !longLivedToken && (\n <TokenExchangeIframe\n oneTimeToken={oneTimeToken}\n onExchangeComplete={onExchangeComplete}\n enableLogging={enableLogging}\n onExchangeError={setError}\n />\n )}\n </>\n )\n}\n\nexport const useCapitalOsAuthContext = () => useContext(CapitalOsAuthenticationContext)\n","import React, { useMemo, useRef } from 'react'\n\nimport { CapitalOSError } from '../error'\nimport { useIframeConnection, useIframeUrl } from '../hooks'\nimport { IframeResizer } from '../iframe-resizer'\nimport { tokenDataFromOneTimeToken } from '../utils'\n\nexport interface TokenExchangeIframeProps {\n oneTimeToken: string\n enableLogging?: boolean | undefined\n onExchangeComplete: (jwtToken: string) => void\n onExchangeError?: (error: Error) => void\n}\n\n/**\n * The component is hidden from the user and is only used to exchange a one-time token for a JWT in the authentication context.\n *\n * The token exchange process works as follows:\n * 1. Component renders a hidden iframe with the one-time token in the URL\n * 2. The iframe loads with the long-lived token as part of its url redirect response and establishes a secure connection with the parent window\n * 3. The iframe passes the long-lived token to the parent via postMessage\n * 4. onExchangeComplete callback is triggered with the new JWT\n *\n * If any errors occur during this process, they are passed to onExchangeError.\n */\nexport function TokenExchangeIframe(props: TokenExchangeIframeProps) {\n const { oneTimeToken, enableLogging, onExchangeComplete, onExchangeError } = props\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n const tokenData = useMemo(() => tokenDataFromOneTimeToken(oneTimeToken), [oneTimeToken])\n\n const renderingContext = {\n entryPoint: 'tokenExchange',\n } as const\n\n const url = useIframeUrl({\n tokenData,\n onError: onExchangeError,\n renderingContext,\n })\n\n useIframeConnection({\n iframeRef,\n token: oneTimeToken,\n onError: onExchangeError,\n methods: {\n onLoad: () => {},\n onError: (error) => {\n onExchangeError?.(new CapitalOSError(error))\n },\n tokenExchange: {\n onLongLivedToken: onExchangeComplete,\n },\n },\n })\n\n // Render the hidden iframe.\n return (\n <IframeResizer\n src={url}\n checkOrigin={false}\n style={{ display: 'none' }} // Hidden from view\n log={!!enableLogging}\n ref={iframeRef}\n />\n )\n}\n","/**\n * Base class for all SDK errors\n */\nexport class CapitalOSError extends Error {\n code: ErrorCode\n constructor({ message, code }: { message: string; code: ErrorCode }) {\n super(message)\n this.name = 'CapitalOSError'\n this.code = code\n }\n}\n\nexport const ErrorCode = {\n unauthorized: 'unauthorized',\n invalid_account_status: 'invalid_account_status',\n unsupported_entry_point: 'unsupported_entry_point',\n internal_error: 'internal_error',\n} as const\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode]\n\n/**\n * Represents an error that occurs when an invalid token is encountered.\n */\nexport class InvalidTokenError extends CapitalOSError {\n constructor(message?: string) {\n super({ message: `Invalid token ${message ?? ''}`, code: ErrorCode.unauthorized })\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n\nexport class TokenRefreshError extends CapitalOSError {\n constructor(originalError?: Error) {\n super({\n message: `Failed to refresh token: ${originalError?.message}`,\n code: ErrorCode.unauthorized,\n })\n this.name = 'CapitalOSTokenRefreshError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect, useMemo, useRef } from 'react'\n\nimport { ErrorCode } from './error'\nimport { Account, ThemeColorScheme, CapitalOsRenderingContext, TokenData } from './types'\nimport { buildIframeUrl } from './utils'\n\nconst IFRAME_CONNECTION_TIMEOUT_MILLISECONDS = 10_000\n\n/**\n * An error type providing a reason code and message.\n * Penpal only passes plain objects, so this does not inherit from Error.\n */\nexport type RawErrorDetails = {\n code: ErrorCode\n message: string\n}\n\nexport type IframeConnectionMethods = {\n onLoad: () => void\n onError: (error: RawErrorDetails) => void\n /**\n * Called when the iframe detects that the JWT token has expired.\n * This triggers the token refresh flow, which will obtain a new token\n * and reload the iframe with the fresh token.\n */\n onTokenExpired?: () => void\n cardDetails?: {\n onCardCanceled?: () => void\n }\n contactSupport?: {\n onDone?: () => void\n onCancel?: () => void\n }\n createCard?: {\n onDone?: () => void\n onCancel?: () => void\n }\n createDispute?: {\n onDone?: () => void\n onCancel?: () => void\n }\n devTools?: {\n onClose?: () => void\n }\n legalDocuments?: {\n onDone?: () => void\n }\n makePayment?: {\n onDone?: () => void\n }\n onboarding?: {\n onDone?: (account: Account) => void\n }\n replaceCard?: {\n onDone?: () => void\n onClose?: () => void\n }\n statements?: {\n onDone?: () => void\n }\n terminateCard?: {\n onDone?: () => void\n onClose?: () => void\n }\n tokenExchange?: {\n onLongLivedToken?: (jwtToken: string) => void\n }\n}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n * token was added to the list of dependencies to make sure that the connection is re-established when the token changes.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string | undefined\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\n if (!iframeRef.current) {\n return\n }\n\n const connection = connectToChild({\n iframe: iframeRef.current,\n childOrigin: '*',\n debug: true,\n timeout: IFRAME_CONNECTION_TIMEOUT_MILLISECONDS,\n methods,\n })\n\n connection.promise.catch((error) => {\n onError?.(error)\n })\n\n return () => {\n connection.destroy()\n }\n }, [token, iframeRef])\n}\n\nexport function useIframeUrl({\n tokenData,\n renderingContext,\n theme,\n onError,\n}: {\n tokenData: TokenData | undefined\n renderingContext: CapitalOsRenderingContext\n theme?: ThemeColorScheme | undefined\n onError?: ((error: Error) => void) | undefined\n}) {\n // We assume that onError and renderingContext do not change over the lifetime of the component.\n // We put it in a ref to avoid causing unnecessary re-renders.\n const onErrorRef = useRef(onError)\n const renderingContextRef = useRef(renderingContext)\n\n return useMemo(() => {\n if (!tokenData) {\n return undefined\n }\n return buildIframeUrl({\n tokenData,\n renderingContext: renderingContextRef.current,\n theme,\n onError: onErrorRef.current,\n })\n // wrapped rendering context in a ref since we do not want to reload the iframe unless the token changes.\n }, [tokenData, theme, onErrorRef, renderingContextRef])\n}\n","{\n \"name\": \"@capitalos/react\",\n \"version\": \"1.1.1\",\n \"description\": \"integrate CapitalOS into your react app\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/esm/index.js\",\n \"types\": \"dist/_tsup-dts-rollup.d.ts\",\n \"scripts\": {\n \"build\": \" pnpm lint && tsup src/index.tsx --experimental-dts --minify --format esm,cjs --clean --no-splitting --sourcemap --legacy-output --out-dir dist\",\n \"dev\": \"pnpm build --watch\",\n \"prepublishOnly\": \"pnpm build\",\n \"lint\": \"eslint . --ext .ts,.tsx --fix\",\n \"lint-ci\": \"eslint . --ext .ts,.tsx\"\n },\n \"keywords\": [\n \"capitalos\",\n \"react\"\n ],\n \"homepage\": \"https://docs.capitalos.com/docs/using-react-client-library\",\n \"author\": \"CapitalOS\",\n \"license\": \"MIT\",\n \"files\": [\n \"dist\",\n \"package.json\"\n ],\n \"devDependencies\": {\n \"@changesets/cli\": \"^2.27.12\",\n \"@microsoft/api-extractor\": \"^7.39.5\",\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\n \"@types/iframe-resizer\": \"^3.5.13\",\n \"@types/react\": \"18.0.20\",\n \"@typescript-eslint/eslint-plugin\": \"^7.2.0\",\n \"@typescript-eslint/parser\": \"^7.2.0\",\n \"eslint\": \"^8.57.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"eslint-plugin-prettier\": \"^5.1.3\",\n \"eslint-plugin-react\": \"^7.34.0\",\n \"prettier\": \"^3.2.5\",\n \"react\": \"16.8.0\",\n \"tsup\": \"^8.1.0\",\n \"typescript\": \"^5.6.2\"\n },\n \"dependencies\": {\n \"iframe-resizer\": \"^4.3.9\",\n \"penpal\": \"^6.2.2\"\n },\n \"peerDependencies\": {\n \"react\": \">=16.8.0\"\n }\n}\n","import { version as sdkVersion } from '../package.json'\nimport { InvalidTokenError } from './error'\nimport {\n ThemeColorScheme,\n CapitalOsRenderingContext,\n TokenData,\n TokenType,\n TokenParamKey,\n TokenParamLocation,\n} from './types'\n\n/**\n * Encodes the rendering context as base64 and then URI encodes it.\n */\nexport function encodeRenderingContext<T>(renderingContext: NonNullable<T>) {\n const renderingContextJson = JSON.stringify(renderingContext)\n const renderingContextBase64 = btoa(renderingContextJson)\n const renderingContextEncoded = encodeURIComponent(renderingContextBase64)\n\n return renderingContextEncoded\n}\n\nexport function decodeOneTimeToken(token: string) {\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n return JSON.parse(base64DecodedToken)\n } catch (error) {\n throw new InvalidTokenError()\n }\n}\n\n/**\n * Safely decodes a URL component, handling potential errors\n */\nexport function safeDecodeURIComponent(str: string): string {\n try {\n return decodeURIComponent(str)\n } catch (e) {\n // If decoding fails, it might not have been encoded, so return original\n return str\n }\n}\n\n/**\n * Builds the iframe url from token data, rendering context, and theme.\n */\nexport function buildIframeUrl({\n tokenData,\n renderingContext,\n theme,\n onError,\n}: {\n tokenData: TokenData\n renderingContext: CapitalOsRenderingContext\n theme?: ThemeColorScheme | undefined\n onError?: ((error: Error) => void) | undefined\n}) {\n try {\n const enrichedRenderingContext = renderingContext\n ? {\n ...renderingContext,\n referer: window.location.href,\n }\n : null\n\n const encodedRenderingContext = enrichedRenderingContext ? encodeRenderingContext(enrichedRenderingContext) : null\n\n const url = new URL(tokenData.baseUrl)\n\n // Always safely decode the token before setting it since search params url encode the token and we do not want to double encode it.\n // in dev, since we're using 2 separate server for client and server, we have a redirect which prevents the double encoding.\n const decodedToken = safeDecodeURIComponent(tokenData.token)\n\n if (tokenData.paramLocation === 'search') {\n url.searchParams.set(tokenData.paramKey, decodedToken)\n } else if (tokenData.paramLocation === 'hash') {\n url.hash = tokenData.paramKey + '=' + encodeURIComponent(decodedToken)\n }\n\n url.searchParams.set('sdkVersion', sdkVersion)\n\n if (encodedRenderingContext) {\n url.searchParams.set('renderingContext', encodedRenderingContext)\n }\n\n if (theme) {\n url.searchParams.set('theme', theme)\n }\n\n const urlString = url.toString()\n return urlString\n } catch (error) {\n // communicate a general error about the token being invalid to the parent component, no matter which internal error we encountered during token parsing.\n onError?.(new InvalidTokenError())\n return undefined\n }\n}\n\nexport function tokenDataFromOneTimeToken(oneTimeToken: string): TokenData {\n const tokenObject = decodeOneTimeToken(oneTimeToken)\n const path = tokenObject.path\n if (!path || typeof path !== 'string') {\n throw new InvalidTokenError()\n }\n\n const tokenData: TokenData = {\n token: oneTimeToken,\n tokenType: TokenType.oneTime,\n baseUrl: path,\n paramKey: TokenParamKey.token,\n paramLocation: TokenParamLocation.search,\n }\n\n return tokenData\n}\n","import {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react'\n\n// the events were renamed but package maintainers didn't update the types.\ntype IFrameOptions = Omit<\n BrokenIframeOptions,\n 'closedCallback' | 'scrollCallback' | 'resizedCallback' | 'messageCallback' | 'initCallback'\n> & {\n onClosed?(iframeId: string): void\n onInit?(iframe: IFrameComponent): void\n onMessage?(data: IFrameMessageData): void\n onResized?(data: IFrameResizedData): void\n onScroll?(data: IFrameScrollData): boolean\n}\n\ntype IframeResizerProps = IFrameOptions & IframeHTMLAttributes<HTMLIFrameElement>\ntype EnrichedHtmlIframeElement = HTMLIFrameElement & { iFrameResizer: { removeListeners: () => void } }\n\nexport const IframeResizer = forwardRef((props: IframeResizerProps, ref: React.Ref<HTMLIFrameElement>) => {\n const title = props.title || 'iframe'\n const { iframeHTMLAttributes, resizerOptions } = splitProps(props)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n useEffect(() => {\n // effects run after render, so the ref is guaranteed to be set (unless the component conditionally renders the iframe, which is not the case)\n const iframe = iframeRef.current as EnrichedHtmlIframeElement\n\n iframeResizer({ ...resizerOptions }, iframe)\n\n return () => iframe.iFrameResizer && iframe.iFrameResizer.removeListeners()\n })\n\n // make the ref provided as a prop point to the same place as the internal iframe ref.\n useImperativeHandle(ref, () => iframeRef.current as HTMLIFrameElement)\n\n return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n})\n\nIframeResizer.displayName = 'IframeResizer'\n\nconst resizerOptions = [\n 'autoResize',\n 'bodyBackground',\n 'bodyMargin',\n 'bodyPadding',\n 'checkOrigin',\n 'inPageLinks',\n 'heightCalculationMethod',\n 'interval',\n 'log',\n 'maxHeight',\n 'maxWidth',\n 'minHeight',\n 'minWidth',\n 'resizeFrom',\n 'scrolling',\n 'sizeHeight',\n 'sizeWidth',\n 'warningTimeout',\n 'tolerance',\n 'widthCalculationMethod',\n 'onClosed',\n 'onInit',\n 'onMessage',\n 'onResized',\n 'onScroll',\n]\n\nconst resizerOptionsSet = new Set(resizerOptions)\n\n/**\n * split props into the resizer library options and the native iframe attributes.\n * the code is contains many type assertions because typescript doesn't handle reduce well.\n */\nfunction splitProps(props: IframeResizerProps) {\n const split = (Object.keys(props) as Array<keyof IframeResizerProps>).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n const value = props[key]\n if (resizerOptionsSet.has(key)) {\n if (value !== undefined) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\n }\n } else {\n acc.iframeHTMLAttributes[key as keyof IframeHTMLAttributes<HTMLIFrameElement>] =\n props[key as keyof typeof props]\n }\n return acc\n },\n { resizerOptions: {}, iframeHTMLAttributes: {} },\n )\n\n return split\n}\n","import React, { useMemo } from 'react'\nimport { useState } from 'react'\nimport { CSSProperties } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport { DevToolsButton } from './components/dev-tools-button'\nimport { EntryPoint } from './external-types'\nimport { CommonProps } from './types'\n\nconst styles: Record<string, CSSProperties> = {\n panel: {\n position: 'fixed',\n bottom: '20px',\n left: '20px',\n zIndex: 50,\n },\n}\n\n// #region Dev Tools\nexport type DevToolsProps = CommonProps\n\n/**\n * Renders the CapitalOS Dev Tools experience.\n * Allows for simulating transactions, etc.\n */\nexport function DevTools(props: DevToolsProps) {\n const entryPoint: EntryPoint = 'devTools'\n const renderingContext = useMemo(() => ({ entryPoint }), [entryPoint])\n\n const [isOpen, setIsOpen] = useState(false)\n\n return (\n <aside aria-label=\"CapitalOS dev tools\">\n {!isOpen && <DevToolsButton onClick={() => setIsOpen(!isOpen)} />}\n {isOpen && (\n <div style={styles['panel']}>\n <CapitalOS\n {...props}\n renderingContext={renderingContext}\n methods={{ devTools: { onClose: () => setIsOpen(false) } }}\n enableLogging={true}\n sizeWidth={true}\n loadingComponent={<DevToolsButton isLoading />}\n />\n </div>\n )}\n </aside>\n )\n}\n","import React, { useState } from 'react'\nimport { CSSProperties } from 'react'\n\nconst styles: Record<string, CSSProperties> = {\n bugButton: {\n position: 'fixed',\n left: '12px',\n bottom: '12px',\n margin: '12px',\n padding: '4px',\n display: 'inline-flex',\n alignItems: 'center',\n borderRadius: '9999px',\n border: '1px solid transparent',\n backgroundColor: '#2563eb',\n color: 'white',\n opacity: 0.4,\n boxShadow: '0 1px 3px 0 rgb(0 0 0 / 0.1)',\n cursor: 'pointer',\n zIndex: 50,\n transition: 'opacity 0.3s ease-in-out',\n },\n bugButtonHover: {\n backgroundColor: '#1d4ed8',\n opacity: 1,\n },\n bugButtonFocus: {\n outline: 'none',\n boxShadow: '0 0 0 2px white, 0 0 0 4px #3b82f6',\n },\n bugIcon: {\n width: '20px',\n height: '20px',\n },\n loadingButton: {\n cursor: 'default',\n opacity: 1,\n animation: 'pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite',\n },\n}\n\nconst BugIcon = () => (\n <svg\n style={styles['bugIcon']}\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n strokeWidth=\"1.5\"\n stroke=\"currentColor\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0 1 12 12.75Zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 0 1-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 0 0 2.248-2.354M12 12.75a2.25 2.25 0 0 1-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 0 0-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 0 1 .4-2.253M12 8.25a2.25 2.25 0 0 0-2.248 2.146M12 8.25a2.25 2.25 0 0 1 2.248 2.146M8.683 5a6.032 6.032 0 0 1-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0 1 15.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 0 0-.575-1.752M4.921 6a24.048 24.048 0 0 0-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 0 1-5.223 1.082\"\n />\n </svg>\n)\n\ninterface DevToolsButtonProps {\n onClick?: () => void\n isLoading?: boolean\n}\n\nexport function DevToolsButton({ onClick, isLoading = false }: DevToolsButtonProps) {\n const [isHovered, setIsHovered] = useState(false)\n const [isFocused, setIsFocused] = useState(false)\n\n const buttonStyle = {\n ...styles['bugButton'],\n ...(isLoading && styles['loadingButton']),\n ...(!isLoading && isHovered && styles['bugButtonHover']),\n ...(!isLoading && isFocused && styles['bugButtonFocus']),\n }\n\n if (isLoading) {\n return (\n <div style={buttonStyle}>\n <style>\n {`\n @keyframes pulse {\n 0%, 100% {\n opacity: 1;\n }\n 50% {\n opacity: 0.4;\n }\n }\n `}\n </style>\n <BugIcon />\n </div>\n )\n }\n\n return (\n <button\n id=\"dev-tools-button\"\n onClick={onClick}\n type=\"button\"\n style={buttonStyle}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n onFocus={() => setIsFocused(true)}\n onBlur={() => setIsFocused(false)}\n >\n <BugIcon />\n </button>\n )\n}\n"],"mappings":"+yBAEA,OAAOA,GAAS,WAAAC,MAAe,QCF/B,OAAOC,GAAS,aAAAC,GAAW,WAAAC,GAAS,UAAAC,GAAQ,YAAAC,GAAU,eAAAC,OAAmB,QCEzE,OAAOC,GAAS,iBAAAC,GAAe,cAAAC,GAAY,YAAAC,EAAU,WAAAC,GAAS,eAAAC,EAAa,aAAAC,OAAiB,QCF5F,OAAOC,IAAS,WAAAC,GAAS,UAAAC,OAAc,QCGhC,IAAMC,EAAN,cAA6B,KAAM,CAExC,YAAY,CAAE,QAAAC,EAAS,KAAAC,CAAK,EAAyC,CACnE,MAAMD,CAAO,EACb,KAAK,KAAO,iBACZ,KAAK,KAAOC,CACd,CACF,EAEaC,EAAY,CACvB,aAAc,eACd,uBAAwB,yBACxB,wBAAyB,0BACzB,eAAgB,gBAClB,EAOaC,EAAN,cAAgCJ,CAAe,CACpD,YAAYC,EAAkB,CAC5B,MAAM,CAAE,QAAS,iBAAiBA,GAAA,KAAAA,EAAW,EAAE,GAAI,KAAME,EAAU,YAAa,CAAC,EACjF,KAAK,KAAO,4BACd,CACF,EC7BA,OAAS,kBAAAE,OAAsB,SAC/B,OAAS,aAAAC,GAAW,WAAAC,GAAS,UAAAC,MAAc,QCCzC,IAAAC,EAAW,QCYN,SAASC,GAA0BC,EAAkC,CAC1E,IAAMC,EAAuB,KAAK,UAAUD,CAAgB,EACtDE,EAAyB,KAAKD,CAAoB,EAGxD,OAFgC,mBAAmBC,CAAsB,CAG3E,CAEO,SAASC,EAAmBC,EAAe,CAChD,GAAI,CACF,IAAMC,EAAkB,mBAAmBD,CAAK,EAC1CE,EAAqB,KAAKD,CAAe,EAC/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,QAAAE,CAxUjC,EAwU+BD,EAAaG,EAAAC,EAAbJ,EAAa,CAAX,WAC/B,IAAMK,EAAyB,iBACzBC,EAAmBC,EAAQ,KAAO,CAAE,WAAAF,CAAW,GAAI,CAACA,CAAU,CAAC,EAErE,OAAOG,EAAA,cAACC,EAAAC,EAAAC,EAAA,GAAcR,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,eAAgB,CAAE,OAAAL,CAAO,CAAE,GAAG,CAClH,CAUO,SAASa,GAAYf,EAA+D,CAA/D,IAAAC,EAAAD,EAAE,QAAAgB,EAAQ,OAAAd,EAAQ,QAAAe,CAvV9C,EAuV4BhB,EAA8BG,EAAAC,EAA9BJ,EAA8B,CAA5B,SAAQ,SAAQ,YAC5C,IAAMK,EAAyB,cACzBC,EAAmBC,EAAQ,KAAO,CAAE,WAAAF,EAAY,OAAAU,CAAO,GAAI,CAACA,CAAM,CAAC,EAEzE,OACEP,EAAA,cAACC,EAAAC,EAAAC,EAAA,GAAcR,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,YAAa,CAAE,OAAAL,EAAQ,QAAAe,CAAQ,CAAE,GAAG,CAEnH,CAUO,SAASC,GAAclB,EAAiE,CAAjE,IAAAC,EAAAD,EAAE,QAAAgB,EAAQ,OAAAd,EAAQ,QAAAe,CAxWhD,EAwW8BhB,EAA8BG,EAAAC,EAA9BJ,EAA8B,CAA5B,SAAQ,SAAQ,YAC9C,IAAMK,EAAyB,gBACzBC,EAAmBC,EAAQ,KAAO,CAAE,WAAAF,EAAY,OAAAU,CAAO,GAAI,CAACA,CAAM,CAAC,EAEzE,OACEP,EAAA,cAACC,EAAAC,EAAAC,EAAA,GAAcR,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,cAAe,CAAE,OAAAL,EAAQ,QAAAe,CAAQ,CAAE,GAAG,CAErH","names":["React","useMemo","React","useEffect","useMemo","useRef","useState","useCallback","React","createContext","useContext","useState","useMemo","useCallback","useEffect","React","useMemo","useRef","CapitalOSError","message","code","ErrorCode","InvalidTokenError","connectToChild","useEffect","useMemo","useRef","version","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeOneTimeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","safeDecodeURIComponent","str","e","buildIframeUrl","tokenData","theme","onError","enrichedRenderingContext","__spreadProps","__spreadValues","encodedRenderingContext","url","decodedToken","version","tokenDataFromOneTimeToken","oneTimeToken","path","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","useEffect","connection","connectToChild","error","useIframeUrl","tokenData","renderingContext","theme","onErrorRef","useRef","renderingContextRef","useMemo","buildIframeUrl","iframeResizer","React","forwardRef","useEffect","useImperativeHandle","useRef","IframeResizer","forwardRef","props","ref","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","useRef","useEffect","iframe","iframeResizer","__spreadValues","useImperativeHandle","React","__spreadProps","resizerOptionsSet","acc","key","value","TokenExchangeIframe","props","oneTimeToken","enableLogging","onExchangeComplete","onExchangeError","iframeRef","useRef","tokenData","useMemo","tokenDataFromOneTimeToken","url","useIframeUrl","useIframeConnection","error","CapitalOSError","React","IframeResizer","CapitalOsAuthenticationContext","createContext","CapitalOsAuthenticationProvider","getToken","enableLogging","children","oneTimeToken","setOneTimeToken","useState","baseUrl","setBaseUrl","longLivedToken","setLongLivedToken","isLoading","setIsLoading","error","setError","refreshOneTimeToken","useCallback","__async","newToken","tokenObject","decodeOneTimeToken","url","invalidateToken","useEffect","onExchangeComplete","jwtToken","contextValue","useMemo","CapitalOSError","ErrorCode","React","TokenExchangeIframe","useCapitalOsAuthContext","useContext","CapitalOS","props","tokenProp","className","enableLogging","onError","LoadingComponent","renderingContext","methods","theme","sizeWidth","contextTokenData","error","invalidateToken","useCapitalOsAuthContext","isLoaded","setIsLoaded","useState","iframeRef","useRef","useErrorHandling","tokenData","useMemo","tokenDataFromOneTimeToken","handleTokenExpired","useCallback","CapitalOSError","ErrorCode","useEffect","url","useIframeUrl","useIframeConnection","__spreadValues","err","React","shouldAddPaddingBottom","IframeResizer","data","newHeight","errorFired","React","useMemo","useState","React","useState","styles","BugIcon","React","DevToolsButton","onClick","isLoading","isHovered","setIsHovered","useState","isFocused","setIsFocused","buttonStyle","__spreadValues","styles","DevTools","props","entryPoint","renderingContext","useMemo","isOpen","setIsOpen","useState","React","DevToolsButton","CapitalOS","__spreadProps","__spreadValues","CardsApp","props","entryPoint","renderingContext","useMemo","React","CapitalOS","__spreadProps","__spreadValues","App","IssueCard","_a","_b","cardholder","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","useMemo","React","CapitalOS","__spreadProps","__spreadValues","DisputeTransaction","transactionId","BillPayApp","props","CardDetails","onCardCanceled","AccountDetails","AccountActions","InsightsDashboard","InsightsWidget","widget","hideTitle","height","width","Onboarding","onboardingEntryPoint","onboardingExitPoint","MakePayment","ContactSupport","_a","_b","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","useMemo","React","CapitalOS","__spreadProps","__spreadValues","Statements","LegalDocuments","ReplaceCard","cardId","onClose","TerminateCard"]}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var ce=Object.create;var M=Object.defineProperty,me=Object.defineProperties,le=Object.getOwnPropertyDescriptor,ue=Object.getOwnPropertyDescriptors,fe=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols,ge=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var q=(e,t,o)=>t in e?M(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))V.call(t,o)&&q(e,o,t[o]);if(_)for(var o of _(t))Z.call(t,o)&&q(e,o,t[o]);return e},c=(e,t)=>me(e,ue(t));var g=(e,t)=>{var o={};for(var n in e)V.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&_)for(var n of _(e))t.indexOf(n)<0&&Z.call(e,n)&&(o[n]=e[n]);return o};var Ce=(e,t)=>{for(var o in t)M(e,o,{get:t[o],enumerable:!0})},G=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of fe(t))!V.call(e,r)&&r!==o&&M(e,r,{get:()=>t[r],enumerable:!(n=le(t,r))||n.enumerable});return e};var I=(e,t,o)=>(o=e!=null?ce(ge(e)):{},G(t||!e||!e.__esModule?M(o,"default",{value:e,enumerable:!0}):o,e)),he=e=>G(M({},"__esModule",{value:!0}),e);var Q=(e,t,o)=>new Promise((n,r)=>{var i=f=>{try{p(o.next(f))}catch(h){r(h)}},s=f=>{try{p(o.throw(f))}catch(h){r(h)}},p=f=>f.done?n(f.value):Promise.resolve(f.value).then(i,s);p((o=o.apply(e,t)).next())});var Je={};Ce(Je,{AccountActions:()=>He,AccountDetails:()=>Fe,App:()=>Se,BillPayApp:()=>Ae,CapitalOsAuthenticationProvider:()=>re,CardDetails:()=>ze,CardsApp:()=>pe,ContactSupport:()=>Ne,DevTools:()=>de,DisputeTransaction:()=>Me,InsightsDashboard:()=>Re,InsightsWidget:()=>Be,IssueCard:()=>we,LegalDocuments:()=>je,MakePayment:()=>_e,Onboarding:()=>Ue,ReplaceCard:()=>Ke,Statements:()=>We,TerminateCard:()=>Ve});module.exports=he(Je);var a=I(require("react"));var u=I(require("react"));var m=I(require("react"));var S=I(require("react"));var x=class extends Error{constructor({message:t,code:o}){super(t),this.name="CapitalOSError",this.code=o}},A={unauthorized:"unauthorized",invalid_account_status:"invalid_account_status",unsupported_entry_point:"unsupported_entry_point",internal_error:"internal_error"},L=class extends x{constructor(t){super({message:`Invalid token ${t!=null?t:""}`,code:A.unauthorized}),this.name="CapitalOSInvalidTokenError"}};var ee=require("penpal"),E=require("react");var X="1.1.1";function ke(e){let t=JSON.stringify(e),o=btoa(t);return encodeURIComponent(o)}function J(e){try{let t=decodeURIComponent(e),o=atob(t);return JSON.parse(o)}catch(t){throw new L}}function ve(e){try{return decodeURIComponent(e)}catch(t){return e}}function Y({tokenData:e,renderingContext:t,theme:o,onError:n}){try{let r=t?c(d({},t),{referer:window.location.href}):null,i=r?ke(r):null,s=new URL(e.baseUrl),p=ve(e.token);return e.paramLocation==="search"?s.searchParams.set(e.paramKey,p):e.paramLocation==="hash"&&(s.hash=e.paramKey+"="+encodeURIComponent(p)),s.searchParams.set("sdkVersion",X),i&&s.searchParams.set("renderingContext",i),o&&s.searchParams.set("theme",o),s.toString()}catch(r){n==null||n(new L);return}}function N(e){let o=J(e).path;if(!o||typeof o!="string")throw new L;return{token:e,tokenType:"oneTime",baseUrl:o,paramKey:"token",paramLocation:"search"}}var be=1e4;function W({iframeRef:e,token:t,onError:o,methods:n}){(0,E.useEffect)(()=>{if(!e.current)return;let r=(0,ee.connectToChild)({iframe:e.current,childOrigin:"*",debug:!0,timeout:be,methods:n});return r.promise.catch(i=>{o==null||o(i)}),()=>{r.destroy()}},[t,e])}function j({tokenData:e,renderingContext:t,theme:o,onError:n}){let r=(0,E.useRef)(n),i=(0,E.useRef)(t);return(0,E.useMemo)(()=>{if(e)return Y({tokenData:e,renderingContext:i.current,theme:o,onError:r.current})},[e,o,r,i])}var te=require("iframe-resizer"),y=I(require("react"));var z=(0,y.forwardRef)((e,t)=>{let o=e.title||"iframe",{iframeHTMLAttributes:n,resizerOptions:r}=De(e),i=(0,y.useRef)(null);return(0,y.useEffect)(()=>{let s=i.current;return(0,te.iframeResizer)(d({},r),s),()=>s.iFrameResizer&&s.iFrameResizer.removeListeners()}),(0,y.useImperativeHandle)(t,()=>i.current),y.default.createElement("iframe",c(d({},n),{title:o,ref:i}))});z.displayName="IframeResizer";var Ie=["autoResize","bodyBackground","bodyMargin","bodyPadding","checkOrigin","inPageLinks","heightCalculationMethod","interval","log","maxHeight","maxWidth","minHeight","minWidth","resizeFrom","scrolling","sizeHeight","sizeWidth","warningTimeout","tolerance","widthCalculationMethod","onClosed","onInit","onMessage","onResized","onScroll"],Ee=new Set(Ie);function De(e){return Object.keys(e).reduce((o,n)=>{let r=e[n];return Ee.has(n)?r!==void 0&&(o.resizerOptions[n]=e[n]):o.iframeHTMLAttributes[n]=e[n],o},{resizerOptions:{},iframeHTMLAttributes:{}})}function oe(e){let{oneTimeToken:t,enableLogging:o,onExchangeComplete:n,onExchangeError:r}=e,i=(0,S.useRef)(null),s=(0,S.useMemo)(()=>N(t),[t]),f=j({tokenData:s,onError:r,renderingContext:{entryPoint:"tokenExchange"}});return W({iframeRef:i,token:t,onError:r,methods:{onLoad:()=>{},onError:h=>{r==null||r(new x(h))},tokenExchange:{onLongLivedToken:n}}}),S.default.createElement(z,{src:f,checkOrigin:!1,style:{display:"none"},log:!!o,ref:i})}var ne=(0,m.createContext)({isLoading:!1,invalidateToken:()=>{}}),re=({getToken:e,enableLogging:t,children:o})=>{let[n,r]=(0,m.useState)(void 0),[i,s]=(0,m.useState)(void 0),[p,f]=(0,m.useState)(void 0),[h,k]=(0,m.useState)(!1),[H,v]=(0,m.useState)(void 0),w=(0,m.useCallback)(()=>Q(void 0,null,function*(){k(!0);try{let P=yield e();r(P),v(void 0);let B=J(P),U=new URL(B.path);U.pathname="",s(U.toString())}catch(P){v(P)}finally{k(!1)}}),[e]),D=(0,m.useCallback)(()=>{f(void 0)},[]);(0,m.useEffect)(()=>{p||w()},[p,w]);let R=(0,m.useCallback)(P=>{f(P),r(void 0),v(void 0)},[]),b=(0,m.useMemo)(()=>{if(p&&!i)throw new x({message:"baseUrl is required for long lived tokens",code:A.unauthorized});return{tokenData:p?{token:p,tokenType:"longLived",baseUrl:i,paramKey:"access_token",paramLocation:"hash"}:void 0,isLoading:h,error:H,invalidateToken:D}},[p,h,H,D,i]);return m.default.createElement(m.default.Fragment,null,m.default.createElement(ne.Provider,{value:b},o),n&&!p&&m.default.createElement(oe,{oneTimeToken:n,onExchangeComplete:R,enableLogging:t,onExchangeError:v}))},ie=()=>(0,m.useContext)(ne);function l(e){let{token:t,className:o,enableLogging:n,onError:r,loadingComponent:i,renderingContext:s,methods:p,theme:f,sizeWidth:h}=e,{tokenData:k,error:H,invalidateToken:v}=ie(),[w,D]=(0,u.useState)(!1),R=(0,u.useRef)(null);Oe(H,r);let b=(0,u.useMemo)(()=>t?N(t):k,[t,k]),P=(0,u.useCallback)(()=>{if(n&&console.log("CapitalOS: Token expired, invalidating..."),t){r==null||r(new x({message:"Token expired. Cannot automatically refresh when using token prop.",code:A.unauthorized}));return}v(),D(!1)},[t,v,n,r]);(0,u.useEffect)(()=>{t&&k&&n&&console.warn("CapitalOS: token was provided both from provider and from the token prop. the prop will take precedence")},[t,k,n]);let B=j({tokenData:b,renderingContext:s,theme:f,onError:r});if(W({iframeRef:R,token:b==null?void 0:b.token,onError:O=>{r==null||r(O),D(!0)},methods:d({onLoad:()=>{D(!0)},onError:O=>{let K=new x(O);r==null||r(K)},onTokenExpired:P},p)}),!b||!B)return u.default.createElement(u.default.Fragment,null,i||null);let U=s.entryPoint!=="insightsWidget";return u.default.createElement(u.default.Fragment,null,!w&&i,u.default.createElement(z,{src:B,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:o,log:!!n,ref:R,hidden:!w,onResized:O=>{if(!U)return;let K=`${parseInt(O.height)+12}px`;O.iframe.style.height=K},sizeWidth:h}))}function Oe(e,t){let o=(0,u.useRef)(!1);(0,u.useEffect)(()=>{e&&!o.current&&(t==null||t(e),o.current=!0)},[e,t])}var T=I(require("react")),ae=require("react");var C=I(require("react"));var F={bugButton:{position:"fixed",left:"12px",bottom:"12px",margin:"12px",padding:"4px",display:"inline-flex",alignItems:"center",borderRadius:"9999px",border:"1px solid transparent",backgroundColor:"#2563eb",color:"white",opacity:.4,boxShadow:"0 1px 3px 0 rgb(0 0 0 / 0.1)",cursor:"pointer",zIndex:50,transition:"opacity 0.3s ease-in-out"},bugButtonHover:{backgroundColor:"#1d4ed8",opacity:1},bugButtonFocus:{outline:"none",boxShadow:"0 0 0 2px white, 0 0 0 4px #3b82f6"},bugIcon:{width:"20px",height:"20px"},loadingButton:{cursor:"default",opacity:1,animation:"pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},se=()=>C.default.createElement("svg",{style:F.bugIcon,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor"},C.default.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0 1 12 12.75Zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 0 1-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 0 0 2.248-2.354M12 12.75a2.25 2.25 0 0 1-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 0 0-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 0 1 .4-2.253M12 8.25a2.25 2.25 0 0 0-2.248 2.146M12 8.25a2.25 2.25 0 0 1 2.248 2.146M8.683 5a6.032 6.032 0 0 1-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0 1 15.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 0 0-.575-1.752M4.921 6a24.048 24.048 0 0 0-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 0 1-5.223 1.082"}));function $({onClick:e,isLoading:t=!1}){let[o,n]=(0,C.useState)(!1),[r,i]=(0,C.useState)(!1),s=d(d(d(d({},F.bugButton),t&&F.loadingButton),!t&&o&&F.bugButtonHover),!t&&r&&F.bugButtonFocus);return t?C.default.createElement("div",{style:s},C.default.createElement("style",null,`
|
|
2
2
|
@keyframes pulse {
|
|
3
3
|
0%, 100% {
|
|
4
4
|
opacity: 1;
|
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
opacity: 0.4;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
`),
|
|
10
|
+
`),C.default.createElement(se,null)):C.default.createElement("button",{id:"dev-tools-button",onClick:e,type:"button",style:s,onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),onFocus:()=>i(!0),onBlur:()=>i(!1)},C.default.createElement(se,null))}var Le={panel:{position:"fixed",bottom:"20px",left:"20px",zIndex:50}};function de(e){let t="devTools",o=(0,T.useMemo)(()=>({entryPoint:t}),[t]),[n,r]=(0,ae.useState)(!1);return T.default.createElement("aside",{"aria-label":"CapitalOS dev tools"},!n&&T.default.createElement($,{onClick:()=>r(!n)}),n&&T.default.createElement("div",{style:Le.panel},T.default.createElement(l,c(d({},e),{renderingContext:o,methods:{devTools:{onClose:()=>r(!1)}},enableLogging:!0,sizeWidth:!0,loadingComponent:T.default.createElement($,{isLoading:!0})}))))}function pe(e){let t="cardsApp",o=(0,a.useMemo)(()=>({entryPoint:t}),[t]);return a.default.createElement(l,c(d({},e),{renderingContext:o}))}var Se=pe;function we(r){var i=r,{cardholder:e,onDone:t,onCancel:o}=i,n=g(i,["cardholder","onDone","onCancel"]);let s="createCard",p=(0,a.useMemo)(()=>({entryPoint:s,cardholder:e}),[e]);return a.default.createElement(l,c(d({},n),{renderingContext:p,methods:{createCard:{onDone:t,onCancel:o}}}))}function Me(r){var i=r,{transactionId:e,onDone:t,onCancel:o}=i,n=g(i,["transactionId","onDone","onCancel"]);let s="createDispute",p=(0,a.useMemo)(()=>({entryPoint:s,transactionId:e}),[e]);return a.default.createElement(l,c(d({},n),{renderingContext:p,methods:{createDispute:{onDone:t,onCancel:o}}}))}function Ae(e){let t="billPayApp",o=(0,a.useMemo)(()=>({entryPoint:t}),[t]);return a.default.createElement(l,c(d({},e),{renderingContext:o}))}function ze(e){let i=e,{onCardCanceled:t}=i,o=g(i,["onCardCanceled"]),n="cardDetails",r=(0,a.useMemo)(()=>({entryPoint:n,cardId:e.cardId,cardOnly:e.cardOnly,hideAddress:e.hideAddress}),[n,e.cardId,e.cardOnly]);return a.default.createElement(l,c(d({},o),{renderingContext:r,methods:{cardDetails:{onCardCanceled:t!=null?t:()=>{}}}}))}function Fe(e){let t="accountDetails",o=(0,a.useMemo)(()=>({entryPoint:t}),[t]);return a.default.createElement(l,c(d({},e),{renderingContext:o}))}function He(e){let t="accountActions",o=(0,a.useMemo)(()=>({entryPoint:t}),[t]);return a.default.createElement(l,c(d({},e),{renderingContext:o}))}function Re(e){let t="insightsDashboard",o=(0,a.useMemo)(()=>({entryPoint:t}),[t]);return a.default.createElement(l,c(d({},e),{renderingContext:o}))}function Be(e){let t="insightsWidget",{widget:o,hideTitle:n,height:r,width:i}=e,s=(0,a.useMemo)(()=>({entryPoint:t,widget:o,hideTitle:n,height:r,width:i}),[t,o,n,r,i]);return a.default.createElement(l,c(d({},e),{renderingContext:s}))}function Ue(r){var i=r,{onDone:e,entryPoint:t,exitPoint:o}=i,n=g(i,["onDone","entryPoint","exitPoint"]);let s="onboarding",p=(0,a.useMemo)(()=>({entryPoint:s,onboardingEntryPoint:t,onboardingExitPoint:o}),[s,t,o]);return a.default.createElement(l,c(d({},n),{renderingContext:p,methods:{onboarding:{onDone:e}}}))}function _e(o){var n=o,{onDone:e}=n,t=g(n,["onDone"]);let r="makePayment",i=(0,a.useMemo)(()=>({entryPoint:r}),[r]);return a.default.createElement(l,c(d({},t),{renderingContext:i,methods:{makePayment:{onDone:e}}}))}function Ne(n){var r=n,{onDone:e,onCancel:t}=r,o=g(r,["onDone","onCancel"]);let i="contactSupport",s=(0,a.useMemo)(()=>({entryPoint:i}),[i]);return a.default.createElement(l,c(d({},o),{renderingContext:s,methods:{contactSupport:{onDone:e,onCancel:t}}}))}function We(o){var n=o,{onDone:e}=n,t=g(n,["onDone"]);let r="statements",i=(0,a.useMemo)(()=>({entryPoint:r}),[r]);return a.default.createElement(l,c(d({},t),{renderingContext:i,methods:{statements:{onDone:e}}}))}function je(o){var n=o,{onDone:e}=n,t=g(n,["onDone"]);let r="legalDocuments",i=(0,a.useMemo)(()=>({entryPoint:r}),[r]);return a.default.createElement(l,c(d({},t),{renderingContext:i,methods:{legalDocuments:{onDone:e}}}))}function Ke(r){var i=r,{cardId:e,onDone:t,onClose:o}=i,n=g(i,["cardId","onDone","onClose"]);let s="replaceCard",p=(0,a.useMemo)(()=>({entryPoint:s,cardId:e}),[e]);return a.default.createElement(l,c(d({},n),{renderingContext:p,methods:{replaceCard:{onDone:t,onClose:o}}}))}function Ve(r){var i=r,{cardId:e,onDone:t,onClose:o}=i,n=g(i,["cardId","onDone","onClose"]);let s="terminateCard",p=(0,a.useMemo)(()=>({entryPoint:s,cardId:e}),[e]);return a.default.createElement(l,c(d({},n),{renderingContext:p,methods:{terminateCard:{onDone:t,onClose:o}}}))}0&&(module.exports={AccountActions,AccountDetails,App,BillPayApp,CapitalOsAuthenticationProvider,CardDetails,CardsApp,ContactSupport,DevTools,DisputeTransaction,InsightsDashboard,InsightsWidget,IssueCard,LegalDocuments,MakePayment,Onboarding,ReplaceCard,Statements,TerminateCard});
|
|
11
11
|
//# sourceMappingURL=index.js.map
|