import{i as e,n as t}from"./rolldown-runtime-BKYq3fBv.js";import{Ar as n,Ct as r,Or as i,Ot as a,jr as o}from"./vendor-other-BnH5nyVX.js";import{i as s,r as c}from"./api-z_dXWY_S.js";function captureApiError(e,t,n,r,i,a){let s={api_endpoint:t,error_type:n};r!==void 0&&(s.http_status=r),i&&(s.operation=i),o(e,{tags:s,extra:a?{...a}:void 0})}function isHttpError(e,t){return e instanceof Error&&e.message.startsWith(t)}async function getUserCloudStatus(){try{let e=await c.fetchApi(`/user`,{method:`GET`,headers:{"Content-Type":`application/json`}});if(!e.ok){let t=Error(`Failed to get user: ${e.statusText}`);throw captureApiError(t,`/user`,`http_error`,e.status,void 0,{api:{method:`GET`,endpoint:`/user`,status_code:e.status,status_text:e.statusText}}),t}return e.json()}catch(e){throw isHttpError(e,`Failed to get user:`)||captureApiError(e,`/user`,`network_error`),e}}async function getSurveyCompletedStatus(){try{let e=await c.fetchApi(`/settings/${l}`,{method:`GET`,headers:{"Content-Type":`application/json`}});return e.ok?!a((await e.json()).value):(n({category:`auth`,message:`Survey status check returned non-ok response`,level:`info`,data:{status:e.status,endpoint:`/settings/${l}`}}),!1)}catch(e){return o(e,{tags:{api_endpoint:`/settings/{key}`,error_type:`network_error`},extra:{route_template:`/settings/{key}`,route_actual:`/settings/${l}`},level:`warning`}),!1}}async function submitSurvey(e){try{n({category:`auth`,message:`Submitting survey`,level:`info`,data:{survey_fields:Object.keys(e)}});let t=await c.fetchApi(`/settings`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({[l]:e})});if(!t.ok){let n=Error(`Failed to submit survey: ${t.statusText}`);throw captureApiError(n,`/settings`,`http_error`,t.status,`submit_survey`,{survey:{field_count:Object.keys(e).length,field_names:Object.keys(e)}}),n}n({category:`auth`,message:`Survey submitted successfully`,level:`info`})}catch(e){throw isHttpError(e,`Failed to submit survey:`)||captureApiError(e,`/settings`,`network_error`,void 0,`submit_survey`),e}}var l,u=t((()=>{i(),r(),s(),l=`onboarding_survey`}));export{submitSurvey as i,getUserCloudStatus as n,u as r,getSurveyCompletedStatus as t};
//# sourceMappingURL=auth-BpHxDBwh.js.map