@selinac887/weather-sdk 1.0.2 → 1.0.4

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