atmosx-nwws-parser 1.0.19 → 1.0.22

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.
Files changed (44) hide show
  1. package/README.md +182 -64
  2. package/dist/cjs/index.cjs +3799 -0
  3. package/dist/esm/index.mjs +3757 -0
  4. package/package.json +49 -37
  5. package/src/bootstrap.ts +196 -0
  6. package/src/database.ts +148 -0
  7. package/src/dictionaries/awips.ts +342 -0
  8. package/src/dictionaries/events.ts +142 -0
  9. package/src/dictionaries/icao.ts +237 -0
  10. package/src/dictionaries/offshore.ts +12 -0
  11. package/src/dictionaries/signatures.ts +107 -0
  12. package/src/eas.ts +493 -0
  13. package/src/index.ts +229 -0
  14. package/src/parsers/events/api.ts +151 -0
  15. package/src/parsers/events/cap.ts +138 -0
  16. package/src/parsers/events/text.ts +106 -0
  17. package/src/parsers/events/ugc.ts +109 -0
  18. package/src/parsers/events/vtec.ts +78 -0
  19. package/src/parsers/events.ts +367 -0
  20. package/src/parsers/hvtec.ts +46 -0
  21. package/src/parsers/pvtec.ts +71 -0
  22. package/src/parsers/stanza.ts +132 -0
  23. package/src/parsers/text.ts +166 -0
  24. package/src/parsers/ugc.ts +197 -0
  25. package/src/types.ts +251 -0
  26. package/src/utils.ts +314 -0
  27. package/src/xmpp.ts +144 -0
  28. package/test.js +58 -34
  29. package/tsconfig.json +12 -5
  30. package/tsup.config.ts +14 -0
  31. package/bootstrap.ts +0 -122
  32. package/dist/bootstrap.js +0 -153
  33. package/dist/src/events.js +0 -585
  34. package/dist/src/helper.js +0 -463
  35. package/dist/src/stanza.js +0 -147
  36. package/dist/src/text-parser.js +0 -119
  37. package/dist/src/ugc.js +0 -214
  38. package/dist/src/vtec.js +0 -125
  39. package/src/events.ts +0 -394
  40. package/src/helper.ts +0 -298
  41. package/src/stanza.ts +0 -102
  42. package/src/text-parser.ts +0 -120
  43. package/src/ugc.ts +0 -122
  44. package/src/vtec.ts +0 -99
package/README.md CHANGED
@@ -1,90 +1,208 @@
1
- # AtmosphericX - NOAA Weather Wire Service Parser
2
-
3
-
4
- This repository contains the primary parser for AtmosphericX's NOAA Weather Wire Service parser. It is designed to handle real time weather alerts and messages from the National Weather Service using XMPP. If you do not know basic programming, this parser is not for you. It is intended for developers who want to integrate alerts from NOAA Weather Wire easily into their applications or services without hassle. If you wish to use NWWS without programming, feel free to use our project where most of this code was used - [AtmosphericX](https://github.com/k3yomi/AtmosphericX).
5
-
6
- ## Installation Guide
7
- To install this package, you can use **NPM** (Node Package Manager). Open your terminal and run the following command:
8
-
1
+ <h1 style='font-size: 65px'; align="center">🌪️ AtmosphericX - NOAA Wire + API Parser ⚠️</h1>
2
+ <div align="center">
3
+ <p align = "center">This repository contains the primary parser for AtmosphericX's NOAA Weather Wire Service (NWWS) and National Weather Service (NWS) API. It is designed to handle real-time weather alerts and messages from the National Weather Service, using both XMPP (NWWS) and direct API access (Slower). This parser is intended for developers who want to integrate real-time weather alerts, watches, warnings, and forecast data from the NWS seamlessly into their applications or services. It is not recommended for users without basic programming knowledge. If you wish to access NOAA weather data without programming, consider using our end-user project, which leverages this parser and provides an easy-to-use interface for tracking weather alerts.</small></p>
4
+ <p align = "center">Documentation written by @k3yomi</p>
5
+ <div align="center" style="border: none;">
6
+ <img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/k3yomi/atmosx-nwws-parser">
7
+ <img alt="GitHub forks" src="https://img.shields.io/github/forks/k3yomi/atmosx-nwws-parser">
8
+ <img alt="GitHub issues" src="https://img.shields.io/github/issues/k3yomi/atmosx-nwws-parser">
9
+ <img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/k3yomi/atmosx-nwws-parser">
10
+ </div>
11
+ </div>
12
+
13
+ ## Installation (NPM)
9
14
  ```bash
10
15
  npm install atmosx-nwws-parser
11
16
  ```
12
17
 
13
- ## Usage
14
- ```js
15
- const AtmosXWireParser = require(`atmosx-nwws-parser`); // CJS
16
- import * as AtmosXWireParser from `atmosx-nwws-parser`; // ESM
17
- ```
18
-
19
- ## Configuration and Initialization
20
-
21
- There are several settings you can configure when intializing the parser. Below is the test.js example that shows some of the settings you can use:
22
-
23
- ```js
24
- let Client = new AtmosXWireParser.Parser({
25
- alertSettings: {
26
- onlyCap: false, // Set to true to only receive CAP messages only
27
- betterEvents: true, // Set to true to receive better event handling
28
- ugcPolygons: false, // Set to true to receive UGC Polygons instead of reading from raw products.
29
- expiryCheck: true, // Set to true to check for expired alerts and remove them from the list
30
- filteredAlerts: [] // Alerts you want to only log, leave empty to receive all alerts (Ex. ["Tornado Warning", "Radar Indicated Tornado Warning"])
31
- },
32
- xmpp: {
33
- reconnect: true, // Set to true to enable automatic reconnection if you lose connection
34
- reconnectInterval: 60, // Interval in seconds to attempt reconnection
18
+ ## Example Usage
19
+ ```javascript
20
+ const { AlertManager } = require('atmosx-nwws-parser'); // CJS
21
+ import { AlertManager } from 'atmosx-nwws-parser'; // ESM
22
+
23
+ const parser = new AlertManager({
24
+ database: `shapefiles.db`,
25
+ is_wire: true,
26
+ journal: true,
27
+ noaa_weather_wire_service_settings: {
28
+ reconnection_settings: {
29
+ enabled: true,
30
+ interval: 60,
31
+ },
32
+ credentials: {
33
+ username: `username_here`,
34
+ password: `password_here`,
35
+ nickname: "AtmosphericX Parser",
36
+ },
37
+ cache: {
38
+ enabled: true,
39
+ max_file_size: 5,
40
+ max_db_history: 5000,
41
+ directory: `meow`,
42
+ },
43
+ preferences: {
44
+ disable_ugc: false,
45
+ disable_vtec: false,
46
+ disable_text: false,
47
+ cap_only: false,
48
+ }
35
49
  },
36
- cacheSettings: {
37
- maxMegabytes: 2, // Maximum cache size in megabytes
38
- readCache: false, // Set to true if you wish to reupload the cache from earlier (Now supports reading from CAP, SPS, and Alerts)
39
- cacheDir: `./cache`, // Directory for cache files
50
+ national_weather_service_settings: {
51
+ interval: 15,
52
+ endpoint: `https://api.weather.gov/alerts/active`,
40
53
  },
41
- authentication: {
42
- username: `USERNAME_HERE`, // Your XMPP username
43
- password: `PASSWORD_HERE`, // Your XMPP password
44
- display: `DISPLAY_NAME` // Display name for your XMPP client
54
+ global_settings: {
55
+ parent_events_only: true,
56
+ better_event_parsing: true,
57
+ shapefile_coordinates: false,
58
+ shapefile_skip: 10,
59
+ filtering: {
60
+ events: [`Severe Thunderstorm Warning`],
61
+ filtered_icao: [],
62
+ ignored_icao: [`KWNS`],
63
+ ignored_events: [`Xx`, `Test Message`],
64
+ ugc_filter: [],
65
+ state_filter: [],
66
+ check_expired: true,
67
+ ignore_text_products: true,
68
+ location: {
69
+ unit: `miles`
70
+ },
71
+ },
72
+ eas_settings: {
73
+ directory: null,
74
+ intro_wav: null,
75
+ }
45
76
  },
46
- database: `./database.db`, // Path to the SQLite database file (It will be created if it doesn't exist and will be used to store UGC counties and zones.)
77
+ })
78
+ ```
79
+
80
+ ## NOAA Weather Wire Service (Getting Started)
81
+ To use the NOAA Weather Wire Service (NWWS). You would need to obtain credentials from the National Weather Service. Follow these steps:
82
+ 1. Visit the [NOAA NWWS Registration Page](https://www.weather.gov/nwws/nwws_oi_request).
83
+ 2. Fill out the registration form with the required information.
84
+ 3. Submit the form and wait for approval. You will receive your NWWS credentials via email.
85
+
86
+ ## Events and Listeners
87
+ > All events are in GeoJSON.
88
+
89
+ ### Event `onEvents`
90
+ Triggered when a batch of new alerts are received and processed.
91
+ ```javascript
92
+ parser.on(`onEvents`, (alerts) => {
93
+ console.log(`Received ${alerts.length} new alerts.`);
94
+ alerts.forEach(alert => {
95
+ console.log(`${alert.properties.event} for ${alert.properties.locations}`);
96
+ });
97
+ });
98
+ ```
99
+ Alternatively, you can listen for single alert events using `onSevereThunderstormWarning` or `onTornadoWarning`, etc.
100
+ ```javascript
101
+ parser.on(`onTornadoWarning`, (alert) => {
102
+ console.log(`Tornado Warning issued for ${alert.properties.locations}`);
47
103
  });
48
104
  ```
49
105
 
106
+ ### Event `onReconnection`
107
+ Triggered when the parser attempts to reconnect to the NWWS service.
108
+ ```javascript
109
+ parser.on(`onReconnection`, (data) => {
110
+ console.log(`Reconnection attempt #${data.reconnects}`);
111
+ });
112
+ ```
50
113
 
51
- ## Event Handling
114
+ ### Event `onConnection`
115
+ Triggered when the parser successfully connects to the NWWS service.
116
+ ```javascript
117
+ parser.on(`onConnection`, (nickname) => {
118
+ console.log(`Connected to NWWS service as ${nickname}`);
119
+ });
120
+ ```
52
121
 
53
- You can handle various events emitted by the parser. Here are some examples:
122
+ ### Event `onOccupant`
123
+ Triggered when a new occupant is detected on the NWWS XMPP service.
124
+ ```javascript
125
+ parser.on(`onOccupant`, (data) => {
126
+ console.log(`New occupant detected: ${data.occupant}`);
127
+ });
128
+ ```
54
129
 
55
- ```js
56
- Client.onEvent(`onAlert`, (alerts: Array) => {});
57
- Client.onEvent(`onStormReport`, (report: Object) => {});
58
- Client.onEvent(`onMesoscaleDiscussion`, (discussion: Object) => {});
59
- Client.onEvent(`onMessage`, (stanza: Object) => {});
60
- Client.onEvent(`onOccupant`, (occupant: Object) => {});
61
- Client.onEvent(`onError`, (error: Object) => {});
62
- Client.onEvent(`onReconnect`, (service: Object) => {});
130
+ ### Event `onMessage`
131
+ Triggered when a stanza message is validated and received from the XMPP client.
132
+ ```javascript
133
+ parser.on(`onMessage`, (data) => {
134
+ console.log(`Message received from ${data.from}: ${data.message}`);
135
+ });
136
+ ```
63
137
 
138
+ ### Event `log`
139
+ Triggered for logging purposes, providing log level and message.
140
+ ```javascript
141
+ parser.on(`log`, (message) => {
142
+ console.log(data.message);
143
+ });
64
144
  ```
65
145
 
66
- ## Functions and Methods
67
- You can also use various functions provided by the parser. Here are some examples:
146
+ ## Callbacks and Functions
68
147
 
69
- ```js
70
- // Function to set the display name of the XMPP client (Will only set upon reconnect)
71
- Client.setDisplayName(displayName: String);
148
+ ### Function `setDisplayName(name)`
149
+ Sets the display name for the XMPP client. This requires reconnection to take effect.
150
+ ```javascript
151
+ parser.setDisplayName(`My Weather Parser`);
72
152
  ```
73
153
 
74
- ```js
75
- // Function to manually trigger the cache initialization (Usually called automatically on startup if readCache is true)
76
- Client.initalizeCache()
154
+ ### Function `setCurrentLocation(name, {latitude, longitude})`
155
+ Sets the current location for the parser, which can be used for location-based filtering.
156
+ ```javascript
157
+ parser.setCurrentLocation(`My Location`, {34.05, -118.25 });
77
158
  ```
78
159
 
79
- ## Error Handling
80
- The parser can emit various errors. Here are some common errors you might encounter:
160
+ ### Function `createEasAudio(description, header)`
161
+ Generates an EAS audio file based on the provided description and header. Audio file will be located based on settings provided in the global_settings.eas_settings object.
162
+ ```javascript
163
+ parser.createEasAudio(`This is a test alert`, `EAS Header Info`);
164
+ ```
81
165
 
82
- **error-database-not-configured**: This error occurs when the database is not configured properly. Please set the database path in the constructor.
166
+ ### Function `getAllAlertTypes()`
167
+ Returns an array of all supported alert types by the parser.
168
+ ```javascript
169
+ const alertTypes = parser.getAllAlertTypes();
170
+ console.log(alertTypes);
171
+ ```
83
172
 
84
- **error-reconnecting-too-fast**: This error occurs when the client is attempting to reconnect too fast. Please wait a few seconds before trying again.
173
+ ### Function `searchStanzaDatabase(query)`
174
+ Searches the internal stanza database for messages matching the provided query.
175
+ ```javascript
176
+ const results = parser.searchStanzaDatabase(`Tornado Warning`);
177
+ console.log(results);
178
+ ```
85
179
 
86
- **error-connection-lost**: This error occurs when the connection to the XMPP server has been lost. Please try reconnecting manually as the automatic reconnect feature is not setup for offline halt conditions.
180
+ ### Function `setSettings({})`
181
+ Dynamically updates the parser settings. Accepts the same configuration object as the constructor.
182
+ ```javascript
183
+ parser.setSettings({
184
+ global_settings: {
185
+ filtering: {
186
+ ignored_icao: [`KXYZ`],
187
+ }
188
+ }
189
+ });
190
+ ```
87
191
 
192
+ ### Function `stop()`
193
+ Stops the parser and disconnects from the NWWS service.
194
+ ```javascript
195
+ parser.stop();
196
+ ```
88
197
 
89
- ## Credits
90
- This parser is developed and maintained by [K3YOMI](https://github.com/K3YOMI) and the AtmosphericX Team. It is open-source and available for contributions and improvements. If you find any issues or have suggestions, feel free to open an issue or submit a pull request in the repository.
198
+ ## References
199
+ - [NOAA NWWS Information](https://www.weather.gov/nwws/)
200
+ - [NWS API Documentation](https://www.weather.gov/documentation/services-web-api)
201
+ - [XMPP Protocol](https://xmpp.org/about/technology-overview/)
202
+ - [AtmosphericX](https://github.com/k3yomi/AtmosphericX)
203
+
204
+ ## Acknowledgements
205
+ - [k3yomi](https://github.com/k3yomi)
206
+ - Lead developer @ AtmosphericX and maintainer of this module.
207
+ - [StarflightWx](https://x.com/starflightVR)
208
+ - For testing and providing feedback (Co-Developer and Spotter @ AtmosphericX)