@happyvertical/weather 0.89.5 → 0.89.7
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/dist/index.js +38 -29
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -301,7 +301,11 @@ function D(e) {
|
|
|
301
301
|
}
|
|
302
302
|
//#endregion
|
|
303
303
|
//#region src/providers/google-weather.ts
|
|
304
|
-
|
|
304
|
+
function O(e) {
|
|
305
|
+
let t = e.toLowerCase();
|
|
306
|
+
return t.includes("api_key_invalid") || t.includes("api key not valid");
|
|
307
|
+
}
|
|
308
|
+
var k = class {
|
|
305
309
|
name = "Google Weather";
|
|
306
310
|
providerType = "commercial";
|
|
307
311
|
apiBase = "https://weather.googleapis.com/v1";
|
|
@@ -373,11 +377,16 @@ var O = class {
|
|
|
373
377
|
return !i.alerts || i.alerts.length === 0 ? [] : i.alerts.map((e) => this.transformAlert(e));
|
|
374
378
|
}
|
|
375
379
|
async testConnection() {
|
|
380
|
+
let e = new AbortController(), t = setTimeout(() => e.abort(), this.timeout);
|
|
376
381
|
try {
|
|
377
|
-
let
|
|
378
|
-
|
|
382
|
+
let t = this.buildUrl("/forecast/days:lookup", 37.422, -122.084, "&days=1"), n = await fetch(t, { signal: e.signal });
|
|
383
|
+
if (!n.ok) return !1;
|
|
384
|
+
let r = await n.json();
|
|
385
|
+
return Array.isArray(r?.forecastDays) && r.forecastDays.length > 0;
|
|
379
386
|
} catch {
|
|
380
387
|
return !1;
|
|
388
|
+
} finally {
|
|
389
|
+
clearTimeout(t);
|
|
381
390
|
}
|
|
382
391
|
}
|
|
383
392
|
async supportsLocation(e, t) {
|
|
@@ -404,7 +413,7 @@ var O = class {
|
|
|
404
413
|
if (e.status === 401 || e.status === 403) throw new r(this.name, "Invalid API key");
|
|
405
414
|
if (e.status === 429) throw new n(this.name);
|
|
406
415
|
let i = await e.text();
|
|
407
|
-
throw new t(`API request failed: ${e.statusText} - ${i}`, this.name, `HTTP_${e.status}`);
|
|
416
|
+
throw e.status === 400 && O(i) ? new r(this.name, "Invalid API key") : new t(`API request failed: ${e.statusText} - ${i}`, this.name, `HTTP_${e.status}`);
|
|
408
417
|
}
|
|
409
418
|
transformCurrentConditions(e) {
|
|
410
419
|
return {
|
|
@@ -495,7 +504,7 @@ var O = class {
|
|
|
495
504
|
raw: e
|
|
496
505
|
};
|
|
497
506
|
}
|
|
498
|
-
},
|
|
507
|
+
}, A = 7200 * 60 * 1e3, j = class {
|
|
499
508
|
name = "Open-Meteo";
|
|
500
509
|
providerType = "community";
|
|
501
510
|
forecastApiBase = "https://api.open-meteo.com/v1/forecast";
|
|
@@ -514,7 +523,7 @@ var O = class {
|
|
|
514
523
|
}
|
|
515
524
|
async fetchHistoricalForLocation(e, n, r) {
|
|
516
525
|
m(this.name, e, n);
|
|
517
|
-
let i = c(this.name, r), o = /* @__PURE__ */ new Date(Date.now() -
|
|
526
|
+
let i = c(this.name, r), o = /* @__PURE__ */ new Date(Date.now() - A);
|
|
518
527
|
if (i.end.getTime() > o.getTime()) throw new t("Open-Meteo archive data is published with a 5-7 day lag", this.name, "INVALID_DATE_RANGE", {
|
|
519
528
|
requestedEnd: i.end.toISOString(),
|
|
520
529
|
latestSupportedEnd: o.toISOString()
|
|
@@ -576,7 +585,7 @@ var O = class {
|
|
|
576
585
|
if (!n?.time?.length) return [];
|
|
577
586
|
let r = [];
|
|
578
587
|
for (let i = 0; i < n.time.length; i++) {
|
|
579
|
-
let a =
|
|
588
|
+
let a = N(n.time[i]), o = n.temperature_2m?.[i], s = M(n.relative_humidity_2m?.[i]), c = M(n.wind_speed_10m?.[i]);
|
|
580
589
|
if (Number.isNaN(a.getTime()) || typeof o != "number" || s === void 0 || c === void 0) continue;
|
|
581
590
|
let l = n.weather_code?.[i];
|
|
582
591
|
r.push({
|
|
@@ -584,12 +593,12 @@ var O = class {
|
|
|
584
593
|
temperature: x(o),
|
|
585
594
|
humidity: x(s),
|
|
586
595
|
windSpeed: x(c),
|
|
587
|
-
windDirection:
|
|
596
|
+
windDirection: M(n.wind_direction_10m?.[i]),
|
|
588
597
|
windGust: typeof n.wind_gusts_10m?.[i] == "number" ? x(n.wind_gusts_10m[i]) : void 0,
|
|
589
|
-
conditions:
|
|
590
|
-
cloudCover:
|
|
598
|
+
conditions: P(l),
|
|
599
|
+
cloudCover: M(n.cloud_cover?.[i]),
|
|
591
600
|
visibility: typeof n.visibility?.[i] == "number" ? x(y(n.visibility[i])) : void 0,
|
|
592
|
-
precipAmount:
|
|
601
|
+
precipAmount: M(n.precipitation?.[i]),
|
|
593
602
|
confidence: t === "open-meteo-archive" ? 100 : 90,
|
|
594
603
|
raw: {
|
|
595
604
|
source: t,
|
|
@@ -604,14 +613,14 @@ var O = class {
|
|
|
604
613
|
return r.sort((e, t) => e.timestamp.getTime() - t.timestamp.getTime());
|
|
605
614
|
}
|
|
606
615
|
};
|
|
607
|
-
function
|
|
616
|
+
function M(e) {
|
|
608
617
|
return typeof e == "number" ? e : void 0;
|
|
609
618
|
}
|
|
610
|
-
function
|
|
619
|
+
function N(e) {
|
|
611
620
|
let t = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(e);
|
|
612
621
|
return new Date(t ? e : `${e}Z`);
|
|
613
622
|
}
|
|
614
|
-
function
|
|
623
|
+
function P(e) {
|
|
615
624
|
switch (e) {
|
|
616
625
|
case 0: return "Clear sky";
|
|
617
626
|
case 1: return "Mainly clear";
|
|
@@ -646,7 +655,7 @@ function N(e) {
|
|
|
646
655
|
}
|
|
647
656
|
//#endregion
|
|
648
657
|
//#region src/providers/openweathermap.ts
|
|
649
|
-
var
|
|
658
|
+
var F = class {
|
|
650
659
|
name = "OpenWeatherMap";
|
|
651
660
|
providerType = "commercial";
|
|
652
661
|
apiBase = "https://api.openweathermap.org/data/2.5/forecast";
|
|
@@ -727,7 +736,7 @@ var P = class {
|
|
|
727
736
|
async supportsLocation(e, t) {
|
|
728
737
|
return { valid: !Number.isNaN(e) && !Number.isNaN(t) && e >= -90 && e <= 90 && t >= -180 && t <= 180 }.valid;
|
|
729
738
|
}
|
|
730
|
-
},
|
|
739
|
+
}, I = class {
|
|
731
740
|
name = "OpenWeatherMap One Call";
|
|
732
741
|
providerType = "commercial";
|
|
733
742
|
apiBase = "https://api.openweathermap.org/data/3.0/onecall";
|
|
@@ -833,22 +842,22 @@ var P = class {
|
|
|
833
842
|
async supportsLocation(e, t) {
|
|
834
843
|
return { valid: !Number.isNaN(e) && !Number.isNaN(t) && e >= -90 && e <= 90 && t >= -180 && t <= 180 }.valid;
|
|
835
844
|
}
|
|
836
|
-
},
|
|
845
|
+
}, L = {
|
|
837
846
|
provider: "HAVE_WEATHER_PROVIDER",
|
|
838
847
|
apiKey: "OPENWEATHER_API_KEY",
|
|
839
848
|
googleApiKey: "GOOGLE_API_KEY",
|
|
840
849
|
timeout: "HAVE_WEATHER_TIMEOUT"
|
|
841
850
|
};
|
|
842
|
-
function
|
|
843
|
-
let t = e(
|
|
851
|
+
function R() {
|
|
852
|
+
let t = e(L), n = {};
|
|
844
853
|
if (t.provider && (n.provider = t.provider), t.apiKey && (n.apiKey = t.apiKey), t.googleApiKey && (n.googleApiKey = t.googleApiKey), t.timeout) {
|
|
845
854
|
let e = Number.parseInt(t.timeout, 10);
|
|
846
855
|
Number.isNaN(e) || (n.timeout = e);
|
|
847
856
|
}
|
|
848
857
|
return n;
|
|
849
858
|
}
|
|
850
|
-
function
|
|
851
|
-
let n =
|
|
859
|
+
function z(e) {
|
|
860
|
+
let n = R(), r = {
|
|
852
861
|
...n,
|
|
853
862
|
...e
|
|
854
863
|
}, i = r.provider || n.provider || "environment-canada";
|
|
@@ -887,26 +896,26 @@ function R(e) {
|
|
|
887
896
|
default: throw new t(`Unknown provider: ${i}. Supported providers: environment-canada, openweathermap, openweathermap-onecall, google-weather, open-meteo`, "unknown", "INVALID_PROVIDER");
|
|
888
897
|
}
|
|
889
898
|
}
|
|
890
|
-
async function
|
|
891
|
-
let n =
|
|
899
|
+
async function B(e) {
|
|
900
|
+
let n = z(e);
|
|
892
901
|
switch (n.provider) {
|
|
893
902
|
case "environment-canada": return new T({ timeout: n.timeout });
|
|
894
|
-
case "openweathermap": return new
|
|
903
|
+
case "openweathermap": return new F({
|
|
895
904
|
apiKey: n.apiKey,
|
|
896
905
|
timeout: n.timeout
|
|
897
906
|
});
|
|
898
|
-
case "openweathermap-onecall": return new
|
|
907
|
+
case "openweathermap-onecall": return new I({
|
|
899
908
|
apiKey: n.apiKey,
|
|
900
909
|
timeout: n.timeout
|
|
901
910
|
});
|
|
902
|
-
case "google-weather": return new
|
|
911
|
+
case "google-weather": return new k({
|
|
903
912
|
apiKey: n.apiKey,
|
|
904
913
|
timeout: n.timeout
|
|
905
914
|
});
|
|
906
|
-
case "open-meteo": return new
|
|
915
|
+
case "open-meteo": return new j({ timeout: n.timeout });
|
|
907
916
|
default: throw new t(`Unsupported provider: ${n.provider}`, "unknown", "INVALID_PROVIDER");
|
|
908
917
|
}
|
|
909
918
|
}
|
|
910
|
-
var
|
|
919
|
+
var V = !0;
|
|
911
920
|
//#endregion
|
|
912
|
-
export { r as AuthenticationError, i as InvalidLocationError, a as NoResultsError,
|
|
921
|
+
export { r as AuthenticationError, i as InvalidLocationError, a as NoResultsError, V as PACKAGE_VERSION_INITIALIZED, n as RateLimitError, o as UnsupportedWeatherCapabilityError, t as WeatherError, C as calculateDistance, B as default, B as getWeatherAdapter, m as ensureValidCoordinates, g as fahrenheitToCelsius, S as isInCanada, h as kelvinToCelsius, _ as metersPerSecondToKmPerHour, y as metersToKilometers, v as milesPerHourToKmPerHour, b as milesToKilometers, p as validateCoordinates };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/weather",
|
|
3
|
-
"version": "0.89.
|
|
3
|
+
"version": "0.89.7",
|
|
4
4
|
"description": "Weather data provider abstraction for HAppyVertical SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@happyvertical/utils": "0.89.
|
|
44
|
+
"@happyvertical/utils": "0.89.7"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "25.0.10",
|