@selinac887/weather-sdk 1.0.3 → 1.0.5
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.d.ts +9 -2
- package/dist/index.js +18 -7
- package/package.json +1 -1
- package/src/index.ts +35 -17
package/dist/index.d.ts
CHANGED
|
@@ -23,20 +23,27 @@ export interface GetCurrentWeatherResponse {
|
|
|
23
23
|
export declare function getCurrentWeather(input: GetCurrentWeatherInput): Promise<GetCurrentWeatherResponse>;
|
|
24
24
|
export interface HourlyForecast {
|
|
25
25
|
time: string[];
|
|
26
|
-
[key: string]:
|
|
26
|
+
[key: string]: number[] | string[];
|
|
27
27
|
}
|
|
28
28
|
export interface DailyForecast {
|
|
29
29
|
time: string[];
|
|
30
|
-
[key: string]:
|
|
30
|
+
[key: string]: number[] | string[];
|
|
31
31
|
}
|
|
32
|
+
export type HourlyForecastUnits = Record<string, string>;
|
|
33
|
+
export type DailyForecastUnits = Record<string, string>;
|
|
32
34
|
export interface GetForecastInput extends BaseLocationInput {
|
|
33
35
|
hourly?: string[];
|
|
34
36
|
daily?: string[];
|
|
35
37
|
forecastHours?: number;
|
|
36
38
|
forecastDays?: number;
|
|
39
|
+
current?: string[];
|
|
37
40
|
}
|
|
38
41
|
export interface GetForecastResponse {
|
|
39
42
|
hourly?: HourlyForecast;
|
|
43
|
+
hourly_units?: HourlyForecastUnits;
|
|
40
44
|
daily?: DailyForecast;
|
|
45
|
+
daily_units?: DailyForecastUnits;
|
|
46
|
+
current?: CurrentWeather;
|
|
47
|
+
current_units?: CurrentWeatherUnits;
|
|
41
48
|
}
|
|
42
49
|
export declare function getForecast(input: GetForecastInput): Promise<GetForecastResponse>;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Shared Types
|
|
3
|
-
*/
|
|
4
1
|
export async function getCurrentWeather(input) {
|
|
5
|
-
const { latitude, longitude, timezone = "auto", current
|
|
2
|
+
const { latitude, longitude, timezone = "auto", current } = input;
|
|
6
3
|
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
|
7
4
|
url.searchParams.set("latitude", latitude.toString());
|
|
8
5
|
url.searchParams.set("longitude", longitude.toString());
|
|
@@ -15,11 +12,11 @@ export async function getCurrentWeather(input) {
|
|
|
15
12
|
const raw = await res.json();
|
|
16
13
|
return {
|
|
17
14
|
current: raw.current,
|
|
18
|
-
current_units: raw.current_units,
|
|
15
|
+
current_units: raw.current_units,
|
|
19
16
|
};
|
|
20
17
|
}
|
|
21
18
|
export async function getForecast(input) {
|
|
22
|
-
const { latitude, longitude, timezone = "auto", hourly, daily, forecastHours, forecastDays, } = input;
|
|
19
|
+
const { latitude, longitude, timezone = "auto", hourly, daily, forecastHours, forecastDays, current, } = input;
|
|
23
20
|
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
|
24
21
|
url.searchParams.set("latitude", latitude.toString());
|
|
25
22
|
url.searchParams.set("longitude", longitude.toString());
|
|
@@ -36,9 +33,23 @@ export async function getForecast(input) {
|
|
|
36
33
|
url.searchParams.set("forecast_days", forecastDays.toString());
|
|
37
34
|
}
|
|
38
35
|
}
|
|
36
|
+
if (current?.length) {
|
|
37
|
+
url.searchParams.set("current", current.join(","));
|
|
38
|
+
}
|
|
39
39
|
const res = await fetch(url.toString());
|
|
40
40
|
if (!res.ok) {
|
|
41
41
|
throw new Error(`Open-Meteo API error: ${res.status}`);
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
const raw = await res.json();
|
|
44
|
+
// Extract units if present
|
|
45
|
+
const hourlyUnits = raw.hourly_units;
|
|
46
|
+
const dailyUnits = raw.daily_units;
|
|
47
|
+
return {
|
|
48
|
+
hourly: raw.hourly,
|
|
49
|
+
hourly_units: hourlyUnits,
|
|
50
|
+
daily: raw.daily,
|
|
51
|
+
daily_units: dailyUnits,
|
|
52
|
+
current: raw.current,
|
|
53
|
+
current_units: raw.current_units,
|
|
54
|
+
};
|
|
44
55
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Shared Types
|
|
2
|
+
* Shared Types
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
export interface BaseLocationInput {
|
|
6
5
|
latitude: number;
|
|
7
6
|
longitude: number;
|
|
8
7
|
timezone?: string;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
/*
|
|
10
|
+
/*
|
|
12
11
|
* Current Weather
|
|
13
12
|
*/
|
|
14
|
-
|
|
15
13
|
export interface CurrentWeather {
|
|
16
14
|
time: string;
|
|
17
15
|
interval: number;
|
|
@@ -36,12 +34,7 @@ export interface GetCurrentWeatherResponse {
|
|
|
36
34
|
export async function getCurrentWeather(
|
|
37
35
|
input: GetCurrentWeatherInput
|
|
38
36
|
): Promise<GetCurrentWeatherResponse> {
|
|
39
|
-
const {
|
|
40
|
-
latitude,
|
|
41
|
-
longitude,
|
|
42
|
-
timezone = "auto",
|
|
43
|
-
current,
|
|
44
|
-
} = input;
|
|
37
|
+
const { latitude, longitude, timezone = "auto", current } = input;
|
|
45
38
|
|
|
46
39
|
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
|
47
40
|
url.searchParams.set("latitude", latitude.toString());
|
|
@@ -54,38 +47,45 @@ export async function getCurrentWeather(
|
|
|
54
47
|
throw new Error(`Open-Meteo API error: ${res.status}`);
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
const raw
|
|
50
|
+
const raw = await res.json();
|
|
58
51
|
|
|
59
52
|
return {
|
|
60
53
|
current: raw.current,
|
|
61
|
-
current_units: raw.current_units,
|
|
54
|
+
current_units: raw.current_units,
|
|
62
55
|
};
|
|
63
56
|
}
|
|
64
57
|
|
|
65
|
-
/*
|
|
58
|
+
/*
|
|
66
59
|
* Forecast (Hourly / Daily)
|
|
67
60
|
*/
|
|
68
|
-
|
|
69
61
|
export interface HourlyForecast {
|
|
70
62
|
time: string[];
|
|
71
|
-
[key: string]:
|
|
63
|
+
[key: string]: number[] | string[];
|
|
72
64
|
}
|
|
73
65
|
|
|
74
66
|
export interface DailyForecast {
|
|
75
67
|
time: string[];
|
|
76
|
-
[key: string]:
|
|
68
|
+
[key: string]: number[] | string[];
|
|
77
69
|
}
|
|
78
70
|
|
|
71
|
+
export type HourlyForecastUnits = Record<string, string>;
|
|
72
|
+
export type DailyForecastUnits = Record<string, string>;
|
|
73
|
+
|
|
79
74
|
export interface GetForecastInput extends BaseLocationInput {
|
|
80
75
|
hourly?: string[];
|
|
81
76
|
daily?: string[];
|
|
82
77
|
forecastHours?: number;
|
|
83
78
|
forecastDays?: number;
|
|
79
|
+
current?: string[];
|
|
84
80
|
}
|
|
85
81
|
|
|
86
82
|
export interface GetForecastResponse {
|
|
87
83
|
hourly?: HourlyForecast;
|
|
84
|
+
hourly_units?: HourlyForecastUnits;
|
|
88
85
|
daily?: DailyForecast;
|
|
86
|
+
daily_units?: DailyForecastUnits;
|
|
87
|
+
current?: CurrentWeather;
|
|
88
|
+
current_units?: CurrentWeatherUnits;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
export async function getForecast(
|
|
@@ -99,6 +99,7 @@ export async function getForecast(
|
|
|
99
99
|
daily,
|
|
100
100
|
forecastHours,
|
|
101
101
|
forecastDays,
|
|
102
|
+
current,
|
|
102
103
|
} = input;
|
|
103
104
|
|
|
104
105
|
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
|
@@ -120,10 +121,27 @@ export async function getForecast(
|
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
124
|
+
if (current?.length) {
|
|
125
|
+
url.searchParams.set("current", current.join(","));
|
|
126
|
+
}
|
|
127
|
+
|
|
123
128
|
const res = await fetch(url.toString());
|
|
124
129
|
if (!res.ok) {
|
|
125
130
|
throw new Error(`Open-Meteo API error: ${res.status}`);
|
|
126
131
|
}
|
|
127
132
|
|
|
128
|
-
|
|
133
|
+
const raw = await res.json();
|
|
134
|
+
|
|
135
|
+
// Extract units if present
|
|
136
|
+
const hourlyUnits: HourlyForecastUnits | undefined = raw.hourly_units;
|
|
137
|
+
const dailyUnits: DailyForecastUnits | undefined = raw.daily_units;
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
hourly: raw.hourly,
|
|
141
|
+
hourly_units: hourlyUnits,
|
|
142
|
+
daily: raw.daily,
|
|
143
|
+
daily_units: dailyUnits,
|
|
144
|
+
current: raw.current,
|
|
145
|
+
current_units: raw.current_units,
|
|
146
|
+
};
|
|
129
147
|
}
|