atmosx-nwws-parser 1.0.202 → 1.0.211

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 (75) hide show
  1. package/README.md +203 -3
  2. package/dist/cjs/index.cjs +3730 -0
  3. package/dist/esm/index.mjs +3688 -0
  4. package/package.json +4 -3
  5. package/src/bootstrap.ts +70 -48
  6. package/src/database.ts +97 -48
  7. package/src/dictionaries/events.ts +45 -12
  8. package/src/dictionaries/signatures.ts +43 -45
  9. package/src/eas.ts +146 -81
  10. package/src/index.ts +229 -0
  11. package/src/parsers/{types → events}/api.ts +65 -19
  12. package/src/parsers/events/cap.ts +132 -0
  13. package/src/parsers/events/text.ts +101 -0
  14. package/src/parsers/events/ugc.ts +104 -0
  15. package/src/parsers/events/vtec.ts +73 -0
  16. package/src/parsers/events.ts +215 -155
  17. package/src/parsers/hvtec.ts +46 -0
  18. package/src/parsers/{vtec.ts → pvtec.ts} +32 -27
  19. package/src/parsers/stanza.ts +70 -41
  20. package/src/parsers/text.ts +45 -46
  21. package/src/parsers/ugc.ts +114 -75
  22. package/src/types.ts +240 -170
  23. package/src/utils.ts +196 -99
  24. package/src/xmpp.ts +86 -65
  25. package/test.js +63 -1
  26. package/tsup.config.ts +10 -7
  27. package/dist/cjs/bootstrap.cjs +0 -1000
  28. package/dist/cjs/database.cjs +0 -1105
  29. package/dist/cjs/dictionaries/awips.cjs +0 -370
  30. package/dist/cjs/dictionaries/events.cjs +0 -139
  31. package/dist/cjs/dictionaries/icao.cjs +0 -265
  32. package/dist/cjs/dictionaries/offshore.cjs +0 -40
  33. package/dist/cjs/dictionaries/signatures.cjs +0 -132
  34. package/dist/cjs/eas.cjs +0 -2851
  35. package/dist/cjs/helper.cjs +0 -3013
  36. package/dist/cjs/parsers/events.cjs +0 -2851
  37. package/dist/cjs/parsers/stanza.cjs +0 -1099
  38. package/dist/cjs/parsers/text.cjs +0 -1133
  39. package/dist/cjs/parsers/types/api.cjs +0 -2851
  40. package/dist/cjs/parsers/types/cap.cjs +0 -2851
  41. package/dist/cjs/parsers/types/text.cjs +0 -2851
  42. package/dist/cjs/parsers/types/ugc.cjs +0 -2851
  43. package/dist/cjs/parsers/types/vtec.cjs +0 -2851
  44. package/dist/cjs/parsers/ugc.cjs +0 -1130
  45. package/dist/cjs/parsers/vtec.cjs +0 -1051
  46. package/dist/cjs/types.cjs +0 -17
  47. package/dist/cjs/utils.cjs +0 -2851
  48. package/dist/cjs/xmpp.cjs +0 -2851
  49. package/dist/esm/bootstrap.mjs +0 -963
  50. package/dist/esm/database.mjs +0 -1070
  51. package/dist/esm/dictionaries/awips.mjs +0 -346
  52. package/dist/esm/dictionaries/events.mjs +0 -111
  53. package/dist/esm/dictionaries/icao.mjs +0 -241
  54. package/dist/esm/dictionaries/offshore.mjs +0 -16
  55. package/dist/esm/dictionaries/signatures.mjs +0 -106
  56. package/dist/esm/eas.mjs +0 -2818
  57. package/dist/esm/helper.mjs +0 -2972
  58. package/dist/esm/parsers/events.mjs +0 -2818
  59. package/dist/esm/parsers/stanza.mjs +0 -1063
  60. package/dist/esm/parsers/text.mjs +0 -1097
  61. package/dist/esm/parsers/types/api.mjs +0 -2818
  62. package/dist/esm/parsers/types/cap.mjs +0 -2818
  63. package/dist/esm/parsers/types/text.mjs +0 -2818
  64. package/dist/esm/parsers/types/ugc.mjs +0 -2818
  65. package/dist/esm/parsers/types/vtec.mjs +0 -2818
  66. package/dist/esm/parsers/ugc.mjs +0 -1095
  67. package/dist/esm/parsers/vtec.mjs +0 -1016
  68. package/dist/esm/types.mjs +0 -0
  69. package/dist/esm/utils.mjs +0 -2818
  70. package/dist/esm/xmpp.mjs +0 -2818
  71. package/src/helper.ts +0 -167
  72. package/src/parsers/types/cap.ts +0 -89
  73. package/src/parsers/types/text.ts +0 -54
  74. package/src/parsers/types/ugc.ts +0 -85
  75. package/src/parsers/types/vtec.ts +0 -60
package/README.md CHANGED
@@ -1,6 +1,206 @@
1
- # AtmosphericX - NOAA Weather Wire & NWS API Parser
1
+ <h1 style='font-size: 65px'; align="center">🌪️ AtmosphericX - NOAA Weather 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>
2
12
 
13
+ ## Installation (NPM)
14
+ ```bash
15
+ npm install atmosx-nwws-parser
16
+ ```
3
17
 
4
- This repository contains the parsing of both NOAA Weather Wire Service and National Weather Service. 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.
18
+ ## Example Usage
19
+ ```javascript
20
+ const { AlertManager } = require('atmosx-nwws-parser'); // CJS
21
+ import { AlertManager } from 'atmosx-nwws-parser'; // ESM
5
22
 
6
- TODO: Complete later...
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
+ shapefile_coordinates: false,
49
+ }
50
+ },
51
+ national_weather_service_settings: {
52
+ interval: 15,
53
+ endpoint: `https://api.weather.gov/alerts/active`,
54
+ },
55
+ global_settings: {
56
+ parent_events_only: true,
57
+ better_event_parsing: true,
58
+ filtering: {
59
+ events: [`Severe Thunderstorm Warning`],
60
+ filtered_icoa: [],
61
+ ignored_icoa: [`KWNS`],
62
+ ignored_events: [`Xx`, `Test Message`],
63
+ ugc_filter: [],
64
+ state_filter: [],
65
+ check_expired: true,
66
+ ignore_text_products: true,
67
+ location: {
68
+ unit: `miles`
69
+ },
70
+ },
71
+ eas_settings: {
72
+ directory: null,
73
+ intro_wav: null,
74
+ }
75
+ },
76
+ })
77
+ ```
78
+
79
+ ## NOAA Weather Wire Service (Getting Started)
80
+ To use the NOAA Weather Wire Service (NWWS). You would need to obtain credentials from the National Weather Service. Follow these steps:
81
+ 1. Visit the [NOAA NWWS Registration Page](https://www.weather.gov/nwws/nwws_oi_request).
82
+ 2. Fill out the registration form with the required information.
83
+ 3. Submit the form and wait for approval. You will receive your NWWS credentials via email.
84
+
85
+ ## Events and Listeners
86
+
87
+ ### Event `onAlerts`
88
+ Triggered when a batch of new alerts are received and processed. This will come with an array of alert objects.
89
+ ```javascript
90
+ parser.on(`onAlerts`, (alerts) => {
91
+ console.log(`Received ${alerts.length} new alerts.`);
92
+ alerts.forEach(alert => {
93
+ console.log(`${alert.properties.event} for ${alert.properties.locations}`);
94
+ });
95
+ });
96
+ ```
97
+ Alternatively, you can listen for single alert events using `onSevereThunderstormWarning` or `onTornadoWarning`, etc.
98
+ ```javascript
99
+ parser.on(`onTornadoWarning`, (alert) => {
100
+ console.log(`Tornado Warning issued for ${alert.properties.locations}`);
101
+ });
102
+ ```
103
+
104
+ ### Event `onReconnection`
105
+ Triggered when the parser attempts to reconnect to the NWWS service.
106
+ ```javascript
107
+ parser.on(`onReconnection`, (data) => {
108
+ console.log(`Reconnection attempt #${data.reconnects}`);
109
+ });
110
+ ```
111
+
112
+ ### Event `onConnection`
113
+ Triggered when the parser successfully connects to the NWWS service.
114
+ ```javascript
115
+ parser.on(`onConnection`, (nickname) => {
116
+ console.log(`Connected to NWWS service as ${nickname}`);
117
+ });
118
+ ```
119
+
120
+ ### Event `onOccupant`
121
+ Triggered when a new occupant is detected on the NWWS XMPP service.
122
+ ```javascript
123
+ parser.on(`onOccupant`, (data) => {
124
+ console.log(`New occupant detected: ${data.occupant}`);
125
+ });
126
+ ```
127
+
128
+ ### Event `onMessage`
129
+ Triggered when a stanza message is validated and received from the XMPP client.
130
+ ```javascript
131
+ parser.on(`onMessage`, (data) => {
132
+ console.log(`Message received from ${data.from}: ${data.message}`);
133
+ });
134
+ ```
135
+
136
+ ### Event `log`
137
+ Triggered for logging purposes, providing log level and message.
138
+ ```javascript
139
+ parser.on(`log`, (message) => {
140
+ console.log(data.message);
141
+ });
142
+ ```
143
+
144
+ ## Callbacks and Functions
145
+
146
+ ### Function `setDisplayName(name)`
147
+ Sets the display name for the XMPP client. This requires reconnection to take effect.
148
+ ```javascript
149
+ parser.setDisplayName(`My Weather Parser`);
150
+ ```
151
+
152
+ ### Function `setCurrentLocation(name, {latitude, longitude})`
153
+ Sets the current location for the parser, which can be used for location-based filtering.
154
+ ```javascript
155
+ parser.setCurrentLocation(`My Location`, {34.05, -118.25 });
156
+ ```
157
+
158
+ ### Function `createEasAudio(description, header)`
159
+ 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.
160
+ ```javascript
161
+ parser.createEasAudio(`This is a test alert`, `EAS Header Info`);
162
+ ```
163
+
164
+ ### Function `getAllAlertTypes()`
165
+ Returns an array of all supported alert types by the parser.
166
+ ```javascript
167
+ const alertTypes = parser.getAllAlertTypes();
168
+ console.log(alertTypes);
169
+ ```
170
+
171
+ ### Function `searchStanzaDatabase(query)`
172
+ Searches the internal stanza database for messages matching the provided query.
173
+ ```javascript
174
+ const results = parser.searchStanzaDatabase(`Tornado Warning`);
175
+ console.log(results);
176
+ ```
177
+
178
+ ### Function `setSettings({})`
179
+ Dynamically updates the parser settings. Accepts the same configuration object as the constructor.
180
+ ```javascript
181
+ parser.setSettings({
182
+ global_settings: {
183
+ filtering: {
184
+ ignored_icoa: [`KXYZ`],
185
+ }
186
+ }
187
+ });
188
+ ```
189
+
190
+ ### Function `stop()`
191
+ Stops the parser and disconnects from the NWWS service.
192
+ ```javascript
193
+ parser.stop();
194
+ ```
195
+
196
+ ## References
197
+ - [NOAA NWWS Information](https://www.weather.gov/nwws/)
198
+ - [NWS API Documentation](https://www.weather.gov/documentation/services-web-api)
199
+ - [XMPP Protocol](https://xmpp.org/about/technology-overview/)
200
+ - [AtmosphericX](https://github.com/k3yomi/AtmosphericX)
201
+
202
+ ## Acknowledgements
203
+ - [k3yomi](https://github.com/k3yomi)
204
+ - Lead developer @ AtmosphericX and maintainer of this module.
205
+ - [StarflightWx](https://x.com/starflightVR)
206
+ - For testing and providing feedback (Co-Developer and Spotter @ AtmosphericX)