@capitalos/react 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Capital OS for React
2
+
3
+ React components for integrating with Capital OS
4
+
5
+ ## Requirements
6
+
7
+ React 16.8.0 or later
8
+
9
+ ## Installation
10
+
11
+ ### npm
12
+
13
+ ```bash
14
+ npm install @capitalos/react
15
+ ```
16
+
17
+ ### yarn
18
+
19
+ ```bash
20
+ yarn add @capitalos/react
21
+ ```
22
+
23
+ ### pnpm
24
+
25
+ ```bash
26
+ pnpm add @capitalos/react
27
+ ```
28
+
29
+ ## Documentation
30
+
31
+ Please refer to the [official docs](https://docs.capitalos.com/docs/using-react-client-library) for more details.
32
+
33
+ ## Usage
34
+
35
+ In order to use the components you will need to obtain a client authentication token. refer to the [Capital OS documentation](https://docs.capitalos.com/docs/using-react-client-library) for more information.
36
+
37
+ ```jsx
38
+ import { App } from '@capitalos/react'
39
+
40
+ function MyComponent() {
41
+
42
+ // ... obtain token from backend
43
+
44
+ return (
45
+ <App token={token}>
46
+ )
47
+ }
48
+ ```
49
+
50
+ ## Typecsript support
51
+
52
+ TypeScript definitions for `@capitalos/react` are built into the npm package and should be automatically picked up by your editor.
@@ -0,0 +1,58 @@
1
+ /// <reference types="react" />
2
+
3
+ import { IFrameComponent } from 'iframe-resizer';
4
+ import { IframeHTMLAttributes } from 'react';
5
+ import { IFrameMessageData } from 'iframe-resizer';
6
+ import { IFrameOptions as IFrameOptions_2 } from 'iframe-resizer';
7
+ import { IFrameResizedData } from 'iframe-resizer';
8
+ import { IFrameScrollData } from 'iframe-resizer';
9
+
10
+ /**
11
+ * Renders the CapitalOS App.
12
+ */
13
+ export declare function App(props: {
14
+ /**
15
+ * The token provided by initiate-login.
16
+ */
17
+ token: string;
18
+ /**
19
+ * Optional CSS class name for the component.
20
+ */
21
+ className?: string;
22
+ /**
23
+ * Optional flag indicating whether to log events to the console.
24
+ */
25
+ enableLogging?: boolean;
26
+ /**
27
+ * Optional callback for when the app encounters an error.
28
+ */
29
+ onError?: (error: Error) => void;
30
+ }): JSX.Element | null;
31
+
32
+ /**
33
+ * Base class for all SDK errors
34
+ */
35
+ export declare class CapitalOSError extends Error {
36
+ constructor(message: string);
37
+ }
38
+
39
+ declare type IFrameOptions = Omit<IFrameOptions_2, 'closedCallback' | 'scrollCallback' | 'resizedCallback' | 'messageCallback' | 'initCallback'> & {
40
+ onClosed?(iframeId: string): void;
41
+ onInit?(iframe: IFrameComponent): void;
42
+ onMessage?(data: IFrameMessageData): void;
43
+ onResized?(data: IFrameResizedData): void;
44
+ onScroll?(data: IFrameScrollData): boolean;
45
+ };
46
+
47
+ export declare function IframeResizer(props: IframeResizerProps): JSX.Element;
48
+
49
+ declare type IframeResizerProps = IFrameOptions & IframeHTMLAttributes<HTMLIFrameElement>;
50
+
51
+ /**
52
+ * Represents an error that occurs when an invalid token is encountered.
53
+ */
54
+ export declare class InvalidTokenError extends CapitalOSError {
55
+ constructor();
56
+ }
57
+
58
+ export { }
@@ -0,0 +1,58 @@
1
+ /// <reference types="react" />
2
+
3
+ import { IFrameComponent } from 'iframe-resizer';
4
+ import { IframeHTMLAttributes } from 'react';
5
+ import { IFrameMessageData } from 'iframe-resizer';
6
+ import { IFrameOptions as IFrameOptions_2 } from 'iframe-resizer';
7
+ import { IFrameResizedData } from 'iframe-resizer';
8
+ import { IFrameScrollData } from 'iframe-resizer';
9
+
10
+ /**
11
+ * Renders the CapitalOS App.
12
+ */
13
+ export declare function App(props: {
14
+ /**
15
+ * The token provided by initiate-login.
16
+ */
17
+ token: string;
18
+ /**
19
+ * Optional CSS class name for the component.
20
+ */
21
+ className?: string;
22
+ /**
23
+ * Optional flag indicating whether to log events to the console.
24
+ */
25
+ enableLogging?: boolean;
26
+ /**
27
+ * Optional callback for when the app encounters an error.
28
+ */
29
+ onError?: (error: Error) => void;
30
+ }): JSX.Element | null;
31
+
32
+ /**
33
+ * Base class for all SDK errors
34
+ */
35
+ export declare class CapitalOSError extends Error {
36
+ constructor(message: string);
37
+ }
38
+
39
+ declare type IFrameOptions = Omit<IFrameOptions_2, 'closedCallback' | 'scrollCallback' | 'resizedCallback' | 'messageCallback' | 'initCallback'> & {
40
+ onClosed?(iframeId: string): void;
41
+ onInit?(iframe: IFrameComponent): void;
42
+ onMessage?(data: IFrameMessageData): void;
43
+ onResized?(data: IFrameResizedData): void;
44
+ onScroll?(data: IFrameScrollData): boolean;
45
+ };
46
+
47
+ export declare function IframeResizer(props: IframeResizerProps): JSX.Element;
48
+
49
+ declare type IframeResizerProps = IFrameOptions & IframeHTMLAttributes<HTMLIFrameElement>;
50
+
51
+ /**
52
+ * Represents an error that occurs when an invalid token is encountered.
53
+ */
54
+ export declare class InvalidTokenError extends CapitalOSError {
55
+ constructor();
56
+ }
57
+
58
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";"use client";var L=Object.create;var a=Object.defineProperty,T=Object.defineProperties,R=Object.getOwnPropertyDescriptor,E=Object.getOwnPropertyDescriptors,C=Object.getOwnPropertyNames,u=Object.getOwnPropertySymbols,v=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var I=(e,r,t)=>r in e?a(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,c=(e,r)=>{for(var t in r||(r={}))g.call(r,t)&&I(e,t,r[t]);if(u)for(var t of u(r))y.call(r,t)&&I(e,t,r[t]);return e},h=(e,r)=>T(e,E(r));var x=(e,r)=>{for(var t in r)a(e,t,{get:r[t],enumerable:!0})},b=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of C(r))!g.call(e,i)&&i!==t&&a(e,i,{get:()=>r[i],enumerable:!(o=R(r,i))||o.enumerable});return e};var z=(e,r,t)=>(t=e!=null?L(v(e)):{},b(r||!e||!e.__esModule?a(t,"default",{value:e,enumerable:!0}):t,e)),w=e=>b(a({},"__esModule",{value:!0}),e);var N={};x(N,{App:()=>P});module.exports=w(N);var M=z(require("react"));var d=class extends Error{constructor(r){super(r),this.name="CapitalOSError"}},m=class extends d{constructor(){super("Invalid token"),this.name="CapitalOSInvalidTokenError"}};var F=require("iframe-resizer"),s=z(require("react"));function k(e){let r=e.title||"iframe",{iframeHTMLAttributes:t,resizerOptions:o}=S(e),i=(0,s.useRef)(null);return(0,s.useEffect)(()=>{let n=i.current;return(0,F.iframeResizer)(c({},o),n),()=>n.iFrameResizer&&n.iFrameResizer.removeListeners()}),s.default.createElement("iframe",h(c({},t),{title:r,ref:i}))}var A=["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"],D=new Set(A);function S(e){return Object.keys(e).reduce((t,o)=>(D.has(o)?t.resizerOptions[o]=e[o]:t.iframeHTMLAttributes[o]=e[o],t),{resizerOptions:{},iframeHTMLAttributes:{}})}function P(e){let{token:r,className:t,enableLogging:o,onError:i}=e,n=l=>{i&&i(new m)},f;try{let l=decodeURIComponent(r),O=atob(l),H=JSON.parse(O),{path:p}=H;if(!p)return n(new m),null;f=`${p}?token=${r}`}catch(l){return n(l),null}return M.default.createElement(k,{src:f,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:t,log:!!o})}0&&(module.exports={App});
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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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/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"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ "use client";var b=Object.defineProperty,z=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var p=(e,r,t)=>r in e?b(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,m=(e,r)=>{for(var t in r||(r={}))k.call(r,t)&&p(e,t,r[t]);if(f)for(var t of f(r))M.call(r,t)&&p(e,t,r[t]);return e},u=(e,r)=>z(e,F(r));import v from"react";var l=class extends Error{constructor(r){super(r),this.name="CapitalOSError"}},s=class extends l{constructor(){super("Invalid token"),this.name="CapitalOSInvalidTokenError"}};import{iframeResizer as O}from"iframe-resizer";import H,{useEffect as L,useRef as T}from"react";function I(e){let r=e.title||"iframe",{iframeHTMLAttributes:t,resizerOptions:o}=C(e),n=T(null);return L(()=>{let i=n.current;return O(m({},o),i),()=>i.iFrameResizer&&i.iFrameResizer.removeListeners()}),H.createElement("iframe",u(m({},t),{title:r,ref:n}))}var R=["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"],E=new Set(R);function C(e){return Object.keys(e).reduce((t,o)=>(E.has(o)?t.resizerOptions[o]=e[o]:t.iframeHTMLAttributes[o]=e[o],t),{resizerOptions:{},iframeHTMLAttributes:{}})}function G(e){let{token:r,className:t,enableLogging:o,onError:n}=e,i=a=>{n&&n(new s)},c;try{let a=decodeURIComponent(r),g=atob(a),h=JSON.parse(g),{path:d}=h;if(!d)return i(new s),null;c=`${d}?token=${r}`}catch(a){return i(a),null}return v.createElement(I,{src:c,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:t,log:!!o})}export{G as App};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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,KAAK,KAAO,gBACd,CACF,EAKaC,EAAN,cAAgCF,CAAe,CACpD,aAAc,CACZ,MAAM,eAAe,EACrB,KAAK,KAAO,4BACd,CACF,EClBA,OAME,iBAAAG,MACK,iBACP,OAAOC,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K,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"]}
@@ -0,0 +1 @@
1
+ export { App } from '../_tsup-dts-rollup';
@@ -0,0 +1 @@
1
+ export { App } from '../_tsup-dts-rollup';
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@capitalos/react",
3
+ "version": "0.0.2",
4
+ "description": "integrate CapitalOS into your react app",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/_tsup-dts-rollup.d.ts",
8
+ "keywords": [],
9
+ "author": "CapitalOS",
10
+ "license": "MIT",
11
+ "files": [
12
+ "dist",
13
+ "package.json"
14
+ ],
15
+ "devDependencies": {
16
+ "@microsoft/api-extractor": "^7.39.5",
17
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
18
+ "@types/iframe-resizer": "^3.5.13",
19
+ "@types/react": "18.0.20",
20
+ "tsup": "^8.0.1",
21
+ "typescript": "^5.3.3"
22
+ },
23
+ "dependencies": {
24
+ "iframe-resizer": "^4.3.9",
25
+ "react": "^18.2.0"
26
+ },
27
+ "peerDependencies": {
28
+ "react": ">=16.8.0"
29
+ },
30
+ "scripts": {
31
+ "build": "tsup src/index.tsx --experimental-dts --minify --format esm,cjs --clean --no-splitting --sourcemap --out-dir dist",
32
+ "dev": "pnpm build --watch"
33
+ }
34
+ }