@selinac887/weather-sdk 1.0.0
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/.github/workflows/publish.yml +31 -0
- package/README.md +49 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +40 -0
- package/package.json +18 -0
- package/src/index.ts +117 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*.*.*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout repository
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Setup Node.js
|
|
17
|
+
uses: actions/setup-node@v4
|
|
18
|
+
with:
|
|
19
|
+
node-version: 24
|
|
20
|
+
registry-url: https://registry.npmjs.org/
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: npm ci
|
|
24
|
+
|
|
25
|
+
- name: Build package
|
|
26
|
+
run: npm run build
|
|
27
|
+
|
|
28
|
+
- name: Publish to npm
|
|
29
|
+
run: npm publish --access public
|
|
30
|
+
env:
|
|
31
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Weather SDK
|
|
2
|
+
|
|
3
|
+
A lightweight TypeScript SDK for the [Open-Meteo](https://open-meteo.com/) API,
|
|
4
|
+
providing access to current weather and forecast data.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- Current weather
|
|
9
|
+
- Hourly and daily forecast
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @yourname/weather-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Get current weather
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { getCurrentWeather } from "@yourname/weather-sdk";
|
|
23
|
+
|
|
24
|
+
const data = await getCurrentWeather({
|
|
25
|
+
latitude: -36.85,
|
|
26
|
+
longitude: 174.76,
|
|
27
|
+
current: [
|
|
28
|
+
"temperature_2m",
|
|
29
|
+
"wind_speed_10m",
|
|
30
|
+
"weather_code"
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(data.current.temperature_2m);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Get forecast weather
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { getForecast } from "@yourname/weather-sdk";
|
|
41
|
+
|
|
42
|
+
const forecast = await getForecast({
|
|
43
|
+
latitude: -36.85,
|
|
44
|
+
longitude: 174.76,
|
|
45
|
+
hourly: ["temperature_2m", "relative_humidity_2m"],
|
|
46
|
+
daily: ["temperature_2m_max", "precipitation_sum"],
|
|
47
|
+
forecastDays: 3
|
|
48
|
+
});
|
|
49
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface BaseLocationInput {
|
|
2
|
+
latitude: number;
|
|
3
|
+
longitude: number;
|
|
4
|
+
timezone?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface CurrentWeather {
|
|
7
|
+
time: string;
|
|
8
|
+
interval: number;
|
|
9
|
+
[key: string]: number | string;
|
|
10
|
+
}
|
|
11
|
+
export interface GetCurrentWeatherInput extends BaseLocationInput {
|
|
12
|
+
current: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface GetCurrentWeatherResponse {
|
|
15
|
+
current: CurrentWeather;
|
|
16
|
+
}
|
|
17
|
+
export declare function getCurrentWeather(input: GetCurrentWeatherInput): Promise<GetCurrentWeatherResponse>;
|
|
18
|
+
export interface HourlyForecast {
|
|
19
|
+
time: string[];
|
|
20
|
+
[key: string]: any[];
|
|
21
|
+
}
|
|
22
|
+
export interface DailyForecast {
|
|
23
|
+
time: string[];
|
|
24
|
+
[key: string]: any[];
|
|
25
|
+
}
|
|
26
|
+
export interface GetForecastInput extends BaseLocationInput {
|
|
27
|
+
hourly?: string[];
|
|
28
|
+
daily?: string[];
|
|
29
|
+
forecastHours?: number;
|
|
30
|
+
forecastDays?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface GetForecastResponse {
|
|
33
|
+
hourly?: HourlyForecast;
|
|
34
|
+
daily?: DailyForecast;
|
|
35
|
+
}
|
|
36
|
+
export declare function getForecast(input: GetForecastInput): Promise<GetForecastResponse>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Shared Types
|
|
3
|
+
*/
|
|
4
|
+
export async function getCurrentWeather(input) {
|
|
5
|
+
const { latitude, longitude, timezone = "auto", current, } = input;
|
|
6
|
+
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
|
7
|
+
url.searchParams.set("latitude", latitude.toString());
|
|
8
|
+
url.searchParams.set("longitude", longitude.toString());
|
|
9
|
+
url.searchParams.set("timezone", timezone);
|
|
10
|
+
url.searchParams.set("current", current.join(","));
|
|
11
|
+
const res = await fetch(url.toString());
|
|
12
|
+
if (!res.ok) {
|
|
13
|
+
throw new Error(`Open-Meteo API error: ${res.status}`);
|
|
14
|
+
}
|
|
15
|
+
return res.json();
|
|
16
|
+
}
|
|
17
|
+
export async function getForecast(input) {
|
|
18
|
+
const { latitude, longitude, timezone = "auto", hourly, daily, forecastHours, forecastDays, } = input;
|
|
19
|
+
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
|
20
|
+
url.searchParams.set("latitude", latitude.toString());
|
|
21
|
+
url.searchParams.set("longitude", longitude.toString());
|
|
22
|
+
url.searchParams.set("timezone", timezone);
|
|
23
|
+
if (hourly?.length) {
|
|
24
|
+
url.searchParams.set("hourly", hourly.join(","));
|
|
25
|
+
if (forecastHours) {
|
|
26
|
+
url.searchParams.set("forecast_hours", forecastHours.toString());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (daily?.length) {
|
|
30
|
+
url.searchParams.set("daily", daily.join(","));
|
|
31
|
+
if (forecastDays) {
|
|
32
|
+
url.searchParams.set("forecast_days", forecastDays.toString());
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const res = await fetch(url.toString());
|
|
36
|
+
if (!res.ok) {
|
|
37
|
+
throw new Error(`Open-Meteo API error: ${res.status}`);
|
|
38
|
+
}
|
|
39
|
+
return res.json();
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@selinac887/weather-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"type": "commonjs",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^25.0.3",
|
|
16
|
+
"typescript": "^5.9.3"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Shared Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface BaseLocationInput {
|
|
6
|
+
latitude: number;
|
|
7
|
+
longitude: number;
|
|
8
|
+
timezone?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Current Weather
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface CurrentWeather {
|
|
16
|
+
time: string;
|
|
17
|
+
interval: number;
|
|
18
|
+
[key: string]: number | string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface GetCurrentWeatherInput extends BaseLocationInput {
|
|
22
|
+
current: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface GetCurrentWeatherResponse {
|
|
26
|
+
current: CurrentWeather;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function getCurrentWeather(
|
|
30
|
+
input: GetCurrentWeatherInput
|
|
31
|
+
): Promise<GetCurrentWeatherResponse> {
|
|
32
|
+
const {
|
|
33
|
+
latitude,
|
|
34
|
+
longitude,
|
|
35
|
+
timezone = "auto",
|
|
36
|
+
current,
|
|
37
|
+
} = input;
|
|
38
|
+
|
|
39
|
+
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
|
40
|
+
url.searchParams.set("latitude", latitude.toString());
|
|
41
|
+
url.searchParams.set("longitude", longitude.toString());
|
|
42
|
+
url.searchParams.set("timezone", timezone);
|
|
43
|
+
url.searchParams.set("current", current.join(","));
|
|
44
|
+
|
|
45
|
+
const res = await fetch(url.toString());
|
|
46
|
+
if (!res.ok) {
|
|
47
|
+
throw new Error(`Open-Meteo API error: ${res.status}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return res.json();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Forecast (Hourly / Daily)
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
export interface HourlyForecast {
|
|
58
|
+
time: string[];
|
|
59
|
+
[key: string]: any[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface DailyForecast {
|
|
63
|
+
time: string[];
|
|
64
|
+
[key: string]: any[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface GetForecastInput extends BaseLocationInput {
|
|
68
|
+
hourly?: string[];
|
|
69
|
+
daily?: string[];
|
|
70
|
+
forecastHours?: number;
|
|
71
|
+
forecastDays?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface GetForecastResponse {
|
|
75
|
+
hourly?: HourlyForecast;
|
|
76
|
+
daily?: DailyForecast;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function getForecast(
|
|
80
|
+
input: GetForecastInput
|
|
81
|
+
): Promise<GetForecastResponse> {
|
|
82
|
+
const {
|
|
83
|
+
latitude,
|
|
84
|
+
longitude,
|
|
85
|
+
timezone = "auto",
|
|
86
|
+
hourly,
|
|
87
|
+
daily,
|
|
88
|
+
forecastHours,
|
|
89
|
+
forecastDays,
|
|
90
|
+
} = input;
|
|
91
|
+
|
|
92
|
+
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
|
93
|
+
url.searchParams.set("latitude", latitude.toString());
|
|
94
|
+
url.searchParams.set("longitude", longitude.toString());
|
|
95
|
+
url.searchParams.set("timezone", timezone);
|
|
96
|
+
|
|
97
|
+
if (hourly?.length) {
|
|
98
|
+
url.searchParams.set("hourly", hourly.join(","));
|
|
99
|
+
if (forecastHours) {
|
|
100
|
+
url.searchParams.set("forecast_hours", forecastHours.toString());
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (daily?.length) {
|
|
105
|
+
url.searchParams.set("daily", daily.join(","));
|
|
106
|
+
if (forecastDays) {
|
|
107
|
+
url.searchParams.set("forecast_days", forecastDays.toString());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const res = await fetch(url.toString());
|
|
112
|
+
if (!res.ok) {
|
|
113
|
+
throw new Error(`Open-Meteo API error: ${res.status}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return res.json();
|
|
117
|
+
}
|
package/tsconfig.json
ADDED