@tightrope-dev/link-component 0.1.1 → 0.1.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/dist/index.cjs CHANGED
@@ -33,5 +33,5 @@
33
33
  *
34
34
  * This source code is licensed under the ISC license.
35
35
  * See the LICENSE file in the root directory of this source tree.
36
- */const It=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],me=ae("loader-circle",It);function Mt({linkToken:e,apiBaseUrl:t="https://api.tightrope.dev",onSuccess:r,onError:o,theme:n="light",className:s="",showTokenBadge:l=!0,title:i="Tightrope Link",description:u}){var h,B;const[d,b]=_.useState([]),[w,j]=_.useState(!0),[z,S]=_.useState(null),[f,m]=_.useState(null),[g,C]=_.useState({username:"",password:"",auth_params:{}}),[E,R]=_.useState(!1),[G,P]=_.useState(null),[Z,J]=_.useState(!1);_.useEffect(()=>{(async()=>{try{const y=`${t}/api/integration_methods`,x=await fetch(y);if(!x.ok)throw new Error(`Failed to fetch integrations: ${x.status}`);const N=await x.json();N&&N.integration_methods&&Array.isArray(N.integration_methods)?b(N.integration_methods):S("Invalid data format received")}catch(y){console.error("Error fetching integrations:",y);const x="Failed to load integrations";S(x),o==null||o(x)}finally{j(!1)}})()},[t,o]);const O=p=>/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(p),T=()=>{if(!f)return null;for(const p of d){const y=p.auth_methods.find(x=>x.id===f);if(y)return y}return null},q=async p=>{if(p.preventDefault(),!f||!g.username||!g.password){P("Please fill in all fields");return}const y=T();if(y!=null&&y.auth_params){for(const x of y.auth_params)if(!g.auth_params[x]){const N=`Please fill in the required field: ${x}`;P(N);return}}try{R(!0),P(null);const x=`${t}/api/linked_account_credentials`,N=await fetch(x,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({integration_method_id:f,link_token:e,args:{username:g.username,password:g.password,auth_params:g.auth_params}})}),U=await N.json();if(!N.ok){const $=U.error||`HTTP error! status: ${N.status}`;P($),o==null||o($);return}J(!0),r==null||r({integration_method_id:f,username:g.username}),C({username:"",password:"",auth_params:{}}),m(null)}catch(x){const N=x instanceof Error?x.message:"An error occurred";P(N),o==null||o(N),console.error("Error submitting credentials:",x)}finally{R(!1)}};return a.jsx("div",{className:`${n==="dark"?"dark":""} ${s}`,children:a.jsxs(ht,{className:"w-full max-w-2xl mx-auto shadow-lg border-2",children:[a.jsxs(xt,{className:"space-y-3 pb-8",children:[a.jsxs("div",{className:"space-y-1",children:[a.jsx(vt,{className:"text-2xl font-bold tracking-tight",children:i}),u&&a.jsx(yt,{className:"text-base",children:u})]}),l&&e&&a.jsx("div",{className:"flex items-center gap-2 pt-2",children:a.jsxs(Ct,{variant:O(e)?"secondary":"destructive",children:[O(e)?a.jsx(te,{className:"h-3 w-3 mr-1"}):a.jsx(re,{className:"h-3 w-3 mr-1"}),O(e)?"Valid Token":"Invalid Token"]})})]}),a.jsxs(wt,{className:"space-y-8 pb-8",children:[Z&&a.jsxs(Y,{className:"border-green-200 bg-green-50 dark:bg-green-950 dark:border-green-800",children:[a.jsx(te,{className:"h-5 w-5 text-green-600 dark:text-green-400"}),a.jsx(ee,{className:"text-green-800 dark:text-green-200 font-medium",children:"Credentials submitted successfully!"})]}),a.jsx("div",{children:w?a.jsxs("div",{className:"text-center py-12",children:[a.jsx(me,{className:"h-10 w-10 animate-spin mx-auto mb-4 text-primary"}),a.jsx("p",{className:"text-muted-foreground text-lg",children:"Loading integrations..."})]}):z?a.jsxs(Y,{variant:"destructive",children:[a.jsx(re,{className:"h-4 w-4"}),a.jsx(ee,{children:z})]}):Array.isArray(d)?d.length===0?a.jsx("div",{className:"text-center py-12",children:a.jsx("p",{className:"text-muted-foreground",children:"No integrations available"})}):a.jsxs("div",{className:"space-y-4",children:[a.jsx("div",{className:"text-sm font-medium text-muted-foreground mb-4",children:"Select an integration to connect"}),a.jsx("div",{className:"grid grid-cols-1 gap-3",children:d.map(p=>a.jsx("div",{className:"space-y-2",children:p.auth_methods.map(y=>a.jsx("button",{type:"button",onClick:()=>m(y.id),className:`w-full p-4 rounded-lg border-2 transition-all duration-200 text-left ${f===y.id?"border-primary bg-primary/5 shadow-md":"border-border hover:border-primary/50 hover:bg-accent"}`,children:a.jsxs("div",{className:"flex items-center gap-4",children:[p.provider_logo_url?a.jsx("img",{src:p.provider_logo_url,alt:`${p.provider} logo`,className:"w-12 h-12 object-contain flex-shrink-0",onError:x=>{console.error("Failed to load logo for",p.provider,":",p.provider_logo_url),x.currentTarget.style.display="none"}}):a.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center text-muted-foreground font-semibold text-lg flex-shrink-0",children:p.provider.charAt(0).toUpperCase()}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"font-semibold text-base",children:p.provider}),a.jsx("div",{className:"text-sm text-muted-foreground",children:y.display_name})]}),f===y.id&&a.jsx(te,{className:"h-5 w-5 text-primary flex-shrink-0"})]})},y.id))},p.provider))})]}):a.jsx("div",{className:"text-center py-12",children:a.jsx("p",{className:"text-muted-foreground",children:"Invalid data format"})})}),f&&a.jsxs("div",{className:"space-y-6 pt-6 border-t-2 animate-in fade-in-50 slide-in-from-top-4 duration-300",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"h-1 flex-1 bg-primary rounded-full"}),a.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Enter Credentials"}),a.jsx("div",{className:"h-1 flex-1 bg-primary rounded-full"})]}),a.jsxs("form",{onSubmit:q,className:"space-y-5",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(Q,{htmlFor:"username",className:"text-base font-medium",children:"Username"}),a.jsx(K,{type:"text",id:"username",value:g.username,onChange:p=>C({...g,username:p.target.value}),placeholder:"Enter your username",className:"h-11 text-base",required:!0})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(Q,{htmlFor:"password",className:"text-base font-medium",children:"Password"}),a.jsx(K,{type:"password",id:"password",value:g.password,onChange:p=>C({...g,password:p.target.value}),placeholder:"Enter your password",className:"h-11 text-base",required:!0})]}),(B=(h=T())==null?void 0:h.auth_params)==null?void 0:B.map(p=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Q,{htmlFor:p,className:"text-base font-medium",children:p}),a.jsx(K,{type:"text",id:p,value:g.auth_params[p]||"",onChange:y=>C({...g,auth_params:{...g.auth_params,[p]:y.target.value}}),placeholder:`Enter ${p}`,className:"h-11 text-base",required:!0})]},p)),G&&a.jsxs(Y,{variant:"destructive",children:[a.jsx(re,{className:"h-4 w-4"}),a.jsx(ee,{children:G})]}),a.jsxs("div",{className:"flex gap-3 pt-4",children:[a.jsx(ge,{type:"submit",disabled:E,className:"flex-1 h-11 text-base font-semibold",size:"lg",children:E?a.jsxs(a.Fragment,{children:[a.jsx(me,{className:"mr-2 h-5 w-5 animate-spin"}),"Submitting..."]}):"Submit Credentials"}),a.jsx(ge,{type:"button",variant:"outline",className:"h-11",onClick:()=>{m(null),C({username:"",password:"",auth_params:{}}),P(null)},children:"Cancel"})]})]})]})]})]})})}exports.Link=Mt;
36
+ */const It=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],me=ae("loader-circle",It);function Mt({linkToken:e,apiBaseUrl:t="https://api.tightrope.dev",onSuccess:r,onError:o,theme:n="light",className:s="",showTokenBadge:l=!0,title:i="Tightrope Link",description:u}){var h,B;const[d,b]=_.useState([]),[w,j]=_.useState(!0),[z,S]=_.useState(null),[f,m]=_.useState(null),[g,C]=_.useState({username:"",password:"",auth_params:{}}),[E,R]=_.useState(!1),[G,P]=_.useState(null),[Z,J]=_.useState(!1);_.useEffect(()=>{(async()=>{try{const y=`${t}/integration_methods`,x=await fetch(y);if(!x.ok)throw new Error(`Failed to fetch integrations: ${x.status}`);const N=await x.json();N&&N.integration_methods&&Array.isArray(N.integration_methods)?b(N.integration_methods):S("Invalid data format received")}catch(y){console.error("Error fetching integrations:",y);const x="Failed to load integrations";S(x),o==null||o(x)}finally{j(!1)}})()},[t,o]);const O=p=>/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(p),T=()=>{if(!f)return null;for(const p of d){const y=p.auth_methods.find(x=>x.id===f);if(y)return y}return null},q=async p=>{if(p.preventDefault(),!f||!g.username||!g.password){P("Please fill in all fields");return}const y=T();if(y!=null&&y.auth_params){for(const x of y.auth_params)if(!g.auth_params[x]){const N=`Please fill in the required field: ${x}`;P(N);return}}try{R(!0),P(null);const x=`${t}/linked_account_credentials`,N=await fetch(x,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({integration_method_id:f,link_token:e,args:{username:g.username,password:g.password,auth_params:g.auth_params}})}),U=await N.json();if(!N.ok){const $=U.error||`HTTP error! status: ${N.status}`;P($),o==null||o($);return}J(!0),r==null||r({integration_method_id:f,username:g.username}),C({username:"",password:"",auth_params:{}}),m(null)}catch(x){const N=x instanceof Error?x.message:"An error occurred";P(N),o==null||o(N),console.error("Error submitting credentials:",x)}finally{R(!1)}};return a.jsx("div",{className:`${n==="dark"?"dark":""} ${s}`,children:a.jsxs(ht,{className:"w-full max-w-2xl mx-auto shadow-lg border-2",children:[a.jsxs(xt,{className:"space-y-3 pb-8",children:[a.jsxs("div",{className:"space-y-1",children:[a.jsx(vt,{className:"text-2xl font-bold tracking-tight",children:i}),u&&a.jsx(yt,{className:"text-base",children:u})]}),l&&e&&a.jsx("div",{className:"flex items-center gap-2 pt-2",children:a.jsxs(Ct,{variant:O(e)?"secondary":"destructive",children:[O(e)?a.jsx(te,{className:"h-3 w-3 mr-1"}):a.jsx(re,{className:"h-3 w-3 mr-1"}),O(e)?"Valid Token":"Invalid Token"]})})]}),a.jsxs(wt,{className:"space-y-8 pb-8",children:[Z&&a.jsxs(Y,{className:"border-green-200 bg-green-50 dark:bg-green-950 dark:border-green-800",children:[a.jsx(te,{className:"h-5 w-5 text-green-600 dark:text-green-400"}),a.jsx(ee,{className:"text-green-800 dark:text-green-200 font-medium",children:"Credentials submitted successfully!"})]}),a.jsx("div",{children:w?a.jsxs("div",{className:"text-center py-12",children:[a.jsx(me,{className:"h-10 w-10 animate-spin mx-auto mb-4 text-primary"}),a.jsx("p",{className:"text-muted-foreground text-lg",children:"Loading integrations..."})]}):z?a.jsxs(Y,{variant:"destructive",children:[a.jsx(re,{className:"h-4 w-4"}),a.jsx(ee,{children:z})]}):Array.isArray(d)?d.length===0?a.jsx("div",{className:"text-center py-12",children:a.jsx("p",{className:"text-muted-foreground",children:"No integrations available"})}):a.jsxs("div",{className:"space-y-4",children:[a.jsx("div",{className:"text-sm font-medium text-muted-foreground mb-4",children:"Select an integration to connect"}),a.jsx("div",{className:"grid grid-cols-1 gap-3",children:d.map(p=>a.jsx("div",{className:"space-y-2",children:p.auth_methods.map(y=>a.jsx("button",{type:"button",onClick:()=>m(y.id),className:`w-full p-4 rounded-lg border-2 transition-all duration-200 text-left ${f===y.id?"border-primary bg-primary/5 shadow-md":"border-border hover:border-primary/50 hover:bg-accent"}`,children:a.jsxs("div",{className:"flex items-center gap-4",children:[p.provider_logo_url?a.jsx("img",{src:p.provider_logo_url,alt:`${p.provider} logo`,className:"w-12 h-12 object-contain flex-shrink-0",onError:x=>{console.error("Failed to load logo for",p.provider,":",p.provider_logo_url),x.currentTarget.style.display="none"}}):a.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center text-muted-foreground font-semibold text-lg flex-shrink-0",children:p.provider.charAt(0).toUpperCase()}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"font-semibold text-base",children:p.provider}),a.jsx("div",{className:"text-sm text-muted-foreground",children:y.display_name})]}),f===y.id&&a.jsx(te,{className:"h-5 w-5 text-primary flex-shrink-0"})]})},y.id))},p.provider))})]}):a.jsx("div",{className:"text-center py-12",children:a.jsx("p",{className:"text-muted-foreground",children:"Invalid data format"})})}),f&&a.jsxs("div",{className:"space-y-6 pt-6 border-t-2 animate-in fade-in-50 slide-in-from-top-4 duration-300",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"h-1 flex-1 bg-primary rounded-full"}),a.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Enter Credentials"}),a.jsx("div",{className:"h-1 flex-1 bg-primary rounded-full"})]}),a.jsxs("form",{onSubmit:q,className:"space-y-5",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(Q,{htmlFor:"username",className:"text-base font-medium",children:"Username"}),a.jsx(K,{type:"text",id:"username",value:g.username,onChange:p=>C({...g,username:p.target.value}),placeholder:"Enter your username",className:"h-11 text-base",required:!0})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(Q,{htmlFor:"password",className:"text-base font-medium",children:"Password"}),a.jsx(K,{type:"password",id:"password",value:g.password,onChange:p=>C({...g,password:p.target.value}),placeholder:"Enter your password",className:"h-11 text-base",required:!0})]}),(B=(h=T())==null?void 0:h.auth_params)==null?void 0:B.map(p=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Q,{htmlFor:p,className:"text-base font-medium",children:p}),a.jsx(K,{type:"text",id:p,value:g.auth_params[p]||"",onChange:y=>C({...g,auth_params:{...g.auth_params,[p]:y.target.value}}),placeholder:`Enter ${p}`,className:"h-11 text-base",required:!0})]},p)),G&&a.jsxs(Y,{variant:"destructive",children:[a.jsx(re,{className:"h-4 w-4"}),a.jsx(ee,{children:G})]}),a.jsxs("div",{className:"flex gap-3 pt-4",children:[a.jsx(ge,{type:"submit",disabled:E,className:"flex-1 h-11 text-base font-semibold",size:"lg",children:E?a.jsxs(a.Fragment,{children:[a.jsx(me,{className:"mr-2 h-5 w-5 animate-spin"}),"Submitting..."]}):"Submit Credentials"}),a.jsx(ge,{type:"button",variant:"outline",className:"h-11",onClick:()=>{m(null),C({username:"",password:"",auth_params:{}}),P(null)},children:"Cancel"})]})]})]})]})]})})}exports.Link=Mt;
37
37
  //# sourceMappingURL=index.cjs.map