@capitalos/react 0.2.1-rc2 → 1.0.0-rc.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 CHANGED
@@ -1,2 +1,2 @@
1
- "use client";var H=Object.defineProperty,v=Object.defineProperties;var D=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var y=(e,t,o)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,a=(e,t)=>{for(var o in t||(t={}))L.call(t,o)&&y(e,o,t[o]);if(p)for(var o of p(t))b.call(t,o)&&y(e,o,t[o]);return e},l=(e,t)=>v(e,D(t));var u=(e,t)=>{var o={};for(var r in e)L.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&p)for(var r of p(e))t.indexOf(r)<0&&b.call(e,r)&&(o[r]=e[r]);return o};import h,{useMemo as P}from"react";import g,{useMemo as q,useRef as G,useState as K}from"react";var I=class extends Error{constructor(t){super(t),this.name="CapitalOSError"}},m=class extends I{constructor(){super("Invalid token"),this.name="CapitalOSInvalidTokenError"}};import{connectToChild as S}from"penpal";import{useEffect as w}from"react";var N=1e4;function F({iframeRef:e,token:t,onError:o,methods:r}){w(()=>{let n=S({iframe:e.current,childOrigin:"*",debug:!0,timeout:N,methods:r});return n.promise.catch(i=>{o==null||o(i)}),()=>{n.destroy()}},[t])}import{iframeResizer as A}from"iframe-resizer";import B,{forwardRef as W,useEffect as _,useImperativeHandle as j,useRef as J}from"react";var C=W((e,t)=>{let o=e.title||"iframe",{iframeHTMLAttributes:r,resizerOptions:n}=$(e),i=J(null);return _(()=>{let s=i.current;return A(a({},n),s),()=>s.iFrameResizer&&s.iFrameResizer.removeListeners()}),j(t,()=>i.current),B.createElement("iframe",l(a({},r),{title:o,ref:i}))});C.displayName="IframeResizer";var U=["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"],V=new Set(U);function $(e){return Object.keys(e).reduce((o,r)=>(V.has(r)?o.resizerOptions[r]=e[r]:o.iframeHTMLAttributes[r]=e[r],o),{resizerOptions:{},iframeHTMLAttributes:{}})}function z(e){let t=JSON.stringify(e),o=btoa(t);return encodeURIComponent(o)}function R(e){try{let t=decodeURIComponent(e),o=atob(t);return JSON.parse(o)}catch(t){throw new m}}function f(e){let{token:t,className:o,enableLogging:r,onError:n,loadingComponent:i,renderingContext:s,methods:c}=e,[T,M]=K(!1),x=G(null),k=q(()=>{try{let d=s?z(s):null,E=R(t),{path:O}=E;if(!O)throw new m;return`${O}?token=${t}&renderingContext=${d!=null?d:""}`}catch(d){n==null||n(new m);return}},[t,n]);return F({iframeRef:x,token:t,onError:d=>{n==null||n(d),M(!0)},methods:a({onLoad:()=>M(!0)},c)}),g.createElement(g.Fragment,null,!T&&i,g.createElement(C,{src:k,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:o,log:!!r,ref:x,hidden:!T}))}function ye(e){return h.createElement(f,a({},e))}function Le(n){var i=n,{defaultValues:e,onDone:t,onCancel:o}=i,r=u(i,["defaultValues","onDone","onCancel"]);let s="createCard",c=P(()=>({entryPoint:s,defaultValues:e}),[e]);return h.createElement(f,l(a({},r),{renderingContext:c,methods:{createCard:{onDone:t,onCancel:o}}}))}function be(n){var i=n,{transactionId:e,onDone:t,onCancel:o}=i,r=u(i,["transactionId","onDone","onCancel"]);let s="createDispute",c=P(()=>({entryPoint:s,transactionId:e}),[e]);return h.createElement(f,l(a({},r),{renderingContext:c,methods:{createDispute:{onDone:t,onCancel:o}}}))}export{ye as App,be as DisputeTransaction,Le as IssueCard};
1
+ "use client";var H=Object.defineProperty,S=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var D=(e,t,n)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,i=(e,t)=>{for(var n in t||(t={}))A.call(t,n)&&D(e,n,t[n]);if(y)for(var n of y(t))v.call(t,n)&&D(e,n,t[n]);return e},a=(e,t)=>S(e,_(t));var x=(e,t)=>{var n={};for(var o in e)A.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&y)for(var o of y(e))t.indexOf(o)<0&&v.call(e,o)&&(n[o]=e[o]);return n};import m,{useMemo as l}from"react";import P,{useMemo as Z,useRef as ee,useState as te}from"react";var M="1.0.0-rc.1";var C=class extends Error{constructor({message:t,code:n}){super(t),this.name="CapitalOSError",this.code=n}},W={unauthorized:"unauthorized",invalid_account_status:"invalid_account_status",unsupported_entry_point:"unsupported_entry_point"},g=class extends C{constructor(){super({message:"Invalid token",code:W.unauthorized}),this.name="CapitalOSInvalidTokenError"}};import{connectToChild as j}from"penpal";import{useEffect as B}from"react";var $=1e4;function w({iframeRef:e,token:t,onError:n,methods:o}){B(()=>{let r=j({iframe:e.current,childOrigin:"*",debug:!0,timeout:$,methods:o});return r.promise.catch(s=>{n==null||n(s)}),()=>{r.destroy()}},[t])}import{iframeResizer as V}from"iframe-resizer";import J,{forwardRef as U,useEffect as q,useImperativeHandle as G,useRef as K}from"react";var h=U((e,t)=>{let n=e.title||"iframe",{iframeHTMLAttributes:o,resizerOptions:r}=Y(e),s=K(null);return q(()=>{let d=s.current;return V(i({},r),d),()=>d.iFrameResizer&&d.iFrameResizer.removeListeners()}),G(t,()=>s.current),J.createElement("iframe",a(i({},o),{title:n,ref:s}))});h.displayName="IframeResizer";var Q=["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"],X=new Set(Q);function Y(e){return Object.keys(e).reduce((n,o)=>(X.has(o)?n.resizerOptions[o]=e[o]:n.iframeHTMLAttributes[o]=e[o],n),{resizerOptions:{},iframeHTMLAttributes:{}})}function k(e){let t=JSON.stringify(e),n=btoa(t);return encodeURIComponent(n)}function z(e){try{let t=decodeURIComponent(e),n=atob(t);return JSON.parse(n)}catch(t){throw new g}}function c(e){let{token:t,className:n,enableLogging:o,onError:r,loadingComponent:s,renderingContext:d,methods:u,theme:I}=e,[b,E]=te(!1),O=ee(null),L=Z(()=>{try{let p=d?a(i({},d),{referer:window.location.href}):null,f=p?k(p):null,F=z(t),{path:T}=F;if(!T)throw new g;let R=I?`theme=${I}`:"";return`${T}?token=${t}&sdkVersion=${M}&renderingContext=${f!=null?f:""}${R}`}catch(p){r==null||r(new g);return}},[t,r]);return w({iframeRef:O,token:t,onError:p=>{r==null||r(p),E(!0)},methods:i({onLoad:()=>E(!0),onError:p=>{let f=new C(p);r==null||r(f)}},u)}),P.createElement(P.Fragment,null,!b&&s,P.createElement(h,{src:L,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:n,log:!!o,ref:O,hidden:!b,onResized:p=>{let f=`${parseInt(p.height)+12}px`;p.iframe.style.height=f}}))}function ne(e){let t="cardsApp",n=l(()=>({entryPoint:t}),[t]);return m.createElement(c,a(i({},e),{renderingContext:n}))}var ze=ne;function Le(r){var s=r,{cardholder:e,onDone:t,onCancel:n}=s,o=x(s,["cardholder","onDone","onCancel"]);let d="createCard",u=l(()=>({entryPoint:d,cardholder:e}),[e]);return m.createElement(c,a(i({},o),{renderingContext:u,methods:{createCard:{onDone:t,onCancel:n}}}))}function Fe(r){var s=r,{transactionId:e,onDone:t,onCancel:n}=s,o=x(s,["transactionId","onDone","onCancel"]);let d="createDispute",u=l(()=>({entryPoint:d,transactionId:e}),[e]);return m.createElement(c,a(i({},o),{renderingContext:u,methods:{createDispute:{onDone:t,onCancel:n}}}))}function Re(e){let t="billPayApp",n=l(()=>({entryPoint:t}),[t]);return m.createElement(c,a(i({},e),{renderingContext:n}))}function He(e){let t="cardDetails",n=l(()=>({entryPoint:t,cardId:e.cardId,cardOnly:e.cardOnly}),[t,e.cardId,e.cardOnly]);return m.createElement(c,a(i({},e),{renderingContext:n}))}function Se(e){let t="accountDetails",n=l(()=>({entryPoint:t}),[t]);return m.createElement(c,a(i({},e),{renderingContext:n}))}function _e(e){let t="accountActions",n=l(()=>({entryPoint:t}),[t]);return m.createElement(c,a(i({},e),{renderingContext:n}))}function Ne(e){let t="insightsDashboard",n=l(()=>({entryPoint:t}),[t]);return m.createElement(c,a(i({},e),{renderingContext:n}))}function We(e){let t="insightsWidget",n=e.widget,o=l(()=>({entryPoint:t,widget:n}),[t,n]);return m.createElement(c,a(i({},e),{renderingContext:o}))}function je(r){var s=r,{onDone:e,entryPoint:t,exitPoint:n}=s,o=x(s,["onDone","entryPoint","exitPoint"]);let d="onboarding",u=l(()=>({entryPoint:d,onboardingEntryPoint:t,onboardingExitPoint:n}),[d,t,n]);return m.createElement(c,a(i({},o),{renderingContext:u,methods:{onboarding:{onDone:e}}}))}export{_e as AccountActions,Se as AccountDetails,ze as App,Re as BillPayApp,He as CardDetails,ne as CardsApp,Fe as DisputeTransaction,Ne as InsightsDashboard,We as InsightsWidget,Le as IssueCard,je as Onboarding};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.tsx","../../src/capital-os.tsx","../../src/error.ts","../../src/hooks.ts","../../src/iframe-resizer.tsx","../../src/utils.ts"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport type { EntryPoint, IssueCardDefaultValues } from './external-types'\nimport type { CommonProps } from './types'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(props: CommonProps) {\n return <CapitalOS {...props} />\n}\n\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 defaultValues?: 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({ defaultValues, onDone, onCancel, ...restOfProps }: IssueCardProps) {\n const entryPoint: EntryPoint = 'createCard'\n const renderingContext = useMemo(\n () => ({\n entryPoint,\n defaultValues: defaultValues,\n }),\n [defaultValues],\n )\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createCard: { onDone, onCancel } }} />\n )\n}\n\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","import React, { useMemo, useRef, useState } from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeConnectionMethods, useIframeConnection } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps } from './types'\nimport { decodeToken, encodeRenderingContext } from './utils'\n\ntype CapitalOsProps<T> = CommonProps & {\n renderingContext?: T | undefined\n methods?: Partial<IframeConnectionMethods>\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>(props: CapitalOsProps<T>) {\n const {\n token,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n } = props\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n // memoize the url based on the token so we don't redo the computation on each render.\n const url = useMemo(() => {\n try {\n const encodedRenderingContext = renderingContext ? encodeRenderingContext(renderingContext) : null\n\n const tokenObject = decodeToken(token)\n\n const { path } = tokenObject\n if (!path) {\n throw new InvalidTokenError()\n }\n return `${path}?token=${token}&renderingContext=${encodedRenderingContext ?? ''}`\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 // renderingContext is not part of the dependencies since we do not want to reload the iframe unless the token changes.\n }, [token, onError])\n\n useIframeConnection({\n iframeRef,\n 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: { onLoad: () => setIsLoaded(true), ...methods },\n })\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 />\n </>\n )\n}\n","/**\n * Base class for all SDK errors\n */\nexport class CapitalOSError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'CapitalOSError'\n }\n}\n\n/**\n * Represents an error that occurs when an invalid token is encountered.\n */\nexport class InvalidTokenError extends CapitalOSError {\n constructor() {\n super('Invalid token')\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect } from 'react'\n\nconst IFRAME_CONNECTION_TIMEOUT_MILLISECONDS = 10_000\n\nexport type IframeConnectionMethods = {\n onLoad: () => void\n createCard?: {\n onDone?: () => void\n onCancel?: () => void\n }\n createDispute?: {\n onDone?: () => void\n onCancel?: () => void\n }\n}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\n const connection = connectToChild({\n iframe: iframeRef.current!,\n childOrigin: '*',\n debug: true,\n timeout: IFRAME_CONNECTION_TIMEOUT_MILLISECONDS,\n methods: methods,\n })\n\n connection.promise.catch((error) => {\n onError?.(error)\n })\n\n return () => {\n connection.destroy()\n }\n }, [token])\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).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n if (resizerOptionsSet.has(key)) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\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 { InvalidTokenError } from './error'\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 decodeToken(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"],"mappings":"4lBAEA,OAAOA,GAAS,WAAAC,MAAe,QCF/B,OAAOC,GAAS,WAAAC,EAAS,UAAAC,EAAQ,YAAAC,MAAgB,QCG1C,IAAMC,EAAN,cAA6B,KAAM,CACxC,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,KAAO,gBACd,CACF,EAKaC,EAAN,cAAgCF,CAAe,CACpD,aAAc,CACZ,MAAM,eAAe,EACrB,KAAK,KAAO,4BACd,CACF,EClBA,OAAS,kBAAAG,MAAsB,SAC/B,OAAS,aAAAC,MAAiB,QAE1B,IAAMC,EAAyC,IAiBxC,SAASC,EAAoB,CAClC,UAAAC,EACA,MAAAC,EACA,QAAAC,EACA,QAAAC,CACF,EAKG,CAEDN,EAAU,IAAM,CACd,IAAMO,EAAaR,EAAe,CAChC,OAAQI,EAAU,QAClB,YAAa,IACb,MAAO,GACP,QAASF,EACT,QAASK,CACX,CAAC,EAED,OAAAC,EAAW,QAAQ,MAAOC,GAAU,CAClCH,GAAA,MAAAA,EAAUG,EACZ,CAAC,EAEM,IAAM,CACXD,EAAW,QAAQ,CACrB,CACF,EAAG,CAACH,CAAK,CAAC,CACZ,CCjDA,OAME,iBAAAK,MACK,iBACP,OAAOC,GAA+B,cAAAC,EAAY,aAAAC,EAAW,uBAAAC,EAAqB,UAAAC,MAAc,QAiBzF,IAAMC,EAAgBC,EAAW,CAACC,EAA2BC,IAAsC,CACxG,IAAMC,EAAQF,EAAM,OAAS,SACvB,CAAE,qBAAAG,EAAsB,eAAAC,CAAe,EAAIC,EAAWL,CAAK,EAC3DM,EAAYC,EAA0B,IAAI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ACA,cAAeL,CACjB,GACA,CAACA,CAAa,CAChB,EAEA,OACEN,EAAA,cAACC,EAAAa,EAAAZ,EAAA,GAAcO,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,WAAY,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEnH,CAsBO,SAASO,GAAmBX,EAA8E,CAA9E,IAAAC,EAAAD,EAAE,eAAAY,EAAe,OAAAT,EAAQ,SAAAC,CAxE5D,EAwEmCH,EAAsCI,EAAAC,EAAtCL,EAAsC,CAApC,gBAAe,SAAQ,aAC1D,IAAMM,EAAyB,gBACzBC,EAAmBC,EAAQ,KAAO,CAAE,WAAAF,EAAY,cAAAK,CAAc,GAAI,CAACA,CAAa,CAAC,EAEvF,OACEhB,EAAA,cAACC,EAAAa,EAAAZ,EAAA,GAAcO,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,cAAe,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEtH","names":["React","useMemo","React","useMemo","useRef","useState","CapitalOSError","message","InvalidTokenError","connectToChild","useEffect","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","connection","error","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","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","CapitalOS","props","token","className","enableLogging","onError","LoadingComponent","renderingContext","methods","isLoaded","setIsLoaded","useState","iframeRef","useRef","url","useMemo","encodedRenderingContext","encodeRenderingContext","tokenObject","decodeToken","path","InvalidTokenError","error","useIframeConnection","__spreadValues","React","IframeResizer","App","props","React","CapitalOS","__spreadValues","IssueCard","_a","_b","defaultValues","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","useMemo","__spreadProps","DisputeTransaction","transactionId"]}
1
+ {"version":3,"sources":["../../src/index.tsx","../../src/capital-os.tsx","../../package.json","../../src/error.ts","../../src/hooks.ts","../../src/iframe-resizer.tsx","../../src/utils.ts"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\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}\n\n/**\n * Renders the CapitalOS Manage Card experience.\n */\nexport function CardDetails(props: CardDetailsProps) {\n const entryPoint: EntryPoint = 'cardDetails'\n const renderingContext = useMemo(\n () => ({ entryPoint, cardId: props.cardId, cardOnly: props.cardOnly }),\n [entryPoint, props.cardId, props.cardOnly],\n )\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\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 */\n widget: 'cards-by-month' | 'top-spenders'\n}\n\n/**\n * Renders a specific CapitalOS Insights Widget\n */\nexport function InsightsWidget(props: InsightsWidgetProps) {\n const entryPoint: EntryPoint = 'insightsWidget'\n const widget = props.widget\n const renderingContext = useMemo(() => ({ entryPoint, widget }), [entryPoint, widget])\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","import React, { useMemo, useRef, useState } from 'react'\n\nimport { version as sdkVersion } from '../package.json'\nimport { CapitalOSError, InvalidTokenError } from './error'\nimport { EntryPoint } from './external-types'\nimport { IframeConnectionMethods, useIframeConnection } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps } from './types'\nimport { decodeToken, encodeRenderingContext } from './utils'\n\ntype RenderingContext = {\n entryPoint?: EntryPoint\n referer?: string\n}\n\ntype CapitalOsProps<T extends RenderingContext> = CommonProps & {\n renderingContext: T\n methods?: Partial<IframeConnectionMethods>\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 RenderingContext>(props: CapitalOsProps<T>) {\n const {\n token,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n theme,\n } = props\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n // memoize the url based on the token so we don't redo the computation on each render.\n const url = useMemo(() => {\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 tokenObject = decodeToken(token)\n\n const { path } = tokenObject\n if (!path) {\n throw new InvalidTokenError()\n }\n const themeChunk = theme ? `theme=${theme}` : ''\n return `${path}?token=${token}&sdkVersion=${sdkVersion}&renderingContext=${encodedRenderingContext ?? ''}${themeChunk}`\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 // renderingContext is not part of the dependencies since we do not want to reload the iframe unless the token changes.\n }, [token, onError])\n\n useIframeConnection({\n iframeRef,\n 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: () => setIsLoaded(true),\n onError: (error) => {\n const err = new CapitalOSError(error)\n onError?.(err)\n },\n ...methods,\n },\n })\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 // 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 />\n </>\n )\n}\n","{\n \"name\": \"@capitalos/react\",\n \"version\": \"1.0.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","/**\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} 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() {\n super({ message: 'Invalid token', code: ErrorCode.unauthorized })\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect } from 'react'\n\nimport { ErrorCode } from './error'\nimport { Account } from './types'\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 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}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\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])\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).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n if (resizerOptionsSet.has(key)) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\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 { InvalidTokenError } from './error'\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 decodeToken(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}\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,SAASgB,GAA2CxB,EAKpC,CALoC,IAAAC,EAAAD,EACzD,QAAAG,EACA,WAAYsB,EACZ,UAAWC,CAnNb,EAgN2DzB,EAItDI,EAAAC,EAJsDL,EAItD,CAHH,SACA,aACA,cAMA,IAAMM,EAAyB,aACzBC,EAAmBC,EACvB,KAAO,CAAE,WAAAF,EAAY,qBAAAkB,EAAsB,oBAAAC,CAAoB,GAC/D,CAACnB,EAAYkB,EAAsBC,CAAmB,CACxD,EAEA,OAAOhB,EAAA,cAACC,EAAAC,EAAAC,EAAA,GAAcR,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,WAAY,CAAE,OAAAL,CAAO,CAAE,GAAG,CAC9G","names":["React","useMemo","React","useMemo","useRef","useState","version","CapitalOSError","message","code","ErrorCode","InvalidTokenError","connectToChild","useEffect","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","connection","error","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","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","CapitalOS","props","token","className","enableLogging","onError","LoadingComponent","renderingContext","methods","theme","isLoaded","setIsLoaded","useState","iframeRef","useRef","url","useMemo","enrichedRenderingContext","__spreadProps","__spreadValues","encodedRenderingContext","encodeRenderingContext","tokenObject","decodeToken","path","InvalidTokenError","themeChunk","version","error","useIframeConnection","err","CapitalOSError","React","IframeResizer","data","newHeight","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","AccountDetails","AccountActions","InsightsDashboard","InsightsWidget","widget","Onboarding","onboardingEntryPoint","onboardingExitPoint"]}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";"use client";var A=Object.create;var u=Object.defineProperty,B=Object.defineProperties,W=Object.getOwnPropertyDescriptor,_=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols,J=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var z=(e,t,o)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))h.call(t,o)&&z(e,o,t[o]);if(C)for(var o of C(t))R.call(t,o)&&z(e,o,t[o]);return e},I=(e,t)=>B(e,_(t));var T=(e,t)=>{var o={};for(var r in e)h.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&C)for(var r of C(e))t.indexOf(r)<0&&R.call(e,r)&&(o[r]=e[r]);return o};var U=(e,t)=>{for(var o in t)u(e,o,{get:t[o],enumerable:!0})},P=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of j(t))!h.call(e,n)&&n!==o&&u(e,n,{get:()=>t[n],enumerable:!(r=W(t,n))||r.enumerable});return e};var M=(e,t,o)=>(o=e!=null?A(J(e)):{},P(t||!e||!e.__esModule?u(o,"default",{value:e,enumerable:!0}):o,e)),V=e=>P(u({},"__esModule",{value:!0}),e);var Z={};U(Z,{App:()=>Q,DisputeTransaction:()=>Y,IssueCard:()=>X});module.exports=V(Z);var l=M(require("react"));var m=M(require("react"));var x=class extends Error{constructor(t){super(t),this.name="CapitalOSError"}},c=class extends x{constructor(){super("Invalid token"),this.name="CapitalOSInvalidTokenError"}};var k=require("penpal"),E=require("react"),$=1e4;function H({iframeRef:e,token:t,onError:o,methods:r}){(0,E.useEffect)(()=>{let n=(0,k.connectToChild)({iframe:e.current,childOrigin:"*",debug:!0,timeout:$,methods:r});return n.promise.catch(i=>{o==null||o(i)}),()=>{n.destroy()}},[t])}var v=require("iframe-resizer"),a=M(require("react"));var O=(0,a.forwardRef)((e,t)=>{let o=e.title||"iframe",{iframeHTMLAttributes:r,resizerOptions:n}=K(e),i=(0,a.useRef)(null);return(0,a.useEffect)(()=>{let s=i.current;return(0,v.iframeResizer)(d({},n),s),()=>s.iFrameResizer&&s.iFrameResizer.removeListeners()}),(0,a.useImperativeHandle)(t,()=>i.current),a.default.createElement("iframe",I(d({},r),{title:o,ref:i}))});O.displayName="IframeResizer";var q=["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"],G=new Set(q);function K(e){return Object.keys(e).reduce((o,r)=>(G.has(r)?o.resizerOptions[r]=e[r]:o.iframeHTMLAttributes[r]=e[r],o),{resizerOptions:{},iframeHTMLAttributes:{}})}function D(e){let t=JSON.stringify(e),o=btoa(t);return encodeURIComponent(o)}function S(e){try{let t=decodeURIComponent(e),o=atob(t);return JSON.parse(o)}catch(t){throw new c}}function g(e){let{token:t,className:o,enableLogging:r,onError:n,loadingComponent:i,renderingContext:s,methods:f}=e,[y,L]=(0,m.useState)(!1),b=(0,m.useRef)(null),w=(0,m.useMemo)(()=>{try{let p=s?D(s):null,N=S(t),{path:F}=N;if(!F)throw new c;return`${F}?token=${t}&renderingContext=${p!=null?p:""}`}catch(p){n==null||n(new c);return}},[t,n]);return H({iframeRef:b,token:t,onError:p=>{n==null||n(p),L(!0)},methods:d({onLoad:()=>L(!0)},f)}),m.default.createElement(m.default.Fragment,null,!y&&i,m.default.createElement(O,{src:w,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:o,log:!!r,ref:b,hidden:!y}))}function Q(e){return l.default.createElement(g,d({},e))}function X(n){var i=n,{defaultValues:e,onDone:t,onCancel:o}=i,r=T(i,["defaultValues","onDone","onCancel"]);let s="createCard",f=(0,l.useMemo)(()=>({entryPoint:s,defaultValues:e}),[e]);return l.default.createElement(g,I(d({},r),{renderingContext:f,methods:{createCard:{onDone:t,onCancel:o}}}))}function Y(n){var i=n,{transactionId:e,onDone:t,onCancel:o}=i,r=T(i,["transactionId","onDone","onCancel"]);let s="createDispute",f=(0,l.useMemo)(()=>({entryPoint:s,transactionId:e}),[e]);return l.default.createElement(g,I(d({},r),{renderingContext:f,methods:{createDispute:{onDone:t,onCancel:o}}}))}0&&(module.exports={App,DisputeTransaction,IssueCard});
1
+ "use strict";"use client";var $=Object.create;var y=Object.defineProperty,V=Object.defineProperties,J=Object.getOwnPropertyDescriptor,U=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertyNames,h=Object.getOwnPropertySymbols,G=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var M=(e,t,n)=>t in e?y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,s=(e,t)=>{for(var n in t||(t={}))I.call(t,n)&&M(e,n,t[n]);if(h)for(var n of h(t))w.call(t,n)&&M(e,n,t[n]);return e},d=(e,t)=>V(e,U(t));var P=(e,t)=>{var n={};for(var o in e)I.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&h)for(var o of h(e))t.indexOf(o)<0&&w.call(e,o)&&(n[o]=e[o]);return n};var K=(e,t)=>{for(var n in t)y(e,n,{get:t[n],enumerable:!0})},k=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of q(t))!I.call(e,r)&&r!==n&&y(e,r,{get:()=>t[r],enumerable:!(o=J(t,r))||o.enumerable});return e};var b=(e,t,n)=>(n=e!=null?$(G(e)):{},k(t||!e||!e.__esModule?y(n,"default",{value:e,enumerable:!0}):n,e)),Q=e=>k(y({},"__esModule",{value:!0}),e);var ue={};K(ue,{AccountActions:()=>ce,AccountDetails:()=>de,App:()=>oe,BillPayApp:()=>se,CardDetails:()=>ae,CardsApp:()=>N,DisputeTransaction:()=>ie,InsightsDashboard:()=>pe,InsightsWidget:()=>me,IssueCard:()=>re,Onboarding:()=>le});module.exports=Q(ue);var i=b(require("react"));var u=b(require("react"));var z="1.0.0-rc.1";var x=class extends Error{constructor({message:t,code:n}){super(t),this.name="CapitalOSError",this.code=n}},Y={unauthorized:"unauthorized",invalid_account_status:"invalid_account_status",unsupported_entry_point:"unsupported_entry_point"},C=class extends x{constructor(){super({message:"Invalid token",code:Y.unauthorized}),this.name="CapitalOSInvalidTokenError"}};var L=require("penpal"),F=require("react"),Z=1e4;function R({iframeRef:e,token:t,onError:n,methods:o}){(0,F.useEffect)(()=>{let r=(0,L.connectToChild)({iframe:e.current,childOrigin:"*",debug:!0,timeout:Z,methods:o});return r.promise.catch(a=>{n==null||n(a)}),()=>{r.destroy()}},[t])}var H=require("iframe-resizer"),l=b(require("react"));var E=(0,l.forwardRef)((e,t)=>{let n=e.title||"iframe",{iframeHTMLAttributes:o,resizerOptions:r}=ne(e),a=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let c=a.current;return(0,H.iframeResizer)(s({},r),c),()=>c.iFrameResizer&&c.iFrameResizer.removeListeners()}),(0,l.useImperativeHandle)(t,()=>a.current),l.default.createElement("iframe",d(s({},o),{title:n,ref:a}))});E.displayName="IframeResizer";var ee=["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"],te=new Set(ee);function ne(e){return Object.keys(e).reduce((n,o)=>(te.has(o)?n.resizerOptions[o]=e[o]:n.iframeHTMLAttributes[o]=e[o],n),{resizerOptions:{},iframeHTMLAttributes:{}})}function S(e){let t=JSON.stringify(e),n=btoa(t);return encodeURIComponent(n)}function _(e){try{let t=decodeURIComponent(e),n=atob(t);return JSON.parse(n)}catch(t){throw new C}}function p(e){let{token:t,className:n,enableLogging:o,onError:r,loadingComponent:a,renderingContext:c,methods:f,theme:O}=e,[T,D]=(0,u.useState)(!1),A=(0,u.useRef)(null),W=(0,u.useMemo)(()=>{try{let m=c?d(s({},c),{referer:window.location.href}):null,g=m?S(m):null,j=_(t),{path:v}=j;if(!v)throw new C;let B=O?`theme=${O}`:"";return`${v}?token=${t}&sdkVersion=${z}&renderingContext=${g!=null?g:""}${B}`}catch(m){r==null||r(new C);return}},[t,r]);return R({iframeRef:A,token:t,onError:m=>{r==null||r(m),D(!0)},methods:s({onLoad:()=>D(!0),onError:m=>{let g=new x(m);r==null||r(g)}},f)}),u.default.createElement(u.default.Fragment,null,!T&&a,u.default.createElement(E,{src:W,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:n,log:!!o,ref:A,hidden:!T,onResized:m=>{let g=`${parseInt(m.height)+12}px`;m.iframe.style.height=g}}))}function N(e){let t="cardsApp",n=(0,i.useMemo)(()=>({entryPoint:t}),[t]);return i.default.createElement(p,d(s({},e),{renderingContext:n}))}var oe=N;function re(r){var a=r,{cardholder:e,onDone:t,onCancel:n}=a,o=P(a,["cardholder","onDone","onCancel"]);let c="createCard",f=(0,i.useMemo)(()=>({entryPoint:c,cardholder:e}),[e]);return i.default.createElement(p,d(s({},o),{renderingContext:f,methods:{createCard:{onDone:t,onCancel:n}}}))}function ie(r){var a=r,{transactionId:e,onDone:t,onCancel:n}=a,o=P(a,["transactionId","onDone","onCancel"]);let c="createDispute",f=(0,i.useMemo)(()=>({entryPoint:c,transactionId:e}),[e]);return i.default.createElement(p,d(s({},o),{renderingContext:f,methods:{createDispute:{onDone:t,onCancel:n}}}))}function se(e){let t="billPayApp",n=(0,i.useMemo)(()=>({entryPoint:t}),[t]);return i.default.createElement(p,d(s({},e),{renderingContext:n}))}function ae(e){let t="cardDetails",n=(0,i.useMemo)(()=>({entryPoint:t,cardId:e.cardId,cardOnly:e.cardOnly}),[t,e.cardId,e.cardOnly]);return i.default.createElement(p,d(s({},e),{renderingContext:n}))}function de(e){let t="accountDetails",n=(0,i.useMemo)(()=>({entryPoint:t}),[t]);return i.default.createElement(p,d(s({},e),{renderingContext:n}))}function ce(e){let t="accountActions",n=(0,i.useMemo)(()=>({entryPoint:t}),[t]);return i.default.createElement(p,d(s({},e),{renderingContext:n}))}function pe(e){let t="insightsDashboard",n=(0,i.useMemo)(()=>({entryPoint:t}),[t]);return i.default.createElement(p,d(s({},e),{renderingContext:n}))}function me(e){let t="insightsWidget",n=e.widget,o=(0,i.useMemo)(()=>({entryPoint:t,widget:n}),[t,n]);return i.default.createElement(p,d(s({},e),{renderingContext:o}))}function le(r){var a=r,{onDone:e,entryPoint:t,exitPoint:n}=a,o=P(a,["onDone","entryPoint","exitPoint"]);let c="onboarding",f=(0,i.useMemo)(()=>({entryPoint:c,onboardingEntryPoint:t,onboardingExitPoint:n}),[c,t,n]);return i.default.createElement(p,d(s({},o),{renderingContext:f,methods:{onboarding:{onDone:e}}}))}0&&(module.exports={AccountActions,AccountDetails,App,BillPayApp,CardDetails,CardsApp,DisputeTransaction,InsightsDashboard,InsightsWidget,IssueCard,Onboarding});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx","../src/capital-os.tsx","../src/error.ts","../src/hooks.ts","../src/iframe-resizer.tsx","../src/utils.ts"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport type { EntryPoint, IssueCardDefaultValues } from './external-types'\nimport type { CommonProps } from './types'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(props: CommonProps) {\n return <CapitalOS {...props} />\n}\n\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 defaultValues?: 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({ defaultValues, onDone, onCancel, ...restOfProps }: IssueCardProps) {\n const entryPoint: EntryPoint = 'createCard'\n const renderingContext = useMemo(\n () => ({\n entryPoint,\n defaultValues: defaultValues,\n }),\n [defaultValues],\n )\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createCard: { onDone, onCancel } }} />\n )\n}\n\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","import React, { useMemo, useRef, useState } from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeConnectionMethods, useIframeConnection } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps } from './types'\nimport { decodeToken, encodeRenderingContext } from './utils'\n\ntype CapitalOsProps<T> = CommonProps & {\n renderingContext?: T | undefined\n methods?: Partial<IframeConnectionMethods>\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>(props: CapitalOsProps<T>) {\n const {\n token,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n } = props\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n // memoize the url based on the token so we don't redo the computation on each render.\n const url = useMemo(() => {\n try {\n const encodedRenderingContext = renderingContext ? encodeRenderingContext(renderingContext) : null\n\n const tokenObject = decodeToken(token)\n\n const { path } = tokenObject\n if (!path) {\n throw new InvalidTokenError()\n }\n return `${path}?token=${token}&renderingContext=${encodedRenderingContext ?? ''}`\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 // renderingContext is not part of the dependencies since we do not want to reload the iframe unless the token changes.\n }, [token, onError])\n\n useIframeConnection({\n iframeRef,\n 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: { onLoad: () => setIsLoaded(true), ...methods },\n })\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 />\n </>\n )\n}\n","/**\n * Base class for all SDK errors\n */\nexport class CapitalOSError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'CapitalOSError'\n }\n}\n\n/**\n * Represents an error that occurs when an invalid token is encountered.\n */\nexport class InvalidTokenError extends CapitalOSError {\n constructor() {\n super('Invalid token')\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect } from 'react'\n\nconst IFRAME_CONNECTION_TIMEOUT_MILLISECONDS = 10_000\n\nexport type IframeConnectionMethods = {\n onLoad: () => void\n createCard?: {\n onDone?: () => void\n onCancel?: () => void\n }\n createDispute?: {\n onDone?: () => void\n onCancel?: () => void\n }\n}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\n const connection = connectToChild({\n iframe: iframeRef.current!,\n childOrigin: '*',\n debug: true,\n timeout: IFRAME_CONNECTION_TIMEOUT_MILLISECONDS,\n methods: methods,\n })\n\n connection.promise.catch((error) => {\n onError?.(error)\n })\n\n return () => {\n connection.destroy()\n }\n }, [token])\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).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n if (resizerOptionsSet.has(key)) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\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 { InvalidTokenError } from './error'\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 decodeToken(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"],"mappings":"gkCAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,uBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAL,GAEA,IAAAM,EAA+B,oBCF/B,IAAAC,EAAiD,oBCG1C,IAAMC,EAAN,cAA6B,KAAM,CACxC,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,KAAO,gBACd,CACF,EAKaC,EAAN,cAAgCF,CAAe,CACpD,aAAc,CACZ,MAAM,eAAe,EACrB,KAAK,KAAO,4BACd,CACF,EClBA,IAAAG,EAA+B,kBAC/BC,EAA0B,iBAEpBC,EAAyC,IAiBxC,SAASC,EAAoB,CAClC,UAAAC,EACA,MAAAC,EACA,QAAAC,EACA,QAAAC,CACF,EAKG,IAED,aAAU,IAAM,CACd,IAAMC,KAAa,kBAAe,CAChC,OAAQJ,EAAU,QAClB,YAAa,IACb,MAAO,GACP,QAASF,EACT,QAASK,CACX,CAAC,EAED,OAAAC,EAAW,QAAQ,MAAOC,GAAU,CAClCH,GAAA,MAAAA,EAAUG,EACZ,CAAC,EAEM,IAAM,CACXD,EAAW,QAAQ,CACrB,CACF,EAAG,CAACH,CAAK,CAAC,CACZ,CCjDA,IAAAK,EAOO,0BACPC,EAAgG,oBAiBzF,IAAMC,KAAgB,cAAW,CAACC,EAA2BC,IAAsC,CACxG,IAAMC,EAAQF,EAAM,OAAS,SACvB,CAAE,qBAAAG,EAAsB,eAAAC,CAAe,EAAIC,EAAWL,CAAK,EAC3DM,KAAY,UAA0B,IAAI,EAEhD,sBAAU,IAAM,CAEd,IAAMC,EAASD,EAAU,QAEzB,0BAAcE,EAAA,GAAKJ,GAAkBG,CAAM,EAEpC,IAAMA,EAAO,eAAiBA,EAAO,cAAc,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Y,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEnH,CAsBO,SAASM,EAAmBV,EAA8E,CAA9E,IAAAC,EAAAD,EAAE,eAAAW,EAAe,OAAAR,EAAQ,SAAAC,CAxE5D,EAwEmCH,EAAsCI,EAAAC,EAAtCL,EAAsC,CAApC,gBAAe,SAAQ,aAC1D,IAAMM,EAAyB,gBACzBC,KAAmB,WAAQ,KAAO,CAAE,WAAAD,EAAY,cAAAI,CAAc,GAAI,CAACA,CAAa,CAAC,EAEvF,OACE,EAAAf,QAAA,cAACC,EAAAY,EAAAX,EAAA,GAAcO,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,cAAe,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEtH","names":["src_exports","__export","App","DisputeTransaction","IssueCard","__toCommonJS","import_react","import_react","CapitalOSError","message","InvalidTokenError","import_penpal","import_react","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","connection","error","import_iframe_resizer","import_react","IframeResizer","props","ref","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","iframe","__spreadValues","React","__spreadProps","resizerOptionsSet","acc","key","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","CapitalOS","props","token","className","enableLogging","onError","LoadingComponent","renderingContext","methods","isLoaded","setIsLoaded","iframeRef","url","encodedRenderingContext","encodeRenderingContext","tokenObject","decodeToken","path","InvalidTokenError","error","useIframeConnection","__spreadValues","React","IframeResizer","App","props","React","CapitalOS","__spreadValues","IssueCard","_a","_b","defaultValues","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","__spreadProps","DisputeTransaction","transactionId"]}
1
+ {"version":3,"sources":["../src/index.tsx","../src/capital-os.tsx","../package.json","../src/error.ts","../src/hooks.ts","../src/iframe-resizer.tsx","../src/utils.ts"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\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}\n\n/**\n * Renders the CapitalOS Manage Card experience.\n */\nexport function CardDetails(props: CardDetailsProps) {\n const entryPoint: EntryPoint = 'cardDetails'\n const renderingContext = useMemo(\n () => ({ entryPoint, cardId: props.cardId, cardOnly: props.cardOnly }),\n [entryPoint, props.cardId, props.cardOnly],\n )\n\n return <CapitalOS {...props} renderingContext={renderingContext} />\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 */\n widget: 'cards-by-month' | 'top-spenders'\n}\n\n/**\n * Renders a specific CapitalOS Insights Widget\n */\nexport function InsightsWidget(props: InsightsWidgetProps) {\n const entryPoint: EntryPoint = 'insightsWidget'\n const widget = props.widget\n const renderingContext = useMemo(() => ({ entryPoint, widget }), [entryPoint, widget])\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","import React, { useMemo, useRef, useState } from 'react'\n\nimport { version as sdkVersion } from '../package.json'\nimport { CapitalOSError, InvalidTokenError } from './error'\nimport { EntryPoint } from './external-types'\nimport { IframeConnectionMethods, useIframeConnection } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps } from './types'\nimport { decodeToken, encodeRenderingContext } from './utils'\n\ntype RenderingContext = {\n entryPoint?: EntryPoint\n referer?: string\n}\n\ntype CapitalOsProps<T extends RenderingContext> = CommonProps & {\n renderingContext: T\n methods?: Partial<IframeConnectionMethods>\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 RenderingContext>(props: CapitalOsProps<T>) {\n const {\n token,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n theme,\n } = props\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n // memoize the url based on the token so we don't redo the computation on each render.\n const url = useMemo(() => {\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 tokenObject = decodeToken(token)\n\n const { path } = tokenObject\n if (!path) {\n throw new InvalidTokenError()\n }\n const themeChunk = theme ? `theme=${theme}` : ''\n return `${path}?token=${token}&sdkVersion=${sdkVersion}&renderingContext=${encodedRenderingContext ?? ''}${themeChunk}`\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 // renderingContext is not part of the dependencies since we do not want to reload the iframe unless the token changes.\n }, [token, onError])\n\n useIframeConnection({\n iframeRef,\n 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: () => setIsLoaded(true),\n onError: (error) => {\n const err = new CapitalOSError(error)\n onError?.(err)\n },\n ...methods,\n },\n })\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 // 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 />\n </>\n )\n}\n","{\n \"name\": \"@capitalos/react\",\n \"version\": \"1.0.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","/**\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} 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() {\n super({ message: 'Invalid token', code: ErrorCode.unauthorized })\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect } from 'react'\n\nimport { ErrorCode } from './error'\nimport { Account } from './types'\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 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}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\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])\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).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n if (resizerOptionsSet.has(key)) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\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 { InvalidTokenError } from './error'\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 decodeToken(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"],"mappings":"gkCAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,oBAAAE,GAAA,mBAAAC,GAAA,QAAAC,GAAA,eAAAC,GAAA,gBAAAC,GAAA,aAAAC,EAAA,uBAAAC,GAAA,sBAAAC,GAAA,mBAAAC,GAAA,cAAAC,GAAA,eAAAC,KA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AAAC,EAJsDL,EAItD,CAHH,SACA,aACA,cAMA,IAAMM,EAAyB,aACzBC,KAAmB,WACvB,KAAO,CAAE,WAAAD,EAAY,qBAAAiB,EAAsB,oBAAAC,CAAoB,GAC/D,CAAClB,EAAYiB,EAAsBC,CAAmB,CACxD,EAEA,OAAO,EAAAhB,QAAA,cAACC,EAAAC,EAAAC,EAAA,GAAcP,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,WAAY,CAAE,OAAAL,CAAO,CAAE,GAAG,CAC9G","names":["src_exports","__export","AccountActions","AccountDetails","App","BillPayApp","CardDetails","CardsApp","DisputeTransaction","InsightsDashboard","InsightsWidget","IssueCard","Onboarding","__toCommonJS","import_react","import_react","version","CapitalOSError","message","code","ErrorCode","InvalidTokenError","import_penpal","import_react","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","connection","error","import_iframe_resizer","import_react","IframeResizer","props","ref","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","iframe","__spreadValues","React","__spreadProps","resizerOptionsSet","acc","key","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","CapitalOS","props","token","className","enableLogging","onError","LoadingComponent","renderingContext","methods","theme","isLoaded","setIsLoaded","iframeRef","url","enrichedRenderingContext","__spreadProps","__spreadValues","encodedRenderingContext","encodeRenderingContext","tokenObject","decodeToken","path","InvalidTokenError","themeChunk","version","error","useIframeConnection","err","CapitalOSError","React","IframeResizer","data","newHeight","CardsApp","props","entryPoint","renderingContext","React","CapitalOS","__spreadProps","__spreadValues","App","IssueCard","_a","_b","cardholder","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","React","CapitalOS","__spreadProps","__spreadValues","DisputeTransaction","transactionId","BillPayApp","props","CardDetails","AccountDetails","AccountActions","InsightsDashboard","InsightsWidget","widget","Onboarding","onboardingEntryPoint","onboardingExitPoint"]}
@@ -0,0 +1,19 @@
1
+ export { CardsApp } from '../_tsup-dts-rollup';
2
+ export { IssueCard } from '../_tsup-dts-rollup';
3
+ export { DisputeTransaction } from '../_tsup-dts-rollup';
4
+ export { BillPayApp } from '../_tsup-dts-rollup';
5
+ export { CardDetails } from '../_tsup-dts-rollup';
6
+ export { AccountDetails } from '../_tsup-dts-rollup';
7
+ export { AccountActions } from '../_tsup-dts-rollup';
8
+ export { InsightsDashboard } from '../_tsup-dts-rollup';
9
+ export { InsightsWidget } from '../_tsup-dts-rollup';
10
+ export { Onboarding } from '../_tsup-dts-rollup';
11
+ export { App } from '../_tsup-dts-rollup';
12
+ export { IssueCardProps } from '../_tsup-dts-rollup';
13
+ export { DisputeTransactionProps } from '../_tsup-dts-rollup';
14
+ export { BillPayAppProps } from '../_tsup-dts-rollup';
15
+ export { CardDetailsProps } from '../_tsup-dts-rollup';
16
+ export { AccountDetailsProps } from '../_tsup-dts-rollup';
17
+ export { AccountActionsProps } from '../_tsup-dts-rollup';
18
+ export { InsightsDashboardProps } from '../_tsup-dts-rollup';
19
+ export { InsightsWidgetProps } from '../_tsup-dts-rollup';
@@ -0,0 +1,19 @@
1
+ export { CardsApp } from '../_tsup-dts-rollup';
2
+ export { IssueCard } from '../_tsup-dts-rollup';
3
+ export { DisputeTransaction } from '../_tsup-dts-rollup';
4
+ export { BillPayApp } from '../_tsup-dts-rollup';
5
+ export { CardDetails } from '../_tsup-dts-rollup';
6
+ export { AccountDetails } from '../_tsup-dts-rollup';
7
+ export { AccountActions } from '../_tsup-dts-rollup';
8
+ export { InsightsDashboard } from '../_tsup-dts-rollup';
9
+ export { InsightsWidget } from '../_tsup-dts-rollup';
10
+ export { Onboarding } from '../_tsup-dts-rollup';
11
+ export { App } from '../_tsup-dts-rollup';
12
+ export { IssueCardProps } from '../_tsup-dts-rollup';
13
+ export { DisputeTransactionProps } from '../_tsup-dts-rollup';
14
+ export { BillPayAppProps } from '../_tsup-dts-rollup';
15
+ export { CardDetailsProps } from '../_tsup-dts-rollup';
16
+ export { AccountDetailsProps } from '../_tsup-dts-rollup';
17
+ export { AccountActionsProps } from '../_tsup-dts-rollup';
18
+ export { InsightsDashboardProps } from '../_tsup-dts-rollup';
19
+ export { InsightsWidgetProps } from '../_tsup-dts-rollup';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capitalos/react",
3
- "version": "0.2.1-rc2",
3
+ "version": "1.0.0-rc.1",
4
4
  "description": "integrate CapitalOS into your react app",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -17,7 +17,7 @@
17
17
  "package.json"
18
18
  ],
19
19
  "devDependencies": {
20
- "@changesets/cli": "^2.27.1",
20
+ "@changesets/cli": "^2.27.12",
21
21
  "@microsoft/api-extractor": "^7.39.5",
22
22
  "@trivago/prettier-plugin-sort-imports": "^4.3.0",
23
23
  "@types/iframe-resizer": "^3.5.13",
@@ -29,9 +29,9 @@
29
29
  "eslint-plugin-prettier": "^5.1.3",
30
30
  "eslint-plugin-react": "^7.34.0",
31
31
  "prettier": "^3.2.5",
32
- "tsup": "^8.0.1",
33
- "typescript": "^5.3.3",
34
- "react": "16.8.0"
32
+ "react": "16.8.0",
33
+ "tsup": "^8.1.0",
34
+ "typescript": "^5.6.2"
35
35
  },
36
36
  "dependencies": {
37
37
  "iframe-resizer": "^4.3.9",
@@ -43,6 +43,7 @@
43
43
  "scripts": {
44
44
  "build": " pnpm lint && tsup src/index.tsx --experimental-dts --minify --format esm,cjs --clean --no-splitting --sourcemap --legacy-output --out-dir dist",
45
45
  "dev": "pnpm build --watch",
46
- "lint": "eslint . --ext .ts,.tsx"
46
+ "lint": "eslint . --ext .ts,.tsx --fix",
47
+ "lint-ci": "eslint . --ext .ts,.tsx"
47
48
  }
48
49
  }