@neaps/api 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/README.md +146 -0
- package/bin/server.js +10 -0
- package/dist/index.d.mts +1560 -0
- package/dist/index.mjs +486 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @neaps/api
|
|
2
|
+
|
|
3
|
+
HTTP JSON API for tide predictions using NOAA harmonic constituents.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @neaps/api express
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### As a standalone server
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createApp } from "@neaps/api";
|
|
17
|
+
|
|
18
|
+
const app = createApp();
|
|
19
|
+
|
|
20
|
+
app.listen(3000, () => {
|
|
21
|
+
console.log("Server listening on port 3000");
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### As an Express middleware
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { createApp } from "@neaps/api";
|
|
29
|
+
import express from "express";
|
|
30
|
+
|
|
31
|
+
const mainApp = express();
|
|
32
|
+
|
|
33
|
+
// Mount the API at a specific path
|
|
34
|
+
mainApp.use("/api", createApp());
|
|
35
|
+
|
|
36
|
+
mainApp.listen(3000, () => {
|
|
37
|
+
console.log("Server listening on port 3000");
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API Endpoints
|
|
42
|
+
|
|
43
|
+
### GET /extremes
|
|
44
|
+
|
|
45
|
+
Get high and low tide predictions for the nearest station to given coordinates.
|
|
46
|
+
|
|
47
|
+
**Query Parameters:**
|
|
48
|
+
|
|
49
|
+
- `lat` or `latitude` (required): Latitude (-90 to 90)
|
|
50
|
+
- `lon`, `lng`, or `longitude` (required): Longitude (-180 to 180)
|
|
51
|
+
- `start` (required): Start date/time in ISO 8601 format
|
|
52
|
+
- `end` (required): End date/time in ISO 8601 format
|
|
53
|
+
- `datum` (optional): Vertical datum (MLLW, MLW, MTL, MSL, MHW, MHHW)
|
|
54
|
+
- `units` (optional): Units for water levels (meters or feet, defaults to meters)
|
|
55
|
+
|
|
56
|
+
**Example:**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
curl "http://localhost:3000/extremes?lat=26.772&lon=-80.05&start=2025-12-17T00:00:00Z&end=2025-12-18T00:00:00Z&datum=MLLW&units=feet"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### GET /timeline
|
|
63
|
+
|
|
64
|
+
Get water level predictions at regular intervals for the nearest station.
|
|
65
|
+
|
|
66
|
+
**Query Parameters:** Same as `/extremes`
|
|
67
|
+
|
|
68
|
+
**Example:**
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
curl "http://localhost:3000/timeline?lat=26.772&lon=-80.05&start=2025-12-17T00:00:00Z&end=2025-12-18T00:00:00Z"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### GET /stations
|
|
75
|
+
|
|
76
|
+
Find stations by ID or near a location.
|
|
77
|
+
|
|
78
|
+
**Query Parameters:**
|
|
79
|
+
|
|
80
|
+
- `id` (optional): Station ID or source ID
|
|
81
|
+
- `lat` or `latitude` (optional): Latitude for proximity search
|
|
82
|
+
- `lon`, `lng`, or `longitude` (optional): Longitude for proximity search
|
|
83
|
+
- `limit` (optional): Maximum number of stations to return (1-100, defaults to 10)
|
|
84
|
+
|
|
85
|
+
**Examples:**
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Find a specific station
|
|
89
|
+
curl "http://localhost:3000/stations?id=noaa/8722588"
|
|
90
|
+
|
|
91
|
+
# Find stations near coordinates
|
|
92
|
+
curl "http://localhost:3000/stations?lat=26.772&lon=-80.05&limit=5"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### GET /stations/:id/extremes
|
|
96
|
+
|
|
97
|
+
Get extremes prediction for a specific station.
|
|
98
|
+
|
|
99
|
+
**Path Parameters:**
|
|
100
|
+
|
|
101
|
+
- `id` (required): Station ID (URL-encoded if contains special characters)
|
|
102
|
+
|
|
103
|
+
**Query Parameters:**
|
|
104
|
+
|
|
105
|
+
- `start` (required): Start date/time in ISO 8601 format
|
|
106
|
+
- `end` (required): End date/time in ISO 8601 format
|
|
107
|
+
- `datum` (optional): Vertical datum
|
|
108
|
+
- `units` (optional): Units for water levels
|
|
109
|
+
|
|
110
|
+
**Example:**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
curl "http://localhost:3000/stations/noaa%2F8722588/extremes?start=2025-12-17T00:00:00Z&end=2025-12-18T00:00:00Z"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### GET /stations/:id/timeline
|
|
117
|
+
|
|
118
|
+
Get timeline prediction for a specific station.
|
|
119
|
+
|
|
120
|
+
**Parameters:** Same as `/stations/:id/extremes`
|
|
121
|
+
|
|
122
|
+
**Note:** Timeline predictions are not supported for subordinate stations.
|
|
123
|
+
|
|
124
|
+
### GET /openapi.json
|
|
125
|
+
|
|
126
|
+
Get the OpenAPI 3.0 specification for this API.
|
|
127
|
+
|
|
128
|
+
## Development
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Install dependencies
|
|
132
|
+
npm install
|
|
133
|
+
|
|
134
|
+
# Build
|
|
135
|
+
npm run build
|
|
136
|
+
|
|
137
|
+
# Run tests
|
|
138
|
+
npx vitest
|
|
139
|
+
|
|
140
|
+
# Run tests with coverage
|
|
141
|
+
npx vitest run --coverage
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|
package/bin/server.js
ADDED