@selinac887/weather-sdk 1.0.3 → 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
@@ -23,12 +23,14 @@ 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]: any[];
26
+ [key: string]: number[] | string[];
27
27
  }
28
28
  export interface DailyForecast {
29
29
  time: string[];
30
- [key: string]: any[];
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[];
@@ -37,6 +39,8 @@ export interface GetForecastInput extends BaseLocationInput {
37
39
  }
38
40
  export interface GetForecastResponse {
39
41
  hourly?: HourlyForecast;
42
+ hourly_units?: HourlyForecastUnits;
40
43
  daily?: DailyForecast;
44
+ daily_units?: DailyForecastUnits;
41
45
  }
42
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());
@@ -15,7 +12,7 @@ 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, // include units exactly as API returns
15
+ current_units: raw.current_units,
19
16
  };
20
17
  }
21
18
  export async function getForecast(input) {
@@ -40,5 +37,14 @@ export async function getForecast(input) {
40
37
  if (!res.ok) {
41
38
  throw new Error(`Open-Meteo API error: ${res.status}`);
42
39
  }
43
- 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
+ };
44
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selinac887/weather-sdk",
3
- "version": "1.0.3",
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,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,28 +47,30 @@ export async function getCurrentWeather(
54
47
  throw new Error(`Open-Meteo API error: ${res.status}`);
55
48
  }
56
49
 
57
- const raw: any = await res.json();
50
+ const raw = await res.json();
58
51
 
59
52
  return {
60
53
  current: raw.current,
61
- current_units: raw.current_units, // include units exactly as API returns
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]: any[];
63
+ [key: string]: number[] | string[];
72
64
  }
73
65
 
74
66
  export interface DailyForecast {
75
67
  time: string[];
76
- [key: string]: any[];
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[];
@@ -85,7 +80,9 @@ export interface GetForecastInput extends BaseLocationInput {
85
80
 
86
81
  export interface GetForecastResponse {
87
82
  hourly?: HourlyForecast;
83
+ hourly_units?: HourlyForecastUnits;
88
84
  daily?: DailyForecast;
85
+ daily_units?: DailyForecastUnits;
89
86
  }
90
87
 
91
88
  export async function getForecast(
@@ -125,5 +122,16 @@ export async function getForecast(
125
122
  throw new Error(`Open-Meteo API error: ${res.status}`);
126
123
  }
127
124
 
128
- 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
+ };
129
137
  }