alibidaran commited on
Commit
fb6ca42
·
1 Parent(s): 43ca3cb

cloud hands api

Browse files
Files changed (2) hide show
  1. static/bundle.js +1 -0
  2. static/index.html +14 -0
static/bundle.js ADDED
@@ -0,0 +1 @@
 
 
1
+ var P,w;function I(o,s,e){var t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-end",t.style.width="fit-content",t.style.fontFamily="Roboto, sans-serif";var n=document.createElement("button"),r=document.createElement("span");r.textContent="$"+s.charge,r.style.fontWeight="bold";var i=document.createElement("span");i.textContent=" / Generation",n.appendChild(r),n.appendChild(i),n.style.margin="0.5rem",n.style.padding="1rem 4rem",n.style.backgroundColor="hsla(280, 68%, 60%, 1)",n.style.color="white",n.style.border="none",n.style.fontSize="24px",n.style.alignItems="center",n.style.justifyContent="center",n.style.display="flex",n.style.gap="0.5rem",n.style.borderRadius="8px",n.style.width="fit-content";var h=function(){var u="http://www.w3.org/2000/svg",l=document.createElementNS(u,"svg");l.setAttribute("width","30"),l.setAttribute("height","30"),l.setAttribute("viewBox","0 0 800 800");var d=document.createElementNS(u,"rect");d.setAttribute("width","800.12"),d.setAttribute("height","800.12"),d.setAttribute("x","0.4"),d.setAttribute("y","0.26"),d.setAttribute("rx","96.52"),d.setAttribute("ry","96.52"),d.setAttribute("fill","hsla(280, 68%, 60%, 1)"),l.appendChild(d);var b=document.createElementNS(u,"path");b.setAttribute("d","M674.74 399.88s54.16 117.48 8.73 211.82H543.71s-1.75-89.1 61.14-132.77c62.89-43.67 69.88-79.05 69.88-79.05Z"),b.setAttribute("fill","#ffffff"),l.appendChild(b);var _=document.createElementNS(u,"path");_.setAttribute("d","M424.05 369.75s-.87-120.15 110.93-159.65c0 0 127.53-43.97 148.49-62.7 0 0 10.48 86.09-78.61 93.95 0 0 73.37 75.99 34.07 159.85-39.31 83.86-158.1 77.74-194.79 23.58 0 0-19.97-26.04-20.09-26.2-1.59-2.07 7.93-7.46 9.12-7.71 11.38-2.42 18.97 11.24 26 17.59 22.97 20.76 57.51 31.51 88.05 26.28 44.16-7.56 70.84-45.84 70.41-88.96-.41-41.36-25.05-72.95-63.67-86.96-90.69-32.9-129.9 110.93-129.9 110.93ZM399.09 369.75s.87-120.15-110.93-159.65c0 0-127.53-43.97-148.49-62.7 0 0-10.48 86.09 78.61 93.95 0 0-73.37 75.99-34.07 159.85 39.31 83.86 158.1 77.74 194.79 23.58 0 0 19.91-25.97 20.09-26.2 2.49-3.25-10.73-7.94-12.29-7.9-10.39.23-19.99 15.39-27.57 21.23-21.37 16.48-48.51 26.3-75.67 23.86-46.15-4.15-77.31-42.05-78.02-86.9-.68-42.54 23.81-75.6 63.66-90.05 90.69-32.9 129.9 110.93 129.9 110.93Z"),_.setAttribute("fill","#ffffff"),l.appendChild(_);var A=document.createElementNS(u,"path");A.setAttribute("d","M148.89 399.88s-54.16 117.48-8.73 211.82h139.76s1.75-89.1-61.14-132.77c-62.89-43.67-69.88-79.05-69.88-79.05Z"),A.setAttribute("fill","#ffffff"),l.appendChild(A);var E=document.createElementNS(u,"path");E.setAttribute("d","M411.82 147.42S345 145.7 272.93 178.46c0 0 91.28 24.46 138.89 94.34 47.61-69.88 138.89-94.34 138.89-94.34-72.06-32.76-138.89-31.04-138.89-31.04Z"),E.setAttribute("fill","#ffffff"),l.appendChild(E);var v=document.createElementNS(u,"circle");v.setAttribute("cx","522.31"),v.setAttribute("cy","346.16"),v.setAttribute("r","53.72"),v.setAttribute("fill","#2dd4e0"),l.appendChild(v);var C=document.createElementNS(u,"circle");C.setAttribute("cx","298.26"),C.setAttribute("cy","346.16"),C.setAttribute("r","53.72"),C.setAttribute("fill","#2dd4e0"),l.appendChild(C);var k=document.createElementNS(u,"path");return k.setAttribute("d","M410.25 372.31c-6.56.27-11.51.16-17.12 4.11-5.18 3.65-9.76 8.09-13.85 12.91-2.04 2.41-21 30.77-20.19 31.14 12.37 5.97 22.2 16.26 30.1 27.5 7.89 11.25 14.09 23.57 21.1 35.39 7.01-11.82 13.21-24.15 21.11-35.4 7.9-11.25 17.73-21.54 30.11-27.51-8.57-15.26-17.46-30.9-31.09-41.87-3.57-2.87-7.58-5.45-12.1-6.18-2.29-.37-4.64-.26-6.96-.15-.38.02-.74.03-1.11.05Z"),k.setAttribute("fill","#ffffff"),l.appendChild(k),l}();n.prepend(h);var a=document.createElement("div");a.style.display="flex",a.style.margin="0.5rem",a.style.alignItems="center",a.style.justifyContent="center",a.style.backgroundColor="#78788014",a.style.borderRadius="24px",a.style.width="fit-content",a.style.boxSizing="border-box",a.style.display="none";var f=document.createElement("img");f.src=o.getAvatar(),f.alt="Avatar",f.style.width="32px",f.style.height="32px",f.style.borderRadius="50%",f.style.marginRight="1rem",a.appendChild(f);var p=document.createElement("span");p.textContent=o.getUsername(),p.style.fontSize="20px",p.style.fontWeight="medium",p.style.marginRight="1rem",p.style.color="black",a.appendChild(p);var m=document.createElement("button");m.textContent="▼",m.style.background="none",m.style.border="none",m.style.cursor="pointer",m.style.fontSize="1rem",m.style.marginRight="0.5rem",m.style.color="black",a.appendChild(m);var c=document.createElement("div");c.style.position="absolute",c.style.backgroundColor="#ffffff",c.style.border="1px solid #ccc",c.style.borderRadius="8px",c.style.boxShadow="0 4px 6px rgba(0, 0, 0, 0.1)",c.style.padding="0.5rem",c.style.marginTop="0.5rem",c.style.display="none",c.style.zIndex="1000",c.style.top="100%",c.style.right="0",c.style.width="fit-content",c.style.boxSizing="border-box";var g=document.createElement("button");g.textContent="Logout",g.style.background="none",g.style.border="none",g.style.cursor="pointer",g.style.fontSize="1rem",g.style.color="red",g.style.padding="0.5rem 1rem",g.style.textAlign="left",g.style.width="100%",g.addEventListener("click",function(){o.logout(),a.style.display="none",location.reload()}),c.appendChild(g),a.style.position="relative",a.appendChild(c),m.addEventListener("click",function(){c.style.display=c.style.display==="none"?"block":"none"}),document.addEventListener("click",function(u){a.contains(u.target)||(c.style.display="none")}),t.appendChild(n),t.appendChild(a);var y=document.createElement("span");return y.style.color="red",y.style.margin="0.5rem 0",y.style.fontSize="1rem",y.className="error-message",y.style.display="none",t.insertBefore(y,a),o.IsAuthenticated()&&(f.src=o.getAvatar(),p.textContent=o.getUsername(),a.style.display="flex"),n.addEventListener("click",function(){try{var u=function(){o.IsAuthenticated()&&(f.src=o.getAvatar(),p.textContent=o.getUsername(),a.style.display="flex",o.CloudhandsPurchase(s).then(function(d){d.success?(y.style.display="none",e(d)):(console.log(d),y.textContent=""+(d.message||"Unknown error"),y.style.display="block",t.insertBefore(y,a))}))},l=function(){if(!o.IsAuthenticated())return Promise.resolve(o.Authenticate()).then(function(){})}();return Promise.resolve(l&&l.then?l.then(u):u())}catch(d){return Promise.reject(d)}}),t}function x(o,s){try{var e=o()}catch(t){return s(t)}return e&&e.then?e.then(void 0,s):e}(function(o){o[o.Pending=0]="Pending",o[o.Complete=1]="Complete",o[o.Failed=2]="Failed"})(P||(P={})),function(o){o[o.Each=0]="Each",o[o.Monthly=1]="Monthly"}(w||(w={}));var T=function(){function o(e){this.clientId=void 0,this.codeVerifier=void 0,this.state=void 0,this.NEXT_PUBLIC_API_URL="http://api.localhost:5000",this.NEXT_PUBLIC_LIVE_URL="https://api.cloudhands.ai",this.SDK_VERSION="1.0.0",this.clientId=e,this.codeVerifier=this.getCodeVerifier(),this.state=this.getState()}var s=o.prototype;return s.Authenticate=function(){try{var e=this,t=e.HandleRedirect();return Promise.resolve(t?Promise.resolve(e.ExchangeCodeForToken(t.code)).then(function(){}):Promise.resolve(e.GetAuthUrl()).then(function(n){var r=window.open(n,"CloudhandsAuth","width=600,height=800,scrollbars=no,resizable=no");if(!r)throw new Error("Failed to open authentication popup.");return new Promise(function(i,h){var a=setInterval(function(){try{if(!r||r.closed)return clearInterval(a),void h(new Error("Authentication popup was closed."));var f=new URLSearchParams(r.location.search),p=f.get("code"),m=f.get("state");if(p&&m){if(m!==e.state)return clearInterval(a),r.close(),void h(new Error("Invalid state parameter."));clearInterval(a),r.close(),e.ExchangeCodeForToken(p).then(i).catch(h)}}catch{}},500)})}))}catch(n){return Promise.reject(n)}},s.HandleRedirect=function(){var e=new URLSearchParams(window.location.search),t=e.get("code"),n=e.get("state");return t&&n?{code:t,state:n}:null},s.IsAuthenticated=function(){return!!this.getAccessToken()},s.CreateCharge=function(e,t,n,r){return n===void 0&&(n=w.Each),r===void 0&&(r={}),{author_id:this.clientId,sdk_version:this.SDK_VERSION,charge_type:n,charge:e,event_name:t,metadata:r}},s.GetTransaction=function(e){try{var t=this,n=t.NEXT_PUBLIC_LIVE_URL+"/sdk/transaction/"+e;return Promise.resolve(x(function(){return Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer "+t.getAccessToken()}})).then(function(r){return r.ok?Promise.resolve(r.json()).then(function(i){return i.message}):(console.log(r),null)})},function(r){return console.error("Error fetching transaction:",r),null}))}catch(r){return Promise.reject(r)}},s.GetAuthUrl=function(){try{var e=this,t=""+window.location.href;return e.state=e.generateRandomString(16,16),Promise.resolve(e.generateCodeChallenge(e.codeVerifier)).then(function(n){return"https://cloudhands.ai/auth?response_type=code&client_id="+e.clientId+"&redirect_uri="+t+"&state="+e.state+"&code_challenge="+n+"&code_challenge_method=S256"})}catch(n){return Promise.reject(n)}},s.ExchangeCodeForToken=function(e){try{var t=this,n=t.NEXT_PUBLIC_LIVE_URL+"/token",r=""+window.location.href;return Promise.resolve(x(function(){return Promise.resolve(fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:e,clientId:t.clientId,redirectUri:r,code_Verifier:t.codeVerifier})})).then(function(i){if(!i.ok)throw new Error("Error fetching token: "+i.statusText);return Promise.resolve(i.json()).then(function(h){document.cookie="cloudhands_access_token="+h.access_token+"; path=/; max-age=3600",document.cookie="cloudhands_username="+h.username+"; path=/; max-age=3600",document.cookie="cloudhands_avatar=https://cdn.cloudhands.ai/avatar/"+h.avatar+"; path=/; max-age=3600"})})},function(i){console.error("Error exchanging code for token:",i)}))}catch(i){return Promise.reject(i)}},s.CloudhandsPurchase=function(e){try{var t=this,n=t.NEXT_PUBLIC_LIVE_URL+"/sdk/charge";return Promise.resolve(x(function(){return Promise.resolve(fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+t.getAccessToken()},body:JSON.stringify(e)})).then(function(r){if(!r.ok){console.log(r);var i="Cloudhands response was not ok: "+r.statusText;return console.error(i),{success:!1,message:i}}return Promise.resolve(r.json()).then(function(h){if(h.isSuccessful)return{success:!0,message:"Purchase completed successfully.",transaction_id:h.message.transaction_id};var a=""+(h.errors[0]||"Unknown error");return console.error(a),{success:!1,message:a}})})},function(r){var i="Fetch error: "+(r instanceof Error?r.message:String(r));return console.error(i),{success:!1,message:i}}))}catch(r){return Promise.reject(r)}},s.generateRandomString=function(e,t){for(var n=Math.floor(Math.random()*(t-e+1))+e,r="",i=0;i<n;i++)r+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~".charAt(Math.floor(66*Math.random()));return r},s.generateCodeChallenge=function(e){try{var t=new TextEncoder().encode(e);return Promise.resolve(crypto.subtle.digest("SHA-256",t)).then(function(n){return btoa(String.fromCharCode.apply(String,new Uint8Array(n))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")})}catch(n){return Promise.reject(n)}},s.getState=function(){var e=this.getCookie("cloudhands_state");if(!e){e=this.generateRandomString(16,16);var t=new Date(Date.now()+3e5).toUTCString();document.cookie="cloudhands_state="+e+"; expires="+t+"; path=/"}return e},s.getCodeVerifier=function(){var e=this.getCookie("cloudhands_code_verifier");if(!e){e=this.generateRandomString(43,128);var t=new Date(Date.now()+3e5).toUTCString();document.cookie="cloudhands_code_verifier="+e+"; expires="+t+"; path=/"}return e},s.getCookie=function(e){var t=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return t?decodeURIComponent(t[1]):null},s.getAvatar=function(){return this.getCookie("cloudhands_avatar")||"https://cdn.cloudhands.ai/avatar/default.png"},s.getUsername=function(){return this.getCookie("cloudhands_username")||"Guest"},s.getAccessToken=function(){return this.getCookie("cloudhands_access_token")||null},s.logout=function(){["cloudhands_access_token","cloudhands_username","cloudhands_avatar","cloudhands_state","cloudhands_code_verifier"].forEach(function(t){document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"});var e=new URL(window.location.href);e.searchParams.delete("code"),e.searchParams.delete("state"),window.history.replaceState({},document.title,e.toString())},o}();const R="pK-HHPuHFDr1q1J7NkRHtscqyjfClSRZ";let S=new T(R);function U(o){S.GetTransaction(o.transaction_id).then(s=>{console.log("Transaction details:",s)})}let L=S.CreateCharge(.3,"test event");const N=I(S,L,U);document.body.appendChild(N);
static/index.html ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>Cloudhands Test</title>
6
+ </head>
7
+ <body>
8
+ <h2>Cloudhands Button Below:</h2>
9
+ <div id="cloudhands-button-container"></div>
10
+
11
+ <!-- ✅ Load your Vite-generated JavaScript -->
12
+ <script type="module" src="./bundle.js"></script>
13
+ </body>
14
+ </html>