kmw-sdk 0.0.0-stage → 0.1.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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +273 -2
- package/dist/index.cjs +965 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3619 -0
- package/dist/index.d.ts +3619 -0
- package/dist/index.js +938 -0
- package/dist/index.js.map +1 -0
- package/package.json +84 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# kmw-sdk
|
|
2
|
+
|
|
3
|
+
All notable changes are recorded here by [Changesets](https://github.com/changesets/changesets).
|
|
4
|
+
|
|
5
|
+
## 0.1.0
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- Initial release: typed client for the Kachelmannwetter API v02 with typed errors, retries, timeouts and rate-limit info, optional raw responses, `{ lat, lon }` or `{ lat, lng }` locations, optional enterprise Basic/Bearer auth, plus experimental `climate` and `photos` modules.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 styler2go
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,274 @@
|
|
|
1
|
-
#
|
|
1
|
+
# kmw-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed, zero-dependency TypeScript client for the
|
|
4
|
+
[Kachelmannwetter / Meteologix weather API](https://api.kachelmannwetter.com/v02/_doc.json) (v02).
|
|
5
|
+
|
|
6
|
+
- Covers every documented endpoint: current weather, forecasts, station observations, astronomy and weather symbols.
|
|
7
|
+
- The JSDoc of every value names its unit.
|
|
8
|
+
- Normalized responses: collections are always arrays or records (the API mixes the two), and numeric strings become numbers. Pass `{ raw: true }` to get the unmodified response instead.
|
|
9
|
+
- Errors are typed and thrown. Optional retries, timeouts, `AbortSignal` and rate-limit info.
|
|
10
|
+
- ESM and CommonJS, Node.js 20+, Deno, Bun and browsers. Uses the native `fetch`.
|
|
11
|
+
|
|
12
|
+
> This is an unofficial client. It is not affiliated with Kachelmann GmbH or Meteologix AG.
|
|
13
|
+
> Using the API requires your own subscription and API key; their
|
|
14
|
+
> [terms of service](https://accounts.meteologix.com/static/api-nutzungsbedingungen) apply.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install kmw-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quickstart
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Kachelmann } from "kmw-sdk";
|
|
26
|
+
|
|
27
|
+
// Reads KACHELMANN_API_KEY from the environment if `apiKey` is omitted.
|
|
28
|
+
const client = new Kachelmann({ apiKey: process.env.KACHELMANN_API_KEY });
|
|
29
|
+
|
|
30
|
+
const location = { lat: 52.52, lon: 13.41 };
|
|
31
|
+
|
|
32
|
+
const current = await client.current(location);
|
|
33
|
+
console.log(current.data.temp?.value, "°C");
|
|
34
|
+
|
|
35
|
+
const forecast = await client.forecast.threeDay(location);
|
|
36
|
+
for (const day of forecast.data) {
|
|
37
|
+
console.log(day.dateTime, day.tempMin, "–", day.tempMax, "°C", day.weatherSymbol);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Get an API key in the [Meteologix account portal](https://accounts.meteologix.com/subscriptions)
|
|
42
|
+
under "Manage API Keys". The Hobby plan allows two locations, 120 requests per minute and 700 per day.
|
|
43
|
+
|
|
44
|
+
### Plans and API locations
|
|
45
|
+
|
|
46
|
+
Depending on the subscription, a key works worldwide or only for the **API locations** set in the account portal
|
|
47
|
+
(Hobby / Smart-Home plans: at most two). Set them under "Manage API locations" in the
|
|
48
|
+
[subscription list](https://accounts.meteologix.com/subscriptions) before the first request.
|
|
49
|
+
The API has no endpoint to read these locations, so the client cannot check a location before sending a request.
|
|
50
|
+
A request outside your locations, or for a station your plan does not cover, fails with a `PermissionDeniedError` (HTTP 403).
|
|
51
|
+
`problem` contains the API's explanation; `message` contains it too, followed by a hint to check the API locations:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { PermissionDeniedError } from "kmw-sdk";
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
await client.forecast.threeDay({ lat: 48.14, lon: 11.58 });
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof PermissionDeniedError) {
|
|
60
|
+
console.log("Not covered by this key:", error.problem?.detail ?? error.message);
|
|
61
|
+
} else throw error;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Enterprise authentication (Basic / Bearer)
|
|
66
|
+
|
|
67
|
+
The API also documents HTTP Basic and Bearer authentication, but only
|
|
68
|
+
"for internal and enterprise use". **Use it only if Meteologix told you to**; everyone else uses an API key.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const client = new Kachelmann({ auth: { type: "bearer", token: "<token from Meteologix>" } });
|
|
72
|
+
// or: { type: "basic", username: "…", password: "…" }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
With `auth`, the client sends an `Authorization` header instead of `X-API-Key`. Don't pass `apiKey` as well;
|
|
76
|
+
`KACHELMANN_API_KEY` is ignored. This SDK's tests check the headers only, not a live enterprise account.
|
|
77
|
+
|
|
78
|
+
## Endpoints
|
|
79
|
+
|
|
80
|
+
| Method | Endpoint | Returns |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| `client.current(loc)` | `GET /current/{lat}/{lon}` | Current values, keyed by parameter (`data.temp.value`) |
|
|
83
|
+
| `client.forecast.standard(loc, "1h" \| "3h" \| "6h")` | `GET /forecast/…/standard/{steps}` | Standard parameter package |
|
|
84
|
+
| `client.forecast.advanced(loc, "1h" \| "3h" \| "6h")` | `GET /forecast/…/advanced/{steps}` | Standard parameters plus min/max, cloud layers, radiation, snow, WMO code, symbol |
|
|
85
|
+
| `client.forecast.threeDay(loc, { minDays?, model? })` | `GET /forecast/…/3day` | Day and time-of-day summaries with risks |
|
|
86
|
+
| `client.forecast.trend14Days(loc)` | `GET /forecast/…/trend14days` | 14-day trend with ranges and probabilities |
|
|
87
|
+
| `client.stations.search(loc, { radius? })` | `GET /station/search/{lat}/{lon}` | Nearby stations (`radius` and `distance` in km, `radius` at most 25) |
|
|
88
|
+
| `client.stations.latest(id)` | `GET /station/{id}/observations/latest` | Latest values, keyed by parameter |
|
|
89
|
+
| `client.stations.observations(id, "10min" \| "1h" \| "1d", { threshold? })` | `GET /station/{id}/observations/{steps}` | Raw observations (6 h) or hourly (24 h) / daily (7 d) aggregates |
|
|
90
|
+
| `client.tools.astronomy(loc)` | `GET /tools/astronomy/{lat}/{lon}` | Sun and moon times for 14 days |
|
|
91
|
+
| `client.tools.weatherSymbol(symbol)` | `GET /tools/weatherSymbol/{symbol}.svg` | SVG markup |
|
|
92
|
+
| `client.tools.weatherSymbolUrl(symbol)` | – | Symbol URL for `<img src>` (no request) |
|
|
93
|
+
|
|
94
|
+
Every method accepts `{ signal, timeout }` as its last options argument.
|
|
95
|
+
|
|
96
|
+
## Locations
|
|
97
|
+
|
|
98
|
+
A location is an object with `lat` and either `lon` or `lng`, in decimal degrees (WGS 84).
|
|
99
|
+
Objects from Leaflet, Google Maps or Mapbox (`{ lat, lng }`) and from API responses (`{ lat, lon }`) can be passed directly:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import type { Coordinates } from "kmw-sdk";
|
|
103
|
+
|
|
104
|
+
const berlin: Coordinates = { lat: 52.52, lon: 13.41 };
|
|
105
|
+
await client.current({ lat: 52.52, lng: 13.41 }); // same request
|
|
106
|
+
|
|
107
|
+
const [station] = await client.stations.search(berlin);
|
|
108
|
+
if (station) await client.forecast.threeDay(station); // station has lat/lon
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Coordinates outside −90…90 / −180…180 throw a `RangeError` before any request.
|
|
112
|
+
The types `LatLon`, `LatLng` and `Coordinates` (either of the two) are exported.
|
|
113
|
+
|
|
114
|
+
## Raw responses
|
|
115
|
+
|
|
116
|
+
By default, responses are normalized. Pass `raw: true` to get the body exactly as the API sent it, typed after the OpenAPI spec:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const forecast = await client.forecast.standard(location, "1h", { raw: true });
|
|
120
|
+
// forecast: RawStandardForecast. `data` may be an array or an object map, as documented in the spec.
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`raw` is available on every documented endpoint: `current`, `forecast.*`, `stations.*` and `tools.astronomy`.
|
|
124
|
+
Arguments are still validated, and units are still sent.
|
|
125
|
+
|
|
126
|
+
## Units
|
|
127
|
+
|
|
128
|
+
Forecasts and current weather use the client's `units` (default `"metric"`). You can override them per call:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
const client = new Kachelmann({ units: "imperial" });
|
|
132
|
+
const f = await client.forecast.standard(location, "1h"); // f.systemOfUnits: "imperial"
|
|
133
|
+
const m = await client.forecast.standard(location, "1h", { units: "metric" });
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
| Quantity | `metric` | `imperial` |
|
|
137
|
+
| --- | --- | --- |
|
|
138
|
+
| Temperature | °C | °F |
|
|
139
|
+
| Wind speed and gusts (forecast, current) | **m/s**, not km/h | mph |
|
|
140
|
+
| Precipitation | mm | inch |
|
|
141
|
+
| Snow amount (`snowAmount*`) | mm water equivalent ¹ | inch water equivalent ¹ |
|
|
142
|
+
| Snow height (forecast) | m | inch |
|
|
143
|
+
| Global radiation (forecast) | Wh/m² | Wh/m² |
|
|
144
|
+
| Sunshine (`sunHours`) | h | h |
|
|
145
|
+
|
|
146
|
+
¹ The spec does not state the unit of `snowAmount` explicitly. Water equivalent is the most plausible reading; treat it as unconfirmed.
|
|
147
|
+
|
|
148
|
+
**Station observations ignore `units`.** They are always metric with wind in **knots**,
|
|
149
|
+
snow height in **cm**, and global radiation in kJ/m² (24 h: J/cm²).
|
|
150
|
+
|
|
151
|
+
Conversion helpers are included:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { classifyWmoCode, knotsToKmh, mpsToKmh } from "kmw-sdk";
|
|
155
|
+
|
|
156
|
+
mpsToKmh(4.2, 1); // 15.1
|
|
157
|
+
knotsToKmh(10, 0); // 19
|
|
158
|
+
classifyWmoCode(63); // "rain"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Errors
|
|
162
|
+
|
|
163
|
+
Every failure throws a subclass of `KachelmannError`:
|
|
164
|
+
|
|
165
|
+
| Error | When |
|
|
166
|
+
| --- | --- |
|
|
167
|
+
| `MissingApiKeyError` | No API key configured. Thrown before any request. |
|
|
168
|
+
| `BadRequestError` (400) | Invalid parameters |
|
|
169
|
+
| `AuthenticationError` (401) | Missing, invalid or expired key |
|
|
170
|
+
| `PermissionDeniedError` (403) | Your plan does not include the endpoint, location or station |
|
|
171
|
+
| `NotFoundError` (404) | Unknown station or resource |
|
|
172
|
+
| `RateLimitError` (429) | Rate limit hit. `retryAfter` holds a `Date`. |
|
|
173
|
+
| `ServerError` (5xx) | API failure |
|
|
174
|
+
| `ApiError` | Base class of all HTTP errors: `status`, `url`, `problem` (RFC 7807 body), `rateLimit` |
|
|
175
|
+
| `RequestTimeoutError` | No response within `timeout` ms |
|
|
176
|
+
| `ConnectionError` | Network failure (DNS, TLS, connection reset) |
|
|
177
|
+
| `InvalidResponseError` | Response body is not the expected JSON |
|
|
178
|
+
|
|
179
|
+
Invalid arguments (coordinates out of range, unknown time steps) throw a `RangeError` or `TypeError` before any request.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { PermissionDeniedError, RateLimitError } from "kmw-sdk";
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
await client.stations.observations("10637", "1h");
|
|
186
|
+
} catch (error) {
|
|
187
|
+
if (error instanceof RateLimitError) console.log("Try again at", error.retryAfter);
|
|
188
|
+
else if (error instanceof PermissionDeniedError) console.log("Not in your plan");
|
|
189
|
+
else throw error;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Error messages never contain your API key or enterprise credentials. They are sent only in a header (`X-API-Key` or `Authorization`), never in a URL.
|
|
194
|
+
|
|
195
|
+
## Timeouts, retries and cancellation
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const client = new Kachelmann({
|
|
199
|
+
timeout: 5_000, // per attempt, default 10 000 ms
|
|
200
|
+
retry: { retries: 2, minDelay: 500, maxDelay: 10_000 }, // or simply `retry: 2`
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const controller = new AbortController();
|
|
204
|
+
const forecast = client.forecast.standard(location, "1h", { signal: controller.signal, timeout: 2_000 });
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Retries are **off by default** because plans have a daily request limit. When enabled, retries apply to connection errors, timeouts,
|
|
208
|
+
HTTP 500/502/503/504 and HTTP 429. A 429 is retried only if `x-ratelimit-retry-after` lies within `maxDelay`.
|
|
209
|
+
Backoff is exponential with jitter. Aborting through your signal rejects with the signal's `reason`.
|
|
210
|
+
|
|
211
|
+
## Rate limit
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
await client.current(location);
|
|
215
|
+
client.rateLimit; // { limit: 700, remaining: 623 } from the last response (retryAfter: Date after a 429)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Experimental: climate time series and weather photos
|
|
219
|
+
|
|
220
|
+
The client also offers two modules for endpoints that the kachelmannwetter.com website uses.
|
|
221
|
+
**They are not part of the documented v02 API.** They may change or disappear without notice,
|
|
222
|
+
are marked `@experimental` and are not covered by semver.
|
|
223
|
+
|
|
224
|
+
### `client.experimental.climate`
|
|
225
|
+
|
|
226
|
+
This module lives under `client.experimental` because it does not work with regular API keys yet.
|
|
227
|
+
|
|
228
|
+
Climate stations, warming stripes, heatmaps and daily comparisons as shown on the website's climate time-series page.
|
|
229
|
+
Requests send **your own API key**. In a live test (November 2026) the API **rejected a customer key with HTTP 403** (`PermissionDeniedError`), so this module currently only works with keys the API accepts for these endpoints.
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
const [hit] = await client.experimental.climate.search("Potsdam");
|
|
233
|
+
if (!hit) throw new Error("No climate station found");
|
|
234
|
+
const stripes = await client.experimental.climate.stripes(hit.name, { param: "tlmean", type: "difference", reference: "1961-1990" });
|
|
235
|
+
// stripes.matrix: [year, categoryIndex, value][] (tlmean °C, rrsum mm, shsum h)
|
|
236
|
+
|
|
237
|
+
await client.experimental.climate.stations("DE");
|
|
238
|
+
await client.experimental.climate.station(hit.name); // details, capabilities, records
|
|
239
|
+
await client.experimental.climate.heatmap(hit.name, { param: "rrsum", by: "byMonth", year: 2024 });
|
|
240
|
+
await client.experimental.climate.spaghetti(hit.name, { param: "tlmean", comparedYears: [2024, 2003] }); // at most 5 years
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Responses are passed through mostly unchanged, including snake_case fields.
|
|
244
|
+
|
|
245
|
+
### `client.photos`
|
|
246
|
+
|
|
247
|
+
Read-only access to the community weather photos. No API key is sent.
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
const counts = await client.photos.counts(); // { "2026-11-27": 42, … }
|
|
251
|
+
const photos = await client.photos.list({ from: "2026-11-27", to: "2026-11-28", units: "metric" });
|
|
252
|
+
const photo = photos[0] && (await client.photos.get(photos[0].id));
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Photos are licensed to Kachelmann GmbH and include personal data (uploader names, locations).
|
|
256
|
+
Respect copyright and data-protection law; do not republish them without permission.
|
|
257
|
+
Liking, uploading and view counting need a user account and are not supported.
|
|
258
|
+
|
|
259
|
+
## Known limitations
|
|
260
|
+
|
|
261
|
+
- The unit and time window of `snowAmount` are not documented (see [Units](#units)).
|
|
262
|
+
- `tools.weatherSymbol` works without an API key (checked live in November 2026), so `weatherSymbolUrl()` can be used in `<img src>`.
|
|
263
|
+
- The station search allows a `radius` of at most 25 km (HTTP 403 above). The spec does not mention this limit.
|
|
264
|
+
- The 3-day forecast also returns `precProb`, `precProb1mm` and `precProb10mm` (in %), which the spec does not document. They are typed as optional.
|
|
265
|
+
- Which forecast `model` values your plan may request is not documented. Unknown model names are passed through.
|
|
266
|
+
- The response types follow the OpenAPI spec. A type-level drift check fails the build when the spec changes. Real responses can still differ from the spec; please [open an issue](https://github.com/styler2go/kmw-sdk/issues) if they do.
|
|
267
|
+
|
|
268
|
+
## Contributing
|
|
269
|
+
|
|
270
|
+
See [CONTRIBUTING.md](https://github.com/styler2go/kmw-sdk/blob/main/CONTRIBUTING.md). Security issues: see [SECURITY.md](https://github.com/styler2go/kmw-sdk/blob/main/SECURITY.md).
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
[MIT](LICENSE)
|