atmosx-nwws-parser 1.0.2

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 (84) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +6 -0
  3. package/dist/cjs/bootstrap.cjs +1009 -0
  4. package/dist/cjs/database.cjs +1114 -0
  5. package/dist/cjs/dictionaries/awips.cjs +379 -0
  6. package/dist/cjs/dictionaries/events.cjs +139 -0
  7. package/dist/cjs/dictionaries/icao.cjs +265 -0
  8. package/dist/cjs/dictionaries/offshore.cjs +40 -0
  9. package/dist/cjs/dictionaries/signatures.cjs +132 -0
  10. package/dist/cjs/eas.cjs +2857 -0
  11. package/dist/cjs/helper.cjs +3014 -0
  12. package/dist/cjs/parsers/events.cjs +2857 -0
  13. package/dist/cjs/parsers/stanza.cjs +1108 -0
  14. package/dist/cjs/parsers/text.cjs +1142 -0
  15. package/dist/cjs/parsers/types/api.cjs +2857 -0
  16. package/dist/cjs/parsers/types/cap.cjs +2857 -0
  17. package/dist/cjs/parsers/types/text.cjs +2857 -0
  18. package/dist/cjs/parsers/types/ugc.cjs +2857 -0
  19. package/dist/cjs/parsers/types/vtec.cjs +2857 -0
  20. package/dist/cjs/parsers/ugc.cjs +1139 -0
  21. package/dist/cjs/parsers/vtec.cjs +1060 -0
  22. package/dist/cjs/types.cjs +17 -0
  23. package/dist/cjs/utils.cjs +2857 -0
  24. package/dist/cjs/xmpp.cjs +2857 -0
  25. package/dist/esm/bootstrap.mjs +972 -0
  26. package/dist/esm/database.mjs +1079 -0
  27. package/dist/esm/dictionaries/awips.mjs +355 -0
  28. package/dist/esm/dictionaries/events.mjs +111 -0
  29. package/dist/esm/dictionaries/icao.mjs +241 -0
  30. package/dist/esm/dictionaries/offshore.mjs +16 -0
  31. package/dist/esm/dictionaries/signatures.mjs +106 -0
  32. package/dist/esm/eas.mjs +2824 -0
  33. package/dist/esm/helper.mjs +2974 -0
  34. package/dist/esm/parsers/events.mjs +2824 -0
  35. package/dist/esm/parsers/stanza.mjs +1072 -0
  36. package/dist/esm/parsers/text.mjs +1106 -0
  37. package/dist/esm/parsers/types/api.mjs +2824 -0
  38. package/dist/esm/parsers/types/cap.mjs +2824 -0
  39. package/dist/esm/parsers/types/text.mjs +2824 -0
  40. package/dist/esm/parsers/types/ugc.mjs +2824 -0
  41. package/dist/esm/parsers/types/vtec.mjs +2824 -0
  42. package/dist/esm/parsers/ugc.mjs +1104 -0
  43. package/dist/esm/parsers/vtec.mjs +1025 -0
  44. package/dist/esm/types.mjs +0 -0
  45. package/dist/esm/utils.mjs +2824 -0
  46. package/dist/esm/xmpp.mjs +2824 -0
  47. package/package.json +47 -0
  48. package/shapefiles/FireCounties.dbf +0 -0
  49. package/shapefiles/FireCounties.shp +0 -0
  50. package/shapefiles/FireZones.dbf +0 -0
  51. package/shapefiles/FireZones.shp +0 -0
  52. package/shapefiles/ForecastZones.dbf +0 -0
  53. package/shapefiles/ForecastZones.shp +0 -0
  54. package/shapefiles/Marine.dbf +0 -0
  55. package/shapefiles/Marine.shp +0 -0
  56. package/shapefiles/OffShoreZones.dbf +0 -0
  57. package/shapefiles/OffShoreZones.shp +0 -0
  58. package/shapefiles/USCounties.dbf +0 -0
  59. package/shapefiles/USCounties.shp +0 -0
  60. package/src/bootstrap.ts +171 -0
  61. package/src/database.ts +99 -0
  62. package/src/dictionaries/awips.ts +351 -0
  63. package/src/dictionaries/events.ts +109 -0
  64. package/src/dictionaries/icao.ts +237 -0
  65. package/src/dictionaries/offshore.ts +12 -0
  66. package/src/dictionaries/signatures.ts +103 -0
  67. package/src/eas.ts +428 -0
  68. package/src/helper.ts +167 -0
  69. package/src/parsers/events.ts +289 -0
  70. package/src/parsers/stanza.ts +103 -0
  71. package/src/parsers/text.ts +167 -0
  72. package/src/parsers/types/api.ts +94 -0
  73. package/src/parsers/types/cap.ts +89 -0
  74. package/src/parsers/types/text.ts +54 -0
  75. package/src/parsers/types/ugc.ts +85 -0
  76. package/src/parsers/types/vtec.ts +60 -0
  77. package/src/parsers/ugc.ts +148 -0
  78. package/src/parsers/vtec.ts +66 -0
  79. package/src/types.ts +187 -0
  80. package/src/utils.ts +216 -0
  81. package/src/xmpp.ts +123 -0
  82. package/test.js +1 -0
  83. package/tsconfig.json +14 -0
  84. package/tsup.config.ts +11 -0
@@ -0,0 +1,2857 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ // If the importer is in node compatibility mode or this is not an ESM
38
+ // file that has been converted to a CommonJS file using a Babel-
39
+ // compatible transform (i.e. "__esModule" has not been set), then set
40
+ // "default" to the CommonJS "module.exports" for node compatibility.
41
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
+ mod
43
+ ));
44
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
+ var __async = (__this, __arguments, generator) => {
46
+ return new Promise((resolve, reject) => {
47
+ var fulfilled = (value) => {
48
+ try {
49
+ step(generator.next(value));
50
+ } catch (e) {
51
+ reject(e);
52
+ }
53
+ };
54
+ var rejected = (value) => {
55
+ try {
56
+ step(generator.throw(value));
57
+ } catch (e) {
58
+ reject(e);
59
+ }
60
+ };
61
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
62
+ step((generator = generator.apply(__this, __arguments)).next());
63
+ });
64
+ };
65
+
66
+ // src/parsers/types/cap.ts
67
+ var cap_exports = {};
68
+ __export(cap_exports, {
69
+ CapAlerts: () => CapAlerts,
70
+ default: () => cap_default
71
+ });
72
+ module.exports = __toCommonJS(cap_exports);
73
+
74
+ // src/bootstrap.ts
75
+ var fs = __toESM(require("fs"));
76
+ var path = __toESM(require("path"));
77
+ var events = __toESM(require("events"));
78
+ var xmpp = __toESM(require("@xmpp/client"));
79
+ var shapefile = __toESM(require("shapefile"));
80
+ var xml2js = __toESM(require("xml2js"));
81
+ var cron = __toESM(require("node-cron"));
82
+ var import_better_sqlite3 = __toESM(require("better-sqlite3"));
83
+ var import_axios = __toESM(require("axios"));
84
+ var import_crypto = __toESM(require("crypto"));
85
+ var import_os = __toESM(require("os"));
86
+ var import_say = __toESM(require("say"));
87
+
88
+ // src/dictionaries/events.ts
89
+ var EVENTS = {
90
+ "AF": "Ashfall",
91
+ "AS": "Air Stagnation",
92
+ "BH": "Beach Hazard",
93
+ "BW": "Brisk Wind",
94
+ "BZ": "Blizzard",
95
+ "CF": "Coastal Flood",
96
+ "DF": "Debris Flow",
97
+ "DS": "Dust Storm",
98
+ "EC": "Extreme Cold",
99
+ "EH": "Excessive Heat",
100
+ "XH": "Extreme Heat",
101
+ "EW": "Extreme Wind",
102
+ "FA": "Areal Flood",
103
+ "FF": "Flash Flood",
104
+ "FG": "Dense Fog",
105
+ "FL": "Flood",
106
+ "FR": "Frost",
107
+ "FW": "Fire Weather",
108
+ "FZ": "Freeze",
109
+ "GL": "Gale",
110
+ "HF": "Hurricane Force Wind",
111
+ "HT": "Heat",
112
+ "HU": "Hurricane",
113
+ "HW": "High Wind",
114
+ "HY": "Hydrologic",
115
+ "HZ": "Hard Freeze",
116
+ "IS": "Ice Storm",
117
+ "LE": "Lake Effect Snow",
118
+ "LO": "Low Water",
119
+ "LS": "Lakeshore Flood",
120
+ "LW": "Lake Wind",
121
+ "MA": "Special Marine",
122
+ "EQ": "Earthquake",
123
+ "MF": "Dense Fog",
124
+ "MH": "Ashfall",
125
+ "MS": "Dense Smoke",
126
+ "RB": "Small Craft for Rough Bar",
127
+ "RP": "Rip Current Risk",
128
+ "SC": "Small Craft",
129
+ "SE": "Hazardous Seas",
130
+ "SI": "Small Craft for Winds",
131
+ "SM": "Dense Smoke",
132
+ "SQ": "Snow Squall",
133
+ "SR": "Storm",
134
+ "SS": "Storm Surge",
135
+ "SU": "High Surf",
136
+ "SV": "Severe Thunderstorm",
137
+ "SW": "Small Craft for Hazardous Seas",
138
+ "TO": "Tornado",
139
+ "TR": "Tropical Storm",
140
+ "TS": "Tsunami",
141
+ "TY": "Typhoon",
142
+ "SP": "Special Weather",
143
+ "UP": "Heavy Freezing Spray",
144
+ "WC": "Wind Chill",
145
+ "WI": "Wind",
146
+ "WS": "Winter Storm",
147
+ "WW": "Winter Weather",
148
+ "ZF": "Freezing Fog",
149
+ "ZR": "Freezing Rain",
150
+ "ZY": "Freezing Spray"
151
+ };
152
+ var ACTIONS = {
153
+ "W": "Warning",
154
+ "F": "Forecast",
155
+ "A": "Watch",
156
+ "O": "Outlook",
157
+ "Y": "Advisory",
158
+ "N": "Synopsis",
159
+ "S": "Statement"
160
+ };
161
+ var STATUS = {
162
+ "NEW": "Issued",
163
+ "CON": "Updated",
164
+ "EXT": "Extended",
165
+ "EXA": "Extended",
166
+ "EXB": "Extended",
167
+ "UPG": "Upgraded",
168
+ "COR": "Correction",
169
+ "ROU": "Routine",
170
+ "CAN": "Cancelled",
171
+ "EXP": "Expired"
172
+ };
173
+ var TYPES = {
174
+ "O": "Operational Product",
175
+ "T": "Test Product",
176
+ "E": "Experimental Product",
177
+ "X": "Experimental Product (Non-Operational)"
178
+ };
179
+ var STATUS_CORRELATIONS = [
180
+ { type: "Update", forward: "Updated", cancel: false },
181
+ { type: "Cancel", forward: "Cancelled", cancel: true },
182
+ { type: "Alert", forward: "Issued", cancel: false },
183
+ { type: "Updated", forward: "Updated", cancel: false },
184
+ { type: "Expired", forward: "Expired", cancel: true },
185
+ { type: "Issued", forward: "Issued", cancel: false },
186
+ { type: "Extended", forward: "Updated", cancel: false },
187
+ { type: "Correction", forward: "Updated", cancel: false },
188
+ { type: "Upgraded", forward: "Upgraded", cancel: false },
189
+ { type: "Cancelled", forward: "Cancelled", cancel: true },
190
+ { type: "Routine", forward: "Routine", cancel: false }
191
+ ];
192
+
193
+ // src/dictionaries/offshore.ts
194
+ var OFFSHORE = {
195
+ "Special Weather Statement": "Special Weather Statement",
196
+ "Hurricane Warning": "Hurricane Warning",
197
+ "Hurricane Force Wind Warning": "Hurricane Force Wind Warning",
198
+ "Hurricane Watch": "Hurricane Watch",
199
+ "Tropical Storm Warning": "Tropical Storm Warning",
200
+ "Tropical Storm Watch": "Tropical Storm Watch",
201
+ "High Wind Warning": "High Wind Warning",
202
+ "Gale Warning": "Gale Warning",
203
+ "Small Craft Advisory": "Small Craft Advisory",
204
+ "Small Craft Warning": "Small Craft Warning"
205
+ };
206
+
207
+ // src/dictionaries/awips.ts
208
+ var AWIPS = {
209
+ ABV: `abv`,
210
+ ADA: `administrative-message`,
211
+ ADM: `administrative-message`,
212
+ ADR: `administrative-message`,
213
+ AHD: `area-hydrological-discussion`,
214
+ AHONT1: `high-density-observations-usaf-noaa`,
215
+ AHOPA1: `high-density-observations-usaf-noaa-west-pac`,
216
+ AHOPN1: `high-density-observations-usaf-noaa`,
217
+ AFD: `area-forecast-discussion`,
218
+ AQA: `air-quality-alert`,
219
+ AQI: `ground-level-ozone-forecast`,
220
+ AVA: `avalanche-watch`,
221
+ AVW: `avalanche-warning`,
222
+ AWU: `area-weather-update`,
223
+ AVG: `avalanche-weather-guidance`,
224
+ AWW: `airport-weather-warning`,
225
+ BLU: `blue-alert`,
226
+ CAE: `child-abduction-emergency`,
227
+ CDW: `civil-danger-warning`,
228
+ CEM: `civil-emergency-message`,
229
+ CFW: `coastal-hazard-message`,
230
+ CGR: `coastal-weather-observations`,
231
+ CLI: `daily-climate-report`,
232
+ CLM: `monthly-climate-report`,
233
+ CRF: `contingency-river-forecast`,
234
+ CWA: `center-weather-advisory`,
235
+ CWF: `coastal-waters-forecast`,
236
+ DGT: `drought-information`,
237
+ DSA: `tropical-disturbance-statement`,
238
+ DSW: `dust-storm-warning`,
239
+ EQI: `earthquake-information`,
240
+ EQR: `earthquake-report`,
241
+ EQW: `earthquake-warning`,
242
+ ESF: `hydrologic-outlook`,
243
+ EVI: `evacuation-immediate`,
244
+ EWW: `extreme-wind-warning`,
245
+ FFA: `flood-watch`,
246
+ FFG: `flash-flood-guidance`,
247
+ FFGMPD: `mesoscale-precipitation-discussion`,
248
+ FLS: `flood-advisory`,
249
+ FLW: `flood-warning`,
250
+ FFS: `flash-flood-statement`,
251
+ FFW: `flash-flood-warning`,
252
+ MWS: `marine-weather-statement`,
253
+ MWW: `marine-weather-warning`,
254
+ NMN: `network-message-notification`,
255
+ NOW: `short-term-forecast`,
256
+ NPW: `non-convective-advisory`,
257
+ NSH: `nearshore-marine-forecast`,
258
+ NUW: `nuclear-power-plant-warning`,
259
+ PMDAK: `alaska-discussion`,
260
+ PMDCA: `tropical-discussion`,
261
+ PMDEPD: `extended-forecast-discussion`,
262
+ PMDHI: `hawaii-discussion`,
263
+ PMDHMD: `model-diagnostic-discussion`,
264
+ PMDSA: `south-america-forecast-discussion`,
265
+ PMDSPD: `short-range-forecast-discussion`,
266
+ PNS: `public-information-statement`,
267
+ FRW: `fire-warning`,
268
+ FTM: `free-text-message`,
269
+ FWF: `fire-weather-planning-forecast`,
270
+ FWA: `fire-weather-administrative-message`,
271
+ FWS: `fire-weather-spot-forecast`,
272
+ GLF: `open-lake-forecast`,
273
+ HCM: `hydromet-coordination-message`,
274
+ HMT: `hmt`,
275
+ HMW: `hazardous-materials-warning`,
276
+ HPA: `high-pollution-advisory`,
277
+ HLS: `hurricane-local-statement`,
278
+ HMD: `rainfall-and-flood-outlook-product`,
279
+ HSF: `high-seas-forecast`,
280
+ HWO: `hazardous-weather-outlook`,
281
+ HYD: `supplementary-temp-and-precip`,
282
+ LAE: `local-area-emergency`,
283
+ LCO: `local-cooperative-observation`,
284
+ LEW: `law-enforcement-warning`,
285
+ LSR: `local-storm-report`,
286
+ ICE: `ice-outlook`,
287
+ MIS: `meteorological-impact-statement`,
288
+ OAV: `other-aviation-report`,
289
+ OEP: `taf-collaboration-product`,
290
+ OFF: `offshore-waters-forecast`,
291
+ OMR: `other-marine-reports`,
292
+ OSO: `weather-roundup`,
293
+ PFM: `point-forecast-matrices`,
294
+ PSH: `post-tropical-event-report`,
295
+ PWO: `public-severe-weather-outlook`,
296
+ QPFERD: `excessive-rainfall-discussion`,
297
+ QPFHSD: `heavy-snow-discussion`,
298
+ QPS: `quantitative-precipitation-forecast`,
299
+ REC: `recreational-forecast`,
300
+ REPNT0: `recco-observations-non-tropical-cyclone`,
301
+ REPNT1: `recco-observations-tropical-cyclone`,
302
+ REPNT2: `vortex-data-message`,
303
+ REPNTS: `supplementary-vortex-data-message`,
304
+ REPNT3: `dropsonde-observations`,
305
+ REPPN0: `recco-observations-non-tropical-cyclone`,
306
+ REPPN1: `recco-observations-tropical-cyclone`,
307
+ REPPN2: `vortex-data-message`,
308
+ REPPNS: `supplementary-vortex-data-message`,
309
+ REPPN3: `dropsonde-observations`,
310
+ REPPA0: `recco-observations-west-pac-non-tropical-cyclone`,
311
+ REPPA1: `recco-observations-west-pac-tropical-cyclone`,
312
+ REPPA2: `vortex-data-message-west-pac`,
313
+ REPPAS: `supplementary-vortex-data-message-west-pac`,
314
+ REPPA3: `dropsonde-observations-west-pac`,
315
+ REPRPD: `weather-reconnaissance-flights`,
316
+ RER: `record-event-report`,
317
+ RFD: `grassland-fire-danger`,
318
+ RFW: `red-flag-warning`,
319
+ RHW: `radiological-hazard-warning`,
320
+ RRM: `rainfall-storm-total`,
321
+ RTP: `regional-temperature-and-precipitation`,
322
+ RVA: `hydrologic-summary`,
323
+ RVD: `river-and-lake-summary`,
324
+ RVF: `river-forecast`,
325
+ RVS: `hydrologic-statement`,
326
+ RWR: `weather-roundup`,
327
+ RWS: `regional-weather-summary`,
328
+ SAB: `special-avalanche-bulletin`,
329
+ SCC: `storm-summary`,
330
+ SFT: `state-forecast-tabular-product`,
331
+ SIG: `convective-sigment`,
332
+ SMF: `smoke-management-weather-forecast`,
333
+ SMW: `special-marine-warning`,
334
+ SPS: `special-weather-statement`,
335
+ SPW: `shelter-in-place-warning`,
336
+ SQW: `snow-squall-warning`,
337
+ SRF: `surf-zone-forecast`,
338
+ STF: `tabular-state-forecast`,
339
+ STQ: `spot-forecast-request`,
340
+ SVR: `severe-thunderstorm-warning`,
341
+ SVS: `severe-weather-statement`,
342
+ SWOMCD: `mesoscale-convective-discussion`,
343
+ TAF: `terminal-aerodrome-forecast`,
344
+ TCD: `tropical-cyclone-discussion`,
345
+ TCE: `tropical-cyclone-position-estimate`,
346
+ TCM: `tropical-storm-forecast`,
347
+ TCU: `tropical-cyclone-update`,
348
+ TCV: `tropical-watch-warning-local-statement`,
349
+ TIB: `tsunami-information-statement`,
350
+ TID: `tide-data`,
351
+ TMA: `tsunami-message-acknowledgement`,
352
+ TOE: `telephone-outage-emergency`,
353
+ TOR: `tornado-warning`,
354
+ TWD: `tropical-weather-discussion`,
355
+ TWO: `tropical-weather-outlook`,
356
+ VAA: `volcanic-ash-advisory`,
357
+ VOW: `volcano-warning`,
358
+ WCN: `watch-county-notification`,
359
+ WRK: `work-product`,
360
+ WSV: `volcanic-ash-sigmet`,
361
+ WSW: `winter-weather-message`,
362
+ XTEUS: `wpc-contiguous-us-daily-max-min-temps`,
363
+ ZFP: `zone-forecast-package`,
364
+ RR1: `hydro-meteorological-data-report-pt1`,
365
+ RR2: `hydro-meteorological-data-report-pt2`,
366
+ RR3: `hydro-meteorological-data-report-pt3`,
367
+ RR4: `hydro-meteorological-data-report-pt4`,
368
+ RR5: `hydro-meteorological-data-report-pt5`,
369
+ RR6: `hydro-meteorological-data-report-pt6`,
370
+ RR7: `hydro-meteorological-data-report-pt7`,
371
+ RR8: `hydro-meteorological-data-report-pt8`,
372
+ RR9: `hydro-meteorological-data-report-pt9`,
373
+ SFP: `state-forecast-product`,
374
+ AFM: `area-forecast-matrices`,
375
+ AAG: `aag`,
376
+ ADV: `adv`,
377
+ AFP: `afp`,
378
+ AFW: `afw`,
379
+ AGO: `ago`,
380
+ AIR: `air`,
381
+ ALG: `alg`,
382
+ ALT: `alt`,
383
+ AVD: `avd`,
384
+ AWO: `awo`,
385
+ BOY: `boy`,
386
+ BRT: `brt`,
387
+ CF6: `cf6`,
388
+ CFP: `cfp`,
389
+ CLS: `cls`,
390
+ CMM: `cmm`,
391
+ COD: `cod`,
392
+ CRN: `crn`,
393
+ CUR: `cur`,
394
+ CWD: `cwd`,
395
+ CWS: `cws`,
396
+ DAY: `day`,
397
+ DDO: `ddo`,
398
+ DMO: `dmo`,
399
+ DSM: `dsm`,
400
+ ECD: `ecd`,
401
+ EFP: `efp`,
402
+ EOL: `eol`,
403
+ EOM: `eom`,
404
+ ESG: `esg`,
405
+ ESP: `esp`,
406
+ ESS: `ess`,
407
+ ETT: `ett`,
408
+ FA0: `fa0`,
409
+ FA7: `fa7`,
410
+ FA8: `fa8`,
411
+ FA9: `fa9`,
412
+ FD0: `fd0`,
413
+ FD1: `fd1`,
414
+ FD3: `fd3`,
415
+ FD5: `fd5`,
416
+ FD8: `fd8`,
417
+ FD9: `fd9`,
418
+ FDI: `fdi`,
419
+ FFH: `ffh`,
420
+ FFP: `ffp`,
421
+ FLR: `flr`,
422
+ FOP: `fop`,
423
+ FRH: `frh`,
424
+ FSH: `fsh`,
425
+ FTP: `ftp`,
426
+ FWD: `fwd`,
427
+ FWL: `fwl`,
428
+ FWM: `fwm`,
429
+ FWN: `fwn`,
430
+ FWO: `fwo`,
431
+ FZL: `fzl`,
432
+ GEN: `gen`,
433
+ GMT: `gmt`,
434
+ HD0: `hd0`,
435
+ HD2: `hd2`,
436
+ HD3: `hd3`,
437
+ HD4: `hd4`,
438
+ HD6: `hd6`,
439
+ HD8: `hd8`,
440
+ HML: `hml`,
441
+ HWR: `hwr`,
442
+ LAK: `lak`,
443
+ LEV: `lev`,
444
+ LLL: `lll`,
445
+ HP2: `hp2`,
446
+ HRR: `hrr`,
447
+ HYM: `hym`,
448
+ ICO: `ico`,
449
+ IDM: `idm`,
450
+ MAN: `man`,
451
+ MAP: `map`,
452
+ MAR: `mar`,
453
+ MAV: `mav`,
454
+ MCG: `mcg`,
455
+ MCX: `mcx`,
456
+ MET: `met`,
457
+ MEX: `mex`,
458
+ MFM: `mfm`,
459
+ MFP: `mfp`,
460
+ MHF: `mhf`,
461
+ MME: `mme`,
462
+ MMG: `mmg`,
463
+ MRP: `mrp`,
464
+ MSM: `msm`,
465
+ MTR: `mtr`,
466
+ MTT: `mtt`,
467
+ MVF: `mvf`,
468
+ NWR: `nwr`,
469
+ OFA: `ofa`,
470
+ OPU: `opu`,
471
+ OPW: `opw`,
472
+ OSB: `osb`,
473
+ PFW: `pfw`,
474
+ PLS: `pls`,
475
+ PMD: `pmd`,
476
+ POE: `poe`,
477
+ PRB: `prb`,
478
+ PTS: `pts`,
479
+ PWS: `pws`,
480
+ QPF: `qpf`,
481
+ QPG: `qpg`,
482
+ RBG: `rbg`,
483
+ REP: `rep`,
484
+ RFM: `rfm`,
485
+ RFR: `rfr`,
486
+ RRA: `rra`,
487
+ RRS: `rrs`,
488
+ RRY: `rry`,
489
+ RRZ: `rrz`,
490
+ RVC: `rvc`,
491
+ RVG: `rvg`,
492
+ RVK: `rvk`,
493
+ RVM: `rvm`,
494
+ RVO: `rvo`,
495
+ RVR: `rvr`,
496
+ RVU: `rvu`,
497
+ SAF: `saf`,
498
+ SAG: `sag`,
499
+ SAT: `sat`,
500
+ SAW: `saw`,
501
+ SCN: `scn`,
502
+ SCP: `scp`,
503
+ SCS: `scs`,
504
+ SCV: `scv`,
505
+ SEL: `sel`,
506
+ SGL: `sgl`,
507
+ SPE: `spe`,
508
+ SPN: `spn`,
509
+ SRG: `srg`,
510
+ SSM: `ssm`,
511
+ STA: `sta`,
512
+ SUM: `sum`,
513
+ SWE: `swe`,
514
+ SYN: `syn`,
515
+ TAP: `tap`,
516
+ TCA: `tca`,
517
+ TCP: `tcp`,
518
+ TCS: `tcs`,
519
+ TPT: `tpt`,
520
+ TST: `tst`,
521
+ TSU: `tsu`,
522
+ TUV: `tuv`,
523
+ TVL: `tvl`,
524
+ TWS: `tws`,
525
+ TXT: `txt`,
526
+ UVI: `uvi`,
527
+ VFT: `vft`,
528
+ WA0: `wa0`,
529
+ WA1: `wa1`,
530
+ WA2: `wa2`,
531
+ WA3: `wa3`,
532
+ WA4: `wa4`,
533
+ WA5: `wa5`,
534
+ WA6: `wa6`,
535
+ WA7: `wa7`,
536
+ WA8: `wa8`,
537
+ WA9: `wa9`,
538
+ WAR: `war`,
539
+ WAT: `wat`,
540
+ WCL: `wcl`,
541
+ WEE: `wee`,
542
+ WEK: `wek`,
543
+ WOU: `wou`,
544
+ WRM: `wrm`,
545
+ WS1: `ws1`,
546
+ WS2: `ws2`,
547
+ WS3: `ws3`,
548
+ WS4: `ws4`,
549
+ WS5: `ws5`,
550
+ WS6: `ws6`,
551
+ WSC: `wsc`,
552
+ WST: `wst`,
553
+ WTA: `wta`,
554
+ WWA: `wwa`,
555
+ WWP: `wwp`,
556
+ XF0: `xf0`,
557
+ XOB: `xob`
558
+ };
559
+
560
+ // src/dictionaries/signatures.ts
561
+ var TAGS = {
562
+ "A LARGE AND EXTREMELY DANGEROUS TORNADO": "Large and Dangerous Tornado",
563
+ "THIS IS A PARTICULARLY DANGEROUS SITUATION": "Particularly Dangerous Situation",
564
+ "RADAR INDICATED ROTATION": "Radar Indicated Tornado",
565
+ "WEATHER SPOTTERS CONFIRMED TORNADO": "Confirmed by Storm Spotters",
566
+ "A SEVERE THUNDERSTORM CAPABLE OF PRODUCING A TORNADO": "Developing Tornado",
567
+ "LAW ENFORCEMENT CONFIRMED TORNADO": "Reported by Law Enforcement",
568
+ "A TORNADO IS ON THE GROUND": "Confirmed Tornado",
569
+ "WEATHER SPOTTERS REPORTED FUNNEL CLOUD": "Confirmed Funnel Cloud by Storm Spotters",
570
+ "PUBLIC CONFIRMED TORNADO": "Public reports of Tornado",
571
+ "RADAR CONFIRMED": "Radar Confirmed",
572
+ "TORNADO WAS REPORTED BRIEFLY ON THE GROUND": "Tornado no longer on ground",
573
+ "SPOTTERS INDICATE THAT A FUNNEL CLOUD CONTINUES WITH THIS STORM": "Funnel Cloud Continues",
574
+ "A TORNADO MAY DEVELOP AT ANY TIME": "Potentional still exists for Tornado to form",
575
+ "LIFE-THREATENING SITUATION": "Life Threating Situation",
576
+ "COMPLETE DESTRUCTION IS POSSIBLE": "Extremly Damaging Tornado",
577
+ "POTENTIALLY DEADLY TORNADO": "Deadly Tornado",
578
+ "RADAR INDICATED": "Radar Indicated",
579
+ "HAIL DAMAGE TO VEHICLES IS EXPECTED": "Damaging to Vehicles",
580
+ "EXPECT WIND DAMAGE": "Wind Damage",
581
+ "FREQUENT LIGHTNING": "Frequent Lightning",
582
+ "PEOPLE AND ANIMALS OUTDOORS WILL BE INJURED": "Capable of Injuring People and Animals",
583
+ "TRAINED WEATHER SPOTTERS": "Confirmed by Storm Spotters",
584
+ "SOURCE...PUBLIC": "Confirmed by Public",
585
+ "SMALL CRAFT COULD BE DAMAGED": "Potential Damage to Small Craft",
586
+ "A TORNADO WATCH REMAINS IN EFFECT": "Active Tornado Watch",
587
+ "TENNIS BALL SIZE HAIL": "Tennis Ball Size Hail",
588
+ "BASEBALL SIZE HAIL": "Baseball Size Hail",
589
+ "GOLF BALL SIZE HAIL": "Golf Ball Size Hail",
590
+ "QUARTER SIZE HAIL": "Quarter Size Hail",
591
+ "PING PONG BALL SIZE HAIL": "Ping Pong Ball Size Hail",
592
+ "NICKEL SIZE HAIL": "Nickel Size Hail",
593
+ "DOPPLER RADAR.": "Confirmed by Radar",
594
+ "DOPPLER RADAR AND AUTOMATED GAUGES.": "Confirmed by Radar and Gauges",
595
+ "FLASH FLOODING CAUSED BY THUNDERSTORMS.": "Caused by Thunderstorm",
596
+ "SOURCE...EMERGENCY MANAGEMENT.": "Confirmed by Emergency Management",
597
+ "FLASH FLOODING CAUSED BY HEAVY RAIN.": "Caused by heavy rain",
598
+ "SOURCE...LAW ENFORCEMENT REPORTED.": "Confirmed by Law Enforcement"
599
+ };
600
+ var CANCEL_SIGNATURES = [
601
+ "THIS_MESSAGE_IS_FOR_TEST_PURPOSES_ONLY",
602
+ "this is a test",
603
+ "subsided sufficiently for the advisory to be cancelled",
604
+ "has been cancelled",
605
+ "will be allowed to expire",
606
+ "has diminished",
607
+ "and no longer",
608
+ "has been replaced",
609
+ "The threat has ended",
610
+ "has weakened below severe"
611
+ ];
612
+ var MESSAGE_SIGNATURES = [
613
+ { regex: /\r?\n/g, replacement: " " },
614
+ { regex: /\s+/g, replacement: " " },
615
+ { regex: /\*/g, replacement: "." },
616
+ { regex: /\bUTC\b/g, replacement: "Coordinated Universal Time" },
617
+ { regex: /\bGMT\b/g, replacement: "Greenwich Mean Time" },
618
+ { regex: /\bEST\b/g, replacement: "Eastern Standard Time" },
619
+ { regex: /\bEDT\b/g, replacement: "Eastern Daylight Time" },
620
+ { regex: /\bCST\b/g, replacement: "Central Standard Time" },
621
+ { regex: /\bCDT\b/g, replacement: "Central Daylight Time" },
622
+ { regex: /\bMST\b/g, replacement: "Mountain Standard Time" },
623
+ { regex: /\bMDT\b/g, replacement: "Mountain Daylight Time" },
624
+ { regex: /\bPST\b/g, replacement: "Pacific Standard Time" },
625
+ { regex: /\bPDT\b/g, replacement: "Pacific Daylight Time" },
626
+ { regex: /\bAKST\b/g, replacement: "Alaska Standard Time" },
627
+ { regex: /\bAKDT\b/g, replacement: "Alaska Daylight Time" },
628
+ { regex: /\bHST\b/g, replacement: "Hawaii Standard Time" },
629
+ { regex: /\bHDT\b/g, replacement: "Hawaii Daylight Time" },
630
+ { regex: /\bmph\b/g, replacement: "miles per hour" },
631
+ { regex: /\bkm\/h\b/g, replacement: "kilometers per hour" },
632
+ { regex: /\bkmh\b/g, replacement: "kilometers per hour" },
633
+ { regex: /\bkt\b/g, replacement: "knots" },
634
+ { regex: /\bNE\b/g, replacement: "northeast" },
635
+ { regex: /\bNW\b/g, replacement: "northwest" },
636
+ { regex: /\bSE\b/g, replacement: "southeast" },
637
+ { regex: /\bSW\b/g, replacement: "southwest" },
638
+ { regex: /\bNM\b/g, replacement: "nautical miles" },
639
+ { regex: /\bdeg\b/g, replacement: "degrees" },
640
+ { regex: /\btstm\b/g, replacement: "thunderstorm" },
641
+ { regex: /\bmm\b/g, replacement: "millimeters" },
642
+ { regex: /\bcm\b/g, replacement: "centimeters" },
643
+ { regex: /\bin\b/g, replacement: "inches" },
644
+ { regex: /\bft\b/g, replacement: "feet" },
645
+ { regex: /\bmi\b/g, replacement: "miles" },
646
+ { regex: /\bhr\b/g, replacement: "hour" },
647
+ { regex: /\bhourly\b/g, replacement: "per hour" },
648
+ { regex: /\bkg\b/g, replacement: "kilograms" },
649
+ { regex: /\bg\/kg\b/g, replacement: "grams per kilogram" },
650
+ { regex: /\bmb\b/g, replacement: "millibars" },
651
+ { regex: /\bhPa\b/g, replacement: "hectopascals" },
652
+ { regex: /\bPa\b/g, replacement: "pascals" },
653
+ { regex: /\bKPa\b/g, replacement: "kilopascals" },
654
+ { regex: /\bC\/hr\b/g, replacement: "degrees Celsius per hour" },
655
+ { regex: /\bF\/hr\b/g, replacement: "degrees Fahrenheit per hour" },
656
+ { regex: /\bC\/min\b/g, replacement: "degrees Celsius per minute" },
657
+ { regex: /\bF\/min\b/g, replacement: "degrees Fahrenheit per minute" },
658
+ { regex: /\bC\b/g, replacement: "degrees Celsius" },
659
+ { regex: /\bF\b/g, replacement: "degrees Fahrenheit" }
660
+ ];
661
+
662
+ // src/dictionaries/icao.ts
663
+ var ICAOs = {
664
+ "KLCH": "Lake Charles, LA",
665
+ "TSTL": "St. Louis, MO",
666
+ "PABC": "Bethel, AK",
667
+ "TCMH": "Columbus, OH",
668
+ "KEPZ": "El Paso, TX",
669
+ "KCYS": "Cheyenne, WY",
670
+ "KJKL": "Jackson, KY",
671
+ "KPAH": "Paducah, KY",
672
+ "KEMX": "Tucson, AZ",
673
+ "KMHX": "Morehead City, NC",
674
+ "PAPD": "Fairbanks, AK",
675
+ "KDLH": "Duluth, MN",
676
+ "TADW": "Andrews Air Force Base, MD",
677
+ "KOKX": "Brookhaven, NY",
678
+ "KLZK": "Little Rock, AR",
679
+ "KHGX": "Houston, TX",
680
+ "TMSY": "New Orleans, LA",
681
+ "KDGX": "Jackson/Brandon, MS",
682
+ "KCTP": "Caribou, ME",
683
+ "KAMA": "Amarillo, TX",
684
+ "PGUA": "Andersen AFB, GU",
685
+ "KAPX": "Gaylord, MI",
686
+ "PAHG": "Kenai, AK",
687
+ "KLWX": "Sterling, VA",
688
+ "HWPA2": "Homer, AK",
689
+ "KGRK": "Fort Hood, TX",
690
+ "KAKQ": "Wakefield, VA",
691
+ "ROCO2": "Norman, OK",
692
+ "KCLX": "Charleston, SC",
693
+ "TPHX": "Phoenix, AZ",
694
+ "KNKX": "San Diego, CA",
695
+ "TDEN": "Denver, CO",
696
+ "TLAS": "Las Vegas, NV",
697
+ "KBUF": "Buffalo, NY",
698
+ "KTLX": "Norman, OK",
699
+ "KILX": "Lincoln, IL",
700
+ "KHDC": "Hammond, LA",
701
+ "KVWX": "Evansville, IN",
702
+ "TCLT": "Charlotte, NC",
703
+ "TEWR": "Newark, NJ",
704
+ "KFSD": "Sioux Falls, SD",
705
+ "KEAX": "Pleasant Hill, MO",
706
+ "KICX": "Cedar City, UT",
707
+ "KHTX": "Huntsville, AL",
708
+ "PACG": "Sitka, AK",
709
+ "KSOX": "Santa Ana Mountains, CA",
710
+ "TPBI": "West Palm Beach, FL",
711
+ "TSLC": "Salt Lake City, UT",
712
+ "KGLD": "Goodland, KS",
713
+ "TRDU": "Raleigh-Durham, NC",
714
+ "KATX": "Seattle, WA",
715
+ "TICH": "Wichita, KS",
716
+ "TSDF": "Louisville, KY",
717
+ "TBOS": "Boston, MA",
718
+ "TDCA": "Washington, DC",
719
+ "KUEX": "Grand Island, NE",
720
+ "TLKA2": "Talkeetna, AK",
721
+ "KBGM": "Binghamton, NY",
722
+ "TLVE": "Cleveland, OH",
723
+ "KCAE": "Columbia, SC",
724
+ "KDVN": "Quad Cities, IA",
725
+ "KABR": "Aberdeen, SD",
726
+ "KBYX": "Key West, FL",
727
+ "KMPX": "Minneapolis, MN",
728
+ "KCRP": "Corpus Christi, TX",
729
+ "KCBW": "Caribou, ME",
730
+ "KMRX": "Knoxville, TN",
731
+ "KSHV": "Shreveport, LA",
732
+ "KIWA": "Phoenix, AZ",
733
+ "KRGX": "Reno, NV",
734
+ "PHKM": "Kamuela, HI",
735
+ "KABX": "Albuquerque, NM",
736
+ "KBMX": "Birmingham, AL",
737
+ "TMDW": "Chicago Midway, IL",
738
+ "KVAX": "Moody AFB, GA",
739
+ "KHDX": "Holloman AFB, NM",
740
+ "KBRO": "Brownsville, TX",
741
+ "KTWX": "Topeka, KS",
742
+ "KRTX": "Portland, OR",
743
+ "KCXX": "Burlington, VT",
744
+ "KFCX": "Roanoke, VA",
745
+ "KFFC": "Atlanta, GA",
746
+ "KBOX": "Boston, MA",
747
+ "KTLH": "Tallahassee, FL",
748
+ "KPUX": "Pueblo, CO",
749
+ "KFDR": "Altus AFB, OK",
750
+ "KGJX": "Grand Junction, CO",
751
+ "KDTX": "Detroit, MI",
752
+ "PHWA": "Waimea, HI",
753
+ "KMQT": "Marquette, MI",
754
+ "KSJT": "San Angelo, TX",
755
+ "KUDX": "Rapid City, SD",
756
+ "TIAH": "Houston, TX",
757
+ "KSRX": "Fort Smith, AR",
758
+ "TJFK": "New York City, NY",
759
+ "KDDC": "Dodge City, KS",
760
+ "PAKC": "King Salmon, AK",
761
+ "PAIH": "Middleton Island, AK",
762
+ "RODN": "Kadena AB, JA",
763
+ "TBWI": "Baltimore/Washington, MD",
764
+ "KIWX": "Northern Indiana, IN",
765
+ "KFDX": "Cannon AFB, NM",
766
+ "TMIA": "Miami, FL",
767
+ "KICT": "Wichita, KS",
768
+ "TMKE": "Milwaukee, WI",
769
+ "TFLL": "Fort Lauderdale, FL",
770
+ "KARX": "La Crosse, WI",
771
+ "KLRX": "Elko, NV",
772
+ "KDAX": "Sacramento, CA",
773
+ "KGRB": "Green Bay, WI",
774
+ "KLGX": "Langley Hill, WA",
775
+ "KFTG": "Denver, CO",
776
+ "KMKX": "Milwaukee, WI",
777
+ "TTUL": "Tulsa, OK",
778
+ "TDFW": "Dallas/Fort Worth, TX",
779
+ "TTPA": "Tampa Bay, FL",
780
+ "TDAL": "Dallas Love Field, TX",
781
+ "KDFX": "Laughlin AFB, TX",
782
+ "KSFX": "Pocatello, ID",
783
+ "KMTX": "Salt Lake City, UT",
784
+ "PAEC": "Nome, AK",
785
+ "RKSG": "Camp Humphreys, KR",
786
+ "KOAX": "Omaha, NE",
787
+ "PHMO": "Molokai, HI",
788
+ "TDTW": "Detroit, MI",
789
+ "THOU": "Houston, TX",
790
+ "AWPA2": "Anchorage, AK",
791
+ "KTYX": "Fort Drum, NY",
792
+ "KCCX": "State College, PA",
793
+ "TMSP": "Minneapolis, MN",
794
+ "KMVX": "Grand Forks, ND",
795
+ "KBIS": "Bismarck, ND",
796
+ "KBBX": "Beale AFB, CA",
797
+ "KVBX": "Vandenberg AFB, CA",
798
+ "KPOE": "Fort Polk, LA",
799
+ "KMOB": "Mobile, AL",
800
+ "KJGX": "Robins AFB, GA",
801
+ "KMUX": "San Francisco, CA",
802
+ "TMCI": "Kansas City, MO",
803
+ "KLSX": "St. Louis, MO",
804
+ "KMAX": "Medford, OR",
805
+ "KRAX": "Raleigh/Durham, NC",
806
+ "KINX": "Tulsa, OK",
807
+ "RKJK": "Kunsan AB, KR",
808
+ "KSGF": "Springfield, MO",
809
+ "TDAY": "Dayton, OH",
810
+ "KDOX": "Dover AFB, DE",
811
+ "KGGW": "Glasgow, MT",
812
+ "KAMX": "Miami, FL",
813
+ "KENX": "Albany, NY",
814
+ "KTFX": "Great Falls, MT",
815
+ "KPBZ": "Pittsburgh, PA",
816
+ "KMAF": "Midland/Odessa, TX",
817
+ "KPDT": "Pendleton, OR",
818
+ "KLNX": "North Platte, NE",
819
+ "KEOX": "Fort Rucker, AL",
820
+ "KGSP": "Greer, SC",
821
+ "KHPX": "Fort Campbell, KY",
822
+ "KGRR": "Grand Rapids, MI",
823
+ "KLOT": "Chicago, IL",
824
+ "TPIT": "Pittsburgh, PA",
825
+ "KEYX": "Edwards AFB, CA",
826
+ "TIAD": "Dulles, VA",
827
+ "KFWS": "Dallas/Fort Worth, TX",
828
+ "KMLB": "Melbourne, FL",
829
+ "KMBX": "Minot AFB, ND",
830
+ "KDMX": "Des Moines, IA",
831
+ "KEVX": "Eglin AFB, FL",
832
+ "TBNA": "Nashville, TN",
833
+ "KDYX": "Dyess AFB, TX",
834
+ "TOKC": "Oklahoma City, OK",
835
+ "PHKI": "South Kauai, HI",
836
+ "TMCO": "Orlando, FL",
837
+ "KDIX": "Philadelphia, PA",
838
+ "TORD": "Chicago, IL",
839
+ "KYUX": "Yuma, AZ",
840
+ "KVNX": "Vance AFB, OK",
841
+ "TJUA": "San Juan, PR",
842
+ "TATL": "Atlanta, GA",
843
+ "KVTX": "Los Angeles, CA",
844
+ "KIND": "Indianapolis, IN",
845
+ "KCBX": "Boise, ID",
846
+ "KGYX": "Portland, ME",
847
+ "KMXX": "Maxwell AFB, AL",
848
+ "TSJU": "San Juan, PR",
849
+ "KHNX": "San Joaquin Valley, CA",
850
+ "KLVX": "Louisville, KY",
851
+ "KMSX": "Missoula, MT",
852
+ "KJAX": "Jacksonville, FL",
853
+ "KNQA": "Memphis, TN",
854
+ "KRIW": "Riverton/Lander, WY",
855
+ "TCVG": "Covington, KY",
856
+ "KBLX": "Billings, MT",
857
+ "TPHL": "Philadelphia, PA",
858
+ "KRLX": "Charleston, WV",
859
+ "TMEM": "Memphis, TN",
860
+ "KCLE": "Cleveland, OH",
861
+ "KBHX": "Eureka, CA",
862
+ "KLBB": "Lubbock, TX",
863
+ "KOTX": "Spokane, WA",
864
+ "KEWX": "Austin/San Antonio, TX",
865
+ "KGWX": "Columbus AFB, MS",
866
+ "KESX": "Las Vegas, NV",
867
+ "KTBW": "Tampa, FL",
868
+ "KOHX": "Nashville, TN",
869
+ "KLTX": "Wilmington, NC",
870
+ "KFSX": "Flagstaff, AZ",
871
+ "TIDS": "Indianapolis, IN",
872
+ "KILN": "Cincinnati, OH",
873
+ "PAFG": "Fairbanks, AK",
874
+ "KPQR": "Portland, OR",
875
+ "KILM": "Wilmington, NC",
876
+ "KEKA": "Eureka, CA",
877
+ "KCHS": "Charleston, SC",
878
+ "KPHI": "Philadelphia/Mt. Holly, NJ",
879
+ "KUNR": "Rapid City, SD",
880
+ "KMFL": "Miami, FL",
881
+ "TJSJ": "San Juan, PR",
882
+ "KFGF": "Grand Forks, ND",
883
+ "KSEW": "Seattle, WA",
884
+ "PAFC": "Anchorage, AK",
885
+ "KLMK": "Louisville, KY",
886
+ "PHFO": "Honolulu, HI",
887
+ "KLIX": "New Orleans/Baton Rouge, LA",
888
+ "KBOI": "Boise, ID",
889
+ "KPIH": "Pocatello, ID",
890
+ "KMTR": "San Francisco/Monterey, CA",
891
+ "KGJT": "Grand Junction, CO",
892
+ "PAAQ": "Anchorage, AK",
893
+ "KABQ": "Albuquerque, NM",
894
+ "KTAE": "Tallahassee, FL",
895
+ "KCAR": "Caribou, ME",
896
+ "KMFR": "Medford, OR",
897
+ "PGUM": "Guam, GU",
898
+ "PAJK": "Juneau, AK"
899
+ };
900
+
901
+ // src/bootstrap.ts
902
+ var packages = {
903
+ fs,
904
+ path,
905
+ events,
906
+ xmpp,
907
+ shapefile,
908
+ xml2js,
909
+ sqlite3: import_better_sqlite3.default,
910
+ cron,
911
+ axios: import_axios.default,
912
+ crypto: import_crypto.default,
913
+ os: import_os.default,
914
+ say: import_say.default
915
+ };
916
+ var cache = {
917
+ isReady: true,
918
+ sigHalt: false,
919
+ isConnected: false,
920
+ attemptingReconnect: false,
921
+ totalReconnects: 0,
922
+ lastStanza: null,
923
+ session: null,
924
+ lastConnect: null,
925
+ db: null,
926
+ events: new events.EventEmitter(),
927
+ isProcessingAudioQueue: false,
928
+ audioQueue: []
929
+ };
930
+ var settings = {
931
+ database: path.join(process.cwd(), "shapefiles.db"),
932
+ isNWWS: true,
933
+ NoaaWeatherWireService: {
934
+ clientReconnections: {
935
+ canReconnect: true,
936
+ currentInterval: 60
937
+ },
938
+ clientCredentials: {
939
+ username: null,
940
+ password: null,
941
+ nickname: "AtmosphericX Standalone Parser"
942
+ },
943
+ cache: {
944
+ read: false,
945
+ maxSizeMB: 5,
946
+ maxHistory: 5e3,
947
+ directory: null
948
+ },
949
+ alertPreferences: {
950
+ isCapOnly: false,
951
+ isShapefileUGC: false
952
+ }
953
+ },
954
+ NationalWeatherService: {
955
+ checkInterval: 15,
956
+ endpoint: "https://api.weather.gov/alerts/active"
957
+ },
958
+ global: {
959
+ useParentEvents: true,
960
+ betterEventParsing: true,
961
+ alertFiltering: {
962
+ filteredEvents: [],
963
+ filteredICOAs: [],
964
+ ignoredICOAs: [`KWNS`],
965
+ ignoredEvents: [`Unknown`, `Test Message`],
966
+ ugcFilter: [],
967
+ stateFilter: [],
968
+ checkExpired: true
969
+ },
970
+ easSettings: {
971
+ easAlerts: [],
972
+ easDirectory: null,
973
+ easIntroWav: null
974
+ }
975
+ }
976
+ };
977
+ var definitions = {
978
+ events: EVENTS,
979
+ actions: ACTIONS,
980
+ status: STATUS,
981
+ productTypes: TYPES,
982
+ correlations: STATUS_CORRELATIONS,
983
+ offshore: OFFSHORE,
984
+ awips: AWIPS,
985
+ cancelSignatures: CANCEL_SIGNATURES,
986
+ messageSignatures: MESSAGE_SIGNATURES,
987
+ tags: TAGS,
988
+ ICAO: ICAOs,
989
+ enhancedEvents: [
990
+ { "Tornado Warning": {
991
+ "Tornado Emergency": { description: "tornado emergency", condition: (tornadoThreatTag) => tornadoThreatTag === "OBSERVED" },
992
+ "PDS Tornado Warning": { description: "particularly dangerous situation", condition: (damageThreatTag) => damageThreatTag === "CONSIDERABLE" },
993
+ "Confirmed Tornado Warning": { condition: (tornadoThreatTag) => tornadoThreatTag === "OBSERVED" },
994
+ "Radar Indicated Tornado Warning": { condition: (tornadoThreatTag) => tornadoThreatTag !== "OBSERVED" }
995
+ } },
996
+ { "Tornado Watch": {
997
+ "PDS Tornado Watch": { description: "particularly dangerous situation" }
998
+ } },
999
+ { "Flash Flood Warning": {
1000
+ "Flash Flood Emergency": { description: "flash flood emergency" },
1001
+ "Considerable Flash Flood Warning": { condition: (damageThreatTag) => damageThreatTag === "CONSIDERABLE" }
1002
+ } },
1003
+ { "Severe Thunderstorm Warning": {
1004
+ "EDS Severe Thunderstorm Warning": { description: "extremely dangerous situation" },
1005
+ "Destructive Severe Thunderstorm Warning": { condition: (damageThreatTag) => damageThreatTag === "DESTRUCTIVE" },
1006
+ "Considerable Severe Thunderstorm Warning": { condition: (damageThreatTag) => damageThreatTag === "CONSIDERABLE" }
1007
+ } }
1008
+ ],
1009
+ expressions: {
1010
+ 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`,
1011
+ wmo: `[A-Z0-9]{6}\\s[A-Z]{4}\\s\\d{6}`,
1012
+ ugc1: `(\\w{2}[CZ](\\d{3}((-|>)\\s?(
1013
+
1014
+ )?))+)`,
1015
+ ugc2: `(\\d{6}(-|>)\\s?(
1016
+
1017
+ )?)`,
1018
+ ugc3: `(\\d{6})(?=-|$)`,
1019
+ 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}`,
1020
+ wmoID: `[A-Z0-9]{2}([A-Z]{3})`
1021
+ },
1022
+ shapefiles: [
1023
+ { id: `C`, file: `USCounties` },
1024
+ { id: `Z`, file: `ForecastZones` },
1025
+ { id: `Z`, file: `FireZones` },
1026
+ { id: `Z`, file: `OffShoreZones` },
1027
+ { id: `Z`, file: `FireCounties` },
1028
+ { id: `Z`, file: `Marine` }
1029
+ ],
1030
+ messages: {
1031
+ shapefile_creation: `[NOTICE] DO NOT CLOSE THIS PROJECT UNTIL THE SHAPEFILES ARE DONE COMPLETING!
1032
+ THIS COULD TAKE A WHILE DEPENDING ON THE SPEED OF YOUR STORAGE!!
1033
+ 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!`,
1034
+ shapefile_creation_finished: `[NOTICE] SHAPEFILES HAVE BEEN SUCCESSFULLY CREATED AND THE DATABASE IS READY FOR USE!`,
1035
+ not_ready: "[ERROR] You can NOT create another instance without shutting down the current one first, please make sure to call the stop() method first!",
1036
+ invalid_nickname: "[WARNING] The nickname you provided is invalid, please provide a valid nickname to continue.",
1037
+ eas_no_directory: "[WARNING] You have not set a directory for EAS audio files to be saved to, please set the 'easDirectory' setting in the global settings to enable EAS audio generation."
1038
+ }
1039
+ };
1040
+
1041
+ // src/parsers/text.ts
1042
+ var TextParser = class {
1043
+ /**
1044
+ * textProductToString extracts a specific value from a text-based weather product message based on a given key and optional removal strings.
1045
+ *
1046
+ * @public
1047
+ * @static
1048
+ * @param {string} message
1049
+ * @param {string} value
1050
+ * @param {string[]} [removal=[]]
1051
+ * @returns {(string | null)}
1052
+ */
1053
+ static textProductToString(message, value, removal = []) {
1054
+ const lines = message.split("\n");
1055
+ for (const line of lines) {
1056
+ if (line.includes(value)) {
1057
+ let result = line.slice(line.indexOf(value) + value.length).trim();
1058
+ for (const str of removal) {
1059
+ result = result.split(str).join("");
1060
+ }
1061
+ result = result.replace(value, "").replace("<", "").trim();
1062
+ return result || null;
1063
+ }
1064
+ }
1065
+ return null;
1066
+ }
1067
+ /**
1068
+ * textProductToPolygon extracts geographical coordinates from a text-based weather product message and returns them as an array of [longitude, latitude] pairs.
1069
+ *
1070
+ * @public
1071
+ * @static
1072
+ * @param {string} message
1073
+ * @returns {[number, number][]}
1074
+ */
1075
+ static textProductToPolygon(message) {
1076
+ const coordinates = [];
1077
+ const latLonMatch = message.match(/LAT\.{3}LON\s+([\d\s]+)/i);
1078
+ if (!latLonMatch || !latLonMatch[1]) return coordinates;
1079
+ const coordStrings = latLonMatch[1].replace(/\n/g, " ").trim().split(/\s+/);
1080
+ for (let i = 0; i < coordStrings.length - 1; i += 2) {
1081
+ const lat = parseFloat(coordStrings[i]) / 100;
1082
+ const lon = -parseFloat(coordStrings[i + 1]) / 100;
1083
+ if (!isNaN(lat) && !isNaN(lon)) {
1084
+ coordinates.push([lon, lat]);
1085
+ }
1086
+ }
1087
+ if (coordinates.length > 2) {
1088
+ coordinates.push(coordinates[0]);
1089
+ }
1090
+ return coordinates;
1091
+ }
1092
+ /**
1093
+ * textProductToDescription extracts the main description from a text-based weather product message.
1094
+ *
1095
+ * @public
1096
+ * @static
1097
+ * @param {string} message
1098
+ * @param {string} [handle=null]
1099
+ * @returns {string}
1100
+ */
1101
+ static textProductToDescription(message, handle = null) {
1102
+ const original = message;
1103
+ const dateRegex = /\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}/gim;
1104
+ const discoveredDates = Array.from(message.matchAll(dateRegex));
1105
+ if (discoveredDates.length) {
1106
+ const lastMatch = discoveredDates[discoveredDates.length - 1][0];
1107
+ const startIdx = message.lastIndexOf(lastMatch);
1108
+ if (startIdx !== -1) {
1109
+ const endIdx = message.indexOf("&&", startIdx);
1110
+ message = message.substring(startIdx + lastMatch.length, endIdx !== -1 ? endIdx : void 0).trimStart();
1111
+ if (message.startsWith("/")) message = message.slice(1).trimStart();
1112
+ if (handle && message.includes(handle)) {
1113
+ const handleIdx = message.indexOf(handle);
1114
+ message = message.substring(handleIdx + handle.length).trimStart();
1115
+ if (message.startsWith("/")) message = message.slice(1).trimStart();
1116
+ }
1117
+ }
1118
+ } else if (handle) {
1119
+ const handleIdx = message.indexOf(handle);
1120
+ if (handleIdx !== -1) {
1121
+ let afterHandle = message.substring(handleIdx + handle.length).trimStart();
1122
+ if (afterHandle.startsWith("/")) afterHandle = afterHandle.slice(1).trimStart();
1123
+ const latEnd = afterHandle.indexOf("&&");
1124
+ message = latEnd !== -1 ? afterHandle.substring(0, latEnd).trim() : afterHandle.trim();
1125
+ }
1126
+ }
1127
+ return message.replace(/\s+/g, " ").trim().startsWith("ISSUED TIME...") ? original : message.trim();
1128
+ }
1129
+ /**
1130
+ * awipTextToEvent converts an AWIPS ID prefix from a text-based weather product message to its corresponding event type and prefix.
1131
+ *
1132
+ * @public
1133
+ * @static
1134
+ * @param {string} message
1135
+ * @returns {{ type: any; prefix: any; }}
1136
+ */
1137
+ static awipTextToEvent(message) {
1138
+ for (const [prefix, type] of Object.entries(definitions.awips)) {
1139
+ if (message.startsWith(prefix)) {
1140
+ return { type, prefix };
1141
+ }
1142
+ }
1143
+ return { type: `XX`, prefix: `XX` };
1144
+ }
1145
+ /**
1146
+ * getXmlValues recursively searches a parsed XML object for specified keys and extracts their values.
1147
+ *
1148
+ * @public
1149
+ * @static
1150
+ * @param {*} parsed
1151
+ * @param {string[]} valuesToExtract
1152
+ * @returns {Record<string, any>}
1153
+ */
1154
+ static getXmlValues(parsed, valuesToExtract) {
1155
+ const extracted = {};
1156
+ const findValueByKey = (obj, searchKey) => {
1157
+ const results = [];
1158
+ if (obj === null || typeof obj !== "object") {
1159
+ return results;
1160
+ }
1161
+ const searchKeyLower = searchKey.toLowerCase();
1162
+ for (const key in obj) {
1163
+ if (obj.hasOwnProperty(key) && key.toLowerCase() === searchKeyLower) {
1164
+ results.push(obj[key]);
1165
+ }
1166
+ }
1167
+ if (Array.isArray(obj)) {
1168
+ for (const item of obj) {
1169
+ if (item.valueName && item.valueName.toLowerCase() === searchKeyLower && item.value !== void 0) {
1170
+ results.push(item.value);
1171
+ }
1172
+ const nestedResults = findValueByKey(item, searchKey);
1173
+ results.push(...nestedResults);
1174
+ }
1175
+ }
1176
+ for (const key in obj) {
1177
+ if (obj.hasOwnProperty(key)) {
1178
+ const nestedResults = findValueByKey(obj[key], searchKey);
1179
+ results.push(...nestedResults);
1180
+ }
1181
+ }
1182
+ return results;
1183
+ };
1184
+ for (const key of valuesToExtract) {
1185
+ const values = findValueByKey(parsed.alert, key);
1186
+ const uniqueValues = [...new Set(values)];
1187
+ extracted[key] = uniqueValues.length === 0 ? null : uniqueValues.length === 1 ? uniqueValues[0] : uniqueValues;
1188
+ }
1189
+ return extracted;
1190
+ }
1191
+ };
1192
+ var text_default = TextParser;
1193
+
1194
+ // src/parsers/ugc.ts
1195
+ var UGCParser = class {
1196
+ /**
1197
+ * ugcExtractor extracts and parses UGC codes from a given message string.
1198
+ *
1199
+ * @public
1200
+ * @static
1201
+ * @async
1202
+ * @param {string} message
1203
+ * @returns {unknown}
1204
+ */
1205
+ static ugcExtractor(message) {
1206
+ return __async(this, null, function* () {
1207
+ const header = this.getHeader(message);
1208
+ const zones = this.getZones(header);
1209
+ const expiry = this.getExpiry(message);
1210
+ const locations = yield this.getLocations(zones);
1211
+ const ugc = zones.length > 0 ? { zones, locations, expiry } : null;
1212
+ return ugc;
1213
+ });
1214
+ }
1215
+ /**
1216
+ * getHeader extracts the UGC header from a UGC message string.
1217
+ *
1218
+ * @public
1219
+ * @static
1220
+ * @param {string} message
1221
+ * @returns {*}
1222
+ */
1223
+ static getHeader(message) {
1224
+ const start = message.search(new RegExp(definitions.expressions.ugc1, "gimu"));
1225
+ const end = message.substring(start).search(new RegExp(definitions.expressions.ugc2, "gimu"));
1226
+ const full = message.substring(start, start + end).replace(/\s+/g, "").slice(0, -1);
1227
+ return full;
1228
+ }
1229
+ /**
1230
+ * getExpiry extracts the expiry date and time from a UGC message and returns it as a Date object.
1231
+ *
1232
+ * @public
1233
+ * @static
1234
+ * @param {string} message
1235
+ * @returns {*}
1236
+ */
1237
+ static getExpiry(message) {
1238
+ const start = message.match(new RegExp(definitions.expressions.ugc3, "gimu"));
1239
+ if (start != null) {
1240
+ const day = parseInt(start[0].substring(0, 2), 10);
1241
+ const hour = parseInt(start[0].substring(2, 4), 10);
1242
+ const minute = parseInt(start[0].substring(4, 6), 10);
1243
+ const now = /* @__PURE__ */ new Date();
1244
+ const expires = new Date(now.getUTCFullYear(), now.getUTCMonth(), day, hour, minute, 0);
1245
+ return expires;
1246
+ }
1247
+ return null;
1248
+ }
1249
+ /**
1250
+ * getLocations retrieves unique location names for the provided UGC zone codes from the database.
1251
+ *
1252
+ * @public
1253
+ * @static
1254
+ * @async
1255
+ * @param {String[]} zones
1256
+ * @returns {unknown}
1257
+ */
1258
+ static getLocations(zones) {
1259
+ return __async(this, null, function* () {
1260
+ const locations = [];
1261
+ for (let i = 0; i < zones.length; i++) {
1262
+ const id = zones[i].trim();
1263
+ const located = yield cache.db.prepare(`SELECT location FROM shapefiles WHERE id = ?`).get(id);
1264
+ located != void 0 ? locations.push(located.location) : locations.push(id);
1265
+ }
1266
+ return Array.from(new Set(locations)).sort();
1267
+ });
1268
+ }
1269
+ /**
1270
+ * getCoordinates retrieves geographical coordinates for the provided UGC zone codes from the database.
1271
+ *
1272
+ * @public
1273
+ * @static
1274
+ * @param {String[]} zones
1275
+ * @returns {{}}
1276
+ */
1277
+ static getCoordinates(zones) {
1278
+ let coordinates = [];
1279
+ for (let i = 0; i < zones.length; i++) {
1280
+ const id = zones[i].trim();
1281
+ let located = cache.db.prepare(`SELECT geometry FROM shapefiles WHERE id = ?`).get(id);
1282
+ if (located != void 0) {
1283
+ let geometry = JSON.parse(located.geometry);
1284
+ if ((geometry == null ? void 0 : geometry.type) === "Polygon") {
1285
+ coordinates.push(...geometry.coordinates[0].map((coord) => [coord[0], coord[1]]));
1286
+ break;
1287
+ }
1288
+ }
1289
+ }
1290
+ return coordinates;
1291
+ }
1292
+ /**
1293
+ * getZones parses a UGC header string and returns an array of individual UGC zone codes.
1294
+ *
1295
+ * @public
1296
+ * @static
1297
+ * @param {string} header
1298
+ * @returns {*}
1299
+ */
1300
+ static getZones(header) {
1301
+ const ugcSplit = header.split("-");
1302
+ const zones = [];
1303
+ let state = ugcSplit[0].substring(0, 2);
1304
+ let format = ugcSplit[0].substring(2, 3);
1305
+ for (let i = 0; i < ugcSplit.length; i++) {
1306
+ if (/^[A-Z]/.test(ugcSplit[i])) {
1307
+ state = ugcSplit[i].substring(0, 2);
1308
+ if (ugcSplit[i].includes(">")) {
1309
+ let [start, end] = ugcSplit[i].split(">"), startNum = parseInt(start.substring(3), 10), endNum = parseInt(end, 10);
1310
+ for (let j = startNum; j <= endNum; j++) zones.push(`${state}${format}${j.toString().padStart(3, "0")}`);
1311
+ } else zones.push(ugcSplit[i]);
1312
+ continue;
1313
+ }
1314
+ if (ugcSplit[i].includes(">")) {
1315
+ let [start, end] = ugcSplit[i].split(">"), startNum = parseInt(start, 10), endNum = parseInt(end, 10);
1316
+ for (let j = startNum; j <= endNum; j++) zones.push(`${state}${format}${j.toString().padStart(3, "0")}`);
1317
+ } else zones.push(`${state}${format}${ugcSplit[i]}`);
1318
+ }
1319
+ return zones.filter((item) => item !== "");
1320
+ }
1321
+ };
1322
+ var ugc_default = UGCParser;
1323
+
1324
+ // src/parsers/vtec.ts
1325
+ var VtecParser = class {
1326
+ /**
1327
+ * vtecExtractor extracts and parses VTEC codes from a given message string.
1328
+ *
1329
+ * @public
1330
+ * @static
1331
+ * @async
1332
+ * @param {string} message
1333
+ * @returns {unknown}
1334
+ */
1335
+ static vtecExtractor(message) {
1336
+ return __async(this, null, function* () {
1337
+ const vtecs = [];
1338
+ const matches = message.match(new RegExp(definitions.expressions.vtec, "g"));
1339
+ if (!matches) return null;
1340
+ for (let i = 0; i < matches.length; i++) {
1341
+ const vtec = matches[i];
1342
+ const parts = vtec.split(`.`);
1343
+ const dates = parts[6].split(`-`);
1344
+ vtecs.push({
1345
+ raw: vtec,
1346
+ type: definitions.productTypes[parts[0]],
1347
+ tracking: `${parts[2]}-${parts[3]}-${parts[4]}-${parts[5]}`,
1348
+ event: `${definitions.events[parts[3]]} ${definitions.actions[parts[4]]}`,
1349
+ status: definitions.status[parts[1]],
1350
+ wmo: message.match(new RegExp(definitions.expressions.wmo, "gimu")),
1351
+ expires: this.parseExpiryDate(dates)
1352
+ });
1353
+ }
1354
+ return vtecs;
1355
+ });
1356
+ }
1357
+ /**
1358
+ * parseExpiryDate converts VTEC expiry date format to a standard ISO 8601 format with timezone adjustment.
1359
+ *
1360
+ * @private
1361
+ * @static
1362
+ * @param {String[]} args
1363
+ * @returns {string}
1364
+ */
1365
+ static parseExpiryDate(args) {
1366
+ if (args[1] == `000000T0000Z`) return `Invalid Date Format`;
1367
+ const expires = `${(/* @__PURE__ */ new Date()).getFullYear().toString().substring(0, 2)}${args[1].substring(0, 2)}-${args[1].substring(2, 4)}-${args[1].substring(4, 6)}T${args[1].substring(7, 9)}:${args[1].substring(9, 11)}:00`;
1368
+ const local = new Date(new Date(expires).getTime() - 4 * 60 * 6e4);
1369
+ const pad = (n) => n.toString().padStart(2, "0");
1370
+ return `${local.getFullYear()}-${pad(local.getMonth() + 1)}-${pad(local.getDate())}T${pad(local.getHours())}:${pad(local.getMinutes())}:00.000-04:00`;
1371
+ }
1372
+ };
1373
+ var vtec_default = VtecParser;
1374
+
1375
+ // src/parsers/types/vtec.ts
1376
+ var VTECAlerts = class {
1377
+ /**
1378
+ * event processes validated VTEC alert messages, extracting relevant information and compiling it into structured event objects.
1379
+ *
1380
+ * @public
1381
+ * @static
1382
+ * @async
1383
+ * @param {types.TypeCompiled} validated
1384
+ * @returns {*}
1385
+ */
1386
+ static event(validated) {
1387
+ return __async(this, null, function* () {
1388
+ var _a;
1389
+ let processed = [];
1390
+ const messages = (_a = validated.message.split(/(?=\$\$)/g)) == null ? void 0 : _a.map((msg) => msg.trim());
1391
+ if (!messages || messages.length == 0) return;
1392
+ for (let i = 0; i < messages.length; i++) {
1393
+ const tick = performance.now();
1394
+ const message = messages[i];
1395
+ const getVTEC = yield vtec_default.vtecExtractor(message);
1396
+ const getUGC = yield ugc_default.ugcExtractor(message);
1397
+ if (getVTEC != null && getUGC != null) {
1398
+ for (let j = 0; j < getVTEC.length; j++) {
1399
+ const vtec = getVTEC[j];
1400
+ const getBaseProperties = yield events_default.getBaseProperties(message, validated, getUGC, vtec);
1401
+ const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties, vtec);
1402
+ processed.push({
1403
+ preformance: performance.now() - tick,
1404
+ tracking: vtec.tracking,
1405
+ header: getHeader,
1406
+ vtec: vtec.raw,
1407
+ history: [{ description: getBaseProperties.description, issued: getBaseProperties.issued, type: vtec.status }],
1408
+ properties: __spreadValues({ event: vtec.event, parent: vtec.event, action_type: vtec.status }, getBaseProperties)
1409
+ });
1410
+ }
1411
+ }
1412
+ }
1413
+ events_default.validateEvents(processed);
1414
+ });
1415
+ }
1416
+ };
1417
+ var vtec_default2 = VTECAlerts;
1418
+
1419
+ // src/parsers/types/ugc.ts
1420
+ var UGCAlerts = class {
1421
+ /**
1422
+ * getTracking generates a unique tracking identifier based on the sender's ICAO code and a hash of the UGC zones.
1423
+ *
1424
+ * @private
1425
+ * @static
1426
+ * @param {types.BaseProperties} baseProperties
1427
+ * @param {string[]} zones
1428
+ * @returns {string}
1429
+ */
1430
+ static getTracking(baseProperties, zones) {
1431
+ return `${baseProperties.sender_icao} (${packages.crypto.createHash("md5").update(zones.join(``)).digest("hex")}})`;
1432
+ }
1433
+ /**
1434
+ * getEvent determines the event name based on offshore definitions or formats it from the attributes.
1435
+ *
1436
+ * @private
1437
+ * @static
1438
+ * @param {string} message
1439
+ * @param {Record<string, any>} attributes
1440
+ * @returns {*}
1441
+ */
1442
+ static getEvent(message, attributes) {
1443
+ const offshoreEvent = Object.keys(definitions.offshore).find((event) => message.toLowerCase().includes(event.toLowerCase()));
1444
+ if (offshoreEvent != void 0) return Object.keys(definitions.offshore).find((event) => message.toLowerCase().includes(event.toLowerCase()));
1445
+ return attributes.type.split(`-`).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(` `);
1446
+ }
1447
+ /**
1448
+ * event processes validated UGC alert messages, extracting relevant information and compiling it into structured event objects.
1449
+ *
1450
+ * @public
1451
+ * @static
1452
+ * @async
1453
+ * @param {types.TypeCompiled} validated
1454
+ * @returns {*}
1455
+ */
1456
+ static event(validated) {
1457
+ return __async(this, null, function* () {
1458
+ var _a;
1459
+ let processed = [];
1460
+ const messages = (_a = validated.message.split(/(?=\$\$|ISSUED TIME...|=================================================)/g)) == null ? void 0 : _a.map((msg) => msg.trim());
1461
+ if (!messages || messages.length == 0) return;
1462
+ for (let i = 0; i < messages.length; i++) {
1463
+ const tick = performance.now();
1464
+ const message = messages[i];
1465
+ const getUGC = yield ugc_default.ugcExtractor(message);
1466
+ if (getUGC != null) {
1467
+ const getBaseProperties = yield events_default.getBaseProperties(message, validated, getUGC);
1468
+ const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1469
+ const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1470
+ processed.push({
1471
+ preformance: performance.now() - tick,
1472
+ tracking: this.getTracking(getBaseProperties, getUGC.zones),
1473
+ header: getHeader,
1474
+ vtec: `N/A`,
1475
+ history: [{ description: getBaseProperties.description, issued: getBaseProperties.issued, type: `Issued` }],
1476
+ properties: __spreadValues({ event: getEvent, parent: getEvent, action_type: `Issued` }, getBaseProperties)
1477
+ });
1478
+ }
1479
+ }
1480
+ events_default.validateEvents(processed);
1481
+ });
1482
+ }
1483
+ };
1484
+ var ugc_default2 = UGCAlerts;
1485
+
1486
+ // src/parsers/types/text.ts
1487
+ var UGCAlerts2 = class {
1488
+ static getTracking(baseProperties) {
1489
+ return `${baseProperties.sender_icao}`;
1490
+ }
1491
+ static getEvent(message, attributes) {
1492
+ const offshoreEvent = Object.keys(definitions.offshore).find((event) => message.toLowerCase().includes(event.toLowerCase()));
1493
+ if (offshoreEvent) return Object.keys(definitions.offshore).find((event) => message.toLowerCase().includes(event.toLowerCase()));
1494
+ return attributes.type.split(`-`).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(` `);
1495
+ }
1496
+ static event(validated) {
1497
+ return __async(this, null, function* () {
1498
+ var _a;
1499
+ let processed = [];
1500
+ const messages = (_a = validated.message.split(/(?=\$\$|ISSUED TIME...|=================================================)/g)) == null ? void 0 : _a.map((msg) => msg.trim());
1501
+ if (!messages || messages.length == 0) return;
1502
+ for (let i = 0; i < messages.length; i++) {
1503
+ const tick = performance.now();
1504
+ const message = messages[i];
1505
+ const getBaseProperties = yield events_default.getBaseProperties(message, validated);
1506
+ const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1507
+ const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1508
+ processed.push({
1509
+ preformance: performance.now() - tick,
1510
+ tracking: this.getTracking(getBaseProperties),
1511
+ header: getHeader,
1512
+ vtec: `N/A`,
1513
+ history: [{ description: getBaseProperties.description, issued: getBaseProperties.issued, type: `Issued` }],
1514
+ properties: __spreadValues({ event: getEvent, parent: getEvent, action_type: `Issued` }, getBaseProperties)
1515
+ });
1516
+ }
1517
+ events_default.validateEvents(processed);
1518
+ });
1519
+ }
1520
+ };
1521
+ var text_default2 = UGCAlerts2;
1522
+
1523
+ // src/parsers/types/api.ts
1524
+ var APIAlerts = class {
1525
+ static getTracking(extracted) {
1526
+ return extracted.vtec ? (() => {
1527
+ const vtecValue = Array.isArray(extracted.vtec) ? extracted.vtec[0] : extracted.vtec;
1528
+ const splitVTEC = vtecValue.split(".");
1529
+ return `${splitVTEC[2]}-${splitVTEC[3]}-${splitVTEC[4]}-${splitVTEC[5]}`;
1530
+ })() : `${extracted.wmoidentifier} (${extracted.ugc})`;
1531
+ }
1532
+ static getICAO(vtec) {
1533
+ var _a, _b;
1534
+ const icao = vtec ? vtec.split(`.`)[2] : `N/A`;
1535
+ const name = (_b = (_a = definitions.ICAO) == null ? void 0 : _a[icao]) != null ? _b : `N/A`;
1536
+ return { icao, name };
1537
+ }
1538
+ static event(validated) {
1539
+ return __async(this, null, function* () {
1540
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca;
1541
+ let processed = [];
1542
+ const messages = Object.values(JSON.parse(validated.message).features);
1543
+ for (let feature of messages) {
1544
+ const tick = performance.now();
1545
+ const getVTEC = (_d = (_c = (_b = (_a = feature == null ? void 0 : feature.properties) == null ? void 0 : _a.parameters) == null ? void 0 : _b.VTEC) == null ? void 0 : _c[0]) != null ? _d : null;
1546
+ const getWmo = (_g = (_f = (_e = feature == null ? void 0 : feature.properties) == null ? void 0 : _e.parameters) == null ? void 0 : _f.WMOidentifier[0]) != null ? _g : null;
1547
+ const getUgc = (_j = (_i = (_h = feature == null ? void 0 : feature.properties) == null ? void 0 : _h.geocode) == null ? void 0 : _i.UGC) != null ? _j : null;
1548
+ const getHeadline = (_n = (_m = (_l = (_k = feature == null ? void 0 : feature.properties) == null ? void 0 : _k.parameters) == null ? void 0 : _l.NWSheadline) == null ? void 0 : _m[0]) != null ? _n : "";
1549
+ const getDescription = `${getHeadline} ${(_p = (_o = feature == null ? void 0 : feature.properties) == null ? void 0 : _o.description) != null ? _p : ``}`;
1550
+ const getAWIP = (_t = (_s = (_r = (_q = feature == null ? void 0 : feature.properties) == null ? void 0 : _q.parameters) == null ? void 0 : _r.AWIPSidentifier) == null ? void 0 : _s[0]) != null ? _t : null;
1551
+ const getHeader = events_default.getHeader(__spreadValues({}, { getAwip: { prefix: getAWIP == null ? void 0 : getAWIP.slice(0, -3) } }));
1552
+ const getSource = text_default.textProductToString(getDescription, `SOURCE...`, [`.`]) || `N/A`;
1553
+ const getOffice = this.getICAO(getVTEC || ``);
1554
+ processed.push({
1555
+ preformance: performance.now() - tick,
1556
+ tracking: this.getTracking({ vtec: getVTEC, wmoidentifier: getWmo, ugc: getUgc ? getUgc.join(`,`) : null }),
1557
+ header: getHeader,
1558
+ vtec: getVTEC || `N/A`,
1559
+ history: [{
1560
+ description: (_v = (_u = feature == null ? void 0 : feature.properties) == null ? void 0 : _u.description) != null ? _v : `N/A`,
1561
+ action: (_x = (_w = feature == null ? void 0 : feature.properties) == null ? void 0 : _w.messageType) != null ? _x : `N/A`,
1562
+ time: ((_y = feature == null ? void 0 : feature.properties) == null ? void 0 : _y.sent) ? new Date((_z = feature == null ? void 0 : feature.properties) == null ? void 0 : _z.sent).toLocaleString() : `N/A`
1563
+ }],
1564
+ properties: {
1565
+ locations: (_B = (_A = feature == null ? void 0 : feature.properties) == null ? void 0 : _A.areaDesc) != null ? _B : `N/A`,
1566
+ event: (_D = (_C = feature == null ? void 0 : feature.properties) == null ? void 0 : _C.event) != null ? _D : `N/A`,
1567
+ issued: ((_E = feature == null ? void 0 : feature.properties) == null ? void 0 : _E.sent) ? new Date((_F = feature == null ? void 0 : feature.properties) == null ? void 0 : _F.sent).toLocaleString() : `N/A`,
1568
+ expires: ((_G = feature == null ? void 0 : feature.properties) == null ? void 0 : _G.expires) ? new Date((_H = feature == null ? void 0 : feature.properties) == null ? void 0 : _H.expires).toLocaleString() : `N/A`,
1569
+ parent: (_J = (_I = feature == null ? void 0 : feature.properties) == null ? void 0 : _I.event) != null ? _J : `N/A`,
1570
+ action_type: (_L = (_K = feature == null ? void 0 : feature.properties) == null ? void 0 : _K.messageType) != null ? _L : `N/A`,
1571
+ description: (_N = (_M = feature == null ? void 0 : feature.properties) == null ? void 0 : _M.description) != null ? _N : `N/A`,
1572
+ sender_name: getOffice.name || `N/A`,
1573
+ sender_icao: getOffice.icao || `N/A`,
1574
+ attributes: validated.attributes,
1575
+ geocode: {
1576
+ UGC: (_Q = (_P = (_O = feature == null ? void 0 : feature.properties) == null ? void 0 : _O.geocode) == null ? void 0 : _P.UGC) != null ? _Q : [`XX000`]
1577
+ },
1578
+ parameters: {
1579
+ wmo: ((_T = (_S = (_R = feature == null ? void 0 : feature.properties) == null ? void 0 : _R.parameters) == null ? void 0 : _S.WMOidentifier) == null ? void 0 : _T[0]) || getWmo || `N/A`,
1580
+ source: getSource,
1581
+ max_hail_size: ((_V = (_U = feature == null ? void 0 : feature.properties) == null ? void 0 : _U.parameters) == null ? void 0 : _V.maxHailSize) || `N/A`,
1582
+ max_wind_gust: ((_X = (_W = feature == null ? void 0 : feature.properties) == null ? void 0 : _W.parameters) == null ? void 0 : _X.maxWindGust) || `N/A`,
1583
+ damage_threat: ((_Z = (_Y = feature == null ? void 0 : feature.properties) == null ? void 0 : _Y.parameters) == null ? void 0 : _Z.thunderstormDamageThreat) || [`N/A`],
1584
+ tornado_detection: ((_$ = (__ = feature == null ? void 0 : feature.properties) == null ? void 0 : __.parameters) == null ? void 0 : _$.tornadoDetection) || [`N/A`],
1585
+ flood_detection: ((_ba = (_aa = feature == null ? void 0 : feature.properties) == null ? void 0 : _aa.parameters) == null ? void 0 : _ba.floodDetection) || [`N/A`],
1586
+ discussion_tornado_intensity: "N/A",
1587
+ peakWindGust: `N/A`,
1588
+ peakHailSize: `N/A`
1589
+ },
1590
+ geometry: (_ca = feature == null ? void 0 : feature.geometry) != null ? _ca : null
1591
+ }
1592
+ });
1593
+ }
1594
+ events_default.validateEvents(processed);
1595
+ });
1596
+ }
1597
+ };
1598
+ var api_default = APIAlerts;
1599
+
1600
+ // src/parsers/stanza.ts
1601
+ var StanzaParser = class {
1602
+ /**
1603
+ * validate handles the validation of incoming XMPP stanzas to ensure they contain valid alert data.
1604
+ * You can also feed debug / cache data directly into this function by specifying the second parameter
1605
+ * which is the attributes object that would normally be parsed from the XMPP stanza.
1606
+ *
1607
+ * @public
1608
+ * @static
1609
+ * @param {*} stanza
1610
+ * @param {(boolean | types.TypeAttributes)} [isDebug=false]
1611
+ * @returns {{ message: any; attributes: types.TypeAttributes; isCap: any; isVtec: boolean; isCapDescription: any; awipsType: any; isApi: boolean; ignore: boolean; }}
1612
+ */
1613
+ static validate(stanza, isDebug = false) {
1614
+ var _a;
1615
+ if (isDebug !== false) {
1616
+ const vTypes = isDebug;
1617
+ const message = stanza;
1618
+ const attributes = vTypes;
1619
+ const isCap = (_a = vTypes.isCap) != null ? _a : message.includes(`<?xml`);
1620
+ const isCapDescription = message.includes(`<areaDesc>`);
1621
+ const isVtec = message.match(definitions.expressions.vtec) != null;
1622
+ const isUGC = message.match(definitions.expressions.ugc1) != null;
1623
+ const awipsType = this.getType(attributes);
1624
+ return { message, attributes, isCap, isVtec, isUGC, isCapDescription, awipsType, isApi: false, ignore: false };
1625
+ }
1626
+ if (stanza.is(`message`)) {
1627
+ let cb = stanza.getChild(`x`);
1628
+ if (cb && cb.children) {
1629
+ let message = unescape(cb.children[0]);
1630
+ let attributes = cb.attrs;
1631
+ if (attributes.awipsid && attributes.awipsid.length > 1) {
1632
+ const isCap = message.includes(`<?xml`);
1633
+ const isCapDescription = message.includes(`<areaDesc>`);
1634
+ const isVtec = message.match(definitions.expressions.vtec) != null;
1635
+ const isUGC = message.match(definitions.expressions.ugc1) != null;
1636
+ const awipsType = this.getType(attributes);
1637
+ const isApi = false;
1638
+ this.cache({ message, attributes, isCap, isVtec, awipsType: awipsType.type, awipsPrefix: awipsType.prefix });
1639
+ return { message, attributes, isCap, isApi, isVtec, isUGC, isCapDescription, awipsType, ignore: false };
1640
+ }
1641
+ }
1642
+ }
1643
+ return { message: null, attributes: null, isApi: null, isCap: null, isVtec: null, isUGC: null, isCapDescription: null, awipsType: null, ignore: true };
1644
+ }
1645
+ /**
1646
+ * getType determines the AWIPS type of the alert based on its attributes, specifically the awipsid.
1647
+ * If no matching type is found, it defaults to 'default'.
1648
+ *
1649
+ * @private
1650
+ * @static
1651
+ * @param {unknown} attributes
1652
+ * @returns {*}
1653
+ */
1654
+ static getType(attributes) {
1655
+ const attrs = attributes;
1656
+ if (!attrs || !attrs.awipsid) return { type: `XX`, prefix: `XX` };
1657
+ for (const [prefix, type] of Object.entries(definitions.awips)) {
1658
+ if (attrs.awipsid.startsWith(prefix)) {
1659
+ return { type, prefix };
1660
+ }
1661
+ }
1662
+ return { type: `XX`, prefix: `XX` };
1663
+ }
1664
+ /**
1665
+ * cache stores the compiled alert data into a cache file if caching is enabled in the settings.
1666
+ *
1667
+ * @private
1668
+ * @static
1669
+ * @param {unknown} compiled
1670
+ */
1671
+ static cache(compiled) {
1672
+ const data = compiled;
1673
+ const settings2 = settings;
1674
+ if (!settings2.NoaaWeatherWireService.cache.directory) return;
1675
+ if (!packages.fs.existsSync(settings2.NoaaWeatherWireService.cache.directory)) {
1676
+ packages.fs.mkdirSync(settings2.NoaaWeatherWireService.cache.directory, { recursive: true });
1677
+ }
1678
+ data.message = data.message.replace(/\$\$/g, `
1679
+ STANZA ATTRIBUTES...${JSON.stringify(data.attributes)}
1680
+ ISSUED TIME...${(/* @__PURE__ */ new Date()).toISOString()}
1681
+ $$$
1682
+ `);
1683
+ if (!data.message.includes(`STANZA ATTRIBUTES...`)) {
1684
+ data.message += `
1685
+ STANZA ATTRIBUTES...${JSON.stringify(data.attributes)}
1686
+ ISSUED TIME...${(/* @__PURE__ */ new Date()).toISOString()}
1687
+ $$
1688
+ `;
1689
+ }
1690
+ packages.fs.appendFileSync(`${settings2.NoaaWeatherWireService.cache.directory}/category-${data.awipsPrefix}-${data.awipsType}s-${data.isCap ? `cap` : `raw`}${data.isVtec ? `-vtec` : ``}.bin`, `=================================================
1691
+ ${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}
1692
+ =================================================
1693
+ ${data.message}`, "utf8");
1694
+ packages.fs.appendFileSync(`${settings2.NoaaWeatherWireService.cache.directory}/cache-${data.isCap ? `cap` : `raw`}${data.isVtec ? `-vtec` : ``}.bin`, `=================================================
1695
+ ${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}
1696
+ =================================================
1697
+ ${data.message}`, "utf8");
1698
+ }
1699
+ };
1700
+ var stanza_default = StanzaParser;
1701
+
1702
+ // src/database.ts
1703
+ var Database = class {
1704
+ /**
1705
+ * handleAlertCache stores a unique alert in the SQLite database and ensures the total number of alerts does not exceed 5000.
1706
+ *
1707
+ * @public
1708
+ * @static
1709
+ * @async
1710
+ * @param {*} alert
1711
+ * @returns {*}
1712
+ */
1713
+ static stanzaCacheImport(stanza) {
1714
+ return __async(this, null, function* () {
1715
+ const settings2 = settings;
1716
+ cache.db.prepare(`INSERT OR IGNORE INTO stanzas (stanza) VALUES (?)`).run(stanza);
1717
+ const count = cache.db.prepare(`SELECT COUNT(*) as total FROM stanzas`).get();
1718
+ if (count.total > settings2.NoaaWeatherWireService.cache.maxHistory) {
1719
+ cache.db.prepare(`DELETE FROM stanzas WHERE rowid IN (SELECT rowid FROM stanzas ORDER BY rowid ASC LIMIT ?)`).run(count.total - settings2.NoaaWeatherWireService.cache.maxHistory / 2);
1720
+ }
1721
+ });
1722
+ }
1723
+ /**
1724
+ * loadDatabase initializes the SQLite database and imports shapefile data if the database or table does not exist.
1725
+ *
1726
+ * @public
1727
+ * @static
1728
+ * @async
1729
+ * @returns {Promise<void>}
1730
+ */
1731
+ static loadDatabase() {
1732
+ return __async(this, null, function* () {
1733
+ const settings2 = settings;
1734
+ try {
1735
+ if (!packages.fs.existsSync(settings2.database)) {
1736
+ packages.fs.writeFileSync(settings2.database, "");
1737
+ }
1738
+ cache.db = new packages.sqlite3(settings2.database);
1739
+ const shapfileTable = cache.db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='shapefiles'`).get();
1740
+ const stanzaTable = cache.db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='stanzas'`).get();
1741
+ if (!stanzaTable) {
1742
+ cache.db.prepare(`CREATE TABLE stanzas (id INTEGER PRIMARY KEY AUTOINCREMENT, stanza TEXT)`).run();
1743
+ }
1744
+ if (!shapfileTable) {
1745
+ cache.db.prepare(`CREATE TABLE shapefiles (id TEXT PRIMARY KEY, location TEXT, geometry TEXT)`).run();
1746
+ console.log(definitions.messages.shapefile_creation);
1747
+ for (const shape of definitions.shapefiles) {
1748
+ const { id, file } = shape;
1749
+ const filepath = packages.path.join(__dirname, `../../shapefiles`, file);
1750
+ const { features } = yield packages.shapefile.read(filepath, filepath);
1751
+ console.log(`Importing ${features.length} entries from ${file}...`);
1752
+ const insertStmt = cache.db.prepare(`INSERT OR REPLACE INTO shapefiles (id, location, geometry)VALUES (?, ?, ?)`);
1753
+ const insertTransaction = cache.db.transaction((entries) => {
1754
+ for (const feature of entries) {
1755
+ const { properties, geometry } = feature;
1756
+ let final, location;
1757
+ switch (true) {
1758
+ case !!properties.FIPS:
1759
+ final = `${properties.STATE}${id}${properties.FIPS.substring(2)}`;
1760
+ location = `${properties.COUNTYNAME}, ${properties.STATE}`;
1761
+ break;
1762
+ case !!properties.FULLSTAID:
1763
+ final = `${properties.ST}${id}${properties.WFO}`;
1764
+ location = `${properties.CITY}, ${properties.STATE}`;
1765
+ break;
1766
+ case !!properties.STATE:
1767
+ final = `${properties.STATE}${id}${properties.ZONE}`;
1768
+ location = `${properties.NAME}, ${properties.STATE}`;
1769
+ break;
1770
+ default:
1771
+ final = properties.ID;
1772
+ location = properties.NAME;
1773
+ break;
1774
+ }
1775
+ insertStmt.run(final, location, JSON.stringify(geometry));
1776
+ }
1777
+ });
1778
+ yield insertTransaction(features);
1779
+ }
1780
+ console.log(definitions.messages.shapefile_creation_finished);
1781
+ }
1782
+ } catch (error) {
1783
+ cache.events.emit("onError", { code: "error-load-database", message: `Failed to load database: ${error.message}` });
1784
+ }
1785
+ });
1786
+ }
1787
+ };
1788
+ var database_default = Database;
1789
+
1790
+ // src/xmpp.ts
1791
+ var Xmpp = class {
1792
+ /**
1793
+ * isSessionReconnectionEligible checks if the XMPP session is eligible for reconnection based on the last
1794
+ * received stanza time and current interval.
1795
+ *
1796
+ * @public
1797
+ * @static
1798
+ * @async
1799
+ * @param {number} currentInterval
1800
+ * @returns {Promise<void>}
1801
+ */
1802
+ static isSessionReconnectionEligible(currentInterval) {
1803
+ return __async(this, null, function* () {
1804
+ const settings2 = settings;
1805
+ if ((cache.isConnected || cache.sigHalt) && cache.session) {
1806
+ const lastStanza = Date.now() - cache.lastStanza;
1807
+ if (lastStanza >= currentInterval * 1e3) {
1808
+ if (!cache.attemptingReconnect) {
1809
+ cache.attemptingReconnect = true;
1810
+ cache.isConnected = false;
1811
+ cache.totalReconnects += 1;
1812
+ cache.events.emit(`onReconnect`, { reconnects: cache.totalReconnects, lastStanza, lastName: settings2.NoaaWeatherWireService.clientCredentials.nickname });
1813
+ yield cache.session.stop().catch(() => {
1814
+ });
1815
+ yield cache.session.start().catch(() => {
1816
+ });
1817
+ }
1818
+ }
1819
+ }
1820
+ });
1821
+ }
1822
+ /**
1823
+ * deploySession initializes and starts the XMPP client session, setting up event listeners for
1824
+ * connection management and message handling. This function is specifically tailored for
1825
+ * NoaaWeatherWireService and connects to their XMPP server.
1826
+ *
1827
+ * @public
1828
+ * @static
1829
+ * @async
1830
+ * @returns {Promise<void>}
1831
+ */
1832
+ static deploySession() {
1833
+ return __async(this, null, function* () {
1834
+ var _a, _b;
1835
+ const settings2 = settings;
1836
+ cache.session = packages.xmpp.client({
1837
+ service: `xmpp://nwws-oi.weather.gov`,
1838
+ domain: `nwws-oi.weather.gov`,
1839
+ username: settings2.NoaaWeatherWireService.clientCredentials.username,
1840
+ password: settings2.NoaaWeatherWireService.clientCredentials.password
1841
+ });
1842
+ (_b = (_a = settings2.NoaaWeatherWireService.clientCredentials).nickname) != null ? _b : _a.nickname = settings2.NoaaWeatherWireService.clientCredentials.username;
1843
+ cache.session.on(`online`, (address) => __async(null, null, function* () {
1844
+ if (cache.lastConnect && Date.now() - cache.lastConnect < 10 * 1e3) {
1845
+ cache.sigHalt = true;
1846
+ utils_default.sleep(2 * 1e3).then(() => __async(null, null, function* () {
1847
+ yield cache.session.stop();
1848
+ }));
1849
+ cache.events.emit(`onError`, { code: `error-reconnecting-too-fast`, message: `The client is attempting to reconnect too fast. Please wait a few seconds before trying again.` });
1850
+ return;
1851
+ }
1852
+ cache.isConnected = true;
1853
+ cache.sigHalt = false;
1854
+ cache.lastConnect = Date.now();
1855
+ cache.session.send(packages.xmpp.xml("presence", { to: `nwws@conference.nwws-oi.weather.gov/${settings2.NoaaWeatherWireService.clientCredentials.nickname}`, xmlns: "http://jabber.org/protocol/muc" }));
1856
+ cache.session.send(packages.xmpp.xml("presence", { to: `nwws@conference.nwws-oi.weather.gov`, type: "available" }));
1857
+ cache.events.emit(`onConnection`, settings2.NoaaWeatherWireService.clientCredentials.nickname);
1858
+ if (cache.attemptingReconnect) {
1859
+ utils_default.sleep(15 * 1e3).then(() => {
1860
+ cache.attemptingReconnect = false;
1861
+ });
1862
+ }
1863
+ }));
1864
+ cache.session.on(`offline`, () => __async(null, null, function* () {
1865
+ cache.isConnected = false;
1866
+ cache.sigHalt = true;
1867
+ cache.events.emit(`onError`, { code: `connection-lost`, message: `XMPP connection went offline` });
1868
+ }));
1869
+ cache.session.on(`error`, (error) => __async(null, null, function* () {
1870
+ cache.isConnected = false;
1871
+ cache.sigHalt = true;
1872
+ cache.events.emit(`onError`, { code: `connection-error`, message: error.message });
1873
+ }));
1874
+ cache.session.on(`stanza`, (stanza) => __async(null, null, function* () {
1875
+ try {
1876
+ cache.lastStanza = Date.now();
1877
+ if (stanza.is(`message`)) {
1878
+ const validate = stanza_default.validate(stanza);
1879
+ if (validate.ignore || validate.isCap && !settings2.NoaaWeatherWireService.alertPreferences.isCapOnly || !validate.isCap && settings2.NoaaWeatherWireService.alertPreferences.isCapOnly || validate.isCap && !validate.isCapDescription) return;
1880
+ events_default.eventHandler(validate);
1881
+ cache.events.emit(`onMessage`, validate);
1882
+ database_default.stanzaCacheImport(JSON.stringify(validate));
1883
+ }
1884
+ if (stanza.is(`presence`) && stanza.attrs.from && stanza.attrs.from.startsWith("nwws@conference.nwws-oi.weather.gov/")) {
1885
+ const occupant = stanza.attrs.from.split("/").slice(1).join("/");
1886
+ cache.events.emit("onOccupant", { occupant, type: stanza.attrs.type === "unavailable" ? "unavailable" : "available" });
1887
+ }
1888
+ } catch (e) {
1889
+ cache.events.emit(`onError`, { code: `error-processing-stanza`, message: e.message });
1890
+ }
1891
+ }));
1892
+ yield cache.session.start();
1893
+ });
1894
+ }
1895
+ };
1896
+ var xmpp_default = Xmpp;
1897
+
1898
+ // src/utils.ts
1899
+ var Utils = class {
1900
+ /**
1901
+ * Zzzzzzz... yeah not much to explain here. Simple sleep function that returns a promise after the specified milliseconds.
1902
+ *
1903
+ * @public
1904
+ * @static
1905
+ * @async
1906
+ * @param {number} ms
1907
+ * @returns {Promise<void>}
1908
+ */
1909
+ static sleep(ms) {
1910
+ return __async(this, null, function* () {
1911
+ return new Promise((resolve) => setTimeout(resolve, ms));
1912
+ });
1913
+ }
1914
+ /**
1915
+ * loadCollectionCache reads cached alert files from the specified cache directory and processes them.
1916
+ *
1917
+ * @public
1918
+ * @static
1919
+ * @async
1920
+ * @returns {Promise<void>}
1921
+ */
1922
+ static loadCollectionCache() {
1923
+ return __async(this, null, function* () {
1924
+ try {
1925
+ const settings2 = settings;
1926
+ if (settings2.NoaaWeatherWireService.cache.read && settings2.NoaaWeatherWireService.cache.directory) {
1927
+ if (!packages.fs.existsSync(settings2.NoaaWeatherWireService.cache.directory)) return;
1928
+ const cacheDir = settings2.NoaaWeatherWireService.cache.directory;
1929
+ const getAllFiles = packages.fs.readdirSync(cacheDir).filter((file) => file.endsWith(".bin") && file.startsWith("cache-"));
1930
+ for (const file of getAllFiles) {
1931
+ const start = Date.now();
1932
+ const filepath = packages.path.join(cacheDir, file);
1933
+ const readFile = packages.fs.readFileSync(filepath, { encoding: "utf-8" });
1934
+ const isCap = readFile.includes(`<?xml`);
1935
+ if (isCap && !settings2.NoaaWeatherWireService.alertPreferences.isCapOnly) continue;
1936
+ if (!isCap && settings2.NoaaWeatherWireService.alertPreferences.isCapOnly) continue;
1937
+ const validate = stanza_default.validate(readFile, { awipsid: file, isCap, raw: true, issue: void 0 });
1938
+ yield events_default.eventHandler(validate);
1939
+ }
1940
+ }
1941
+ } catch (error) {
1942
+ cache.events.emit("onError", { code: "error-load-cache", message: `Failed to load cache: ${error.message}` });
1943
+ }
1944
+ });
1945
+ }
1946
+ /**
1947
+ * loadGeoJsonData fetches GeoJSON data from the National Weather Service endpoint and processes each alert.
1948
+ *
1949
+ * @public
1950
+ * @static
1951
+ * @async
1952
+ * @returns {Promise<void>}
1953
+ */
1954
+ static loadGeoJsonData() {
1955
+ return __async(this, null, function* () {
1956
+ try {
1957
+ const settings2 = settings;
1958
+ const response = yield this.createHttpRequest(settings2.NationalWeatherService.endpoint);
1959
+ if (!response.error) {
1960
+ events_default.eventHandler({ message: JSON.stringify(response.message), attributes: {}, isCap: true, isApi: true, isVtec: false, isUGC: false, isCapDescription: false, awipsType: { type: "api", prefix: "AP" }, ignore: false });
1961
+ }
1962
+ } catch (error) {
1963
+ cache.events.emit("onError", { code: "error-fetching-nws-data", message: `Failed to fetch NWS data: ${error.message}` });
1964
+ }
1965
+ });
1966
+ }
1967
+ /**
1968
+ * detectUncaughtExceptions sets up a global handler for uncaught exceptions in the Node.js process,
1969
+ *
1970
+ * @public
1971
+ * @static
1972
+ */
1973
+ static detectUncaughtExceptions() {
1974
+ if (process.listeners("uncaughtException").some((l) => l.name === "uncaughtExceptionHandler")) return;
1975
+ process.on(`uncaughtException`, (error) => {
1976
+ cache.events.emit(`onError`, { message: `Uncaught Exception: ${error.message}`, code: `error-uncaught-exception`, stack: error.stack });
1977
+ });
1978
+ }
1979
+ /**
1980
+ * createHttpRequest performs an HTTP GET request to the specified URL with optional settings.
1981
+ *
1982
+ * @public
1983
+ * @static
1984
+ * @async
1985
+ * @param {string} url
1986
+ * @param {?types.HTTPSettings} [options]
1987
+ * @returns {unknown}
1988
+ */
1989
+ static createHttpRequest(url, options) {
1990
+ return __async(this, null, function* () {
1991
+ var _a, _b;
1992
+ const defaultOptions = {
1993
+ timeout: 1e4,
1994
+ headers: {
1995
+ "User-Agent": "AtmosphericX",
1996
+ "Accept": "application/geo+json, text/plain, */*; q=0.9",
1997
+ "Accept-Language": "en-US,en;q=0.9"
1998
+ }
1999
+ };
2000
+ const requestOptions = __spreadProps(__spreadValues(__spreadValues({}, defaultOptions), options), {
2001
+ headers: __spreadValues(__spreadValues({}, defaultOptions.headers), (_a = options == null ? void 0 : options.headers) != null ? _a : {})
2002
+ });
2003
+ try {
2004
+ const resp = yield packages.axios.get(url, {
2005
+ headers: requestOptions.headers,
2006
+ timeout: requestOptions.timeout,
2007
+ maxRedirects: 0,
2008
+ validateStatus: (status) => status === 200 || status === 500
2009
+ });
2010
+ return { error: false, message: resp.data };
2011
+ } catch (err) {
2012
+ return { error: true, message: (_b = err == null ? void 0 : err.message) != null ? _b : String(err) };
2013
+ }
2014
+ });
2015
+ }
2016
+ /**
2017
+ * garbageCollectionCache removes files from the cache directory that exceed the specified maximum file size in megabytes.
2018
+ *
2019
+ * @public
2020
+ * @static
2021
+ * @param {number} maxFileMegabytes
2022
+ */
2023
+ static garbageCollectionCache(maxFileMegabytes) {
2024
+ try {
2025
+ const settings2 = settings;
2026
+ if (!settings2.NoaaWeatherWireService.cache.directory) return;
2027
+ if (!packages.fs.existsSync(settings2.NoaaWeatherWireService.cache.directory)) return;
2028
+ const maxBytes = maxFileMegabytes * 1024 * 1024;
2029
+ const cacheDirectory = settings2.NoaaWeatherWireService.cache.directory;
2030
+ const stackFiles = [cacheDirectory], files = [];
2031
+ while (stackFiles.length) {
2032
+ const currentDirectory = stackFiles.pop();
2033
+ packages.fs.readdirSync(currentDirectory).forEach((file) => {
2034
+ const fullPath = packages.path.join(currentDirectory, file);
2035
+ const stat = packages.fs.statSync(fullPath);
2036
+ if (stat.isDirectory()) stackFiles.push(fullPath);
2037
+ else files.push({ file: fullPath, size: stat.size });
2038
+ });
2039
+ }
2040
+ if (!files.length) return;
2041
+ files.forEach((f) => {
2042
+ if (f.size > maxBytes) packages.fs.unlinkSync(f.file);
2043
+ });
2044
+ } catch (error) {
2045
+ cache.events.emit("onError", { code: "error-garbage-collection", message: `Failed to perform garbage collection: ${error.message}` });
2046
+ }
2047
+ }
2048
+ /**
2049
+ * handleCronJob performs periodic tasks based on whether the client is connected to NWWS or fetching data from NWS.
2050
+ *
2051
+ * @public
2052
+ * @static
2053
+ * @param {boolean} isNwws
2054
+ */
2055
+ static handleCronJob(isNwws) {
2056
+ try {
2057
+ const settings2 = settings;
2058
+ if (isNwws) {
2059
+ if (settings2.NoaaWeatherWireService.cache.read) void this.garbageCollectionCache(settings2.NoaaWeatherWireService.cache.maxSizeMB);
2060
+ if (settings2.NoaaWeatherWireService.clientReconnections.canReconnect) void xmpp_default.isSessionReconnectionEligible(settings2.NoaaWeatherWireService.clientReconnections.currentInterval);
2061
+ } else {
2062
+ void this.loadGeoJsonData();
2063
+ }
2064
+ } catch (error) {
2065
+ cache.events.emit("onError", { code: "error-cron-job", message: `Failed to perform scheduled tasks: ${error.message}` });
2066
+ }
2067
+ }
2068
+ /**
2069
+ * mergeClientSettings merges user-provided settings into the existing client settings, allowing for nested objects to be merged correctly.
2070
+ *
2071
+ * @public
2072
+ * @static
2073
+ * @param {Record<string, any>} target
2074
+ * @param {Record<string, any>} settings
2075
+ */
2076
+ static mergeClientSettings(target, settings2) {
2077
+ for (const key in settings2) {
2078
+ if (settings2.hasOwnProperty(key)) {
2079
+ if (typeof settings2[key] === "object" && settings2[key] !== null && !Array.isArray(settings2[key])) {
2080
+ if (!target[key] || typeof target[key] !== "object") {
2081
+ target[key] = {};
2082
+ }
2083
+ this.mergeClientSettings(target[key], settings2[key]);
2084
+ } else {
2085
+ target[key] = settings2[key];
2086
+ }
2087
+ }
2088
+ }
2089
+ }
2090
+ };
2091
+ var utils_default = Utils;
2092
+
2093
+ // src/eas.ts
2094
+ var EAS = class {
2095
+ /**
2096
+ * generateEASAudio creates an EAS-compliant audio file in WAV format containing the provided message and VTEC header.
2097
+ *
2098
+ * @public
2099
+ * @static
2100
+ * @param {string} message
2101
+ * @param {string} vtec
2102
+ * @returns {*}
2103
+ */
2104
+ static generateEASAudio(message, vtec) {
2105
+ return new Promise((resolve) => __async(this, null, function* () {
2106
+ const settings2 = settings;
2107
+ for (const { regex, replacement } of definitions.messageSignatures) {
2108
+ message = message.replace(regex, replacement);
2109
+ }
2110
+ const assetsDir = settings2.global.easSettings.easDirectory;
2111
+ if (!assetsDir) {
2112
+ console.warn(definitions.messages.eas_no_directory);
2113
+ return resolve(null);
2114
+ }
2115
+ const rngFile = `${vtec.replace(/[^a-zA-Z0-9]/g, `_`)}`.substring(0, 32).replace(/^_+|_+$/g, "");
2116
+ if (!packages.fs.existsSync(assetsDir)) {
2117
+ packages.fs.mkdirSync(assetsDir);
2118
+ }
2119
+ const tmpTTS = packages.path.join(assetsDir, `/tmp/${rngFile}.wav`);
2120
+ const outTTS = packages.path.join(assetsDir, `/output/${rngFile}.wav`);
2121
+ const voice = process.platform === "win32" ? "Microsoft David Desktop" : "en-US-GuyNeural";
2122
+ if (!packages.fs.existsSync(packages.path.join(assetsDir, `/tmp`))) {
2123
+ packages.fs.mkdirSync(packages.path.join(assetsDir, `/tmp`), { recursive: true });
2124
+ }
2125
+ if (!packages.fs.existsSync(packages.path.join(assetsDir, `/output`))) {
2126
+ packages.fs.mkdirSync(packages.path.join(assetsDir, `/output`), { recursive: true });
2127
+ }
2128
+ packages.say.export(message, voice, 1, tmpTTS);
2129
+ yield utils_default.sleep(2500);
2130
+ let ttsBuffer = null;
2131
+ while (!packages.fs.existsSync(tmpTTS) || (ttsBuffer = packages.fs.readFileSync(tmpTTS)).length === 0) {
2132
+ yield utils_default.sleep(500);
2133
+ }
2134
+ const ttsWav = this.parseWavPCM16(ttsBuffer);
2135
+ const ttsSamples = this.resamplePCM16(ttsWav.samples, ttsWav.sampleRate, 8e3);
2136
+ const ttsRadio = this.applyNWREffect(ttsSamples, 8e3);
2137
+ let toneRadio = null;
2138
+ if (packages.fs.existsSync(settings2.global.easSettings.easIntroWav)) {
2139
+ const toneBuffer = packages.fs.readFileSync(settings2.global.easSettings.easIntroWav);
2140
+ const toneWav = this.parseWavPCM16(toneBuffer);
2141
+ const toneSamples = toneWav.sampleRate !== 8e3 ? this.resamplePCM16(toneWav.samples, toneWav.sampleRate, 8e3) : toneWav.samples;
2142
+ toneRadio = this.applyNWREffect(toneSamples, 8e3);
2143
+ }
2144
+ let build = toneRadio != null ? [toneRadio, this.generateSilence(0.5, 8e3)] : [];
2145
+ build.push(this.generateSAMEHeader(vtec, 3, 8e3, { preMarkSec: 1.1, gapSec: 0.5 }), this.generateSilence(0.5, 8e3), this.generateAttentionTone(8, 8e3), this.generateSilence(0.5, 8e3), ttsRadio);
2146
+ for (let i = 0; i < 3; i++) {
2147
+ build.push(this.generateSAMEHeader(vtec, 1, 8e3, { preMarkSec: 0.5, gapSec: 0.1 }));
2148
+ build.push(this.generateSilence(0.5, 8e3));
2149
+ }
2150
+ const allSamples = this.concatPCM16(build);
2151
+ const finalSamples = this.addNoise(allSamples, 2e-3);
2152
+ const outBuffer = this.encodeWavPCM16(Array.from(finalSamples).map((v) => ({ value: v })), 8e3);
2153
+ packages.fs.writeFileSync(outTTS, outBuffer);
2154
+ try {
2155
+ packages.fs.unlinkSync(tmpTTS);
2156
+ } catch (error) {
2157
+ if (error.code !== "EBUSY") {
2158
+ throw error;
2159
+ }
2160
+ }
2161
+ return Promise.resolve(outTTS);
2162
+ }));
2163
+ }
2164
+ /**
2165
+ * encodeWavPCM16 encodes an array of samples into a WAV PCM 16-bit Buffer.
2166
+ *
2167
+ * @private
2168
+ * @static
2169
+ * @param {Record<string, number>[]} samples
2170
+ * @param {number} [sampleRate=8000]
2171
+ * @returns {Buffer}
2172
+ */
2173
+ static encodeWavPCM16(samples, sampleRate = 8e3) {
2174
+ const bytesPerSample = 2;
2175
+ const blockAlign = 1 * bytesPerSample;
2176
+ const byteRate = sampleRate * blockAlign;
2177
+ const subchunk2Size = samples.length * bytesPerSample;
2178
+ const chunkSize = 36 + subchunk2Size;
2179
+ const buffer = Buffer.alloc(44 + subchunk2Size);
2180
+ let o = 0;
2181
+ buffer.write("RIFF", o);
2182
+ o += 4;
2183
+ buffer.writeUInt32LE(chunkSize, o);
2184
+ o += 4;
2185
+ buffer.write("WAVE", o);
2186
+ o += 4;
2187
+ buffer.write("fmt ", o);
2188
+ o += 4;
2189
+ buffer.writeUInt32LE(16, o);
2190
+ o += 4;
2191
+ buffer.writeUInt16LE(1, o);
2192
+ o += 2;
2193
+ buffer.writeUInt16LE(1, o);
2194
+ o += 2;
2195
+ buffer.writeUInt32LE(sampleRate, o);
2196
+ o += 4;
2197
+ buffer.writeUInt32LE(byteRate, o);
2198
+ o += 4;
2199
+ buffer.writeUInt16LE(blockAlign, o);
2200
+ o += 2;
2201
+ buffer.writeUInt16LE(16, o);
2202
+ o += 2;
2203
+ buffer.write("data", o);
2204
+ o += 4;
2205
+ buffer.writeUInt32LE(subchunk2Size, o);
2206
+ o += 4;
2207
+ for (let i = 0; i < samples.length; i++, o += 2) {
2208
+ buffer.writeInt16LE(samples[i].value, o);
2209
+ }
2210
+ return buffer;
2211
+ }
2212
+ /**
2213
+ * parseWavPCM16 decodes a WAV PCM 16-bit Buffer into its sample data and format information.
2214
+ *
2215
+ * @private
2216
+ * @static
2217
+ * @param {Buffer} buffer
2218
+ * @returns {{ samples: any; sampleRate: any; channels: any; bitsPerSample: any; }}
2219
+ */
2220
+ static parseWavPCM16(buffer) {
2221
+ if (buffer.toString("ascii", 0, 4) !== "RIFF" || buffer.toString("ascii", 8, 12) !== "WAVE") {
2222
+ return null;
2223
+ }
2224
+ let fmt = null;
2225
+ let data = null;
2226
+ let i = 12;
2227
+ while (i + 8 <= buffer.length) {
2228
+ const id = buffer.toString("ascii", i, i + 4);
2229
+ const size = buffer.readUInt32LE(i + 4);
2230
+ const start = i + 8;
2231
+ const end = start + size;
2232
+ if (id === "fmt ") fmt = buffer.slice(start, end);
2233
+ if (id === "data") data = buffer.slice(start, end);
2234
+ i = end + size % 2;
2235
+ }
2236
+ if (!fmt || !data) return null;
2237
+ const audioFormat = fmt.readUInt16LE(0);
2238
+ const channels = fmt.readUInt16LE(2);
2239
+ const sampleRate = fmt.readUInt32LE(4);
2240
+ const bitsPerSample = fmt.readUInt16LE(14);
2241
+ if (audioFormat !== 1 || bitsPerSample !== 16 || channels !== 1) {
2242
+ return null;
2243
+ }
2244
+ const samples = new Int16Array(data.buffer, data.byteOffset, data.length / 2);
2245
+ return { samples: new Int16Array(samples), sampleRate, channels, bitsPerSample };
2246
+ }
2247
+ /**
2248
+ * concatPCM16 concatenates multiple Int16Array buffers into a single Int16Array buffer.
2249
+ *
2250
+ * @private
2251
+ * @static
2252
+ * @param {Int16Array[]} arrays
2253
+ * @returns {*}
2254
+ */
2255
+ static concatPCM16(arrays) {
2256
+ let total = 0;
2257
+ for (const a of arrays) total += a.length;
2258
+ const out = new Int16Array(total);
2259
+ let o = 0;
2260
+ for (const a of arrays) {
2261
+ out.set(a, o);
2262
+ o += a.length;
2263
+ }
2264
+ return out;
2265
+ }
2266
+ /**
2267
+ * pcm16toFloat converts an Int16Array of PCM 16-bit samples to a Float32Array of normalized float samples.
2268
+ *
2269
+ * @private
2270
+ * @static
2271
+ * @param {Int16Array} int16
2272
+ * @returns {*}
2273
+ */
2274
+ static pcm16toFloat(int16) {
2275
+ const out = new Float32Array(int16.length);
2276
+ for (let i = 0; i < int16.length; i++) out[i] = int16[i] / 32768;
2277
+ return out;
2278
+ }
2279
+ /**
2280
+ * floatToPcm16 converts a Float32Array of normalized float samples to an Int16Array of PCM 16-bit samples.
2281
+ *
2282
+ * @private
2283
+ * @static
2284
+ * @param {Float32Array} float32
2285
+ * @returns {*}
2286
+ */
2287
+ static floatToPcm16(float32) {
2288
+ const out = new Int16Array(float32.length);
2289
+ for (let i = 0; i < float32.length; i++) {
2290
+ let v = Math.max(-1, Math.min(1, float32[i]));
2291
+ out[i] = Math.round(v * 32767);
2292
+ }
2293
+ return out;
2294
+ }
2295
+ /**
2296
+ * resamplePCM16 resamples an Int16Array of PCM 16-bit samples from the original sample rate to the target sample rate using linear interpolation.
2297
+ *
2298
+ * @private
2299
+ * @static
2300
+ * @param {Int16Array} int16
2301
+ * @param {number} originalRate
2302
+ * @param {number} targetRate
2303
+ * @returns {*}
2304
+ */
2305
+ static resamplePCM16(int16, originalRate, targetRate) {
2306
+ if (originalRate === targetRate) return int16;
2307
+ const ratio = targetRate / originalRate;
2308
+ const outLen = Math.max(1, Math.round(int16.length * ratio));
2309
+ const out = new Int16Array(outLen);
2310
+ for (let i = 0; i < outLen; i++) {
2311
+ const pos = i / ratio;
2312
+ const i0 = Math.floor(pos);
2313
+ const i1 = Math.min(i0 + 1, int16.length - 1);
2314
+ const frac = pos - i0;
2315
+ const v = int16[i0] * (1 - frac) + int16[i1] * frac;
2316
+ out[i] = Math.round(v);
2317
+ }
2318
+ return out;
2319
+ }
2320
+ /**
2321
+ * generateSilence creates an Int16Array of PCM 16-bit samples representing silence for the specified duration in milliseconds.
2322
+ *
2323
+ * @private
2324
+ * @static
2325
+ * @param {number} ms
2326
+ * @param {number} [sampleRate=8000]
2327
+ * @returns {*}
2328
+ */
2329
+ static generateSilence(ms, sampleRate = 8e3) {
2330
+ return new Int16Array(Math.floor(ms * sampleRate));
2331
+ }
2332
+ /**
2333
+ * generateAttentionTone creates an Int16Array of PCM 16-bit samples representing the EAS attention tone for the specified duration in milliseconds.
2334
+ *
2335
+ * @private
2336
+ * @static
2337
+ * @param {*} ms
2338
+ * @param {number} [sampleRate=8000]
2339
+ * @returns {*}
2340
+ */
2341
+ static generateAttentionTone(ms, sampleRate = 8e3) {
2342
+ const len = Math.floor(ms * sampleRate);
2343
+ const out = new Int16Array(len);
2344
+ const f1 = 853;
2345
+ const f2 = 960;
2346
+ const twoPi = Math.PI * 2;
2347
+ const amp = 0.1;
2348
+ const fadeLen = Math.floor(sampleRate * 0);
2349
+ for (let i = 0; i < len; i++) {
2350
+ const t = i / sampleRate;
2351
+ const s = Math.sin(twoPi * f1 * t) + Math.sin(twoPi * f2 * t);
2352
+ let gain = 1;
2353
+ if (i < fadeLen) gain = i / fadeLen;
2354
+ else if (i > len - fadeLen) gain = (len - i) / fadeLen;
2355
+ const v = Math.max(-1, Math.min(1, s / 2 * amp * gain));
2356
+ out[i] = Math.round(v * 32767);
2357
+ }
2358
+ return out;
2359
+ }
2360
+ /**
2361
+ * applyNWREffect applies a series of audio processing effects to simulate the sound characteristics of NOAA Weather Radio broadcasts.
2362
+ *
2363
+ * @private
2364
+ * @static
2365
+ * @param {Int16Array} int16
2366
+ * @param {number} [sampleRate=8000]
2367
+ * @returns {*}
2368
+ */
2369
+ static applyNWREffect(int16, sampleRate = 8e3) {
2370
+ const hpCut = 3555;
2371
+ const lpCut = 1600;
2372
+ const noiseLevel = 0;
2373
+ const crushBits = 8;
2374
+ const x = this.pcm16toFloat(int16);
2375
+ const dt = 1 / sampleRate;
2376
+ const rcHP = 1 / (2 * Math.PI * hpCut);
2377
+ const aHP = rcHP / (rcHP + dt);
2378
+ let yHP = 0, xPrev = 0;
2379
+ for (let i = 0; i < x.length; i++) {
2380
+ const xi = x[i];
2381
+ yHP = aHP * (yHP + xi - xPrev);
2382
+ xPrev = xi;
2383
+ x[i] = yHP;
2384
+ }
2385
+ const rcLP = 1 / (2 * Math.PI * lpCut);
2386
+ const aLP = dt / (rcLP + dt);
2387
+ let yLP = 0;
2388
+ for (let i = 0; i < x.length; i++) {
2389
+ yLP = yLP + aLP * (x[i] - yLP);
2390
+ x[i] = yLP;
2391
+ }
2392
+ const compGain = 2;
2393
+ const norm = Math.tanh(compGain);
2394
+ for (let i = 0; i < x.length; i++) x[i] = Math.tanh(x[i] * compGain) / norm;
2395
+ const levels = Math.pow(2, crushBits) - 1;
2396
+ return this.floatToPcm16(x);
2397
+ }
2398
+ /**
2399
+ * addNoise adds low-level white noise to an Int16Array of PCM 16-bit samples to simulate analog broadcast imperfections.
2400
+ *
2401
+ * @private
2402
+ * @static
2403
+ * @param {Int16Array} int16
2404
+ * @param {number} [noiseLevel=0.02]
2405
+ * @returns {*}
2406
+ */
2407
+ static addNoise(int16, noiseLevel = 0.02) {
2408
+ const x = this.pcm16toFloat(int16);
2409
+ for (let i = 0; i < x.length; i++) x[i] += (Math.random() * 2 - 1) * noiseLevel;
2410
+ let peak = 0;
2411
+ for (let i = 0; i < x.length; i++) peak = Math.max(peak, Math.abs(x[i]));
2412
+ if (peak > 1) for (let i = 0; i < x.length; i++) x[i] *= 0.98 / peak;
2413
+ return this.floatToPcm16(x);
2414
+ }
2415
+ /**
2416
+ * asciiTo8N1Bits converts an ASCII string to a sequence of bits using 8-N-1 encoding (8 data bits, no parity, 1 stop bit).
2417
+ *
2418
+ * @private
2419
+ * @static
2420
+ * @param {string} str
2421
+ * @returns {{}}
2422
+ */
2423
+ static asciiTo8N1Bits(str) {
2424
+ const bits = [];
2425
+ for (let i = 0; i < str.length; i++) {
2426
+ const c = str.charCodeAt(i) & 255;
2427
+ bits.push(0);
2428
+ for (let b = 0; b < 8; b++) bits.push(c >> b & 1);
2429
+ bits.push(1, 1);
2430
+ }
2431
+ return bits;
2432
+ }
2433
+ /**
2434
+ * generateAFSK generates an Int16Array of PCM 16-bit samples representing AFSK modulation of the provided bit sequence.
2435
+ *
2436
+ * @private
2437
+ * @static
2438
+ * @param {number[]} bits
2439
+ * @param {number} [sampleRate=8000]
2440
+ * @returns {*}
2441
+ */
2442
+ static generateAFSK(bits, sampleRate = 8e3) {
2443
+ const baud = 520.83;
2444
+ const markFreq = 2083.3;
2445
+ const spaceFreq = 1562.5;
2446
+ const amplitude = 0.6;
2447
+ const twoPi = Math.PI * 2;
2448
+ const result = [];
2449
+ let phase = 0;
2450
+ let frac = 0;
2451
+ for (let b = 0; b < bits.length; b++) {
2452
+ const bit = bits[b];
2453
+ const freq = bit ? markFreq : spaceFreq;
2454
+ const samplesPerBit = sampleRate / baud + frac;
2455
+ const n = Math.round(samplesPerBit);
2456
+ frac = samplesPerBit - n;
2457
+ const inc = twoPi * freq / sampleRate;
2458
+ for (let i = 0; i < n; i++) {
2459
+ result.push(Math.round(Math.sin(phase) * amplitude * 32767));
2460
+ phase += inc;
2461
+ if (phase > twoPi) phase -= twoPi;
2462
+ }
2463
+ }
2464
+ const fadeSamples = Math.floor(sampleRate * 2e-3);
2465
+ for (let i = 0; i < fadeSamples; i++) {
2466
+ const gain = i / fadeSamples;
2467
+ result[i] = Math.round(result[i] * gain);
2468
+ result[result.length - 1 - i] = Math.round(result[result.length - 1 - i] * gain);
2469
+ }
2470
+ return Int16Array.from(result);
2471
+ }
2472
+ /**
2473
+ * generateSAMEHeader generates an Int16Array of PCM 16-bit samples representing the SAME header repeated the specified number of times.
2474
+ *
2475
+ * @private
2476
+ * @static
2477
+ * @param {string} vtec
2478
+ * @param {number} repeats
2479
+ * @param {number} [sampleRate=8000]
2480
+ * @param {{preMarkSec?: number, gapSec?: number}} [options={}]
2481
+ * @returns {*}
2482
+ */
2483
+ static generateSAMEHeader(vtec, repeats, sampleRate = 8e3, options = {}) {
2484
+ var _a, _b;
2485
+ const preMarkSec = (_a = options.preMarkSec) != null ? _a : 0.3;
2486
+ const gapSec = (_b = options.gapSec) != null ? _b : 0.1;
2487
+ const bursts = [];
2488
+ const gap = this.generateSilence(gapSec, sampleRate);
2489
+ for (let i = 0; i < repeats; i++) {
2490
+ const bodyBits = this.asciiTo8N1Bits(vtec);
2491
+ const body = this.generateAFSK(bodyBits, sampleRate);
2492
+ const extendedBodyDuration = Math.round(preMarkSec * sampleRate);
2493
+ const extendedBody = new Int16Array(extendedBodyDuration + gap.length);
2494
+ for (let j = 0; j < extendedBodyDuration; j++) {
2495
+ extendedBody[j] = Math.round(body[j % body.length] * 0.2);
2496
+ }
2497
+ extendedBody.set(gap, extendedBodyDuration);
2498
+ bursts.push(extendedBody);
2499
+ if (i !== repeats - 1) bursts.push(gap);
2500
+ }
2501
+ return this.concatPCM16(bursts);
2502
+ }
2503
+ };
2504
+ var eas_default = EAS;
2505
+
2506
+ // src/parsers/events.ts
2507
+ var EventParser = class {
2508
+ /**
2509
+ * getBaseProperties extracts and compiles the base properties of an alert message, including location, timing, description, sender information, and various parameters.
2510
+ *
2511
+ * @public
2512
+ * @static
2513
+ * @async
2514
+ * @param {string} message
2515
+ * @param {types.TypeCompiled} validated
2516
+ * @param {types.UGCParsed} [ugc=null]
2517
+ * @param {types.VTECParsed} [vtec=null]
2518
+ * @returns {Promise<types.BaseProperties>}
2519
+ */
2520
+ static getBaseProperties(message, validated, ugc = null, vtec = null) {
2521
+ return __async(this, null, function* () {
2522
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2523
+ const settings2 = settings;
2524
+ const definitions2 = {
2525
+ tornado: text_default.textProductToString(message, `TORNADO...`) || text_default.textProductToString(message, `WATERSPOUT...`) || `N/A`,
2526
+ hail: text_default.textProductToString(message, `MAX HAIL SIZE...`, [`IN`]) || text_default.textProductToString(message, `HAIL...`, [`IN`]) || `N/A`,
2527
+ gusts: text_default.textProductToString(message, `MAX WIND GUST...`) || text_default.textProductToString(message, `WIND...`) || `N/A`,
2528
+ flood: text_default.textProductToString(message, `FLASH FLOOD...`) || `N/A`,
2529
+ damage: text_default.textProductToString(message, `DAMAGE THREAT...`) || `N/A`,
2530
+ source: text_default.textProductToString(message, `SOURCE...`, [`.`]) || `N/A`,
2531
+ attributes: text_default.textProductToString(message, `STANZA ATTRIBUTES...`) ? JSON.parse(text_default.textProductToString(message, `STANZA ATTRIBUTES...`)) : null,
2532
+ polygon: text_default.textProductToPolygon(message),
2533
+ description: text_default.textProductToDescription(message, (_a = vtec == null ? void 0 : vtec.raw) != null ? _a : null),
2534
+ wmo: message.match(new RegExp(definitions.expressions.wmo, "imu")),
2535
+ mdTorIntensity: text_default.textProductToString(message, `MOST PROBABLE PEAK TORNADO INTENSITY...`) || `N/A`,
2536
+ mdWindGusts: text_default.textProductToString(message, `MOST PROBABLE PEAK WIND GUST...`) || `N/A`,
2537
+ mdHailSize: text_default.textProductToString(message, `MOST PROBABLE PEAK HAIL SIZE...`) || `N/A`
2538
+ };
2539
+ const getOffice = this.getICAO(vtec, (_c = (_b = validated.attributes) != null ? _b : definitions2.attributes) != null ? _c : {}, definitions2.wmo);
2540
+ const getCorrectIssued = this.getCorrectIssuedDate((_e = (_d = definitions2.attributes) != null ? _d : validated.attributes) != null ? _e : {});
2541
+ const getCorrectExpiry = this.getCorrectExpiryDate(vtec, ugc);
2542
+ const getAwip = text_default.awipTextToEvent((_g = (_f = definitions2.attributes) == null ? void 0 : _f.awipsid) != null ? _g : validated.awipsType.prefix);
2543
+ const base = {
2544
+ locations: (ugc == null ? void 0 : ugc.locations.join(`; `)) || `No Location Specified (UGC Missing)`,
2545
+ issued: getCorrectIssued,
2546
+ expires: getCorrectExpiry,
2547
+ geocode: { UGC: (ugc == null ? void 0 : ugc.zones) || [`XX000`] },
2548
+ description: definitions2.description,
2549
+ sender_name: getOffice.name,
2550
+ sender_icao: getOffice.icao,
2551
+ attributes: __spreadProps(__spreadValues(__spreadValues({}, validated.attributes), definitions2.attributes), {
2552
+ getAwip
2553
+ }),
2554
+ parameters: {
2555
+ wmo: Array.isArray(definitions2.wmo) ? definitions2.wmo[0] : (_h = definitions2.wmo) != null ? _h : `N/A`,
2556
+ source: definitions2.source,
2557
+ max_hail_size: definitions2.hail,
2558
+ max_wind_gust: definitions2.gusts,
2559
+ damage_threat: definitions2.damage,
2560
+ tornado_detection: definitions2.tornado,
2561
+ flood_detection: definitions2.flood,
2562
+ discussion_tornado_intensity: definitions2.mdTorIntensity,
2563
+ discussion_wind_intensity: definitions2.mdWindGusts,
2564
+ discussion_hail_intensity: definitions2.mdHailSize
2565
+ },
2566
+ geometry: definitions2.polygon.length > 0 ? { type: "Polygon", coordinates: definitions2.polygon } : null
2567
+ };
2568
+ if (settings2.NoaaWeatherWireService.alertPreferences.isShapefileUGC && base.geometry == null && ugc != null) {
2569
+ const coordinates = yield ugc_default.getCoordinates(ugc.zones);
2570
+ base.geometry = { type: "Polygon", coordinates };
2571
+ }
2572
+ return base;
2573
+ });
2574
+ }
2575
+ /**
2576
+ * enhanceEvent refines the event name based on specific conditions and tags found in the event's description and parameters.
2577
+ *
2578
+ * @public
2579
+ * @static
2580
+ * @param {types.TypeAlert} event
2581
+ * @returns {{ eventName: any; tags: any; }}
2582
+ */
2583
+ static enhanceEvent(event) {
2584
+ var _a, _b, _c, _d, _e;
2585
+ let eventName = (_b = (_a = event == null ? void 0 : event.properties) == null ? void 0 : _a.event) != null ? _b : `Unknown Event`;
2586
+ const defEventTable = definitions.enhancedEvents;
2587
+ const defEventTags = definitions.tags;
2588
+ const properties = event == null ? void 0 : event.properties;
2589
+ const parameters = properties == null ? void 0 : properties.parameters;
2590
+ const description = (_c = properties == null ? void 0 : properties.description) != null ? _c : `Unknown Description`;
2591
+ const damageThreatTag = (_d = parameters == null ? void 0 : parameters.damage_threat) != null ? _d : `N/A`;
2592
+ const tornadoThreatTag = (_e = parameters == null ? void 0 : parameters.tornado_detection) != null ? _e : `N/A`;
2593
+ for (const eventGroup of defEventTable) {
2594
+ const [baseEvent, conditions] = Object.entries(eventGroup)[0];
2595
+ if (eventName === baseEvent) {
2596
+ for (const [specificEvent, condition] of Object.entries(conditions)) {
2597
+ const conditionMet = condition.description && description.includes(condition.description.toLowerCase()) || condition.condition && condition.condition(damageThreatTag || tornadoThreatTag);
2598
+ if (conditionMet) {
2599
+ eventName = specificEvent;
2600
+ break;
2601
+ }
2602
+ }
2603
+ if (baseEvent === "Severe Thunderstorm Warning" && damageThreatTag === "POSSIBLE" && !eventName.includes("(TPROB)")) eventName += " (TPROB)";
2604
+ break;
2605
+ }
2606
+ }
2607
+ const tags = Object.entries(defEventTags).filter(([key]) => description.includes(key.toLowerCase())).map(([, value]) => value);
2608
+ return { eventName, tags: tags.length > 0 ? tags : [`N/A`] };
2609
+ }
2610
+ /**
2611
+ * getCorrectExpiryDate determines the correct expiration date for an alert based on VTEC information or UGC zones.
2612
+ *
2613
+ * @public
2614
+ * @static
2615
+ * @param {unknown[]} events
2616
+ */
2617
+ static validateEvents(events2) {
2618
+ var _a, _b, _c, _d, _e;
2619
+ if (events2.length == 0) return;
2620
+ const settings2 = settings;
2621
+ const filteringSettings = (_b = (_a = settings) == null ? void 0 : _a.global) == null ? void 0 : _b.alertFiltering;
2622
+ const easSettings = (_d = (_c = settings) == null ? void 0 : _c.global) == null ? void 0 : _d.easSettings;
2623
+ const globalSettings = (_e = settings) == null ? void 0 : _e.global;
2624
+ const sets = {};
2625
+ const bools = {};
2626
+ const megered = __spreadValues(__spreadValues(__spreadValues({}, filteringSettings), easSettings), globalSettings);
2627
+ for (const key in megered) {
2628
+ const setting = megered[key];
2629
+ if (Array.isArray(setting)) {
2630
+ sets[key] = new Set(setting.map((item) => item.toLowerCase()));
2631
+ }
2632
+ if (typeof setting === "boolean") {
2633
+ bools[key] = setting;
2634
+ }
2635
+ }
2636
+ const filtered = events2.filter((alert) => {
2637
+ var _a2, _b2, _c2, _d2;
2638
+ const originalEvent = alert;
2639
+ const props = originalEvent == null ? void 0 : originalEvent.properties;
2640
+ const ugcs = (_b2 = (_a2 = props == null ? void 0 : props.geocode) == null ? void 0 : _a2.UGC) != null ? _b2 : [];
2641
+ if (bools == null ? void 0 : bools.betterEventParsing) {
2642
+ const { eventName, tags } = this.enhanceEvent(originalEvent);
2643
+ originalEvent.properties.event = eventName;
2644
+ originalEvent.properties.tags = tags;
2645
+ }
2646
+ const eventCheck = (bools == null ? void 0 : bools.useParentEvents) ? (_c2 = props.parent) == null ? void 0 : _c2.toLowerCase() : (_d2 = props.event) == null ? void 0 : _d2.toLowerCase();
2647
+ const statusCorrelation = definitions.correlations.find((c) => c.type === originalEvent.properties.action_type);
2648
+ for (const key in sets) {
2649
+ const setting = sets[key];
2650
+ if (key === "filteredEvents" && setting.size > 0 && eventCheck != null && !setting.has(eventCheck)) return false;
2651
+ if (key === "ignoredEvents" && setting.size > 0 && eventCheck != null && setting.has(eventCheck)) return false;
2652
+ if (key === "filteredICOAs" && setting.size > 0 && props.sender_icao != null && !setting.has(props.sender_icao.toLowerCase())) return false;
2653
+ if (key === "ignoredICOAs" && setting.size > 0 && props.sender_icao != null && setting.has(props.sender_icao.toLowerCase())) return false;
2654
+ if (key === "ugcFilter" && setting.size > 0 && ugcs.length > 0 && !ugcs.some((ugc) => setting.has(ugc.toLowerCase()))) return false;
2655
+ if (key === "stateFilter" && setting.size > 0 && ugcs.length > 0 && !ugcs.some((ugc) => setting.has(ugc.substring(0, 2).toLowerCase()))) return false;
2656
+ if (key === "easAlerts" && setting.size > 0 && eventCheck != null && setting.has(eventCheck) && settings2.isNWWS) {
2657
+ eas_default.generateEASAudio(props.description, alert.header);
2658
+ }
2659
+ }
2660
+ for (const key in bools) {
2661
+ const setting = bools[key];
2662
+ if (key === "checkExpired" && setting && new Date(props == null ? void 0 : props.expires).getTime() < (/* @__PURE__ */ new Date()).getTime()) return false;
2663
+ }
2664
+ originalEvent.properties.action_type = statusCorrelation ? statusCorrelation.forward : originalEvent.properties.action_type;
2665
+ originalEvent.properties.is_cancelled = statusCorrelation ? statusCorrelation.cancel == true && bools.checkExpired : false;
2666
+ if (props.description) {
2667
+ const detectedPhrase = definitions.cancelSignatures.find((sig) => props.description.toLowerCase().includes(sig.toLowerCase()));
2668
+ if (detectedPhrase && bools.checkExpired) {
2669
+ originalEvent.properties.action_type = "Cancel";
2670
+ originalEvent.properties.is_cancelled = true;
2671
+ return false;
2672
+ }
2673
+ }
2674
+ if (originalEvent.vtec) {
2675
+ const getType = originalEvent.vtec.split(`.`)[0];
2676
+ const isTestProduct = definitions.productTypes[getType] == `Test Product`;
2677
+ if (isTestProduct) {
2678
+ return false;
2679
+ }
2680
+ }
2681
+ cache.events.emit(`on${originalEvent.properties.parent.replace(/\s+/g, "")}`);
2682
+ return true;
2683
+ });
2684
+ if (filtered.length > 0) {
2685
+ cache.events.emit(`onAlerts`, filtered);
2686
+ }
2687
+ }
2688
+ /**
2689
+ * getHeader constructs a standardized alert header string based on provided attributes, properties, and VTEC information.
2690
+ *
2691
+ * @public
2692
+ * @static
2693
+ * @param {types.TypeAttributes} attributes
2694
+ * @param {?types.BaseProperties} [properties]
2695
+ * @param {?types.VTECParsed} [vtec]
2696
+ * @returns {string}
2697
+ */
2698
+ static getHeader(attributes, properties, vtec) {
2699
+ var _a, _b, _c, _d, _e, _f, _g;
2700
+ const parent = `ATSX`;
2701
+ const alertType = (_d = (_c = (_a = attributes == null ? void 0 : attributes.awipsType) == null ? void 0 : _a.type) != null ? _c : (_b = attributes == null ? void 0 : attributes.getAwip) == null ? void 0 : _b.prefix) != null ? _d : `XX`;
2702
+ const ugc = ((_e = properties == null ? void 0 : properties.geocode) == null ? void 0 : _e.UGC) != null ? (_f = properties == null ? void 0 : properties.geocode) == null ? void 0 : _f.UGC.join(`-`) : `000000`;
2703
+ const status = (vtec == null ? void 0 : vtec.status) || "Issued";
2704
+ const issued = (properties == null ? void 0 : properties.issued) != null ? (_g = new Date(properties == null ? void 0 : properties.issued)) == null ? void 0 : _g.toISOString().replace(/[-:]/g, "").split(".")[0] : (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").split(".")[0];
2705
+ const sender = (properties == null ? void 0 : properties.sender_icao) || `XXXX`;
2706
+ const header = `ZCZC-${parent}-${alertType}-${ugc}-${status}-${issued}-${sender}-`;
2707
+ return header;
2708
+ }
2709
+ /**
2710
+ * eventHandler routes the validated alert message to the appropriate event parser based on its type (API, CAP, VTEC, UGC, or plain text).
2711
+ *
2712
+ * @public
2713
+ * @static
2714
+ * @param {types.TypeCompiled} validated
2715
+ * @returns {*}
2716
+ */
2717
+ static eventHandler(validated) {
2718
+ if (validated.isApi) return api_default.event(validated);
2719
+ if (validated.isCap) return cap_default.event(validated);
2720
+ if (!validated.isCap && validated.isVtec && validated.isUGC) return vtec_default2.event(validated);
2721
+ if (!validated.isCap && !validated.isVtec && validated.isUGC) return ugc_default2.event(validated);
2722
+ if (!validated.isCap && !validated.isVtec && !validated.isUGC) return text_default2.event(validated);
2723
+ }
2724
+ /**
2725
+ * getICAO retrieves the ICAO code and corresponding office name based on VTEC tracking information, message attributes, or WMO code.
2726
+ *
2727
+ * @private
2728
+ * @static
2729
+ * @param {types.VTECParsed} vtec
2730
+ * @param {Record<string, string>} attributes
2731
+ * @param {(RegExpMatchArray | string | null)} WMO
2732
+ * @returns {{ icao: any; name: any; }}
2733
+ */
2734
+ static getICAO(vtec, attributes, WMO) {
2735
+ var _a, _b, _c;
2736
+ const icao = vtec != null ? vtec == null ? void 0 : vtec.tracking.split(`-`)[0] : (_a = attributes == null ? void 0 : attributes.cccc) != null ? _a : WMO != null ? Array.isArray(WMO) ? WMO[0] : WMO : `N/A`;
2737
+ const name = (_c = (_b = definitions.ICAO) == null ? void 0 : _b[icao]) != null ? _c : `N/A`;
2738
+ return { icao, name };
2739
+ }
2740
+ /**
2741
+ * getCorrectIssuedDate ensures the issued date is valid and falls back to the current date if not.
2742
+ *
2743
+ * @private
2744
+ * @static
2745
+ * @param {Record<string, string>} attributes
2746
+ * @returns {*}
2747
+ */
2748
+ static getCorrectIssuedDate(attributes) {
2749
+ const time = attributes.issue != null ? new Date(attributes.issue).toLocaleString() : (attributes == null ? void 0 : attributes.issue) != null ? new Date(attributes.issue).toLocaleString() : (/* @__PURE__ */ new Date()).toLocaleString();
2750
+ if (time == `Invalid Date`) return (/* @__PURE__ */ new Date()).toLocaleString();
2751
+ return time;
2752
+ }
2753
+ /**
2754
+ * getCorrectExpiryDate determines the correct expiration date for an alert based on VTEC information or UGC zones.
2755
+ *
2756
+ * @private
2757
+ * @static
2758
+ * @param {types.VTECParsed} vtec
2759
+ * @param {types.UGCParsed} ugc
2760
+ * @returns {*}
2761
+ */
2762
+ static getCorrectExpiryDate(vtec, ugc) {
2763
+ const time = (vtec == null ? void 0 : vtec.expires) && !isNaN(new Date(vtec.expires).getTime()) ? new Date(vtec.expires).toLocaleString() : (ugc == null ? void 0 : ugc.expiry) != null ? new Date(ugc.expiry).toLocaleString() : new Date((/* @__PURE__ */ new Date()).getTime() + 1 * 60 * 60 * 1e3).toLocaleString();
2764
+ if (time == `Invalid Date`) return new Date((/* @__PURE__ */ new Date()).getTime() + 1 * 60 * 60 * 1e3).toLocaleString();
2765
+ return time;
2766
+ }
2767
+ };
2768
+ var events_default = EventParser;
2769
+
2770
+ // src/parsers/types/cap.ts
2771
+ var CapAlerts = class {
2772
+ static getTracking(extracted) {
2773
+ return extracted.vtec ? (() => {
2774
+ const vtecValue = Array.isArray(extracted.vtec) ? extracted.vtec[0] : extracted.vtec;
2775
+ const splitVTEC = vtecValue.split(".");
2776
+ return `${splitVTEC[2]}-${splitVTEC[3]}-${splitVTEC[4]}-${splitVTEC[5]}`;
2777
+ })() : `${extracted.wmoidentifier} (${extracted.ugc})`;
2778
+ }
2779
+ static event(validated) {
2780
+ return __async(this, null, function* () {
2781
+ var _a;
2782
+ let processed = [];
2783
+ const messages = (_a = validated.message.match(/<\?xml[\s\S]*?<\/alert>/g)) == null ? void 0 : _a.map((msg) => msg.trim());
2784
+ if (messages == null || messages.length === 0) return;
2785
+ for (let message of messages) {
2786
+ const tick = performance.now();
2787
+ message = message.substring(message.indexOf(`<?xml version="1.0"`), message.lastIndexOf(`>`) + 1);
2788
+ const parser = new packages.xml2js.Parser({ explicitArray: false, mergeAttrs: true, trim: true });
2789
+ const parsed = yield parser.parseStringPromise(message);
2790
+ if (parsed == null || parsed.alert == null) continue;
2791
+ const extracted = text_default.getXmlValues(parsed, [
2792
+ `vtec`,
2793
+ `wmoidentifier`,
2794
+ `ugc`,
2795
+ `areadesc`,
2796
+ `expires`,
2797
+ `sent`,
2798
+ `msgtype`,
2799
+ `description`,
2800
+ `event`,
2801
+ `sendername`,
2802
+ `tornadodetection`,
2803
+ `polygon`,
2804
+ `maxHailSize`,
2805
+ `maxWindGust`,
2806
+ `thunderstormdamagethreat`,
2807
+ `tornadodamagethreat`,
2808
+ `waterspoutdetection`,
2809
+ `flooddetection`
2810
+ ]);
2811
+ const getHeader = events_default.getHeader(__spreadValues({}, validated.attributes));
2812
+ const getSource = text_default.textProductToString(extracted.description, `SOURCE...`, [`.`]) || `N/A`;
2813
+ processed.push({
2814
+ preformance: performance.now() - tick,
2815
+ tracking: this.getTracking(extracted),
2816
+ header: getHeader,
2817
+ vtec: extracted.vtec || `N/A`,
2818
+ history: [{ description: extracted.description || `N/A`, issued: extracted.sent ? new Date(extracted.sent).toLocaleString() : `N/A`, type: extracted.msgtype || `N/A` }],
2819
+ properties: {
2820
+ locations: extracted.areadesc || `N/A`,
2821
+ event: extracted.event || `N/A`,
2822
+ issued: extracted.sent ? new Date(extracted.sent).toLocaleString() : `N/A`,
2823
+ expires: extracted.expires ? new Date(extracted.expires).toLocaleString() : `N/A`,
2824
+ parent: extracted.event || `N/A`,
2825
+ action_type: extracted.msgtype || `N/A`,
2826
+ description: extracted.description || `N/A`,
2827
+ sender_name: extracted.sendername || `N/A`,
2828
+ sender_icao: extracted.wmoidentifier ? extracted.wmoidentifier.substring(extracted.wmoidentifier.length - 4) : `N/A`,
2829
+ attributes: validated.attributes,
2830
+ geocode: {
2831
+ UGC: [extracted.ugc]
2832
+ },
2833
+ parameters: {
2834
+ wmo: extracted.wmoidentifier || `N/A`,
2835
+ source: getSource,
2836
+ max_hail_size: extracted.maxHailSize || `N/A`,
2837
+ max_wind_gust: extracted.maxWindGust || `N/A`,
2838
+ damage_threat: extracted.thunderstormdamagethreat || `N/A`,
2839
+ tornado_detection: extracted.tornadodetection || extracted.waterspoutdetection || `N/A`,
2840
+ flood_detection: extracted.flooddetection || `N/A`,
2841
+ discussion_tornado_intensity: `N/A`,
2842
+ discussion_wind_intensity: `N/A`,
2843
+ discussion_hail_intensity: `N/A`
2844
+ },
2845
+ geometry: extracted.polygon ? { type: `Polygon`, coordinates: extracted.polygon.split(` `).map((coord) => coord.split(`,`).map((num) => parseFloat(num))) } : null
2846
+ }
2847
+ });
2848
+ }
2849
+ events_default.validateEvents(processed);
2850
+ });
2851
+ }
2852
+ };
2853
+ var cap_default = CapAlerts;
2854
+ // Annotate the CommonJS export names for ESM import in node:
2855
+ 0 && (module.exports = {
2856
+ CapAlerts
2857
+ });