@capitalos/react 0.0.4 → 0.0.5

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/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx","../src/error.ts","../src/iframe-resizer.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeResizer } from './iframe-resizer'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(\n props: {\n /**\n * The token provided by initiate-login.\n */\n token: string\n /**\n * Optional CSS class name for the component.\n */\n className?: string\n /**\n * Optional flag indicating whether to log events to the console.\n */\n enableLogging?: boolean\n\n /**\n * Optional callback for when the app encounters an error.\n */\n onError?: (error: Error) => void\n },\n) {\n const { token, className, enableLogging, onError } = props\n\n const handleError = (error: unknown) => {\n if (onError) {\n onError(new InvalidTokenError())\n }\n }\n\n let url: string | undefined = undefined\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n const jsonToken = JSON.parse(base64DecodedToken)\n const { path } = jsonToken\n if (!path) {\n handleError(new InvalidTokenError())\n return null\n }\n\n // construct the URL for the app\n url = `${path}?token=${token}`\n } catch (error) {\n handleError(error)\n return null\n }\n\n return (\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 />\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 {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, useEffect, 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 function IframeResizer(props: IframeResizerProps) {\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 renderes 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 return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n}\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"],"mappings":"85BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAAkB,oBCCX,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,EAOO,0BACPC,EAA+D,oBAiBxD,SAASC,EAAcC,EAA2B,CACvD,IAAMC,EAAQD,EAAM,OAAS,SACvB,CAAE,qBAAAE,EAAsB,eAAAC,CAAe,EAAIC,EAAWJ,CAAK,EAC3DK,KAAY,UAA0B,IAAI,EAEhD,sBAAU,IAAM,CAEd,IAAMC,EAASD,EAAU,QAEzB,0BAAcE,EAAA,GAAKJ,GAAkBG,CAAM,EAEpC,IAAMA,EAAO,eAAiBA,EAAO,cAAc,gBAAgB,CAC5E,CAAC,EAEM,EAAAE,QAAA,cAAC,SAAAC,EAAAF,EAAA,GAAWL,GAAX,CAAiC,MAAOD,EAAO,IAAKI,GAAW,CACzE,CAEA,IAAMF,EAAiB,CACrB,aACA,iBACA,aACA,cACA,cACA,cACA,0BACA,WACA,MACA,YACA,WACA,YACA,WACA,aACA,YACA,aACA,YACA,iBACA,YACA,yBACA,WACA,SACA,YACA,YACA,UACF,EAEMO,EAAoB,IAAI,IAAIP,CAAc,EAMhD,SAASC,EAAWJ,EAA2B,CAiB7C,OAhBc,OAAO,KAAKA,CAAK,EAAE,OAI/B,CAACW,EAAKC,KACAF,EAAkB,IAAIE,CAAG,EAC3BD,EAAI,eAAeC,CAA0B,EAAIZ,EAAMY,CAAyB,EAEhFD,EAAI,qBAAqBC,CAAoD,EAC3EZ,EAAMY,CAAyB,EAE5BD,GAET,CAAE,eAAgB,CAAC,EAAG,qBAAsB,CAAC,CAAE,CACjD,CAGF,CFpFO,SAASE,EACdC,EAmBA,CACA,GAAM,CAAE,MAAAC,EAAO,UAAAC,EAAW,cAAAC,EAAe,QAAAC,CAAQ,EAAIJ,EAE/CK,EAAeC,GAAmB,CAClCF,GACFA,EAAQ,IAAIG,CAAmB,CAEnC,EAEIC,EACJ,GAAI,CACF,IAAMC,EAAkB,mBAAmBR,CAAK,EAC1CS,EAAqB,KAAKD,CAAe,EACzCE,EAAY,KAAK,MAAMD,CAAkB,EACzC,CAAE,KAAAE,CAAK,EAAID,EACjB,GAAI,CAACC,EACH,OAAAP,EAAY,IAAIE,CAAmB,EAC5B,KAITC,EAAM,GAAGI,CAAI,UAAUX,CAAK,EAC9B,OAASK,EAAO,CACd,OAAAD,EAAYC,CAAK,EACV,IACT,CAEA,OACE,EAAAO,QAAA,cAACC,EAAA,CACC,IAAKN,EACL,MAAM,kBACN,YAAa,GACb,MAAO,CAAE,MAAO,MAAO,OAAQ,MAAO,SAAU,MAAO,EACvD,UAAWN,EACX,IAAK,CAAC,CAACC,EACT,CAEJ","names":["src_exports","__export","App","__toCommonJS","import_react","CapitalOSError","message","InvalidTokenError","import_iframe_resizer","import_react","IframeResizer","props","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","iframe","__spreadValues","React","__spreadProps","resizerOptionsSet","acc","key","App","props","token","className","enableLogging","onError","handleError","error","InvalidTokenError","url","urlDecodedToken","base64DecodedToken","jsonToken","path","React","IframeResizer"]}
1
+ {"version":3,"sources":["../src/index.tsx","../src/error.ts","../src/iframe-resizer.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeResizer } from './iframe-resizer'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(props: {\n /**\n * The token provided by initiate-login.\n */\n token: string\n /**\n * Optional CSS class name for the component.\n */\n className?: string\n /**\n * Optional flag indicating whether to log events to the console.\n */\n enableLogging?: boolean\n\n /**\n * Optional callback for when the app encounters an error.\n */\n onError?: (error: Error) => void\n}) {\n const { token, className, enableLogging, onError } = props\n\n const handleError = (error: unknown) => {\n if (onError) {\n onError(new InvalidTokenError())\n }\n }\n\n let url: string | undefined = undefined\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n const jsonToken = JSON.parse(base64DecodedToken)\n const { path } = jsonToken\n if (!path) {\n handleError(new InvalidTokenError())\n return null\n }\n\n // construct the URL for the app\n url = `${path}?token=${token}`\n } catch (error) {\n handleError(error)\n return null\n }\n\n return (\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 />\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 {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, useEffect, 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 function IframeResizer(props: IframeResizerProps) {\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 renderes 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 return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n}\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"],"mappings":"85BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAAkB,oBCCX,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,EAOO,0BACPC,EAA+D,oBAiBxD,SAASC,EAAcC,EAA2B,CACvD,IAAMC,EAAQD,EAAM,OAAS,SACvB,CAAE,qBAAAE,EAAsB,eAAAC,CAAe,EAAIC,EAAWJ,CAAK,EAC3DK,KAAY,UAA0B,IAAI,EAEhD,sBAAU,IAAM,CAEd,IAAMC,EAASD,EAAU,QAEzB,0BAAcE,EAAA,GAAKJ,GAAkBG,CAAM,EAEpC,IAAMA,EAAO,eAAiBA,EAAO,cAAc,gBAAgB,CAC5E,CAAC,EAEM,EAAAE,QAAA,cAAC,SAAAC,EAAAF,EAAA,GAAWL,GAAX,CAAiC,MAAOD,EAAO,IAAKI,GAAW,CACzE,CAEA,IAAMF,EAAiB,CACrB,aACA,iBACA,aACA,cACA,cACA,cACA,0BACA,WACA,MACA,YACA,WACA,YACA,WACA,aACA,YACA,aACA,YACA,iBACA,YACA,yBACA,WACA,SACA,YACA,YACA,UACF,EAEMO,EAAoB,IAAI,IAAIP,CAAc,EAMhD,SAASC,EAAWJ,EAA2B,CAiB7C,OAhBc,OAAO,KAAKA,CAAK,EAAE,OAI/B,CAACW,EAAKC,KACAF,EAAkB,IAAIE,CAAG,EAC3BD,EAAI,eAAeC,CAA0B,EAAIZ,EAAMY,CAAyB,EAEhFD,EAAI,qBAAqBC,CAAoD,EAC3EZ,EAAMY,CAAyB,EAE5BD,GAET,CAAE,eAAgB,CAAC,EAAG,qBAAsB,CAAC,CAAE,CACjD,CAGF,CFpFO,SAASE,EAAIC,EAkBjB,CACD,GAAM,CAAE,MAAAC,EAAO,UAAAC,EAAW,cAAAC,EAAe,QAAAC,CAAQ,EAAIJ,EAE/CK,EAAeC,GAAmB,CAClCF,GACFA,EAAQ,IAAIG,CAAmB,CAEnC,EAEIC,EACJ,GAAI,CACF,IAAMC,EAAkB,mBAAmBR,CAAK,EAC1CS,EAAqB,KAAKD,CAAe,EACzCE,EAAY,KAAK,MAAMD,CAAkB,EACzC,CAAE,KAAAE,CAAK,EAAID,EACjB,GAAI,CAACC,EACH,OAAAP,EAAY,IAAIE,CAAmB,EAC5B,KAITC,EAAM,GAAGI,CAAI,UAAUX,CAAK,EAC9B,OAASK,EAAO,CACd,OAAAD,EAAYC,CAAK,EACV,IACT,CAEA,OACE,EAAAO,QAAA,cAACC,EAAA,CACC,IAAKN,EACL,MAAM,kBACN,YAAa,GACb,MAAO,CAAE,MAAO,MAAO,OAAQ,MAAO,SAAU,MAAO,EACvD,UAAWN,EACX,IAAK,CAAC,CAACC,EACT,CAEJ","names":["src_exports","__export","App","__toCommonJS","import_react","CapitalOSError","message","InvalidTokenError","import_iframe_resizer","import_react","IframeResizer","props","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","iframe","__spreadValues","React","__spreadProps","resizerOptionsSet","acc","key","App","props","token","className","enableLogging","onError","handleError","error","InvalidTokenError","url","urlDecodedToken","base64DecodedToken","jsonToken","path","React","IframeResizer"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx","../src/error.ts","../src/iframe-resizer.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeResizer } from './iframe-resizer'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(\n props: {\n /**\n * The token provided by initiate-login.\n */\n token: string\n /**\n * Optional CSS class name for the component.\n */\n className?: string\n /**\n * Optional flag indicating whether to log events to the console.\n */\n enableLogging?: boolean\n\n /**\n * Optional callback for when the app encounters an error.\n */\n onError?: (error: Error) => void\n },\n) {\n const { token, className, enableLogging, onError } = props\n\n const handleError = (error: unknown) => {\n if (onError) {\n onError(new InvalidTokenError())\n }\n }\n\n let url: string | undefined = undefined\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n const jsonToken = JSON.parse(base64DecodedToken)\n const { path } = jsonToken\n if (!path) {\n handleError(new InvalidTokenError())\n return null\n }\n\n // construct the URL for the app\n url = `${path}?token=${token}`\n } catch (error) {\n handleError(error)\n return null\n }\n\n return (\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 />\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 {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, useEffect, 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 function IframeResizer(props: IframeResizerProps) {\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 renderes 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 return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n}\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"],"mappings":"0bAEA,OAAOA,MAAW,QCCX,IAAMC,EAAN,cAA6B,KAAM,CACxC,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb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,CAEnC,EAEIC,EACJ,GAAI,CACF,IAAMC,EAAkB,mBAAmBR,CAAK,EAC1CS,EAAqB,KAAKD,CAAe,EACzCE,EAAY,KAAK,MAAMD,CAAkB,EACzC,CAAE,KAAAE,CAAK,EAAID,EACjB,GAAI,CAACC,EACH,OAAAP,EAAY,IAAIE,CAAmB,EAC5B,KAITC,EAAM,GAAGI,CAAI,UAAUX,CAAK,EAC9B,OAASK,EAAO,CACd,OAAAD,EAAYC,CAAK,EACV,IACT,CAEA,OACEO,EAAA,cAACC,EAAA,CACC,IAAKN,EACL,MAAM,kBACN,YAAa,GACb,MAAO,CAAE,MAAO,MAAO,OAAQ,MAAO,SAAU,MAAO,EACvD,UAAWN,EACX,IAAK,CAAC,CAACC,EACT,CAEJ","names":["React","CapitalOSError","message","InvalidTokenError","iframeResizer","React","useEffect","useRef","IframeResizer","props","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","useRef","useEffect","iframe","iframeResizer","__spreadValues","React","__spreadProps","resizerOptionsSet","acc","key","App","props","token","className","enableLogging","onError","handleError","error","InvalidTokenError","url","urlDecodedToken","base64DecodedToken","jsonToken","path","React","IframeResizer"]}
1
+ {"version":3,"sources":["../src/index.tsx","../src/error.ts","../src/iframe-resizer.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeResizer } from './iframe-resizer'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(props: {\n /**\n * The token provided by initiate-login.\n */\n token: string\n /**\n * Optional CSS class name for the component.\n */\n className?: string\n /**\n * Optional flag indicating whether to log events to the console.\n */\n enableLogging?: boolean\n\n /**\n * Optional callback for when the app encounters an error.\n */\n onError?: (error: Error) => void\n}) {\n const { token, className, enableLogging, onError } = props\n\n const handleError = (error: unknown) => {\n if (onError) {\n onError(new InvalidTokenError())\n }\n }\n\n let url: string | undefined = undefined\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n const jsonToken = JSON.parse(base64DecodedToken)\n const { path } = jsonToken\n if (!path) {\n handleError(new InvalidTokenError())\n return null\n }\n\n // construct the URL for the app\n url = `${path}?token=${token}`\n } catch (error) {\n handleError(error)\n return null\n }\n\n return (\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 />\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 {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, useEffect, 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 function IframeResizer(props: IframeResizerProps) {\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 renderes 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 return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n}\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"],"mappings":"0bAEA,OAAOA,MAAW,QCCX,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,OAME,iBAAAG,MACK,iBACP,OAAOC,GAA+B,aAAAC,EAAW,UAAAC,MAAc,QAiBxD,SAASC,EAAcC,EAA2B,CACvD,IAAMC,EAAQD,EAAM,OAAS,SACvB,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CAAK,EAC9B,OAASK,EAAO,CACd,OAAAD,EAAYC,CAAK,EACV,IACT,CAEA,OACEO,EAAA,cAACC,EAAA,CACC,IAAKN,EACL,MAAM,kBACN,YAAa,GACb,MAAO,CAAE,MAAO,MAAO,OAAQ,MAAO,SAAU,MAAO,EACvD,UAAWN,EACX,IAAK,CAAC,CAACC,EACT,CAEJ","names":["React","CapitalOSError","message","InvalidTokenError","iframeResizer","React","useEffect","useRef","IframeResizer","props","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","useRef","useEffect","iframe","iframeResizer","__spreadValues","React","__spreadProps","resizerOptionsSet","acc","key","App","props","token","className","enableLogging","onError","handleError","error","InvalidTokenError","url","urlDecodedToken","base64DecodedToken","jsonToken","path","React","IframeResizer"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capitalos/react",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "integrate CapitalOS into your react app",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",