@i-giann/open-meteo-wrapper 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +36 -26
- package/package.json +1 -1
package/LICENSE
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react"),$=require("zustand"),z=require("immer");function V(e,a){let t;try{t=e()}catch{return}return{getItem:u=>{var r;const s=c=>c===null?null:JSON.parse(c,void 0),i=(r=t.getItem(u))!=null?r:null;return i instanceof Promise?i.then(s):s(i)},setItem:(u,r)=>t.setItem(u,JSON.stringify(r,void 0)),removeItem:u=>t.removeItem(u)}}const k=e=>a=>{try{const t=e(a);return t instanceof Promise?t:{then(o){return k(o)(t)},catch(o){return this}}}catch(t){return{then(o){return this},catch(o){return k(o)(t)}}}},X=(e,a)=>(t,o,u)=>{let r={storage:V(()=>localStorage),partialize:d=>d,version:0,merge:(d,T)=>({...T,...d}),...a},s=!1;const i=new Set,c=new Set;let m=r.storage;if(!m)return e((...d)=>{console.warn(`[zustand persist middleware] Unable to update item '${r.name}', the given storage is currently unavailable.`),t(...d)},o,u);const g=()=>{const d=r.partialize({...o()});return m.setItem(r.name,{state:d,version:r.version})},p=u.setState;u.setState=(d,T)=>{p(d,T),g()};const l=e((...d)=>{t(...d),g()},o,u);u.getInitialState=()=>l;let v;const b=()=>{var d,T;if(!m)return;s=!1,i.forEach(R=>{var y;return R((y=o())!=null?y:l)});const N=((T=r.onRehydrateStorage)==null?void 0:T.call(r,(d=o())!=null?d:l))||void 0;return k(m.getItem.bind(m))(r.name).then(R=>{if(R)if(typeof R.version=="number"&&R.version!==r.version){if(r.migrate){const y=r.migrate(R.state,R.version);return y instanceof Promise?y.then(D=>[!0,D]):[!0,y]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,R.state];return[!1,void 0]}).then(R=>{var y;const[D,U]=R;if(v=r.merge(U,(y=o())!=null?y:l),t(v,!0),D)return g()}).then(()=>{N==null||N(v,void 0),v=o(),s=!0,c.forEach(R=>R(v))}).catch(R=>{N==null||N(void 0,R)})};return u.persist={setOptions:d=>{r={...r,...d},d.storage&&(m=d.storage)},clearStorage:()=>{m==null||m.removeItem(r.name)},getOptions:()=>r,rehydrate:()=>b(),hasHydrated:()=>s,onHydrate:d=>(i.add(d),()=>{i.delete(d)}),onFinishHydration:d=>(c.add(d),()=>{c.delete(d)})},r.skipHydration||b(),v||l},ee=X;var I=(e=>(e.SUCCESS="success",e.ERROR="error",e.WARNING="warning",e.INFO="info",e))(I||{}),w=(e=>(e.NETWORK_ERROR="network_error",e.API_ERROR="api_error",e.DATA_ERROR="data_error",e.UNKNOWN_ERROR="unknown_error",e))(w||{}),G=(e=>(e.Temperature="temperature_2m",e.RelativeHumidity="relative_humidity_2m",e.DewPoint="dew_point_2m",e.ApparentTemperature="apparent_temperature",e.PrecipitationProbability="precipitation_probability",e.Precipitation="precipitation",e.Rain="rain",e.Snowfall="snowfall",e.SnowDepth="snow_depth",e.WeatherCode="weather_code",e.PressureMsl="pressure_msl",e.CloudCover="cloud_cover",e.Visibility="visibility",e.WindSpeed="wind_speed_10m",e.WindDirection="wind_direction_10m",e.UvIndex="uv_index",e.IsDay="is_day",e))(G||{}),j=(e=>(e.TemperatureMax="temperature_2m_max",e.TemperatureMin="temperature_2m_min",e.Sunrise="sunrise",e.Sunset="sunset",e.DaylightDuration="daylight_duration",e))(j||{}),E=(e=>(e.UNKNOWN="Desconocido",e.LOW="Bajo",e.MODERATE="Moderado",e.HIGH="Alto",e))(E||{}),h=(e=>(e.clear_sky="Cielo despejado",e.mainly_clear="Mayormente despejado",e.partly_cloudy="Parcialmente nublado",e.overcast="Mayormente nublado",e.fog="Niebla",e.depositing_rime_fog="Niebla con escarcha",e.drizzle_light="Llovizna ligera",e.drizzle_moderate="Llovizna moderada",e.drizzle_dense="Llovizna densa",e.freezing_drizzle_light="Llovizna helada ligera",e.freezing_drizzle_dense="Llovizna helada densa",e.rain_slight="Lluvia ligera",e.rain_moderate="Lluvia moderada",e.rain_heavy="Lluvia intensa",e.freezing_rain_light="Lluvia helada ligera",e.freezing_rain_heavy="Lluvia helada intensa",e.snowfall_slight="Nevada ligera",e.snowfall_moderate="Nevada moderada",e.snowfall_heavy="Nevada intensa",e.snow_grains="Precipitación de granos de nieve",e.rain_showers_slight="Chubascos ligeros",e.rain_showers_moderate="Chubascos moderados",e.rain_showers_violent="Chubascos violentos",e.snow_showers_slight="Chubascos de nieve ligeros",e.snow_showers_heavy="Chubascos de nieve intensos",e.thunderstorm="Tormenta",e))(h||{});const te="https://api.open-meteo.com/v1/forecast",A={DEFAULT_TIMEZONE:"America/Sao_Paulo",DEFAULT_HOURLY_PARAMS:[G.Temperature,G.WeatherCode],DEFAULT_DAILY_PARAMS:[j.TemperatureMax,j.TemperatureMin],DEFAULT_PAST_DAYS:0,DEFAULT_FORECAST_DAYS:7,DEFAULT_CACHE_DURATION:10*60*1e3,REQUEST_TIMEOUT:1e4},H={DESCRIPTIONS:{[E.UNKNOWN]:"No se puede determinar el riesgo de exposición",[E.LOW]:"Puedes disfrutar de estar afuera con seguridad",[E.MODERATE]:"Busca sombra durante las horas del mediodía. Ponte una remera, utiliza protector solar y un sombrero.",[E.HIGH]:"Evita estar afuera durante las horas del mediodía. Asegúrate de buscar sombra. La remera, el protector solar y el sombrero son imprescindibles."}},re={0:h.clear_sky,1:h.mainly_clear,2:h.partly_cloudy,3:h.overcast,45:h.fog,48:h.depositing_rime_fog,51:h.drizzle_light,53:h.drizzle_moderate,55:h.drizzle_dense,56:h.freezing_drizzle_light,57:h.freezing_drizzle_dense,61:h.rain_slight,63:h.rain_moderate,65:h.rain_heavy,66:h.freezing_rain_light,67:h.freezing_rain_heavy,71:h.snowfall_slight,73:h.snowfall_moderate,75:h.snowfall_heavy,77:h.snow_grains,80:h.rain_showers_slight,81:h.rain_showers_moderate,82:h.rain_showers_violent,85:h.snow_showers_slight,86:h.snow_showers_heavy,95:h.thunderstorm},f={time:"iso8601",hour:"iso8601",temperature_2m:"ºC",temperature_2m_max:"ºC",temperature_2m_min:"ºC",dew_point_2m:"ºC",apparent_temperature:"ºC",relative_humidity_2m:"%",precipitation_probability:"%",precipitation:"mm",rain:"mm",snowfall:"cm",snow_depth:"m",pressure_msl:"hPa",wind_speed_10m:"km/h",wind_direction_10m:"°",cloud_cover:"%",visibility:"km",weather_code:"wmo code",sunrise:"iso8601",sunset:"iso8601",daylight_duration:"h",is_day:"flag"};class ae{async fetchRaw({latitude:a,longitude:t,hourly:o=A.DEFAULT_HOURLY_PARAMS,daily:u=A.DEFAULT_DAILY_PARAMS,timezone:r=A.DEFAULT_TIMEZONE,past_days:s=A.DEFAULT_PAST_DAYS,forecast_days:i=A.DEFAULT_FORECAST_DAYS}){try{const c=new URL(te),m=new URLSearchParams({latitude:a.toString(),longitude:t.toString(),hourly:o.join(","),daily:u.join(","),timezone:r,past_days:s.toString(),forecast_days:i.toString()});c.search=m.toString();const g=new AbortController,p=setTimeout(()=>g.abort(),A.REQUEST_TIMEOUT),l=await fetch(c.toString(),{signal:g.signal});return clearTimeout(p),l.ok?await l.json():l.status>=500?this.buildError({error:"Debido a un problema en el servidor, no podemos obtener la información del clima.",info:"Por favor, inténtalo de nuevo más tarde.",status:l.status,errorType:w.API_ERROR}):l.status>=400?l.status===408?this.buildError({error:"La solicitud ha tardado demasiado tiempo en completarse.",status:408,info:"Revisa tu conexión a internet e intenta de nuevo.",type:I.WARNING,errorType:w.NETWORK_ERROR}):this.buildError({error:"No pudimos obtener la información del clima.",info:"Verifica que la ubicación ingresada sea correcta e inténtalo de nuevo.",status:l.status,type:I.WARNING,errorType:w.API_ERROR}):this.buildError({error:"Ocurrió un error al obtener los datos del clima.",status:l.status,errorType:w.UNKNOWN_ERROR})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?this.buildError({error:"La solicitud ha tardado demasiado tiempo en completarse.",status:408,info:"Revisa tu conexión a internet e intenta de nuevo.",type:I.WARNING,errorType:w.NETWORK_ERROR}):this.buildError({error:"Ocurrió un error inesperado al obtener los datos meteorológicos.",type:I.ERROR,status:0,errorType:w.UNKNOWN_ERROR})}}buildError({error:a,info:t,status:o,type:u,errorType:r}){return{error:a||"Error desconocido.",info:t,status:o||0,type:u||I.ERROR,errorType:r||w.UNKNOWN_ERROR}}}const ne=e=>e<0?E.UNKNOWN:e<=2?E.LOW:e<=7?E.MODERATE:E.HIGH,oe=e=>e<0?H.DESCRIPTIONS[E.UNKNOWN]:e<=2?H.DESCRIPTIONS[E.LOW]:e<=7?H.DESCRIPTIONS[E.MODERATE]:H.DESCRIPTIONS[E.HIGH];class ie{adapt(a,t,o){const u=t,r=u+1,s=t+o+1,i=this.processWeatherData(a,u,r),c=i.length>0?i[0]:{};return{pastDay:this.processWeatherData(a,0,u),currentDay:c,forecast:this.processWeatherData(a,r,s),timezone:a.timezone,latitude:a.latitude,longitude:a.longitude}}processWeatherData(a,t,o){const{daily:u}=a,r=[],{time:s,temperature_2m_max:i,temperature_2m_min:c,sunrise:m,sunset:g,daylight_duration:p}=u;for(let l=t;l<o;l++){const v={};s!=null&&s[l]&&(v.day={value:new Date(s[l]),unit:f.time}),(i==null?void 0:i[l])!==void 0&&(v.temperatureMax={value:i[l],unit:f.temperature_2m_max}),(c==null?void 0:c[l])!==void 0&&(v.temperatureMin={value:c[l],unit:f.temperature_2m_min}),m!=null&&m[l]&&(v.sunrise={value:new Date(m[l]),unit:f.sunrise}),g!=null&&g[l]&&(v.sunset={value:new Date(g[l]),unit:f.sunset}),(p==null?void 0:p[l])!==void 0&&(v.daylightDuration={value:p[l]/3600,unit:f.daylight_duration}),v.hourly=this.getHourlyData(a,l),r.push(v)}return r}getHourlyData(a,t){const{hourly:o,daily:u}=a,{time:r,temperature_2m:s,relative_humidity_2m:i,dew_point_2m:c,apparent_temperature:m,precipitation_probability:g,precipitation:p,rain:l,snowfall:v,snow_depth:b,weather_code:d,pressure_msl:T,cloud_cover:N,visibility:R,wind_direction_10m:y,wind_speed_10m:D,uv_index:U,is_day:C}=o,L=a.timezone||"UTC";let F,M,P;const W=u.time[t];if(typeof W=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(W)){const S=W.split("-").map(Number);F=S[0],M=S[1]-1,P=S[2]}else{const S=new Date(W);F=Number(S.toLocaleString("en",{timeZone:L,year:"numeric"})),M=Number(S.toLocaleString("en",{timeZone:L,month:"numeric"}))-1,P=Number(S.toLocaleString("en",{timeZone:L,day:"numeric"}))}const Y=[];for(let S=0;S<24;S++){let K=-1;for(let n=0;n<r.length;n++){const _=new Date(r[n]),O=Number(_.toLocaleString("en",{timeZone:L,year:"numeric"})),J=Number(_.toLocaleString("en",{timeZone:L,month:"numeric"}))-1,B=Number(_.toLocaleString("en",{timeZone:L,day:"numeric"})),Q=Number(_.toLocaleString("en",{timeZone:L,hour:"numeric",hour12:!1}));if(O===F&&J===M&&B===P&&Q===S){K=n;break}}if(K!==-1){const n=K,_={};if(_.hour={value:new Date(r[n]),unit:f.hour},(s==null?void 0:s[n])!==void 0&&(_.temperature={value:s[n],unit:f.temperature_2m}),(i==null?void 0:i[n])!==void 0&&(_.relativeHumidity={value:i[n],unit:f.relative_humidity_2m}),(c==null?void 0:c[n])!==void 0&&(_.dewPoint={value:c[n],unit:f.dew_point_2m}),(m==null?void 0:m[n])!==void 0&&(_.apparentTemperature={value:m[n],unit:f.apparent_temperature}),(g==null?void 0:g[n])!==void 0&&(_.precipitationProbability={value:g[n],unit:f.precipitation_probability}),(p==null?void 0:p[n])!==void 0&&(_.precipitation={value:p[n],unit:f.precipitation}),(l==null?void 0:l[n])!==void 0&&(_.rain={value:l[n],unit:f.rain}),(v==null?void 0:v[n])!==void 0&&(_.snowfall={value:v[n],unit:f.snowfall}),(b==null?void 0:b[n])!==void 0&&(_.snowDepth={value:b[n],unit:f.snow_depth}),(d==null?void 0:d[n])!==void 0){_.weatherCode={value:d[n],unit:f.weather_code};const O=re[d[n]];O&&(_.weatherDescription={value:O,unit:"text"})}if((T==null?void 0:T[n])!==void 0&&(_.pressureMsl={value:T[n],unit:f.pressure_msl}),(N==null?void 0:N[n])!==void 0&&(_.cloudCover={value:N[n],unit:f.cloud_cover}),(R==null?void 0:R[n])!==void 0&&(_.visibility={value:R[n]/1e3,unit:f.visibility}),((D==null?void 0:D[n])!==void 0||(y==null?void 0:y[n])!==void 0)&&(_.wind={speed:{value:(D==null?void 0:D[n])||0,unit:f.wind_speed_10m}},(y==null?void 0:y[n])!==void 0&&(_.wind.direction={value:y[n],unit:f.wind_direction_10m})),(U==null?void 0:U[n])!==void 0){const O=U[n];_.uv={value:O,riskLevel:ne(O),description:oe(O),unit:"index"}}(C==null?void 0:C[n])!==void 0&&(_.isDay={value:C[n],unit:f.is_day}),Y.push(_)}else{const n=new Date(Date.UTC(F,M,P,S,0,0,0));Y.push({hour:{value:n,unit:f.hour}})}}return Y}}const Z=async(e,a)=>{const{latitude:t,longitude:o,hourly:u=A.DEFAULT_HOURLY_PARAMS,daily:r=A.DEFAULT_DAILY_PARAMS,timezone:s=A.DEFAULT_TIMEZONE,past_days:i=A.DEFAULT_PAST_DAYS,forecast_days:c=A.DEFAULT_FORECAST_DAYS}=e,m=(a==null?void 0:a.client)||new ae,g=(a==null?void 0:a.adapter)||new ie,p=await m.fetchRaw({latitude:t,longitude:o,hourly:u,daily:r,timezone:s,past_days:i,forecast_days:c});return"error"in p?p:g.adapt(p,i||0,c||0)};let se=e=>Z(e);function ue(e,a){return JSON.stringify(e)===JSON.stringify(a)}const q=$.create()(ee((e,a)=>({data:null,loading:!1,error:null,autoRefresh:!0,fetchParams:null,lastFetchTime:null,cacheDuration:10*60*1e3,fetchWeather:async t=>{const o=a(),u=Date.now();if(!(o.fetchParams&&ue(o.fetchParams,t)&&o.data&&o.lastFetchTime!==null&&u-o.lastFetchTime<o.cacheDuration)){e(z.produce(s=>{s.loading=!0,s.error=null,s.fetchParams=t}));try{const s=await se(t);if("error"in s){e(z.produce(i=>{i.error=s,i.loading=!1}));return}e(z.produce(i=>{i.data=s,i.loading=!1,i.error=null,i.lastFetchTime=Date.now()}))}catch(s){const i=s instanceof Error?s.message:"Error desconocido.";e(z.produce(c=>{c.error={error:i,type:I.WARNING,errorType:w.UNKNOWN_ERROR,status:0},c.loading=!1}))}}},isLoading:()=>a().loading,hasError:()=>a().error!==null,getError:()=>a().error,clearError:()=>e(z.produce(t=>{t.error=null})),setAutoRefresh:t=>{e({autoRefresh:t}),t&&a().scheduleAutoRefresh()},scheduleAutoRefresh:()=>{const{data:t,fetchParams:o}=a();if(!t||!t.timezone||!o)return;const u=new Date().toLocaleString("es-ES",{timeZone:t.timezone}),r=new Date(u),s=new Date(r);s.setHours(24,0,0,0);const i=s.getTime()-r.getTime();setTimeout(async()=>{await a().fetchWeather(o),a().scheduleAutoRefresh()},i)},getAllWeatherData:()=>a().data,getCurrentDayWeather:()=>{var t;return((t=a().data)==null?void 0:t.currentDay)||null},getPastDayWeather:()=>{var t;return((t=a().data)==null?void 0:t.pastDay)||null},getForecastWeather:()=>{var t;return((t=a().data)==null?void 0:t.forecast)||null},getCurrentHourWeather(){var i,c;const{data:t}=a();if(!t)return null;const o=t.timezone,u=new Date().toLocaleString("en",{timeZone:o}),r=new Date(u);return((c=(i=t.currentDay)==null?void 0:i.hourly)==null?void 0:c.find(m=>m.hour?new Date(m.hour.value).getHours()===r.getHours():null))||null}}),{name:"weather-store",partialize:e=>({data:e.data,fetchParams:e.fetchParams,lastFetchTime:e.lastFetchTime,autoRefresh:e.autoRefresh})})),le=()=>{const e=q(),a=x.useCallback(async o=>{await e.fetchWeather(o)},[e.fetchWeather]);return x.useEffect(()=>{e.autoRefresh&&e.fetchParams&&e.scheduleAutoRefresh()},[e.autoRefresh,e.fetchParams]),{...x.useMemo(()=>{var o,u,r;return{data:e.data,currentDay:((o=e.data)==null?void 0:o.currentDay)||null,pastDays:((u=e.data)==null?void 0:u.pastDay)||null,forecast:((r=e.data)==null?void 0:r.forecast)||null,currentHour:e.getCurrentHourWeather(),isLoading:e.loading,error:e.error}},[e.data,e.loading,e.error]),fetchWeather:a,setAutoRefresh:e.setAutoRefresh,clearError:e.clearError}};exports.fetchWeather=Z;exports.useWeather=le;exports.useWeatherStore=q;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react"),$=require("zustand"),z=require("immer");function V(e,a){let t;try{t=e()}catch{return}return{getItem:u=>{var r;const s=c=>c===null?null:JSON.parse(c,void 0),i=(r=t.getItem(u))!=null?r:null;return i instanceof Promise?i.then(s):s(i)},setItem:(u,r)=>t.setItem(u,JSON.stringify(r,void 0)),removeItem:u=>t.removeItem(u)}}const j=e=>a=>{try{const t=e(a);return t instanceof Promise?t:{then(o){return j(o)(t)},catch(o){return this}}}catch(t){return{then(o){return this},catch(o){return j(o)(t)}}}},X=(e,a)=>(t,o,u)=>{let r={storage:V(()=>localStorage),partialize:d=>d,version:0,merge:(d,T)=>({...T,...d}),...a},s=!1;const i=new Set,c=new Set;let m=r.storage;if(!m)return e((...d)=>{console.warn(`[zustand persist middleware] Unable to update item '${r.name}', the given storage is currently unavailable.`),t(...d)},o,u);const g=()=>{const d=r.partialize({...o()});return m.setItem(r.name,{state:d,version:r.version})},p=u.setState;u.setState=(d,T)=>{p(d,T),g()};const l=e((...d)=>{t(...d),g()},o,u);u.getInitialState=()=>l;let v;const b=()=>{var d,T;if(!m)return;s=!1,i.forEach(R=>{var y;return R((y=o())!=null?y:l)});const w=((T=r.onRehydrateStorage)==null?void 0:T.call(r,(d=o())!=null?d:l))||void 0;return j(m.getItem.bind(m))(r.name).then(R=>{if(R)if(typeof R.version=="number"&&R.version!==r.version){if(r.migrate){const y=r.migrate(R.state,R.version);return y instanceof Promise?y.then(D=>[!0,D]):[!0,y]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,R.state];return[!1,void 0]}).then(R=>{var y;const[D,U]=R;if(v=r.merge(U,(y=o())!=null?y:l),t(v,!0),D)return g()}).then(()=>{w==null||w(v,void 0),v=o(),s=!0,c.forEach(R=>R(v))}).catch(R=>{w==null||w(void 0,R)})};return u.persist={setOptions:d=>{r={...r,...d},d.storage&&(m=d.storage)},clearStorage:()=>{m==null||m.removeItem(r.name)},getOptions:()=>r,rehydrate:()=>b(),hasHydrated:()=>s,onHydrate:d=>(i.add(d),()=>{i.delete(d)}),onFinishHydration:d=>(c.add(d),()=>{c.delete(d)})},r.skipHydration||b(),v||l},ee=X;var L=(e=>(e.SUCCESS="success",e.ERROR="error",e.WARNING="warning",e.INFO="info",e))(L||{}),N=(e=>(e.NETWORK_ERROR="network_error",e.API_ERROR="api_error",e.DATA_ERROR="data_error",e.UNKNOWN_ERROR="unknown_error",e))(N||{}),Y=(e=>(e.Temperature="temperature_2m",e.RelativeHumidity="relative_humidity_2m",e.DewPoint="dew_point_2m",e.ApparentTemperature="apparent_temperature",e.PrecipitationProbability="precipitation_probability",e.Precipitation="precipitation",e.Rain="rain",e.Snowfall="snowfall",e.SnowDepth="snow_depth",e.WeatherCode="weather_code",e.PressureMsl="pressure_msl",e.CloudCover="cloud_cover",e.Visibility="visibility",e.WindSpeed="wind_speed_10m",e.WindDirection="wind_direction_10m",e.UvIndex="uv_index",e.IsDay="is_day",e))(Y||{}),K=(e=>(e.TemperatureMax="temperature_2m_max",e.TemperatureMin="temperature_2m_min",e.Sunrise="sunrise",e.Sunset="sunset",e.DaylightDuration="daylight_duration",e))(K||{}),E=(e=>(e.UNKNOWN="Desconocido",e.LOW="Bajo",e.MODERATE="Moderado",e.HIGH="Alto",e))(E||{}),h=(e=>(e.clear_sky="Cielo despejado",e.mainly_clear="Mayormente despejado",e.partly_cloudy="Parcialmente nublado",e.overcast="Mayormente nublado",e.fog="Niebla",e.depositing_rime_fog="Niebla con escarcha",e.drizzle_light="Llovizna ligera",e.drizzle_moderate="Llovizna moderada",e.drizzle_dense="Llovizna densa",e.freezing_drizzle_light="Llovizna helada ligera",e.freezing_drizzle_dense="Llovizna helada densa",e.rain_slight="Lluvia ligera",e.rain_moderate="Lluvia moderada",e.rain_heavy="Lluvia intensa",e.freezing_rain_light="Lluvia helada ligera",e.freezing_rain_heavy="Lluvia helada intensa",e.snowfall_slight="Nevada ligera",e.snowfall_moderate="Nevada moderada",e.snowfall_heavy="Nevada intensa",e.snow_grains="Precipitación de granos de nieve",e.rain_showers_slight="Chubascos ligeros",e.rain_showers_moderate="Chubascos moderados",e.rain_showers_violent="Chubascos violentos",e.snow_showers_slight="Chubascos de nieve ligeros",e.snow_showers_heavy="Chubascos de nieve intensos",e.thunderstorm="Tormenta",e))(h||{});const te="https://api.open-meteo.com/v1/forecast",A={DEFAULT_TIMEZONE:"America/Sao_Paulo",DEFAULT_HOURLY_PARAMS:[Y.Temperature,Y.WeatherCode],DEFAULT_DAILY_PARAMS:[K.TemperatureMax,K.TemperatureMin],DEFAULT_PAST_DAYS:0,DEFAULT_FORECAST_DAYS:7,DEFAULT_CACHE_DURATION:10*60*1e3,REQUEST_TIMEOUT:1e4},H={RANGES:{[E.LOW]:{},[E.MODERATE]:{},[E.HIGH]:{}},DESCRIPTIONS:{[E.UNKNOWN]:"No se puede determinar el riesgo de exposición",[E.LOW]:"Puedes disfrutar de estar afuera con seguridad",[E.MODERATE]:"Busca sombra durante las horas del mediodía. Ponte una remera, utiliza protector solar y un sombrero.",[E.HIGH]:"Evita estar afuera durante las horas del mediodía. Asegúrate de buscar sombra. La remera, el protector solar y el sombrero son imprescindibles."}},re={0:h.clear_sky,1:h.mainly_clear,2:h.partly_cloudy,3:h.overcast,45:h.fog,48:h.depositing_rime_fog,51:h.drizzle_light,53:h.drizzle_moderate,55:h.drizzle_dense,56:h.freezing_drizzle_light,57:h.freezing_drizzle_dense,61:h.rain_slight,63:h.rain_moderate,65:h.rain_heavy,66:h.freezing_rain_light,67:h.freezing_rain_heavy,71:h.snowfall_slight,73:h.snowfall_moderate,75:h.snowfall_heavy,77:h.snow_grains,80:h.rain_showers_slight,81:h.rain_showers_moderate,82:h.rain_showers_violent,85:h.snow_showers_slight,86:h.snow_showers_heavy,95:h.thunderstorm},f={time:"iso8601",hour:"iso8601",temperature_2m:"ºC",temperature_2m_max:"ºC",temperature_2m_min:"ºC",dew_point_2m:"ºC",apparent_temperature:"ºC",relative_humidity_2m:"%",precipitation_probability:"%",precipitation:"mm",rain:"mm",snowfall:"cm",snow_depth:"m",pressure_msl:"hPa",wind_speed_10m:"km/h",wind_direction_10m:"°",cloud_cover:"%",visibility:"km",weather_code:"wmo code",sunrise:"iso8601",sunset:"iso8601",daylight_duration:"h",is_day:"flag"};class ae{async fetchRaw({latitude:a,longitude:t,hourly:o=A.DEFAULT_HOURLY_PARAMS,daily:u=A.DEFAULT_DAILY_PARAMS,timezone:r=A.DEFAULT_TIMEZONE,past_days:s=A.DEFAULT_PAST_DAYS,forecast_days:i=A.DEFAULT_FORECAST_DAYS}){try{const c=new URL(te),m=new URLSearchParams({latitude:a.toString(),longitude:t.toString(),hourly:o.join(","),daily:u.join(","),timezone:r,past_days:s.toString(),forecast_days:i.toString()});c.search=m.toString();const g=new AbortController,p=setTimeout(()=>g.abort(),A.REQUEST_TIMEOUT),l=await fetch(c.toString(),{signal:g.signal});return clearTimeout(p),l.ok?await l.json():l.status>=500?this.buildError({error:"Debido a un problema en el servidor, no podemos obtener la información del clima.",info:"Por favor, inténtalo de nuevo más tarde.",status:l.status,errorType:N.API_ERROR}):l.status>=400?l.status===408?this.buildError({error:"La solicitud ha tardado demasiado tiempo en completarse.",status:408,info:"Revisa tu conexión a internet e intenta de nuevo.",type:L.WARNING,errorType:N.NETWORK_ERROR}):this.buildError({error:"No pudimos obtener la información del clima.",info:"Verifica que la ubicación ingresada sea correcta e inténtalo de nuevo.",status:l.status,type:L.WARNING,errorType:N.API_ERROR}):this.buildError({error:"Ocurrió un error al obtener los datos del clima.",status:l.status,errorType:N.UNKNOWN_ERROR})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?this.buildError({error:"La solicitud ha tardado demasiado tiempo en completarse.",status:408,info:"Revisa tu conexión a internet e intenta de nuevo.",type:L.WARNING,errorType:N.NETWORK_ERROR}):this.buildError({error:"Ocurrió un error inesperado al obtener los datos meteorológicos.",type:L.ERROR,status:0,errorType:N.UNKNOWN_ERROR})}}buildError({error:a,info:t,status:o,type:u,errorType:r}){return{error:a||"Error desconocido.",info:t,status:o||0,type:u||L.ERROR,errorType:r||N.UNKNOWN_ERROR}}}const ne=e=>e<0?E.UNKNOWN:e<=2?E.LOW:e<=7?E.MODERATE:E.HIGH,oe=e=>e<0?H.DESCRIPTIONS[E.UNKNOWN]:e<=2?H.DESCRIPTIONS[E.LOW]:e<=7?H.DESCRIPTIONS[E.MODERATE]:H.DESCRIPTIONS[E.HIGH];class ie{adapt(a,t,o){const u=t,r=u+1,s=t+o+1,i=this.processWeatherData(a,u,r),c=i.length>0?i[0]:{};return{pastDay:this.processWeatherData(a,0,u),currentDay:c,forecast:this.processWeatherData(a,r,s),timezone:a.timezone,latitude:a.latitude,longitude:a.longitude}}processWeatherData(a,t,o){const{daily:u}=a,r=[],{time:s,temperature_2m_max:i,temperature_2m_min:c,sunrise:m,sunset:g,daylight_duration:p}=u;for(let l=t;l<o;l++){const v={};s!=null&&s[l]&&(v.day={value:new Date(s[l]),unit:f.time}),(i==null?void 0:i[l])!==void 0&&(v.temperatureMax={value:i[l],unit:f.temperature_2m_max}),(c==null?void 0:c[l])!==void 0&&(v.temperatureMin={value:c[l],unit:f.temperature_2m_min}),m!=null&&m[l]&&(v.sunrise={value:new Date(m[l]),unit:f.sunrise}),g!=null&&g[l]&&(v.sunset={value:new Date(g[l]),unit:f.sunset}),(p==null?void 0:p[l])!==void 0&&(v.daylightDuration={value:p[l]/3600,unit:f.daylight_duration}),v.hourly=this.getHourlyData(a,l),r.push(v)}return r}getHourlyData(a,t){const{hourly:o,daily:u}=a,{time:r,temperature_2m:s,relative_humidity_2m:i,dew_point_2m:c,apparent_temperature:m,precipitation_probability:g,precipitation:p,rain:l,snowfall:v,snow_depth:b,weather_code:d,pressure_msl:T,cloud_cover:w,visibility:R,wind_direction_10m:y,wind_speed_10m:D,uv_index:U,is_day:C}=o,I=a.timezone||"UTC";let M,F,P;const W=u.time[t];if(typeof W=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(W)){const S=W.split("-").map(Number);M=S[0],F=S[1]-1,P=S[2]}else{const S=new Date(W);M=Number(S.toLocaleString("en",{timeZone:I,year:"numeric"})),F=Number(S.toLocaleString("en",{timeZone:I,month:"numeric"}))-1,P=Number(S.toLocaleString("en",{timeZone:I,day:"numeric"}))}const G=[];for(let S=0;S<24;S++){let x=-1;for(let n=0;n<r.length;n++){const _=new Date(r[n]),O=Number(_.toLocaleString("en",{timeZone:I,year:"numeric"})),J=Number(_.toLocaleString("en",{timeZone:I,month:"numeric"}))-1,B=Number(_.toLocaleString("en",{timeZone:I,day:"numeric"})),Q=Number(_.toLocaleString("en",{timeZone:I,hour:"numeric",hour12:!1}));if(O===M&&J===F&&B===P&&Q===S){x=n;break}}if(x!==-1){const n=x,_={};if(_.hour={value:new Date(r[n]),unit:f.hour},(s==null?void 0:s[n])!==void 0&&(_.temperature={value:s[n],unit:f.temperature_2m}),(i==null?void 0:i[n])!==void 0&&(_.relativeHumidity={value:i[n],unit:f.relative_humidity_2m}),(c==null?void 0:c[n])!==void 0&&(_.dewPoint={value:c[n],unit:f.dew_point_2m}),(m==null?void 0:m[n])!==void 0&&(_.apparentTemperature={value:m[n],unit:f.apparent_temperature}),(g==null?void 0:g[n])!==void 0&&(_.precipitationProbability={value:g[n],unit:f.precipitation_probability}),(p==null?void 0:p[n])!==void 0&&(_.precipitation={value:p[n],unit:f.precipitation}),(l==null?void 0:l[n])!==void 0&&(_.rain={value:l[n],unit:f.rain}),(v==null?void 0:v[n])!==void 0&&(_.snowfall={value:v[n],unit:f.snowfall}),(b==null?void 0:b[n])!==void 0&&(_.snowDepth={value:b[n],unit:f.snow_depth}),(d==null?void 0:d[n])!==void 0){_.weatherCode={value:d[n],unit:f.weather_code};const O=re[d[n]];O&&(_.weatherDescription={value:O,unit:"text"})}if((T==null?void 0:T[n])!==void 0&&(_.pressureMsl={value:T[n],unit:f.pressure_msl}),(w==null?void 0:w[n])!==void 0&&(_.cloudCover={value:w[n],unit:f.cloud_cover}),(R==null?void 0:R[n])!==void 0&&(_.visibility={value:R[n]/1e3,unit:f.visibility}),((D==null?void 0:D[n])!==void 0||(y==null?void 0:y[n])!==void 0)&&(_.wind={speed:{value:(D==null?void 0:D[n])||0,unit:f.wind_speed_10m}},(y==null?void 0:y[n])!==void 0&&(_.wind.direction={value:y[n],unit:f.wind_direction_10m})),(U==null?void 0:U[n])!==void 0){const O=U[n];_.uv={value:O,riskLevel:ne(O),description:oe(O),unit:"index"}}(C==null?void 0:C[n])!==void 0&&(_.isDay={value:C[n],unit:f.is_day}),G.push(_)}else{const n=new Date(Date.UTC(M,F,P,S,0,0,0));G.push({hour:{value:n,unit:f.hour}})}}return G}}const Z=async(e,a)=>{const{latitude:t,longitude:o,hourly:u=A.DEFAULT_HOURLY_PARAMS,daily:r=A.DEFAULT_DAILY_PARAMS,timezone:s=A.DEFAULT_TIMEZONE,past_days:i=A.DEFAULT_PAST_DAYS,forecast_days:c=A.DEFAULT_FORECAST_DAYS}=e,m=(a==null?void 0:a.client)||new ae,g=(a==null?void 0:a.adapter)||new ie,p=await m.fetchRaw({latitude:t,longitude:o,hourly:u,daily:r,timezone:s,past_days:i,forecast_days:c});return"error"in p?p:g.adapt(p,i||0,c||0)};let se=e=>Z(e);function ue(e,a){return JSON.stringify(e)===JSON.stringify(a)}const q=$.create()(ee((e,a)=>({data:null,loading:!1,error:null,autoRefresh:!0,fetchParams:null,lastFetchTime:null,cacheDuration:10*60*1e3,fetchWeather:async t=>{const o=a(),u=Date.now();if(!(o.fetchParams&&ue(o.fetchParams,t)&&o.data&&o.lastFetchTime!==null&&u-o.lastFetchTime<o.cacheDuration)){e(z.produce(s=>{s.loading=!0,s.error=null,s.fetchParams=t}));try{const s=await se(t);if("error"in s){e(z.produce(i=>{i.error=s,i.loading=!1}));return}e(z.produce(i=>{i.data=s,i.loading=!1,i.error=null,i.lastFetchTime=Date.now()}))}catch(s){const i=s instanceof Error?s.message:"Error desconocido.";e(z.produce(c=>{c.error={error:i,type:L.WARNING,errorType:N.UNKNOWN_ERROR,status:0},c.loading=!1}))}}},isLoading:()=>a().loading,hasError:()=>a().error!==null,getError:()=>a().error,clearError:()=>e(z.produce(t=>{t.error=null})),setAutoRefresh:t=>{e({autoRefresh:t}),t&&a().scheduleAutoRefresh()},scheduleAutoRefresh:()=>{const{data:t,fetchParams:o}=a();if(!t||!t.timezone||!o)return;const u=new Date().toLocaleString("es-ES",{timeZone:t.timezone}),r=new Date(u),s=new Date(r);s.setHours(24,0,0,0);const i=s.getTime()-r.getTime();setTimeout(async()=>{await a().fetchWeather(o),a().scheduleAutoRefresh()},i)},getAllWeatherData:()=>a().data,getCurrentDayWeather:()=>{var t;return((t=a().data)==null?void 0:t.currentDay)||null},getPastDayWeather:()=>{var t;return((t=a().data)==null?void 0:t.pastDay)||null},getForecastWeather:()=>{var t;return((t=a().data)==null?void 0:t.forecast)||null},getCurrentHourWeather(){var i,c;const{data:t}=a();if(!t)return null;const o=t.timezone,u=new Date().toLocaleString("en",{timeZone:o}),r=new Date(u);return((c=(i=t.currentDay)==null?void 0:i.hourly)==null?void 0:c.find(m=>m.hour?new Date(m.hour.value).getHours()===r.getHours():null))||null}}),{name:"weather-store",partialize:e=>({data:e.data,fetchParams:e.fetchParams,lastFetchTime:e.lastFetchTime,autoRefresh:e.autoRefresh})})),le=()=>{const e=q(),a=k.useCallback(async o=>{await e.fetchWeather(o)},[e.fetchWeather]);return k.useEffect(()=>{e.autoRefresh&&e.fetchParams&&e.scheduleAutoRefresh()},[e.autoRefresh,e.fetchParams]),{...k.useMemo(()=>{var o,u,r;return{data:e.data,currentDay:((o=e.data)==null?void 0:o.currentDay)||null,pastDays:((u=e.data)==null?void 0:u.pastDay)||null,forecast:((r=e.data)==null?void 0:r.forecast)||null,currentHour:e.getCurrentHourWeather(),isLoading:e.loading,error:e.error}},[e.data,e.loading,e.error]),fetchWeather:a,setAutoRefresh:e.setAutoRefresh,clearError:e.clearError}};exports.DailyParams=K;exports.ErrorType=N;exports.HourlyParams=Y;exports.MessageType=L;exports.fetchWeather=Z;exports.useWeather=le;exports.useWeatherStore=q;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ export { fetchWeather } from "./services/weatherService";
|
|
|
18
18
|
* Este módulo contiene las propiedades necesarias para realizar una solicitud de datos
|
|
19
19
|
* meteorológicos.
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export { DailyParams, HourlyParams, MessageType, ErrorType } from "./types/weatherTypes";
|
|
22
|
+
export type { FetchWeatherProps, StructureWeatherData, FetchError, DailyWeatherData, HourlyWeatherData, WeatherValue, DateValue, TextValue, WindData, UVData, UvRiskLevels, WeatherDescriptions, } from "./types/weatherTypes";
|
package/dist/index.esm.js
CHANGED
|
@@ -47,8 +47,8 @@ const x = (e) => (a) => {
|
|
|
47
47
|
storage: V(() => localStorage),
|
|
48
48
|
partialize: (c) => c,
|
|
49
49
|
version: 0,
|
|
50
|
-
merge: (c,
|
|
51
|
-
...
|
|
50
|
+
merge: (c, A) => ({
|
|
51
|
+
...A,
|
|
52
52
|
...c
|
|
53
53
|
}),
|
|
54
54
|
...a
|
|
@@ -72,8 +72,8 @@ const x = (e) => (a) => {
|
|
|
72
72
|
version: r.version
|
|
73
73
|
});
|
|
74
74
|
}, p = u.setState;
|
|
75
|
-
u.setState = (c,
|
|
76
|
-
p(c,
|
|
75
|
+
u.setState = (c, A) => {
|
|
76
|
+
p(c, A), g();
|
|
77
77
|
};
|
|
78
78
|
const l = e(
|
|
79
79
|
(...c) => {
|
|
@@ -85,13 +85,13 @@ const x = (e) => (a) => {
|
|
|
85
85
|
u.getInitialState = () => l;
|
|
86
86
|
let v;
|
|
87
87
|
const L = () => {
|
|
88
|
-
var c,
|
|
88
|
+
var c, A;
|
|
89
89
|
if (!m) return;
|
|
90
90
|
s = !1, i.forEach((R) => {
|
|
91
91
|
var y;
|
|
92
92
|
return R((y = o()) != null ? y : l);
|
|
93
93
|
});
|
|
94
|
-
const N = ((
|
|
94
|
+
const N = ((A = r.onRehydrateStorage) == null ? void 0 : A.call(r, (c = o()) != null ? c : l)) || void 0;
|
|
95
95
|
return x(m.getItem.bind(m))(r.name).then((R) => {
|
|
96
96
|
if (R)
|
|
97
97
|
if (typeof R.version == "number" && R.version !== r.version) {
|
|
@@ -143,19 +143,19 @@ const x = (e) => (a) => {
|
|
|
143
143
|
})
|
|
144
144
|
}, r.skipHydration || L(), v || l;
|
|
145
145
|
}, ee = X;
|
|
146
|
-
var I = /* @__PURE__ */ ((e) => (e.SUCCESS = "success", e.ERROR = "error", e.WARNING = "warning", e.INFO = "info", e))(I || {}), w = /* @__PURE__ */ ((e) => (e.NETWORK_ERROR = "network_error", e.API_ERROR = "api_error", e.DATA_ERROR = "data_error", e.UNKNOWN_ERROR = "unknown_error", e))(w || {}),
|
|
147
|
-
const te = "https://api.open-meteo.com/v1/forecast",
|
|
146
|
+
var I = /* @__PURE__ */ ((e) => (e.SUCCESS = "success", e.ERROR = "error", e.WARNING = "warning", e.INFO = "info", e))(I || {}), w = /* @__PURE__ */ ((e) => (e.NETWORK_ERROR = "network_error", e.API_ERROR = "api_error", e.DATA_ERROR = "data_error", e.UNKNOWN_ERROR = "unknown_error", e))(w || {}), G = /* @__PURE__ */ ((e) => (e.Temperature = "temperature_2m", e.RelativeHumidity = "relative_humidity_2m", e.DewPoint = "dew_point_2m", e.ApparentTemperature = "apparent_temperature", e.PrecipitationProbability = "precipitation_probability", e.Precipitation = "precipitation", e.Rain = "rain", e.Snowfall = "snowfall", e.SnowDepth = "snow_depth", e.WeatherCode = "weather_code", e.PressureMsl = "pressure_msl", e.CloudCover = "cloud_cover", e.Visibility = "visibility", e.WindSpeed = "wind_speed_10m", e.WindDirection = "wind_direction_10m", e.UvIndex = "uv_index", e.IsDay = "is_day", e))(G || {}), k = /* @__PURE__ */ ((e) => (e.TemperatureMax = "temperature_2m_max", e.TemperatureMin = "temperature_2m_min", e.Sunrise = "sunrise", e.Sunset = "sunset", e.DaylightDuration = "daylight_duration", e))(k || {}), E = /* @__PURE__ */ ((e) => (e.UNKNOWN = "Desconocido", e.LOW = "Bajo", e.MODERATE = "Moderado", e.HIGH = "Alto", e))(E || {}), h = /* @__PURE__ */ ((e) => (e.clear_sky = "Cielo despejado", e.mainly_clear = "Mayormente despejado", e.partly_cloudy = "Parcialmente nublado", e.overcast = "Mayormente nublado", e.fog = "Niebla", e.depositing_rime_fog = "Niebla con escarcha", e.drizzle_light = "Llovizna ligera", e.drizzle_moderate = "Llovizna moderada", e.drizzle_dense = "Llovizna densa", e.freezing_drizzle_light = "Llovizna helada ligera", e.freezing_drizzle_dense = "Llovizna helada densa", e.rain_slight = "Lluvia ligera", e.rain_moderate = "Lluvia moderada", e.rain_heavy = "Lluvia intensa", e.freezing_rain_light = "Lluvia helada ligera", e.freezing_rain_heavy = "Lluvia helada intensa", e.snowfall_slight = "Nevada ligera", e.snowfall_moderate = "Nevada moderada", e.snowfall_heavy = "Nevada intensa", e.snow_grains = "Precipitación de granos de nieve", e.rain_showers_slight = "Chubascos ligeros", e.rain_showers_moderate = "Chubascos moderados", e.rain_showers_violent = "Chubascos violentos", e.snow_showers_slight = "Chubascos de nieve ligeros", e.snow_showers_heavy = "Chubascos de nieve intensos", e.thunderstorm = "Tormenta", e))(h || {});
|
|
147
|
+
const te = "https://api.open-meteo.com/v1/forecast", T = {
|
|
148
148
|
/** Zona horaria por defecto para las consultas */
|
|
149
149
|
DEFAULT_TIMEZONE: "America/Sao_Paulo",
|
|
150
150
|
/** Parámetros meteorológicos por hora solicitados por defecto */
|
|
151
151
|
DEFAULT_HOURLY_PARAMS: [
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
G.Temperature,
|
|
153
|
+
G.WeatherCode
|
|
154
154
|
],
|
|
155
155
|
/** Parámetros meteorológicos diarios solicitados por defecto */
|
|
156
156
|
DEFAULT_DAILY_PARAMS: [
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
k.TemperatureMax,
|
|
158
|
+
k.TemperatureMin
|
|
159
159
|
],
|
|
160
160
|
/** Número de días pasados a incluir por defecto */
|
|
161
161
|
DEFAULT_PAST_DAYS: 0,
|
|
@@ -166,6 +166,12 @@ const te = "https://api.open-meteo.com/v1/forecast", A = {
|
|
|
166
166
|
/** Timeout para las solicitudes HTTP en milisegundos */
|
|
167
167
|
REQUEST_TIMEOUT: 1e4
|
|
168
168
|
}, H = {
|
|
169
|
+
/** Rangos de índice UV para cada nivel de riesgo */
|
|
170
|
+
RANGES: {
|
|
171
|
+
[E.LOW]: {},
|
|
172
|
+
[E.MODERATE]: {},
|
|
173
|
+
[E.HIGH]: {}
|
|
174
|
+
},
|
|
169
175
|
/** Descripciones de recomendaciones por nivel de riesgo UV */
|
|
170
176
|
DESCRIPTIONS: {
|
|
171
177
|
[E.UNKNOWN]: "No se puede determinar el riesgo de exposición",
|
|
@@ -242,11 +248,11 @@ class ae {
|
|
|
242
248
|
async fetchRaw({
|
|
243
249
|
latitude: a,
|
|
244
250
|
longitude: t,
|
|
245
|
-
hourly: o =
|
|
246
|
-
daily: u =
|
|
247
|
-
timezone: r =
|
|
248
|
-
past_days: s =
|
|
249
|
-
forecast_days: i =
|
|
251
|
+
hourly: o = T.DEFAULT_HOURLY_PARAMS,
|
|
252
|
+
daily: u = T.DEFAULT_DAILY_PARAMS,
|
|
253
|
+
timezone: r = T.DEFAULT_TIMEZONE,
|
|
254
|
+
past_days: s = T.DEFAULT_PAST_DAYS,
|
|
255
|
+
forecast_days: i = T.DEFAULT_FORECAST_DAYS
|
|
250
256
|
}) {
|
|
251
257
|
try {
|
|
252
258
|
const d = new URL(te), m = new URLSearchParams({
|
|
@@ -259,7 +265,7 @@ class ae {
|
|
|
259
265
|
forecast_days: i.toString()
|
|
260
266
|
});
|
|
261
267
|
d.search = m.toString();
|
|
262
|
-
const g = new AbortController(), p = setTimeout(() => g.abort(),
|
|
268
|
+
const g = new AbortController(), p = setTimeout(() => g.abort(), T.REQUEST_TIMEOUT), l = await fetch(d.toString(), {
|
|
263
269
|
signal: g.signal
|
|
264
270
|
});
|
|
265
271
|
return clearTimeout(p), l.ok ? await l.json() : l.status >= 500 ? this.buildError({
|
|
@@ -366,7 +372,7 @@ class ie {
|
|
|
366
372
|
snowfall: v,
|
|
367
373
|
snow_depth: L,
|
|
368
374
|
weather_code: c,
|
|
369
|
-
pressure_msl:
|
|
375
|
+
pressure_msl: A,
|
|
370
376
|
cloud_cover: N,
|
|
371
377
|
visibility: R,
|
|
372
378
|
wind_direction_10m: y,
|
|
@@ -437,8 +443,8 @@ class ie {
|
|
|
437
443
|
const O = re[c[n]];
|
|
438
444
|
O && (_.weatherDescription = { value: O, unit: "text" });
|
|
439
445
|
}
|
|
440
|
-
if ((
|
|
441
|
-
value:
|
|
446
|
+
if ((A == null ? void 0 : A[n]) !== void 0 && (_.pressureMsl = {
|
|
447
|
+
value: A[n],
|
|
442
448
|
unit: f.pressure_msl
|
|
443
449
|
}), (N == null ? void 0 : N[n]) !== void 0 && (_.cloudCover = {
|
|
444
450
|
value: N[n],
|
|
@@ -478,11 +484,11 @@ const se = async (e, a) => {
|
|
|
478
484
|
const {
|
|
479
485
|
latitude: t,
|
|
480
486
|
longitude: o,
|
|
481
|
-
hourly: u =
|
|
482
|
-
daily: r =
|
|
483
|
-
timezone: s =
|
|
484
|
-
past_days: i =
|
|
485
|
-
forecast_days: d =
|
|
487
|
+
hourly: u = T.DEFAULT_HOURLY_PARAMS,
|
|
488
|
+
daily: r = T.DEFAULT_DAILY_PARAMS,
|
|
489
|
+
timezone: s = T.DEFAULT_TIMEZONE,
|
|
490
|
+
past_days: i = T.DEFAULT_PAST_DAYS,
|
|
491
|
+
forecast_days: d = T.DEFAULT_FORECAST_DAYS
|
|
486
492
|
} = e, m = (a == null ? void 0 : a.client) || new ae(), g = (a == null ? void 0 : a.adapter) || new ie(), p = await m.fetchRaw({
|
|
487
493
|
latitude: t,
|
|
488
494
|
longitude: o,
|
|
@@ -667,6 +673,10 @@ const de = $()(
|
|
|
667
673
|
};
|
|
668
674
|
};
|
|
669
675
|
export {
|
|
676
|
+
k as DailyParams,
|
|
677
|
+
w as ErrorType,
|
|
678
|
+
G as HourlyParams,
|
|
679
|
+
I as MessageType,
|
|
670
680
|
se as fetchWeather,
|
|
671
681
|
_e as useWeather,
|
|
672
682
|
de as useWeatherStore
|