module.exports=[941178,e=>{"use strict";var t=e.i(626369),r=e.i(254799),i=e.i(689960);function n(e){return e.toString("base64").replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}async function a(e,t={}){let r=new AbortController,i=setTimeout(()=>r.abort("timeout"),15e3);try{return await fetch(e,{...t,signal:r.signal})}finally{clearTimeout(i)}}class o{generatePkcePair(){let e=n(r.default.randomBytes(32)),t=n(r.default.createHash("sha256").update(e).digest());return{verifier:e,challenge:t}}initiateDeviceFlow(){let{verifier:e,challenge:r}=this.generatePkcePair(),n=(0,i.v4)(),a=(0,i.v4)(),o=new URLSearchParams({challenge:r,challenge_method:"S256",machine_id:a,nonce:n});return{verificationUriComplete:`${t.QODER_LOGIN_URL}?${o.toString()}`,codeVerifier:e,nonce:n,machineId:a}}async pollDeviceToken({nonce:e,codeVerifier:r}){let i;if(!e||!r)throw Error("pollDeviceToken: missing nonce or code verifier");let n=`${t.QODER_DEVICE_TOKEN_URL}?nonce=${encodeURIComponent(e)}&verifier=${encodeURIComponent(r)}&challenge_method=S256`,s=await a(n,{method:"GET",headers:{Accept:"application/json","User-Agent":"Go-http-client/2.0"}});if(202===s.status||404===s.status)return{status:"pending"};let l=await s.text();if(!s.ok){let e=`Qoder device token poll failed: HTTP ${s.status}`;try{let t=JSON.parse(l);t.message&&(e=`Qoder device token poll failed: ${t.message}`)}catch{}throw Error(e)}try{i=JSON.parse(l)}catch(e){throw Error(`Qoder device token poll: invalid JSON response (${e.message})`)}if(!i.token)throw Error("Qoder device token poll returned 200 but no token");let c=o.parseExpiry(i.expires_at,i.expires_in);return{status:"ok",accessToken:i.token,refreshToken:i.refresh_token||"",userId:i.user_id||"",expireTime:c,rawResponse:i}}async fetchUserInfo(e){try{let r=await a(t.QODER_USERINFO_URL,{method:"GET",headers:{Authorization:`Bearer ${e}`,Accept:"application/json","User-Agent":"Go-http-client/2.0"}});if(!r.ok)return{name:"",email:""};let i=await r.json();return{name:(i.name||i.username||"").trim(),email:(i.email||"").trim(),organizationId:(i.organization_id||"").trim()}}catch{return{name:"",email:""}}}static parseExpiry(e,t){if("number"==typeof e&&Number.isFinite(e)&&e>0)return e;let r="string"==typeof e?e.trim():"";if(r){if(/^\d+$/.test(r)){let e=Number.parseInt(r,10);if(Number.isFinite(e)&&e>0)return e}let e=Date.parse(r);if(!Number.isNaN(e))return e}return"number"==typeof t&&Number.isFinite(t)&&t>=0?Date.now()+1e3*t:Date.now()+2592e6}}e.s(["QoderService",0,o])}];

//# sourceMappingURL=src_lib_oauth_services_qoder_0xftoz9.js.map