import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{n as t,r as n}from"./vendor-sentry-CDgv_WWe.js";import{B as r}from"./vendor-other-CrvBxfcV.js";import{r as i}from"./api-3C7_IVZO.js";var a=`onboarding_survey`;function captureApiError(e,t,r,i,a,o){let s={api_endpoint:t,error_type:r};i!==void 0&&(s.http_status=i),a&&(s.operation=a),n(e,{tags:s,extra:o?{...o}:void 0})}function isHttpError(e,t){return e instanceof Error&&e.message.startsWith(t)}async function getUserCloudStatus(){try{let e=await i.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 i.fetchApi(`/settings/${a}`,{method:`GET`,headers:{"Content-Type":`application/json`}});return e.ok?!r((await e.json()).value):(t({category:`auth`,message:`Survey status check returned non-ok response`,level:`info`,data:{status:e.status,endpoint:`/settings/${a}`}}),!1)}catch(e){return n(e,{tags:{api_endpoint:`/settings/{key}`,error_type:`network_error`},extra:{route_template:`/settings/{key}`,route_actual:`/settings/${a}`},level:`warning`}),!1}}async function submitSurvey(e){try{t({category:`auth`,message:`Submitting survey`,level:`info`,data:{survey_fields:Object.keys(e)}});let n=await i.fetchApi(`/settings`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({[a]:e})});if(!n.ok){let t=Error(`Failed to submit survey: ${n.statusText}`);throw captureApiError(t,`/settings`,`http_error`,n.status,`submit_survey`,{survey:{field_count:Object.keys(e).length,field_names:Object.keys(e)}}),t}t({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}}export{getUserCloudStatus as n,submitSurvey as r,getSurveyCompletedStatus as t};
//# sourceMappingURL=auth-CwHXDOkG.js.map