atmosx-nwws-parser 1.0.185 → 1.0.191

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 CHANGED
@@ -12,7 +12,8 @@ npm install atmosx-nwws-parser
12
12
 
13
13
  ## Usage
14
14
  ```js
15
- const AtmosXWireParser = require(`atmosx-nwws-parser`);
15
+ const AtmosXWireParser = require(`atmosx-nwws-parser`); // CJS
16
+ import * as AtmosXWireParser from `atmosx-nwws-parser`; // ESM
16
17
  ```
17
18
 
18
19
  ## Configuration and Initialization
@@ -20,7 +21,7 @@ const AtmosXWireParser = require(`atmosx-nwws-parser`);
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:
21
22
 
22
23
  ```js
23
- let Client = new AtmosXWireParser({
24
+ let Client = new AtmosXWireParser.Parser({
24
25
  alertSettings: {
25
26
  onlyCap: false, // Set to true to only receive CAP messages only
26
27
  betterEvents: true, // Set to true to receive better event handling
@@ -64,26 +65,26 @@ Client.onEvent(`onReconnect`, (service: Object) => {});
64
65
 
65
66
  ## Functions and Methods
66
67
  You can also use various functions provided by the parser. Here are some examples:
67
- ```js
68
- // Debugging function to create your own alert manually
69
- Client.forwardCustomStanza(stanza: String, attributes: Object);
70
- ```
71
68
 
72
69
  ```js
73
70
  // Function to set the display name of the XMPP client (Will only set upon reconnect)
74
71
  Client.setDisplayName(displayName: String);
75
72
  ```
76
73
 
74
+ ```js
75
+ // Function to manually trigger the cache initialization (Usually called automatically on startup if readCache is true)
76
+ Client.initalizeCache()
77
+ ```
78
+
77
79
  ## Error Handling
78
80
  The parser can emit various errors. Here are some common errors you might encounter:
79
81
 
80
- **not-authorized**: This error occurs when the parser is not authorized to connect to the XMPP server. Ensure that your username and password are correct.
82
+ **error-database-not-configured**: This error occurs when the database is not configured properly. Please set the database path in the constructor.
81
83
 
82
- **unreachable-host**: This error indicates that the parser cannot reach the XMPP server. Check your internet connection and ensure that the server address is correct.
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.
83
85
 
84
- **service-error**: This error occurs when there is an issue with the XMPP service. It could be due to server maintenance or other issues. You can try reconnecting after some time.
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.
85
87
 
86
- **no-database-dir**: This error occurs when the database directory does not exist. Ensure that the directory specified in the `database` setting exists or create it before running the parser.
87
88
 
88
89
  ## Credits
89
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.
@@ -1,32 +1,69 @@
1
- module.exports = {
2
- cache: {},
3
- settings: {},
4
- static: {},
5
- packages: {},
6
- definitions: {}
7
- }
1
+ /*
2
+ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Written by: k3yomi@GitHub
12
+ */
8
13
 
9
- module.exports.packages = {
10
- fs: require(`fs`),
11
- path: require(`path`),
12
- events: require(`events`),
13
- xmpp: require(`@xmpp/client`),
14
- shapefile: require(`shapefile`),
15
- xml2js: require(`xml2js`),
16
- sqlite3: require(`better-sqlite3`),
17
- mStanza: require(`./src/stanza.js`),
18
- mVtec: require(`./src/vtec.js`),
19
- mUGC: require(`./src/ugc.js`),
20
- mText: require(`./src/text.js`),
21
- mEvents: require(`./src/events.js`),
22
14
 
23
- }
15
+ import * as fs from 'fs';
16
+ import * as path from 'path';
17
+ import * as events from 'events';
18
+ import * as xmpp from '@xmpp/client';
19
+ import * as shapefile from 'shapefile';
20
+ import * as xml2js from 'xml2js';
21
+ import sqlite3 from 'better-sqlite3';
24
22
 
25
- module.exports.definitions = {
23
+
24
+ export const packages = {fs, path, events, xmpp, shapefile, xml2js, sqlite3 };
25
+
26
+ export const statics = {
27
+ events: new events.EventEmitter(),
28
+ session: null as any,
29
+ db: null as any,
30
+ };
31
+
32
+ export const cache = {
33
+ lastStanza: Date.now(),
34
+ session: null as any,
35
+ lastConnect: null as any,
36
+ sigHault: false,
37
+ isConnected: false,
38
+ attemptingReconnect: false,
39
+ totalReconnects: 0
40
+ };
41
+
42
+ export const settings = {
43
+ alertSettings: {
44
+ ugcPolygons: false,
45
+ onlyCap: false,
46
+ betterEvents: false,
47
+ expiryCheck: true,
48
+ filteredAlerts: [],
49
+ },
50
+ xmpp: {
51
+ reconnect: true,
52
+ reconnectInterval: 60,
53
+ },
54
+ cacheSettings: {
55
+ readCache: false,
56
+ maxMegabytes: 1,
57
+ cacheDir: null,
58
+ },
59
+ database: path.join(process.cwd(), 'shapefiles.db'),
60
+ };
61
+
62
+ export const definitions = {
26
63
  events: { "AF": "Ashfall", "AS": "Air Stagnation", "BH": "Beach Hazard", "BW": "Brisk Wind", "BZ": "Blizzard", "CF": "Coastal Flood", "DF": "Debris Flow", "DS": "Dust Storm", "EC": "Extreme Cold", "EH": "Excessive Heat", "XH": "Extreme Heat", "EW": "Extreme Wind", "FA": "Areal Flood", "FF": "Flash Flood", "FG": "Dense Fog", "FL": "Flood", "FR": "Frost", "FW": "Fire Weather", "FZ": "Freeze", "GL": "Gale", "HF": "Hurricane Force Wind", "HT": "Heat", "HU": "Hurricane", "HW": "High Wind", "HY": "Hydrologic", "HZ": "Hard Freeze", "IS": "Ice Storm", "LE": "Lake Effect Snow", "LO": "Low Water", "LS": "Lakeshore Flood", "LW": "Lake Wind", "MA": "Special Marine", "MF": "Dense Fog", "MH": "Ashfall", "MS": "Dense Smoke", "RB": "Small Craft for Rough Bar", "RP": "Rip Current Risk", "SC": "Small Craft", "SE": "Hazardous Seas", "SI": "Small Craft for Winds", "SM": "Dense Smoke", "SQ": "Snow Squall", "SR": "Storm", "SS": "Storm Surge", "SU": "High Surf", "SV": "Severe Thunderstorm", "SW": "Small Craft for Hazardous Seas", "TO": "Tornado", "TR": "Tropical Storm", "TS": "Tsunami", "TY": "Typhoon", "UP": "Heavy Freezing Spray", "WC": "Wind Chill", "WI": "Wind", "WS": "Winter Storm", "WW": "Winter Weather", "ZF": "Freezing Fog", "ZR": "Freezing Rain", "ZY": "Freezing Spray" },
27
64
  actions: { "W": "Warning", "F": "Forecast", "A": "Watch", "O": "Outlook", "Y": "Advisory", "N": "Synopsis", "S": "Statement"},
28
65
  status: { "NEW": "Issued", "CON": "Updated", "EXT": "Extended", "EXA": "Extended", "EXB": "Extended", "UPG": "Upgraded", "COR": "Correction", "ROU": "Routine", "CAN": "Cancelled", "EXP": "Expired" },
29
- awips: { SWOMCD: `mesoscale-discussion`, LSR: `local-storm-report`, SPS: `special-weather-statement`, LSR: "local-storm-report"},
66
+ awips: { SWOMCD: `mesoscale-discussion`, LSR: `local-storm-report`, SPS: `special-weather-statement`},
30
67
  expressions: {
31
68
  vtec: `[OTEX].(NEW|CON|EXT|EXA|EXB|UPG|CAN|EXP|COR|ROU).[A-Z]{4}.[A-Z]{2}.[WAYSFON].[0-9]{4}.[0-9]{6}T[0-9]{4}Z-[0-9]{6}T[0-9]{4}Z`,
32
69
  wmo: `[A-Z0-9]{6}\\s[A-Z]{4}\\s\\d{6}`,
@@ -74,39 +111,12 @@ module.exports.definitions = {
74
111
  "SOURCE...LAW ENFORCEMENT REPORTED.": "Confirmed by Law Enforcement"
75
112
  },
76
113
  haultingConditions: [
77
- { error: "not-authorized", message: "You do not have the proper credentials to access this service.", code: "credential-error"},
78
- { error: "unreachable-host", message: "The host could not be reached. Please check your internet connection or the host address.", code: "xmpp-error" },
79
- { error: "service-error", message: "An error occurred while connecting to the NOAA Weather Wire Service. Please try again later.", code: "xmpp-error" },
80
- { error: "no-database-dir", message: "Database directory is not set. Please set the databaseDir in the metadata.", code: "no-database" },
81
- { error: "rapid-reconnect", message: "The client is reconnecting too rapidly. Please wait a moment before trying again.", code: "xmpp-error" }
82
- ]
83
- }
84
- module.exports.settings = {
85
- alertSettings: {
86
- ugcPolygons: false,
87
- onlyCap: false,
88
- betterEvents: false,
89
- expiryCheck: true,
90
- filteredAlerts: [],
91
- },
92
- xmpp: {
93
- reconnect: true,
94
- reconnectInterval: 60,
95
- },
96
- cacheSettings: {
97
- readCache: false,
98
- maxMegabytes: 1,
99
- cacheDir: false,
100
- },
101
- database: module.exports.packages.path.join(process.cwd(), 'shapefiles.db'),
114
+ { error: "error-database-not-configured", message: "The database is not configured properly. Please set the database path in the constructor." },
115
+ { error: "error-reconnecting-too-fast", message: "The client is attempting to reconnect too fast. Please wait a few seconds before trying again." },
116
+ { error: "error-connection-lost", message: "The connection to the XMPP server has been lost. Please try reconnecting manually as the automatic reconnect feature is not setup for offline hault conditions." },
117
+ ],
118
+ messages: {
119
+ shapefile_creation: `\n\n[NOTICE] DO NOT CLOSE THIS PROJECT UNTIL THE SHAPEFILES ARE DONE COMPLETING!\n\t THIS COULD TAKE A WHILE DEPENDING ON THE SPEED OF YOUR STORAGE!!\n\t IF YOU CLOSE YOUR PROJECT, THE SHAPEFILES WILL NOT BE CREATED AND YOU WILL NEED TO DELETE ${settings.database} AND RESTART TO CREATE THEM AGAIN!\n\n`,
120
+ shapefile_creation_finished: `\n\n[NOTICE] SHAPEFILES HAVE BEEN SUCCESSFULLY CREATED AND THE DATABASE IS READY FOR USE!\n\n`
121
+ }
102
122
  };
103
- module.exports.cache = {
104
- lastStanza: new Date().getTime(),
105
- session: null,
106
- sigHault: false,
107
- isConnected: false,
108
- attemptingReconnect: false,
109
- totalReconnects: 0
110
- };
111
-
112
- module.exports.static.events = new module.exports.packages.events.EventEmitter();
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ /*
3
+ _ _ __ __
4
+ /\ | | | | (_) \ \ / /
5
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
6
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
7
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
8
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
9
+ | |
10
+ |_|
11
+
12
+ Written by: k3yomi@GitHub
13
+ */
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.definitions = exports.settings = exports.cache = exports.statics = exports.packages = void 0;
52
+ var fs = __importStar(require("fs"));
53
+ var path = __importStar(require("path"));
54
+ var events = __importStar(require("events"));
55
+ var xmpp = __importStar(require("@xmpp/client"));
56
+ var shapefile = __importStar(require("shapefile"));
57
+ var xml2js = __importStar(require("xml2js"));
58
+ var better_sqlite3_1 = __importDefault(require("better-sqlite3"));
59
+ exports.packages = { fs: fs, path: path, events: events, xmpp: xmpp, shapefile: shapefile, xml2js: xml2js, sqlite3: better_sqlite3_1.default };
60
+ exports.statics = {
61
+ events: new events.EventEmitter(),
62
+ session: null,
63
+ db: null,
64
+ };
65
+ exports.cache = {
66
+ lastStanza: Date.now(),
67
+ session: null,
68
+ lastConnect: null,
69
+ sigHault: false,
70
+ isConnected: false,
71
+ attemptingReconnect: false,
72
+ totalReconnects: 0
73
+ };
74
+ exports.settings = {
75
+ alertSettings: {
76
+ ugcPolygons: false,
77
+ onlyCap: false,
78
+ betterEvents: false,
79
+ expiryCheck: true,
80
+ filteredAlerts: [],
81
+ },
82
+ xmpp: {
83
+ reconnect: true,
84
+ reconnectInterval: 60,
85
+ },
86
+ cacheSettings: {
87
+ readCache: false,
88
+ maxMegabytes: 1,
89
+ cacheDir: null,
90
+ },
91
+ database: path.join(process.cwd(), 'shapefiles.db'),
92
+ };
93
+ exports.definitions = {
94
+ events: { "AF": "Ashfall", "AS": "Air Stagnation", "BH": "Beach Hazard", "BW": "Brisk Wind", "BZ": "Blizzard", "CF": "Coastal Flood", "DF": "Debris Flow", "DS": "Dust Storm", "EC": "Extreme Cold", "EH": "Excessive Heat", "XH": "Extreme Heat", "EW": "Extreme Wind", "FA": "Areal Flood", "FF": "Flash Flood", "FG": "Dense Fog", "FL": "Flood", "FR": "Frost", "FW": "Fire Weather", "FZ": "Freeze", "GL": "Gale", "HF": "Hurricane Force Wind", "HT": "Heat", "HU": "Hurricane", "HW": "High Wind", "HY": "Hydrologic", "HZ": "Hard Freeze", "IS": "Ice Storm", "LE": "Lake Effect Snow", "LO": "Low Water", "LS": "Lakeshore Flood", "LW": "Lake Wind", "MA": "Special Marine", "MF": "Dense Fog", "MH": "Ashfall", "MS": "Dense Smoke", "RB": "Small Craft for Rough Bar", "RP": "Rip Current Risk", "SC": "Small Craft", "SE": "Hazardous Seas", "SI": "Small Craft for Winds", "SM": "Dense Smoke", "SQ": "Snow Squall", "SR": "Storm", "SS": "Storm Surge", "SU": "High Surf", "SV": "Severe Thunderstorm", "SW": "Small Craft for Hazardous Seas", "TO": "Tornado", "TR": "Tropical Storm", "TS": "Tsunami", "TY": "Typhoon", "UP": "Heavy Freezing Spray", "WC": "Wind Chill", "WI": "Wind", "WS": "Winter Storm", "WW": "Winter Weather", "ZF": "Freezing Fog", "ZR": "Freezing Rain", "ZY": "Freezing Spray" },
95
+ actions: { "W": "Warning", "F": "Forecast", "A": "Watch", "O": "Outlook", "Y": "Advisory", "N": "Synopsis", "S": "Statement" },
96
+ status: { "NEW": "Issued", "CON": "Updated", "EXT": "Extended", "EXA": "Extended", "EXB": "Extended", "UPG": "Upgraded", "COR": "Correction", "ROU": "Routine", "CAN": "Cancelled", "EXP": "Expired" },
97
+ awips: { SWOMCD: "mesoscale-discussion", LSR: "local-storm-report", SPS: "special-weather-statement" },
98
+ expressions: {
99
+ vtec: "[OTEX].(NEW|CON|EXT|EXA|EXB|UPG|CAN|EXP|COR|ROU).[A-Z]{4}.[A-Z]{2}.[WAYSFON].[0-9]{4}.[0-9]{6}T[0-9]{4}Z-[0-9]{6}T[0-9]{4}Z",
100
+ wmo: "[A-Z0-9]{6}\\s[A-Z]{4}\\s\\d{6}",
101
+ ugc1: "(\\w{2}[CZ](\\d{3}((-|>)\\s?(\n\n)?))+)",
102
+ ugc2: "(\\d{6}(-|>)\\s?(\n\n)?)",
103
+ dateline: "/d{3,4}s*(AM|PM)?s*[A-Z]{2,4}s+[A-Z]{3,}s+[A-Z]{3,}s+d{1,2}s+d{4}"
104
+ },
105
+ tags: {
106
+ "A LARGE AND EXTREMELY DANGEROUS TORNADO": "Large and Dangerous Tornado",
107
+ "THIS IS A PARTICULARLY DANGEROUS SITUATION": "Particularly Dangerous Situation",
108
+ "RADAR INDICATED ROTATION": "Radar Indicated Tornado",
109
+ "WEATHER SPOTTERS CONFIRMED TORNADO": "Confirmed by Storm Spotters",
110
+ "A SEVERE THUNDERSTORM CAPABLE OF PRODUCING A TORNADO": "Developing Tornado",
111
+ "LAW ENFORCEMENT CONFIRMED TORNADO": "Reported by Law Enforcement",
112
+ "A TORNADO IS ON THE GROUND": "Confirmed Tornado",
113
+ "WEATHER SPOTTERS REPORTED FUNNEL CLOUD": "Confirmed Funnel Cloud by Storm Spotters",
114
+ "PUBLIC CONFIRMED TORNADO": "Public reports of Tornado",
115
+ "RADAR CONFIRMED": "Radar Confirmed",
116
+ "TORNADO WAS REPORTED BRIEFLY ON THE GROUND": "Tornado no longer on ground",
117
+ "SPOTTERS INDICATE THAT A FUNNEL CLOUD CONTINUES WITH THIS STORM": "Funnel Cloud Continues",
118
+ "A TORNADO MAY DEVELOP AT ANY TIME": "Potentional still exists for Tornado to form",
119
+ "LIFE-THREATENING SITUATION": "Life Threating Situation",
120
+ "COMPLETE DESTRUCTION IS POSSIBLE": "Extremly Damaging Tornado",
121
+ "POTENTIALLY DEADLY TORNADO": "Deadly Tornado",
122
+ "RADAR INDICATED": "Radar Indicated",
123
+ "HAIL DAMAGE TO VEHICLES IS EXPECTED": "Damaging to Vehicles",
124
+ "EXPECT WIND DAMAGE": "Wind Damage",
125
+ "FREQUENT LIGHTNING": "Frequent Lightning",
126
+ "PEOPLE AND ANIMALS OUTDOORS WILL BE INJURED": "Capable of Injuring People and Animals",
127
+ "TRAINED WEATHER SPOTTERS": "Confirmed by Storm Spotters",
128
+ "SOURCE...PUBLIC": "Confirmed by Public",
129
+ "SMALL CRAFT COULD BE DAMAGED": "Potential Damage to Small Craft",
130
+ "A TORNADO WATCH REMAINS IN EFFECT": "Active Tornado Watch",
131
+ "TENNIS BALL SIZE HAIL": "Tennis Ball Size Hail",
132
+ "BASEBALL SIZE HAIL": "Baseball Size Hail",
133
+ "GOLF BALL SIZE HAIL": "Golf Ball Size Hail",
134
+ "QUARTER SIZE HAIL": "Quarter Size Hail",
135
+ "PING PONG BALL SIZE HAIL": "Ping Pong Ball Size Hail",
136
+ "NICKEL SIZE HAIL": "Nickel Size Hail",
137
+ "DOPPLER RADAR.": "Confirmed by Radar",
138
+ "DOPPLER RADAR AND AUTOMATED GAUGES.": "Confirmed by Radar and Gauges",
139
+ "FLASH FLOODING CAUSED BY THUNDERSTORMS.": "Caused by Thunderstorm",
140
+ "SOURCE...EMERGENCY MANAGEMENT.": "Confirmed by Emergency Management",
141
+ "FLASH FLOODING CAUSED BY HEAVY RAIN.": "Caused by heavy rain",
142
+ "SOURCE...LAW ENFORCEMENT REPORTED.": "Confirmed by Law Enforcement"
143
+ },
144
+ haultingConditions: [
145
+ { error: "error-database-not-configured", message: "The database is not configured properly. Please set the database path in the constructor." },
146
+ { error: "error-reconnecting-too-fast", message: "The client is attempting to reconnect too fast. Please wait a few seconds before trying again." },
147
+ { error: "error-connection-lost", message: "The connection to the XMPP server has been lost. Please try reconnecting manually as the automatic reconnect feature is not setup for offline hault conditions." },
148
+ ],
149
+ messages: {
150
+ shapefile_creation: "\n\n[NOTICE] DO NOT CLOSE THIS PROJECT UNTIL THE SHAPEFILES ARE DONE COMPLETING!\n\t THIS COULD TAKE A WHILE DEPENDING ON THE SPEED OF YOUR STORAGE!!\n\t IF YOU CLOSE YOUR PROJECT, THE SHAPEFILES WILL NOT BE CREATED AND YOU WILL NEED TO DELETE ".concat(exports.settings.database, " AND RESTART TO CREATE THEM AGAIN!\n\n"),
151
+ shapefile_creation_finished: "\n\n[NOTICE] SHAPEFILES HAVE BEEN SUCCESSFULLY CREATED AND THE DATABASE IS READY FOR USE!\n\n"
152
+ }
153
+ };