1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7831],{3192:(e,t,r)=>{r.d(t,{JWTTokenProvider:()=>i,s:()=>l});var n=r(5155),o=r(2115),u=r(7471);let a=(0,o.createContext)(void 0);function i(e){let{children:t}=e,{getToken:r,isLoaded:i}=(0,u.d)(),[l,c]=(0,o.useState)(null),[s,m]=(0,o.useState)(null),d=(0,o.useCallback)(e=>{try{let t=JSON.parse(atob(e.split(".")[1]));return t.exp?1e3*t.exp:null}catch(e){return console.error("â Failed to decode JWT token:",e),null}},[]),f=(0,o.useCallback)(async()=>{if(l&&s&&Date.now()<s-6e5)return l;try{let e="gleamr-session",t=await r(e?{template:e}:void 0);if(t){let e=d(t);return c(t),m(e),t}}catch(e){console.error("â JWT Token acquisition failed:",e),console.error("Template used:",template),console.error("Auth loaded:",i),c(null),m(null)}return null},[r,l,s,d]),_=(0,o.useCallback)(()=>!s||Date.now()>=s-9e5,[s]),h=(0,o.useCallback)(()=>{c(null),m(null)},[]);return(0,o.useEffect)(()=>{i&&s&&!l&&h()},[i,l,s,h]),(0,n.jsx)(a.Provider,{value:{getValidToken:f,clearToken:h,tokenExpiry:s,isTokenExpiring:_},children:t})}function l(){let e=(0,o.useContext)(a);if(void 0===e)throw Error("useJWTToken must be used within a JWTTokenProvider");return e}},5445:(e,t,r)=>{r.d(t,{D1:()=>h,Fb:()=>b,Hm:()=>k,Qt:()=>m,UQ:()=>s,XH:()=>E,c6:()=>T,cd:()=>y,dr:()=>v,qk:()=>p,sA:()=>d});let n=["hn","product_hunt","chrome_store","alternativeto","reddit","owned_email"],o=["referral","social","email"],u=["launch"],a=["search","social","referral","direct"],i=["google.com","bing.com","duckduckgo.com","news.ycombinator.com","reddit.com","github.com","alternativeto.net","saashub.com","x.com","t.co"],l=["google.com","bing.com","duckduckgo.com"],c=["reddit.com","news.ycombinator.com","x.com","t.co"],s=["launch_landing_viewed","signup_completed"];function m(e){if("object"!=typeof e||null===e)return!1;let t="string"==typeof e.utm_source?e.utm_source:null,r="string"==typeof e.utm_medium?e.utm_medium:null,a="string"==typeof e.utm_campaign?e.utm_campaign:null;return _(t,n)&&_(r,o)&&_(a,u)}function d(e){if("object"!=typeof e||null===e||!_("string"==typeof e.channel?e.channel:null,a))return!1;if(void 0===e.referrer_domain)return!0;let t="string"==typeof e.referrer_domain?e.referrer_domain:null;return"other"===t||_(t,i)}let f="gleamr-attribution-v1";function _(e,t){return null!==e&&t.includes(e)}function h(e){var t,r,a,i,l,c;let s=new URLSearchParams(e),m=null!=(i=null==(t=s.get("utm_source"))?void 0:t.trim().toLowerCase())?i:null,d=null!=(l=null==(r=s.get("utm_medium"))?void 0:r.trim().toLowerCase())?l:null,f=null!=(c=null==(a=s.get("utm_campaign"))?void 0:a.trim().toLowerCase())?c:null;return _(m,n)&&_(d,o)&&_(f,u)?{utm_source:m,utm_medium:d,utm_campaign:f}:null}function p(e,t){let r;if(!e)return{channel:"direct"};try{r=new URL(e).hostname.toLowerCase().replace(/^www\./,"");let n=new URL(t).hostname.toLowerCase().replace(/^www\./,"");if(r===n)return{channel:"direct"}}catch(e){return{channel:"direct"}}let n=e=>r===e||r.endsWith("."+e);for(let e of i)if(n(e)){if(l.includes(e))return{channel:"search",referrer_domain:e};if(c.includes(e))return{channel:"social",referrer_domain:e};return{channel:"referral",referrer_domain:e}}return{channel:"referral",referrer_domain:"other"}}function g(){let e;try{e=localStorage.getItem(f)}catch(e){return null}if(!e)return null;try{let t=JSON.parse(e);if((null==t?void 0:t.v)!==2||"boolean"!=typeof t.landing_sent||!d({channel:t.channel,referrer_domain:t.referrer_domain}))return C(),null;let r=void 0!==t.utm_source||void 0!==t.utm_medium||void 0!==t.utm_campaign;if(r&&!m({utm_source:t.utm_source,utm_medium:t.utm_medium,utm_campaign:t.utm_campaign}))return C(),null;let n="string"==typeof t.ts?Date.parse(t.ts):NaN,o=Date.now();if(Number.isNaN(n)||n>o||o-n>2592e6)return C(),null;let u={v:2,channel:t.channel,ts:t.ts,landing_sent:t.landing_sent};return void 0!==t.referrer_domain&&(u.referrer_domain=t.referrer_domain),r&&(u.utm_source=t.utm_source,u.utm_medium=t.utm_medium,u.utm_campaign=t.utm_campaign),u}catch(e){return C(),null}}function w(e){try{localStorage.setItem(f,JSON.stringify(e))}catch(e){}}function v(e,t){if(null!==g())return;let r={v:2,channel:t.channel,ts:new Date().toISOString(),landing_sent:!1};void 0!==t.referrer_domain&&(r.referrer_domain=t.referrer_domain),e&&(r.utm_source=e.utm_source,r.utm_medium=e.utm_medium,r.utm_campaign=e.utm_campaign),w(r)}function T(){let e=g();return e&&void 0!==e.utm_source?{utm_source:e.utm_source,utm_medium:e.utm_medium,utm_campaign:e.utm_campaign}:null}function y(){let e=g();if(!e)return null;let t={channel:e.channel};return void 0!==e.referrer_domain&&(t.referrer_domain=e.referrer_domain),void 0!==e.utm_source&&(t.utm_source=e.utm_source,t.utm_medium=e.utm_medium,t.utm_campaign=e.utm_campaign),t}function k(){let e=g();if(!e)return null;let t=["channel=".concat(e.channel)];return void 0!==e.referrer_domain&&t.push("ref=".concat(e.referrer_domain)),void 0!==e.utm_source&&(t.push("utm_source=".concat(e.utm_source)),t.push("utm_medium=".concat(e.utm_medium)),t.push("utm_campaign=".concat(e.utm_campaign))),t.join(";")}function b(){let e=g();return null!==e&&void 0!==e.utm_source&&!1===e.landing_sent}function E(){let e=g();e&&!e.landing_sent&&w({...e,landing_sent:!0})}function C(){try{localStorage.removeItem(f)}catch(e){}}},7831:(e,t,r)=>{r.d(t,{RH:()=>c,dA:()=>s});var n=r(2115),o=r(3192),u=r(5445),a=r(5704);
1class i extends Error{constructor(e,t,r){super(e),this.status=t,this.response=r,this.name="ApiClientError"}}function l(e,t,r){async function n(n){let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{method:l="GET",body:c,headers:s={},maxRetries:m=1,cache:d="no-store"}=o,f=n.startsWith("http")||n.startsWith("/api/")?n:"".concat("https://api.gleamr.io").concat(n);for(let o=0;o<=m;o++)try{var _;let h;if(o>0&&r&&r(),!(h=await e()))throw new i("No authentication token available",401);if(3!==h.split(".").length)throw new i("Invalid JWT token format",401);let p=n.startsWith("/api/")?null:(0,u.Hm)(),g={"Content-Type":"application/json",Authorization:"Bearer ".concat(h),..."dev"===a.env.NEXT_PUBLIC_APP_ENV&&{"X-Test-Mode":"true"},...p&&{"X-Gleamr-First-Touch":p},...s};if(t&&("POST"===l||"PUT"===l||"DELETE"===l||"PATCH"===l))try{let e=await t();e&&(g["X-CSRF-Token"]=e)}catch(e){}let w={method:l,cache:d,headers:g};c&&"GET"!==l&&(w.body="string"==typeof c?c:JSON.stringify(c));let v=await fetch(f,w);if(!(null==(_=v.headers.get("content-type"))?void 0:_.includes("application/json")))if(v.ok)return{success:!0,data:null};else{let e=await v.text();throw new i("HTTP ".concat(v.status,": ").concat(e),v.status,v)}let T=await v.json();if(401===v.status&&o<m)continue;if(!v.ok){let e=T.error||"HTTP ".concat(v.status,": ").concat(v.statusText);throw 401===v.status?e.includes("expired")?e="JWT token has expired, retrying with fresh token":e.includes("invalid")&&(e="JWT token is invalid, please re-authenticate"):400===v.status&&e.includes("dangerous")&&(e="Content was blocked by security filters - this may be a false positive"),new i(e,v.status,v)}return T}catch(t){let e=t instanceof TypeError&&(t.message.includes("CORS")||t.message.includes("fetch")||t.message.includes("NetworkError")||t.message.includes("Failed to fetch"));if(o>=m||e||t instanceof i&&401!==t.status){if(console.error("â API Error [".concat(l,"] ").concat(f,":"),t),t instanceof i)return{success:!1,error:t.message};if(e)return{success:!1,error:"Network error: Unable to connect to API. Please check your connection or try again later."};return{success:!1,error:t instanceof Error?t.message:"Unknown error"}}}return{success:!1,error:"Maximum retries exceeded"}}return{get:(e,t)=>n(e,{...t,method:"GET"}),post:(e,t,r)=>n(e,{...r,method:"POST",body:t}),put:(e,t,r)=>n(e,{...r,method:"PUT",body:t}),delete:(e,t,r)=>n(e,{...r,method:"DELETE",body:t}),patch:(e,t,r)=>n(e,{...r,method:"PATCH",body:t}),makeRequest:n}}function c(){let{getValidToken:e,clearToken:t}=(0,o.s)();return(0,n.useMemo)(()=>l(e,void 0,t),[e,t])}function s(){let{getValidToken:e,clearToken:t}=(0,o.s)(),r=(0,n.useMemo)(()=>async()=>{try{let t=await e();if(!t||3!==t.split(".").length)return null;let r=await fetch("".concat("https://api.gleamr.io","/api/auth/csrf-token"),{method:"GET",headers:{Authorization:"Bearer ".concat(t),"Content-Type":"application/json",..."dev"===a.env.NEXT_PUBLIC_APP_ENV&&{"X-Test-Mode":"true"}}});if(!r.ok)return null;let n=await r.json();if(n.success&&n.csrf_token)return n.csrf_token;return null}catch(e){return console.error("CSRF token fetch error:",e),null}},[e]);return(0,n.useMemo)(()=>l(e,r,t),[e,r,t])}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.