@atmosx/event-product-parser 3.0.42 → 3.0.46

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 (87) hide show
  1. package/README.md +70 -22
  2. package/SUPPORTED_EVENTS.md +369 -0
  3. package/dist/cjs/index.cjs +1990 -1758
  4. package/dist/esm/index.mjs +1560 -1329
  5. package/dist/index.d.mts +44 -20
  6. package/dist/index.d.ts +44 -20
  7. package/package.json +1 -1
  8. package/src/@building/building.attachments.ts +42 -0
  9. package/src/@building/building.create.ts +2 -2
  10. package/src/@building/building.enhance.ts +8 -4
  11. package/src/@building/building.geometry.ts +1 -1
  12. package/src/@building/building.headers.ts +1 -1
  13. package/src/@building/building.office.ts +4 -4
  14. package/src/@building/building.properties.ts +15 -13
  15. package/src/@building/building.signature.ts +11 -11
  16. package/src/@building/building.tags.ts +2 -2
  17. package/src/@building/building.tracking.ts +6 -6
  18. package/src/@building/building.validate.ts +5 -3
  19. package/src/@core/core.createEvent.ts +82 -0
  20. package/src/@core/core.query.ts +1 -1
  21. package/src/@core/core.start.ts +1 -1
  22. package/src/@dictionaries/{dictionaries.eventActions.ts → dictionaries.actions.ts} +1 -1
  23. package/src/@dictionaries/{dictionaries.eventAwipAbreviations.ts → dictionaries.awips.ts} +1 -1
  24. package/src/@dictionaries/{dictionaries.eventCancelMessages.ts → dictionaries.cancellation.ts} +1 -1
  25. package/src/@dictionaries/{dictionaries.eventCauses.ts → dictionaries.causes.ts} +1 -1
  26. package/src/@dictionaries/{dictionaries.statusCorrelationText.ts → dictionaries.correlations.ts} +1 -1
  27. package/src/@dictionaries/{dictionaries.betterEventNames.ts → dictionaries.enhanced.ts} +13 -2
  28. package/src/@dictionaries/{dictionaries.eventTypes.ts → dictionaries.events.ts} +1 -1
  29. package/src/@dictionaries/{dictionaries.regExp.ts → dictionaries.expressions.ts} +1 -1
  30. package/src/@dictionaries/{dictionaries.hailStrings.ts → dictionaries.hail.ts} +4 -1
  31. package/src/@dictionaries/{dictionaries.officeICAOs.ts → dictionaries.icao.ts} +1 -1
  32. package/src/@dictionaries/{dictionaries.eventsMatchText.ts → dictionaries.matches.ts} +1 -1
  33. package/src/@dictionaries/{dictionaries.eventProducts.ts → dictionaries.products.ts} +1 -1
  34. package/src/@dictionaries/{dictionaries.eventRecords.ts → dictionaries.records.ts} +1 -1
  35. package/src/@dictionaries/{dictionaries.eventSeverity.ts → dictionaries.severity.ts} +1 -1
  36. package/src/@dictionaries/{dictionaries.shapefileLinks.ts → dictionaries.shapefiles.ts} +1 -1
  37. package/src/@dictionaries/{dictionaries.eventStatus.ts → dictionaries.status.ts} +1 -1
  38. package/src/@dictionaries/{dictionaries.eventTags.ts → dictionaries.tags.ts} +1 -1
  39. package/src/@dictionaries/{dictionaries.testSignatures.ts → dictionaries.test.ts} +3 -2
  40. package/src/@events/events.api.ts +19 -14
  41. package/src/@events/events.text.ts +5 -4
  42. package/src/@events/events.ugc.ts +5 -4
  43. package/src/@events/events.vtec.ts +5 -4
  44. package/src/@manager/manager.mkEvent.ts +4 -4
  45. package/src/@manager/manager.rmEvent.ts +3 -2
  46. package/src/@manager/manager.setHash.ts +1 -1
  47. package/src/@manager/manager.updateListener.ts +124 -0
  48. package/src/@modules/@database/database.cache.ts +1 -1
  49. package/src/@modules/@database/database.init.ts +1 -1
  50. package/src/@modules/@database/database.shapefiles.ts +3 -3
  51. package/src/@modules/@database/database.stanza.ts +2 -2
  52. package/src/@modules/@eas/eas.getCleanDescription.ts +91 -0
  53. package/src/@modules/@eas/eas.getTTS.ts +54 -0
  54. package/src/@modules/@eas/eas.setEasTone.ts +40 -30
  55. package/src/@modules/@stanza/stanza.getAwipsType.ts +3 -3
  56. package/src/@modules/@stanza/stanza.validate.ts +5 -5
  57. package/src/@modules/@utilities/utilities.getLatestIssuance.ts +32 -0
  58. package/src/@modules/@utilities/utilities.getSettings.ts +1 -1
  59. package/src/@modules/@utilities/utilities.setCronSchedule.ts +30 -2
  60. package/src/@modules/@utilities/utilities.setSettings.ts +1 -1
  61. package/src/@modules/@utilities/utilities.setWarning.ts +1 -1
  62. package/src/@modules/@xmpp/xmpp.xDeploy.ts +1 -1
  63. package/src/@modules/@xmpp/xmpp.xReconnect.ts +1 -1
  64. package/src/@modules/@xmpp/xmpp.xStanza.ts +1 -1
  65. package/src/@parsers/@hvtec/hvtec.extract.ts +9 -9
  66. package/src/@parsers/@pvtec/pvtec.extract.ts +13 -13
  67. package/src/@parsers/@text/text.getDescriptionFromProduct.ts +2 -2
  68. package/src/@parsers/@text/text.getEmbed.ts +60 -0
  69. package/src/@parsers/@ugc/ugc.extract.ts +1 -1
  70. package/src/@parsers/@ugc/ugc.header.ts +3 -3
  71. package/src/@types/{types.compiled.ts → type.compiled.ts} +1 -1
  72. package/src/@types/type.event.ts +6 -4
  73. package/src/@types/{types.webhook.ts → type.listener.ts} +11 -6
  74. package/src/@types/type.properties.ts +10 -8
  75. package/src/@types/{types.settings.ts → type.settings.ts} +7 -5
  76. package/src/bootstrap.ts +7 -5
  77. package/src/index.ts +3 -2
  78. package/test.js +19 -19
  79. package/src/@dictionaries/dictionaries.transcribedMessageReplacements.ts +0 -68
  80. package/src/@manager/manager.createWebhook.ts +0 -117
  81. package/src/@manager/manager.updateWebhooks.ts +0 -49
  82. /package/src/@types/{types.attributes.ts → type.attributes.ts} +0 -0
  83. /package/src/@types/{types.hash.ts → type.hash.ts} +0 -0
  84. /package/src/@types/{types.hvtec.ts → type.hvtec.ts} +0 -0
  85. /package/src/@types/{types.pvtec.ts → type.pvtec.ts} +0 -0
  86. /package/src/@types/{types.stanza.ts → type.stanza.ts} +0 -0
  87. /package/src/@types/{types.ugc.ts → type.ugc.ts} +0 -0
@@ -10491,6 +10491,7 @@ var index_exports = {};
10491
10491
  __export(index_exports, {
10492
10492
  Manager: () => Manager,
10493
10493
  clearEvents: () => clearEvents,
10494
+ createEvent: () => createEvent2,
10494
10495
  default: () => index_default,
10495
10496
  getCleanedEvent: () => getCleanedEvent,
10496
10497
  getEventGeometry: () => getEventGeometry,
@@ -10510,7 +10511,7 @@ module.exports = __toCommonJS(index_exports);
10510
10511
  var import_path = __toESM(require("path"));
10511
10512
  var import_node_events = require("events");
10512
10513
  var bootstrap = {
10513
- version: `3.0.42`,
10514
+ version: `3.0.46`,
10514
10515
  isReady: true,
10515
10516
  ratelimits: {},
10516
10517
  session_xmpp: null,
@@ -10566,7 +10567,7 @@ var bootstrap = {
10566
10567
  CallbackInterval: 15,
10567
10568
  EventsEndpoint: `https://api.weather.gov/alerts/active`
10568
10569
  },
10569
- WebhookSettings: [],
10570
+ ListenerSettings: [],
10570
10571
  GlobalSettings: {
10571
10572
  EventManagement: true,
10572
10573
  BetterEventNames: true,
@@ -10586,9 +10587,11 @@ var bootstrap = {
10586
10587
  NodeLocationFiltering: false,
10587
10588
  IgnoreTestProducts: true
10588
10589
  },
10589
- EASSettings: {
10590
- ArchiveDirectory: null,
10591
- IntroWavFile: null
10590
+ ArchiveSettings: {
10591
+ TTL: 60,
10592
+ TextDirectory: null,
10593
+ EasDirectory: null,
10594
+ EasToneout: null
10592
10595
  }
10593
10596
  }
10594
10597
  }
@@ -13602,8 +13605,8 @@ var xError = () => {
13602
13605
  }));
13603
13606
  };
13604
13607
 
13605
- // src/@dictionaries/dictionaries.regExp.ts
13606
- var regExp = {
13608
+ // src/@dictionaries/dictionaries.expressions.ts
13609
+ var dict_expressions = {
13607
13610
  pvtec: new RegExp(`[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`, "g"),
13608
13611
  hvtec: new RegExp(`[a-zA-Z0-9]{4}.[A-Z0-9].[A-Z]{2}.[0-9]{6}T[0-9]{4}Z.[0-9]{6}T[0-9]{4}Z.[0-9]{6}T[0-9]{4}Z.[A-Z]{2}`, "imu"),
13609
13612
  wmo: new RegExp(`[A-Z0-9]{6}\\s[A-Z]{4}\\s\\d{6}`, "imu"),
@@ -13613,8 +13616,8 @@ var regExp = {
13613
13616
  dateline: new RegExp(`\\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")
13614
13617
  };
13615
13618
 
13616
- // src/@dictionaries/dictionaries.eventAwipAbreviations.ts
13617
- var eventAwipAbreviations = {
13619
+ // src/@dictionaries/dictionaries.awips.ts
13620
+ var dict_awips = {
13618
13621
  ABV: `rawinsonde-data-above-100-millibars`,
13619
13622
  ADA: `alarm-alert-administrative-message`,
13620
13623
  ADM: `alert-administrative-message`,
@@ -13969,7 +13972,7 @@ var getAwipsType = (options) => {
13969
13972
  prefix: null
13970
13973
  };
13971
13974
  }
13972
- for (const [prefix, type] of Object.entries(eventAwipAbreviations)) {
13975
+ for (const [prefix, type] of Object.entries(dict_awips)) {
13973
13976
  if (attributes.awipsid.startsWith(prefix)) {
13974
13977
  return { type, prefix };
13975
13978
  }
@@ -13987,8 +13990,8 @@ var validate = (options) => {
13987
13990
  if (attributes.awipsid && attributes.awipsid.length > 1) {
13988
13991
  const isCapEvent = message.includes(`<?xml`);
13989
13992
  const isCapAreaDescription = message.includes(`<areaDesc>`);
13990
- const isVTEC = message.match(regExp.pvtec) != null;
13991
- const isUGC = message.match(regExp.ugc1) != null;
13993
+ const isVTEC = message.match(dict_expressions.pvtec) != null;
13994
+ const isUGC = message.match(dict_expressions.ugc1) != null;
13992
13995
  const getType = getAwipsType({ attributes });
13993
13996
  if (getType.type != null) {
13994
13997
  return {
@@ -14012,7 +14015,7 @@ var validate = (options) => {
14012
14015
  // src/@parsers/@text/text.getDescriptionFromProduct.ts
14013
14016
  var getDescriptionFromProduct = (options) => {
14014
14017
  let message = options.message;
14015
- const dates = Array.from(message.matchAll(regExp.dateline));
14018
+ const dates = Array.from(message.matchAll(dict_expressions.dateline));
14016
14019
  if (dates.length) {
14017
14020
  const lastMatch = dates[dates.length - 1][0];
14018
14021
  const sIndx = message.lastIndexOf(lastMatch);
@@ -14078,8 +14081,8 @@ var getTextFromProduct = (options) => {
14078
14081
  return null;
14079
14082
  };
14080
14083
 
14081
- // src/@dictionaries/dictionaries.officeICAOs.ts
14082
- var officeICAOs = {
14084
+ // src/@dictionaries/dictionaries.icao.ts
14085
+ var dict_icao = {
14083
14086
  "KLUB": "Lubbock, TX",
14084
14087
  "KLCH": "Lake Charles, LA",
14085
14088
  "TSTL": "St. Louis, MO",
@@ -14324,12 +14327,12 @@ var officeICAOs = {
14324
14327
  var getEventOffice = (options) => {
14325
14328
  var _a, _b, _c, _d, _e, _f, _g;
14326
14329
  const office = options.pVtec != null ? (_b = (_a = options.pVtec) == null ? void 0 : _a.tracking) == null ? void 0 : _b.split(`.`)[0] : (_e = (_c = options.attributes) == null ? void 0 : _c.cccc) != null ? _e : options.organization != null ? Array.isArray(options.organization) ? (_d = options.organization) == null ? void 0 : _d[0] : options.organization : null;
14327
- const name = (_g = (_f = officeICAOs) == null ? void 0 : _f[office]) != null ? _g : null;
14330
+ const name = (_g = (_f = dict_icao) == null ? void 0 : _f[office]) != null ? _g : null;
14328
14331
  return { office, name };
14329
14332
  };
14330
14333
 
14331
- // src/@dictionaries/dictionaries.eventTags.ts
14332
- var eventTags = {
14334
+ // src/@dictionaries/dictionaries.tags.ts
14335
+ var dict_tags = {
14333
14336
  "FROSTBITE AND HYPOTHERMIA ARE LIKELY": "Frostbite and Hypothermia Likely",
14334
14337
  "LICKELY BECOME SLICK AND HAZARDOUS": "Slick and Hazardous Roads",
14335
14338
  "SLIPPERY ROAD CONDITIONS": "Slippery Roads",
@@ -14406,13 +14409,13 @@ var eventTags = {
14406
14409
 
14407
14410
  // src/@building/building.tags.ts
14408
14411
  var getEventTags = (message) => {
14409
- return Object.entries(eventTags).filter(([key]) => message == null ? void 0 : message.toLowerCase().includes(key.toLowerCase())).map(([, value]) => value);
14412
+ return Object.entries(dict_tags).filter(([key]) => message == null ? void 0 : message.toLowerCase().includes(key.toLowerCase())).map(([, value]) => value);
14410
14413
  };
14411
14414
 
14412
14415
  // src/@building/building.properties.ts
14413
14416
  var properties = (options) => {
14414
- 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;
14415
- const organization = (_b = (_a = options.message.match(regExp.wmo)) == null ? void 0 : _a[0]) != null ? _b : null;
14417
+ 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;
14418
+ const organization = (_b = (_a = options.message.match(dict_expressions.wmo)) == null ? void 0 : _a[0]) != null ? _b : null;
14416
14419
  const polygons = getPolygonFromProduct(options.message);
14417
14420
  const properties2 = {
14418
14421
  locations: (_e = (_d = (_c = options == null ? void 0 : options.ugc) == null ? void 0 : _c.locations) == null ? void 0 : _d.join(`; `)) != null ? _e : null,
@@ -14439,25 +14442,27 @@ var properties = (options) => {
14439
14442
  wind_threat: (_s = getTextFromProduct({ message: options.message, find: [`WIND THREAT...`] })) != null ? _s : null,
14440
14443
  hail_threat: (_t = getTextFromProduct({ message: options.message, find: [`HAIL THREAT...`], removal: [] })) != null ? _t : null
14441
14444
  },
14442
- spc_parameters: {
14443
- spc_max_tornado: (_u = getTextFromProduct({ message: options.message, find: [`MOST PROBABLE PEAK TORNADO INTENSITY...`] })) != null ? _u : null,
14444
- spc_max_hail: (_v = getTextFromProduct({ message: options.message, find: [`MOST PROBABLE PEAK HAIL SIZE...`] })) != null ? _v : null,
14445
- spc_max_wind: (_w = getTextFromProduct({ message: options.message, find: [`MOST PROBABLE PEAK WIND GUST...`] })) != null ? _w : null,
14446
- spc_watch_issuance: (_x = getTextFromProduct({ message: options.message, find: [`Probability of Watch Issuance...`], removal: [`percent`] })) != null ? _x : null
14445
+ discussion_parameters: {
14446
+ discussion_number: (_w = (_v = (_u = getTextFromProduct({ message: options.message, find: [`Mesoscale Discussion `], removal: [`Mesoscale Discussion`, `Number`, `...`] })) == null ? void 0 : _u.toString()) == null ? void 0 : _v.padStart(4, "0")) != null ? _w : null,
14447
+ discussion_concerning: (_x = getTextFromProduct({ message: options.message, find: [`Concerning...`] })) != null ? _x : null,
14448
+ discussion_max_tornado: (_y = getTextFromProduct({ message: options.message, find: [`MOST PROBABLE PEAK TORNADO INTENSITY...`] })) != null ? _y : null,
14449
+ discussion_max_hail: (_z = getTextFromProduct({ message: options.message, find: [`MOST PROBABLE PEAK HAIL SIZE...`] })) != null ? _z : null,
14450
+ discussion_max_wind: (_A = getTextFromProduct({ message: options.message, find: [`MOST PROBABLE PEAK WIND GUST...`] })) != null ? _A : null,
14451
+ discussion_watch_issuance: (_B = getTextFromProduct({ message: options.message, find: [`Probability of Watch Issuance...`], removal: [`percent`] })) != null ? _B : null
14447
14452
  },
14448
14453
  watch_parameters: {
14449
- watch_number: (_A = (_z = (_y = getTextFromProduct({ message: options.message, find: [`ITIES FOR`, `UPDATE FOR`, `Watch Number `], removal: [`%`, `<`, `:`] })) == null ? void 0 : _y.replace(/(WT|WS|)/g, "")) == null ? void 0 : _z.trim()) != null ? _A : null,
14454
+ watch_number: ((_C = options == null ? void 0 : options.pVtec) == null ? void 0 : _C.is_watch) && ((_M = (_L = (_G = (_F = (_E = (_D = getTextFromProduct({ message: options.message, find: [`ITIES FOR`, `UPDATE FOR`, `Watch Number `], removal: [`%`, `<`, `:`] })) == null ? void 0 : _D.replace(/(WT|WS|)/g, "")) == null ? void 0 : _E.trim()) == null ? void 0 : _F.toString()) == null ? void 0 : _G.padStart(4, "0")) != null ? _L : (_K = (_J = (_I = (_H = options == null ? void 0 : options.pVtec) == null ? void 0 : _H.tracking) == null ? void 0 : _I.slice(-4)) == null ? void 0 : _J.toString()) == null ? void 0 : _K.padStart(4, "0")) != null ? _M : null),
14450
14455
  watch_type: options.message.includes(`TORNADO WATCH`) ? `Tornado` : (options == null ? void 0 : options.message.includes(`SEVERE`)) ? `Severe` : null,
14451
- additional_tornadoes_probability: (_B = getTextFromProduct({ message: options.message, find: [`PROB OF 2 OR MORE TORNADOES`], removal: [`%`, `<`, `:`] })) != null ? _B : null,
14452
- strong_tornadoes_probability: (_C = getTextFromProduct({ message: options.message, find: [`PROB OF 1 OR MORE STRONG /EF2-EF5/ TORNADOES`], removal: [`%`, `<`, `:`] })) != null ? _C : null,
14453
- severe_wind_probability: (_D = getTextFromProduct({ message: options.message, find: [`PROB OF 10 OR MORE SEVERE WIND EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _D : null,
14454
- severe_hail_probability: (_E = getTextFromProduct({ message: options.message, find: [`PROB OF 10 OR MORE SEVERE HAIL EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _E : null,
14455
- hail_2in_probability: (_F = getTextFromProduct({ message: options.message, find: [`PROB OF 1 OR MORE HAIL EVENTS >= 2 INCHES`], removal: [`%`, `<`, `:`] })) != null ? _F : null,
14456
- combined_hail_wind_probability: (_G = getTextFromProduct({ message: options.message, find: [`PROB OF 6 OR MORE COMBINED SEVERE HAIL/WIND EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _G : null,
14457
- max_hail_in: (_H = getTextFromProduct({ message: options.message, find: [`MAX HAIL /INCHES/`], removal: [`%`, `<`, `:`] })) != null ? _H : null,
14458
- max_wind_surface: (_I = getTextFromProduct({ message: options.message, find: [`MAX WIND GUSTS SURFACE /KNOTS/`], removal: [`%`, `<`, `:`] })) != null ? _I : null,
14459
- max_tops_x100feet: (_J = getTextFromProduct({ message: options.message, find: [`MAX TOPS /X 100 FEET/`], removal: [`%`, `<`, `:`] })) != null ? _J : null,
14460
- pds_watch: getTextFromProduct({ message: options.message, find: [`PARTICULARLY DANGEROUS SITUATION`], removal: [`%`, `<`, `:`] }) === `YES`
14456
+ additional_tornadoes_probability: (_N = getTextFromProduct({ message: options.message, find: [`PROB OF 2 OR MORE TORNADOES`], removal: [`%`, `<`, `:`] })) != null ? _N : null,
14457
+ strong_tornadoes_probability: (_O = getTextFromProduct({ message: options.message, find: [`PROB OF 1 OR MORE STRONG /EF2-EF5/ TORNADOES`], removal: [`%`, `<`, `:`] })) != null ? _O : null,
14458
+ severe_wind_probability: (_P = getTextFromProduct({ message: options.message, find: [`PROB OF 10 OR MORE SEVERE WIND EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _P : null,
14459
+ severe_hail_probability: (_Q = getTextFromProduct({ message: options.message, find: [`PROB OF 10 OR MORE SEVERE HAIL EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _Q : null,
14460
+ hail_2in_probability: (_R = getTextFromProduct({ message: options.message, find: [`PROB OF 1 OR MORE HAIL EVENTS >= 2 INCHES`], removal: [`%`, `<`, `:`] })) != null ? _R : null,
14461
+ combined_hail_wind_probability: (_S = getTextFromProduct({ message: options.message, find: [`PROB OF 6 OR MORE COMBINED SEVERE HAIL/WIND EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _S : null,
14462
+ max_hail_in: (_T = getTextFromProduct({ message: options.message, find: [`MAX HAIL /INCHES/`], removal: [`%`, `<`, `:`] })) != null ? _T : null,
14463
+ max_wind_surface: (_U = getTextFromProduct({ message: options.message, find: [`MAX WIND GUSTS SURFACE /KNOTS/`], removal: [`%`, `<`, `:`] })) != null ? _U : null,
14464
+ max_tops_x100feet: (_V = getTextFromProduct({ message: options.message, find: [`MAX TOPS /X 100 FEET/`], removal: [`%`, `<`, `:`] })) != null ? _V : null,
14465
+ pds_watch: getTextFromProduct({ message: options.message, find: [`PARTICULARLY DANGEROUS SITUATION`], removal: [`%`, `<`, `:`] }) === `YES` ? true : null
14461
14466
  }
14462
14467
  };
14463
14468
  if (isNaN(Number(properties2.watch_parameters.watch_number))) {
@@ -14475,8 +14480,8 @@ var getEventHeader = (options) => {
14475
14480
  return `ZCZC-ATMOSX-${options.getType.prefix}-${ugc2}-${(_b = vtec2 == null ? void 0 : vtec2.status) != null ? _b : `Issued`}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").split(".")[0]}-${(_c = properties2.geocode.office.office) != null ? _c : `KWNS`}`;
14476
14481
  };
14477
14482
 
14478
- // src/@dictionaries/dictionaries.eventsMatchText.ts
14479
- var eventsMatchText = {
14483
+ // src/@dictionaries/dictionaries.matches.ts
14484
+ var dict_matches = {
14480
14485
  "Special Weather Statement": "Special Weather Statement",
14481
14486
  "Hurricane Warning": "Hurricane Warning",
14482
14487
  "Hurricane Force Wind Warning": "Hurricane Force Wind Warning",
@@ -14496,7 +14501,7 @@ var eventsMatchText = {
14496
14501
 
14497
14502
  // src/@building/building.tracking.ts
14498
14503
  var getEventTracking = (options) => {
14499
- var _a, _b, _c, _d, _e, _f, _g;
14504
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
14500
14505
  const properties2 = options.properties;
14501
14506
  const attributes = options.attributes;
14502
14507
  const stanza = options.stanza;
@@ -14513,26 +14518,26 @@ var getEventTracking = (options) => {
14513
14518
  }
14514
14519
  if (options.type === `API`) {
14515
14520
  if (options.vtec) {
14516
- const vtecValue = Array.isArray(options.vtec) ? options.vtec[0] : options.vtec;
14521
+ const vtecValue = Array.isArray(options.vtec) ? options.vtec[0].vtec : (_c = options.vtec) == null ? void 0 : _c.vtec;
14517
14522
  const splitPVTEC = vtecValue.split(".");
14518
14523
  return `${splitPVTEC[2]}.${splitPVTEC[3]}.${splitPVTEC[4]}.${splitPVTEC[5]}`;
14519
14524
  }
14520
- const wmoMatch = (_d = (_c = options.organization) == null ? void 0 : _c.wmoidentifier) == null ? void 0 : _d.match(/([A-Z]{4}\d{2})\s+([A-Z]{4})/);
14521
- const station = (_e = wmoMatch == null ? void 0 : wmoMatch[2]) != null ? _e : "N/A";
14525
+ const wmoMatch = (_e = (_d = options.organization) == null ? void 0 : _d.wmoidentifier) == null ? void 0 : _e.match(/([A-Z]{4}\d{2})\s+([A-Z]{4})/);
14526
+ const station = (_f = wmoMatch == null ? void 0 : wmoMatch[2]) != null ? _f : "N/A";
14522
14527
  if (options.organization.featureId) {
14523
14528
  const idMatch = options.organization.featureId.match(/([a-f0-9]+)\.(\d+)\.(\d+)$/);
14524
- return `${station}.${(_f = idMatch == null ? void 0 : idMatch[1]) != null ? _f : "N/A"}`;
14529
+ return `${station}.${(_h = (_g = idMatch == null ? void 0 : idMatch[0]) == null ? void 0 : _g.replace(/\./g, "")) != null ? _h : "N/A"}`;
14525
14530
  }
14526
- const id2 = (_g = wmoMatch == null ? void 0 : wmoMatch[1]) != null ? _g : "N/A";
14527
- return `${station}.${id2}`;
14531
+ const id2 = (_i = wmoMatch == null ? void 0 : wmoMatch[1]) != null ? _i : "N/A";
14532
+ return `${station}.${(_j = id2 == null ? void 0 : id2.replace(/\./g, "")) != null ? _j : "N/A"}`;
14528
14533
  }
14529
14534
  };
14530
14535
 
14531
14536
  // src/@building/building.validate.ts
14532
14537
  var import_crypto = require("crypto");
14533
14538
 
14534
- // src/@dictionaries/dictionaries.betterEventNames.ts
14535
- var betterEventNames = {
14539
+ // src/@dictionaries/dictionaries.enhanced.ts
14540
+ var dict_enhanced = {
14536
14541
  "Tornado Warning": {
14537
14542
  "Tornado Emergency": {
14538
14543
  description: "tornado emergency"
@@ -14550,6 +14555,11 @@ var betterEventNames = {
14550
14555
  },
14551
14556
  "Radar Indicated Tornado Warning": {}
14552
14557
  },
14558
+ "Fire Weather Warning": {
14559
+ "PDS Fire Weather Warning": {
14560
+ description: "particularly dangerous situation"
14561
+ }
14562
+ },
14553
14563
  "Blizzard Warning": {
14554
14564
  "PDS Blizzard Warning": {
14555
14565
  description: "particularly dangerous situation"
@@ -14567,7 +14577,12 @@ var betterEventNames = {
14567
14577
  },
14568
14578
  "Tornado Watch": {
14569
14579
  "PDS Tornado Watch": {
14570
- description: "particularly dangerous situation"
14580
+ pdswatch: true
14581
+ }
14582
+ },
14583
+ "Severe Thunderstorm Watch": {
14584
+ "PDS Severe Thunderstorm Watch": {
14585
+ pdswatch: true
14571
14586
  }
14572
14587
  },
14573
14588
  "Flash Flood Warning": {
@@ -14608,16 +14623,17 @@ var betterEventNames = {
14608
14623
 
14609
14624
  // src/@building/building.enhance.ts
14610
14625
  var getEventEnhancedName = (event) => {
14611
- var _a, _b, _c, _d, _e, _f, _g;
14626
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
14612
14627
  const configurations = bootstrap.settings;
14613
14628
  let name = (_a = event == null ? void 0 : event.properties) == null ? void 0 : _a.event;
14614
14629
  if (!((_b = configurations == null ? void 0 : configurations.GlobalSettings) == null ? void 0 : _b.BetterEventNames)) {
14615
14630
  return name;
14616
14631
  }
14617
14632
  const damage = (_d = (_c = event == null ? void 0 : event.properties) == null ? void 0 : _c.parameters) == null ? void 0 : _d.damage_threat;
14618
- const tornado = (_e = event == null ? void 0 : event.properties) == null ? void 0 : _e.parameters.tornado_threat;
14619
- const description = (_g = (_f = event == null ? void 0 : event.properties) == null ? void 0 : _f.description) == null ? void 0 : _g.toLowerCase();
14620
- for (const [eventKey, eventConfig] of Object.entries(betterEventNames)) {
14633
+ const tornado = (_f = (_e = event == null ? void 0 : event.properties) == null ? void 0 : _e.parameters) == null ? void 0 : _f.tornado_threat;
14634
+ const pdswatch = (_h = (_g = event == null ? void 0 : event.properties) == null ? void 0 : _g.watch_parameters) == null ? void 0 : _h.pds_watch;
14635
+ const description = (_j = (_i = event == null ? void 0 : event.properties) == null ? void 0 : _i.description) == null ? void 0 : _j.toLowerCase();
14636
+ for (const [eventKey, eventConfig] of Object.entries(dict_enhanced)) {
14621
14637
  if (eventKey !== name) continue;
14622
14638
  for (const [paramKey, paramValue] of Object.entries(eventConfig)) {
14623
14639
  let matches = true;
@@ -14630,6 +14646,9 @@ var getEventEnhancedName = (event) => {
14630
14646
  if (paramValue == null ? void 0 : paramValue.tornado) {
14631
14647
  if (paramValue.tornado !== tornado) matches = false;
14632
14648
  }
14649
+ if (paramValue == null ? void 0 : paramValue.pdswatch) {
14650
+ if (paramValue.pdswatch !== pdswatch) matches = false;
14651
+ }
14633
14652
  if (matches) {
14634
14653
  name = paramKey;
14635
14654
  break;
@@ -14639,8 +14658,8 @@ var getEventEnhancedName = (event) => {
14639
14658
  return name;
14640
14659
  };
14641
14660
 
14642
- // src/@dictionaries/dictionaries.statusCorrelationText.ts
14643
- var statusCorrelationText = [
14661
+ // src/@dictionaries/dictionaries.correlations.ts
14662
+ var dict_correlations = [
14644
14663
  { type: "Statement", name: "Statement", isCancel: false, isUpdate: false, isIssued: true, isStatement: true },
14645
14664
  { type: "Update", name: "Updated", isCancel: false, isUpdate: true, isIssued: false, isStatement: false },
14646
14665
  { type: "Cancel", name: "Cancelled", isCancel: true, isUpdate: false, isIssued: false, isStatement: false },
@@ -14655,8 +14674,8 @@ var statusCorrelationText = [
14655
14674
  { type: "Routine", name: "Routine", isCancel: false, isUpdate: true, isIssued: false, isStatement: false }
14656
14675
  ];
14657
14676
 
14658
- // src/@dictionaries/dictionaries.eventCancelMessages.ts
14659
- var eventCancelMessages = [
14677
+ // src/@dictionaries/dictionaries.cancellation.ts
14678
+ var dict_cancellation = [
14660
14679
  "has been cancelled",
14661
14680
  "subsided sufficiently for the advisory to be cancelled",
14662
14681
  "has been cancelled",
@@ -14668,24 +14687,28 @@ var eventCancelMessages = [
14668
14687
  "has weakened below severe"
14669
14688
  ];
14670
14689
 
14671
- // src/@dictionaries/dictionaries.testSignatures.ts
14672
- var testSignatures = [
14690
+ // src/@dictionaries/dictionaries.test.ts
14691
+ var dict_testing = [
14673
14692
  `This is a test message`,
14674
14693
  `Monitoring message only.`,
14675
- `THIS_MESSAGE_IS_FOR_TEST_PURPOSES_ONLY`
14694
+ `THIS_MESSAGE_IS_FOR_TEST_PURPOSES_ONLY`,
14695
+ "TEST MESSAGE"
14676
14696
  ];
14677
14697
 
14678
- // src/@dictionaries/dictionaries.eventProducts.ts
14679
- var eventProducts = {
14698
+ // src/@dictionaries/dictionaries.products.ts
14699
+ var dict_products = {
14680
14700
  "O": "Operational Product",
14681
14701
  "T": "Test Product",
14682
14702
  "E": "Experimental Product",
14683
14703
  "X": "Experimental Product (Non-Operational)"
14684
14704
  };
14685
14705
 
14686
- // src/@dictionaries/dictionaries.hailStrings.ts
14687
- var hailStrings = {
14706
+ // src/@dictionaries/dictionaries.hail.ts
14707
+ var dict_hail = {
14708
+ ".25": "Pea",
14709
+ ".50": "Penny",
14688
14710
  ".75": "Penny",
14711
+ "Up to .75": "Penny",
14689
14712
  ".88": "Nickel",
14690
14713
  "0.75": "Penny",
14691
14714
  "0.88": "Nickel",
@@ -14701,25 +14724,25 @@ var hailStrings = {
14701
14724
 
14702
14725
  // src/@building/building.signature.ts
14703
14726
  var getEventSignature = (event) => {
14704
- var _a, _b, _c, _d, _e, _f;
14727
+ var _a, _b, _c, _d, _e, _f, _g, _h;
14705
14728
  const properties2 = event == null ? void 0 : event.properties;
14706
14729
  const vtec2 = (_b = (_a = event == null ? void 0 : event.properties) == null ? void 0 : _a.metadata) == null ? void 0 : _b.vtec;
14707
- const status = statusCorrelationText.find((c) => c.type === (properties2 == null ? void 0 : properties2.status));
14708
- const csig = eventCancelMessages.find((sig) => properties2.description.toLowerCase().includes(sig.toLowerCase()));
14730
+ const status = dict_correlations.find((c) => c.type === (properties2 == null ? void 0 : properties2.status));
14731
+ const csig = dict_cancellation.find((sig) => properties2.description.toLowerCase().includes(sig.toLowerCase()));
14709
14732
  properties2.status_metadata = __spreadProps(__spreadValues({}, properties2.status_metadata), { is_issued: true, is_test: false });
14710
- if (properties2.parameters.estimated_hail_size) {
14711
- properties2.parameters.estimated_hail_size += ` (${(_c = hailStrings[properties2.parameters.estimated_hail_size]) != null ? _c : "--"})`;
14733
+ if ((_c = properties2 == null ? void 0 : properties2.parameters) == null ? void 0 : _c.estimated_hail_size) {
14734
+ properties2.parameters.estimated_hail_size += ` (${(_e = dict_hail[(_d = properties2 == null ? void 0 : properties2.parameters) == null ? void 0 : _d.estimated_hail_size]) != null ? _e : "--"})`;
14712
14735
  }
14713
14736
  if (status) {
14714
- properties2.status = (_d = status.name) != null ? _d : properties2.status;
14737
+ properties2.status = (_f = status.name) != null ? _f : properties2.status;
14715
14738
  properties2.status_metadata = __spreadProps(__spreadValues({}, properties2.status_metadata), { is_updated: !!status.isUpdate, is_issued: !!status.isIssued, is_expired: !!status.isCancel, is_statement: !!status.isStatement });
14716
14739
  }
14717
14740
  if (csig) {
14718
14741
  properties2.status_metadata = __spreadProps(__spreadValues({}, properties2.status_metadata), { is_expired: true });
14719
14742
  }
14720
- const getProduct = (_f = (_e = vtec2 == null ? void 0 : vtec2.vtec) == null ? void 0 : _e.split(`.`)[0]) == null ? void 0 : _f.replace(`/`, ``);
14721
- const isTestProduct = eventProducts[getProduct] == `Test Product`;
14722
- if (isTestProduct || testSignatures.some((sig) => {
14743
+ const getProduct = (_h = (_g = vtec2 == null ? void 0 : vtec2.vtec) == null ? void 0 : _g.split(`.`)[0]) == null ? void 0 : _h.replace(`/`, ``);
14744
+ const isTestProduct = dict_products[getProduct] == `Test Product`;
14745
+ if (isTestProduct || dict_testing.some((sig) => {
14723
14746
  var _a2, _b2, _c2, _d2;
14724
14747
  return (_d2 = (_a2 = properties2.description) == null ? void 0 : _a2.toLowerCase().includes(sig.toLowerCase())) != null ? _d2 : (_c2 = (_b2 = properties2 == null ? void 0 : properties2.parameters) == null ? void 0 : _b2.instructions) == null ? void 0 : _c2.toLowerCase().includes(sig.toLowerCase());
14725
14748
  })) {
@@ -14746,1849 +14769,2004 @@ var setHash = (event, entry) => {
14746
14769
  }
14747
14770
  };
14748
14771
 
14749
- // src/@modules/@utilities/utilities.createHttp.ts
14750
- var import_request = __toESM(require("request"));
14751
- var createHttp = (options) => __async(null, null, function* () {
14752
- return new Promise((resolve6, reject) => {
14753
- var _a, _b, _c, _d, _e;
14754
- const requestOptions = {
14755
- url: (_a = options.url) != null ? _a : `https://api.weather.gov/alerts/active`,
14756
- headers: (_b = options.headers) != null ? _b : {
14757
- "User-Agent": "AtmosphericX",
14758
- "Accept": "application/geo+json, text/plain, */*; q=0.9",
14759
- "Accept-Language": "en-US,en;q=0.9"
14760
- },
14761
- method: (_c = options.method) != null ? _c : `GET`,
14762
- timeout: (_d = options.timeout) != null ? _d : 1e4,
14763
- proxy: (_e = options.proxy) != null ? _e : null,
14764
- maxRedirects: 1
14765
- };
14766
- if (options.formData) {
14767
- requestOptions["formData"] = options.formData;
14768
- } else if (options.body) {
14769
- requestOptions["body"] = options.body;
14770
- }
14771
- (0, import_request.default)(requestOptions, (error, response2, body) => {
14772
- var _a2, _b2, _c2, _d2, _e2;
14773
- if (error) {
14774
- return resolve6({
14775
- error: true,
14776
- options: requestOptions,
14777
- status: -1,
14778
- message: (_a2 = error.message) != null ? _a2 : `Unknown Error`
14779
- });
14780
- }
14781
- if (response2.statusCode < 200 || response2.statusCode >= 300) {
14782
- return resolve6({
14783
- error: true,
14784
- options: requestOptions,
14785
- status: (_b2 = response2.statusCode) != null ? _b2 : -1,
14786
- message: `HTTP Status Code ${(_c2 = response2.statusCode) != null ? _c2 : `Unknown Status Code`} (${body})`
14787
- });
14788
- }
14789
- if (body == void 0 || body == null) {
14790
- return resolve6({
14791
- error: true,
14792
- options: requestOptions,
14793
- status: (_d2 = response2.statusCode) != null ? _d2 : -1,
14794
- message: `Empty Response Body`
14795
- });
14796
- }
14797
- resolve6({
14798
- error: false,
14799
- options: requestOptions,
14800
- status: (_e2 = response2.statusCode) != null ? _e2 : -1,
14801
- message: body
14802
- });
14803
- });
14804
- });
14805
- });
14772
+ // src/@modules/@eas/eas.getWavPCM16.ts
14773
+ var getWavPCM16 = (buffer) => {
14774
+ if (buffer.toString("ascii", 0, 4) !== "RIFF" || buffer.toString("ascii", 8, 12) !== "WAVE") {
14775
+ return null;
14776
+ }
14777
+ let fmt = null;
14778
+ let data = null;
14779
+ let i = 12;
14780
+ while (i + 8 <= buffer.length) {
14781
+ const id2 = buffer.toString("ascii", i, i + 4);
14782
+ const size = buffer.readUInt32LE(i + 4);
14783
+ const start = i + 8;
14784
+ const end = start + size;
14785
+ if (id2 === "fmt ") fmt = buffer.slice(start, end);
14786
+ if (id2 === "data") data = buffer.slice(start, end);
14787
+ i = end + size % 2;
14788
+ }
14789
+ if (!fmt || !data) return null;
14790
+ const audioFormat = fmt.readUInt16LE(0);
14791
+ const channels = fmt.readUInt16LE(2);
14792
+ const sampleRate = fmt.readUInt32LE(4);
14793
+ const bitsPerSample = fmt.readUInt16LE(14);
14794
+ if (audioFormat !== 1 || bitsPerSample !== 16 || channels !== 1) {
14795
+ return null;
14796
+ }
14797
+ const samples = new Int16Array(data.buffer, data.byteOffset, data.length / 2);
14798
+ return { samples: new Int16Array(samples), sampleRate, channels, bitsPerSample };
14799
+ };
14806
14800
 
14807
- // src/@manager/manager.createWebhook.ts
14808
- var import_form_data = __toESM(require_form_data());
14809
- var createWebhook = (options) => __async(null, null, function* () {
14810
- var _a, _b, _c, _d, _e, _f;
14811
- const event = options.event.properties;
14812
- const settings = options.webhook;
14813
- let body = [
14814
- event.locations ? `**Locations**: ${event.locations.slice(0, 100)}` : null,
14815
- event.issued && event.status != `Expired` ? `**Issued**: <t:${Math.floor(new Date(event.issued).getTime() / 1e3)}:R>` : null,
14816
- event.expires && event.status != `Statement` ? `**Expires**: <t:${Math.floor(new Date(event.expires).getTime() / 1e3)}:R>` : null,
14817
- (() => {
14818
- var _a2, _b2;
14819
- const val = (_a2 = event.parameters.estimated_wind_gusts) != null ? _a2 : null;
14820
- const th = (_b2 = event.parameters.wind_threat) != null ? _b2 : null;
14821
- const combined = [val, th].filter(Boolean).join(" ");
14822
- return combined ? `**Wind Gusts**: ${val} ${th ? `(${th})` : ""}` : null;
14823
- })(),
14824
- (() => {
14825
- var _a2, _b2;
14826
- const val = (_a2 = event.parameters.estimated_hail_size) != null ? _a2 : null;
14827
- const th = (_b2 = event.parameters.hail_threat) != null ? _b2 : null;
14828
- return (val != null ? val : th) ? `**Hail Threat**: ${val} ${th ? `(${th})` : ""}` : null;
14829
- })(),
14830
- event.parameters.damage_threat ? `**Damage Threat**: ${event.parameters.damage_threat}` : null,
14831
- event.parameters.flood_threat ? `**Flood Threat**: ${event.parameters.flood_threat}` : null,
14832
- event.parameters.tornado_threat ? `**Tornado Threat**: ${event.parameters.tornado_threat}` : null,
14833
- event.spc_parameters.spc_max_tornado ? `**Max Tornado Threat**: ${event.spc_parameters.spc_max_tornado}` : null,
14834
- event.spc_parameters.spc_max_hail ? `**Max Hail Threat**: ${event.spc_parameters.spc_max_hail}` : null,
14835
- event.spc_parameters.spc_max_wind ? `**Max Wind Threat**: ${event.spc_parameters.spc_max_wind}` : null,
14836
- event.spc_parameters.spc_watch_issuance ? `**Watch Issuance**: ${event.spc_parameters.spc_watch_issuance}%` : null,
14837
- event.watch_parameters.watch_number ? `**Watch Number**: ${event.watch_parameters.watch_number}` : null,
14838
- event.watch_parameters.strong_tornadoes_probability ? `**Strong Tornadoes Probability**: ${event.watch_parameters.strong_tornadoes_probability}%` : null,
14839
- event.watch_parameters.additional_tornadoes_probability ? `**Additional Tornadoes Probability**: ${event.watch_parameters.additional_tornadoes_probability}%` : null,
14840
- event.watch_parameters.combined_hail_wind_probability ? `**Combined Hail/Wind Probability**: ${event.watch_parameters.combined_hail_wind_probability}%` : null,
14841
- event.watch_parameters.severe_hail_probability ? `**Severe Hail Probability**: ${event.watch_parameters.severe_hail_probability}%` : null,
14842
- event.watch_parameters.hail_2in_probability ? `**Hail \u22652in Probability**: ${event.watch_parameters.hail_2in_probability}%` : null,
14843
- event.watch_parameters.max_hail_in ? `**Max Hail Inches**: ${event.watch_parameters.max_hail_in}` : null,
14844
- event.watch_parameters.severe_wind_probability ? `**Severe Wind Probability**: ${event.watch_parameters.severe_wind_probability}%` : null,
14845
- event.watch_parameters.max_wind_surface ? `**Max Surface Wind**: ${event.watch_parameters.max_wind_surface}` : null,
14846
- event.watch_parameters.max_tops_x100feet ? `**Max Tops (x100 feet)**: ${event.watch_parameters.max_tops_x100feet}` : null,
14847
- ((_a = event.parameters.tags) == null ? void 0 : _a.length) > 0 ? `**Tags**: ${event.parameters.tags.join(", ")}` : null,
14848
- (() => {
14849
- var _a2, _b2, _c2, _d2, _e2, _f2;
14850
- const val = (_c2 = (_b2 = (_a2 = event.geocode) == null ? void 0 : _a2.office) == null ? void 0 : _b2.name) != null ? _c2 : `N/A`;
14851
- const th = (_f2 = (_e2 = (_d2 = event.geocode) == null ? void 0 : _d2.office) == null ? void 0 : _e2.office) != null ? _f2 : null;
14852
- return (val != null ? val : th) ? `**Sender**: ${val} ${th ? `(${th})` : ""}` : null;
14853
- })(),
14854
- ((_b = event.metadata) == null ? void 0 : _b.tracking) ? `**Tracking**: ${event.metadata.tracking}` : null,
14855
- ((_c = event.metadata.history) == null ? void 0 : _c.length) > 0 ? `**Logs**: ${event.metadata.history.length}` : null,
14856
- (() => {
14857
- var _a2;
14858
- if (event.status == `Expired`) {
14859
- return null;
14860
- }
14861
- const desc = ((_a2 = event.description) != null ? _a2 : "").split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
14862
- return desc ? "```\n" + desc + "\n```" : null;
14863
- })()
14864
- ].filter(Boolean).join("\n");
14865
- const isLimited = setTimeoutAction({ identifier: options.webhook.webhook, interval: options.webhook.rate, max: options.webhook.rate, addTime: true });
14866
- if (isLimited.limited) {
14867
- return;
14801
+ // src/@modules/@eas/eas.getSampledPCM16.ts
14802
+ var getSampledPCM16 = (int16, originalRate, targetRate) => {
14803
+ if (originalRate === targetRate) return int16;
14804
+ const ratio = targetRate / originalRate;
14805
+ const outLen = Math.max(1, Math.round(int16.length * ratio));
14806
+ const out = new Int16Array(outLen);
14807
+ for (let i = 0; i < outLen; i++) {
14808
+ const pos = i / ratio;
14809
+ const i0 = Math.floor(pos);
14810
+ const i1 = Math.min(i0 + 1, int16.length - 1);
14811
+ const frac = pos - i0;
14812
+ const v = int16[i0] * (1 - frac) + int16[i1] * frac;
14813
+ out[i] = Math.round(v);
14868
14814
  }
14869
- if (body.length > 1900) {
14870
- body = body.substring(0, 1900) + "\n\n[Message truncated due to length]";
14871
- const blocks = ((_d = body.match(/```/g)) != null ? _d : []).length;
14872
- if (blocks % 2 !== 0) body += "```";
14873
- }
14874
- const form = new import_form_data.default();
14875
- const embed = {
14876
- title: `${event.event} (${event.status})`,
14877
- description: body,
14878
- color: 16711680,
14879
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
14880
- footer: { text: settings.title }
14881
- };
14882
- form.append("payload_json", JSON.stringify({
14883
- username: (_e = settings.title) != null ? _e : "AtmosphericX",
14884
- content: (_f = settings.message) != null ? _f : "",
14885
- embeds: [embed]
14886
- }));
14887
- if (settings.upload) {
14888
- form.append("file", Buffer.from(JSON.stringify(getCleanedEvent(event), null, 2)), {
14889
- filename: `${event.event}_${event.status}_${event.metadata.tracking}.json`,
14890
- contentType: "application/json"
14891
- });
14815
+ return out;
14816
+ };
14817
+
14818
+ // src/@modules/@eas/eas.getPCMToFloat.ts
14819
+ var getPCMToFloat = (int16) => {
14820
+ const out = new Float32Array(int16.length);
14821
+ for (let i = 0; i < int16.length; i++) out[i] = int16[i] / 32768;
14822
+ return out;
14823
+ };
14824
+
14825
+ // src/@modules/@eas/eas.getFloatPCM16.ts
14826
+ var getFloatPCM16 = (float32) => {
14827
+ const out = new Int16Array(float32.length);
14828
+ for (let i = 0; i < float32.length; i++) {
14829
+ let v = Math.max(-1, Math.min(1, float32[i]));
14830
+ out[i] = Math.round(v * 32767);
14892
14831
  }
14893
- yield createHttp({
14894
- url: settings.webhook,
14895
- timeout: 2e3,
14896
- method: `POST`,
14897
- headers: form.getHeaders(),
14898
- body: form
14899
- });
14900
- });
14832
+ return out;
14833
+ };
14901
14834
 
14902
- // src/@manager/manager.updateWebhooks.ts
14903
- var updateWebhooks = (event) => __async(null, null, function* () {
14904
- const settings = bootstrap.settings;
14905
- const webhooks = settings.WebhookSettings;
14906
- const eventName = event.properties.event;
14907
- for (const socket of webhooks) {
14908
- const events = socket.events;
14909
- if (!events || events.length === 0) {
14910
- yield createWebhook({ webhook: socket, event });
14911
- continue;
14912
- }
14913
- const matched = events.some((pattern) => {
14914
- if (!pattern) return false;
14915
- if (pattern === "*" || pattern === eventName) return true;
14916
- if (pattern.includes("*")) {
14917
- const regex = "^" + pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*") + "$";
14918
- return new RegExp(regex).test(eventName);
14919
- }
14920
- return false;
14921
- });
14922
- if (matched) {
14923
- yield createWebhook({ webhook: socket, event });
14835
+ // src/@modules/@eas/eas.setRadioEffect.ts
14836
+ var setRadioEffect = (int16, sampleRate) => {
14837
+ const hpCut = 3555;
14838
+ const lpCut = 1600;
14839
+ const x = getPCMToFloat(int16);
14840
+ const dt = 1 / sampleRate;
14841
+ const rcHP = 1 / (2 * Math.PI * hpCut);
14842
+ const aHP = rcHP / (rcHP + dt);
14843
+ let yHP = 0, xPrev = 0;
14844
+ for (let i = 0; i < x.length; i++) {
14845
+ const xi = x[i];
14846
+ yHP = aHP * (yHP + xi - xPrev);
14847
+ xPrev = xi;
14848
+ x[i] = yHP;
14849
+ }
14850
+ const rcLP = 1 / (2 * Math.PI * lpCut);
14851
+ const aLP = dt / (rcLP + dt);
14852
+ let yLP = 0;
14853
+ for (let i = 0; i < x.length; i++) {
14854
+ yLP = yLP + aLP * (x[i] - yLP);
14855
+ x[i] = yLP;
14856
+ }
14857
+ const compGain = 2;
14858
+ const norm = Math.tanh(compGain);
14859
+ for (let i = 0; i < x.length; i++) x[i] = Math.tanh(x[i] * compGain) / norm;
14860
+ return getFloatPCM16(x);
14861
+ };
14862
+
14863
+ // src/@modules/@eas/eas.setAFSK.ts
14864
+ var setAFSK = (bits, sampleRate) => {
14865
+ const baud = 520.83;
14866
+ const markFreq = 2083.3;
14867
+ const spaceFreq = 1562.5;
14868
+ const amplitude = 0.6;
14869
+ const twoPi = Math.PI * 2;
14870
+ const result = [];
14871
+ let phase = 0;
14872
+ let frac = 0;
14873
+ for (let b = 0; b < bits.length; b++) {
14874
+ const bit = bits[b];
14875
+ const freq = bit ? markFreq : spaceFreq;
14876
+ const samplesPerBit = sampleRate / baud + frac;
14877
+ const n = Math.round(samplesPerBit);
14878
+ frac = samplesPerBit - n;
14879
+ const inc = twoPi * freq / sampleRate;
14880
+ for (let i = 0; i < n; i++) {
14881
+ result.push(Math.round(Math.sin(phase) * amplitude * 32767));
14882
+ phase += inc;
14883
+ if (phase > twoPi) phase -= twoPi;
14924
14884
  }
14925
14885
  }
14926
- });
14886
+ const fadeSamples = Math.floor(sampleRate * 2e-3);
14887
+ for (let i = 0; i < fadeSamples; i++) {
14888
+ const gain = i / fadeSamples;
14889
+ result[i] = Math.round(result[i] * gain);
14890
+ result[result.length - 1 - i] = Math.round(result[result.length - 1 - i] * gain);
14891
+ }
14892
+ return Int16Array.from(result);
14893
+ };
14927
14894
 
14928
- // src/@modules/@utilities/utilities.getShapeNearestPoint.ts
14929
- var getShapeNearestPoint = (coordinates, point) => {
14930
- if (!coordinates || !point) {
14931
- return { proximity: false, point: [0, 0], distance: null };
14895
+ // src/@modules/@eas/eas.setAsciiToBits.ts
14896
+ var setAsciiToBits = (str) => {
14897
+ const bits = [];
14898
+ for (let i = 0; i < str.length; i++) {
14899
+ const c = str.charCodeAt(i) & 255;
14900
+ bits.push(0);
14901
+ for (let b = 0; b < 8; b++) bits.push(c >> b & 1);
14902
+ bits.push(1, 1);
14932
14903
  }
14933
- const normalize = (coords) => {
14934
- if (!Array.isArray(coords)) return [];
14935
- if (typeof coords[0] === "number" && typeof coords[1] === "number") return [];
14936
- if (Array.isArray(coords[0]) && typeof coords[0][0] === "number") {
14937
- return [[coords]];
14938
- }
14939
- if (Array.isArray(coords[0]) && Array.isArray(coords[0][0]) && typeof coords[0][0][0] === "number") {
14940
- return [coords];
14941
- }
14942
- if (Array.isArray(coords[0]) && Array.isArray(coords[0][0]) && Array.isArray(coords[0][0][0]) && typeof coords[0][0][0][0] === "number") {
14943
- return coords;
14944
- }
14945
- return [];
14946
- };
14947
- const polys = normalize(coordinates);
14948
- if (polys.length === 0) return { proximity: false, point: [0, 0], distance: null };
14949
- const lon = point[0];
14950
- const lat = point[1];
14951
- const pointInRing = (pt, ring) => {
14952
- let x = pt[0], y = pt[1];
14953
- let inside = false;
14954
- for (let i = 0, j2 = ring.length - 1; i < ring.length; j2 = i++) {
14955
- const xi = ring[i][0], yi = ring[i][1];
14956
- const xj = ring[j2][0], yj = ring[j2][1];
14957
- const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi + 0) + xi;
14958
- if (intersect) inside = !inside;
14959
- }
14960
- return inside;
14961
- };
14962
- const toRadians = (deg) => deg * Math.PI / 180;
14963
- const haversineMiles = (a, b) => {
14964
- const R = 3958.8;
14965
- const dLat = toRadians(b[1] - a[1]);
14966
- const dLon = toRadians(b[0] - a[0]);
14967
- const lat1 = toRadians(a[1]);
14968
- const lat2 = toRadians(b[1]);
14969
- const sinDLat = Math.sin(dLat / 2);
14970
- const sinDLon = Math.sin(dLon / 2);
14971
- const c = 2 * Math.asin(Math.sqrt(sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon));
14972
- return R * c;
14973
- };
14974
- let minDistance = Infinity;
14975
- let closestPoint = null;
14976
- for (const poly of polys) {
14977
- const outer = poly[0];
14978
- const holes = poly.slice(1);
14979
- if (pointInRing(point, outer)) {
14980
- let inHole = false;
14981
- for (const hole of holes) {
14982
- if (pointInRing(point, hole)) {
14983
- inHole = true;
14984
- break;
14985
- }
14986
- }
14987
- if (!inHole) {
14988
- return { proximity: true, point, distance: 0 };
14989
- }
14990
- }
14991
- for (const ring of poly) {
14992
- for (let i = 0; i < ring.length - 1; i++) {
14993
- const start = [ring[i][0], ring[i][1]];
14994
- const end = [ring[i + 1][0], ring[i + 1][1]];
14995
- const A = lon - start[0];
14996
- const B = lat - start[1];
14997
- const C = end[0] - start[0];
14998
- const D = end[1] - start[1];
14999
- const lenSq = C * C + D * D;
15000
- const t = lenSq === 0 ? 0 : Math.max(0, Math.min(1, (A * C + B * D) / lenSq));
15001
- const candidate = [start[0] + t * C, start[1] + t * D];
15002
- const dist = haversineMiles([lon, lat], candidate);
15003
- if (!isNaN(dist) && dist < minDistance) {
15004
- minDistance = Number(dist.toFixed(3));
15005
- closestPoint = candidate;
15006
- }
15007
- }
14904
+ return bits;
14905
+ };
14906
+
14907
+ // src/@modules/@eas/eas.getMergedPCM16.ts
14908
+ var getMergedPCM16 = (arrays) => {
14909
+ let total = 0;
14910
+ for (const a of arrays) total += a.length;
14911
+ const out = new Int16Array(total);
14912
+ let o = 0;
14913
+ for (const a of arrays) {
14914
+ out.set(a, o);
14915
+ o += a.length;
14916
+ }
14917
+ return out;
14918
+ };
14919
+
14920
+ // src/@modules/@eas/eas.setSameHeader.ts
14921
+ var setSameHeader = (vtec2, repeats, sampleRate = 8e3, options = {}) => {
14922
+ var _a, _b;
14923
+ const preMarkSec = (_a = options.preMarkSec) != null ? _a : 0.3;
14924
+ const gapSec = (_b = options.gapSec) != null ? _b : 0.1;
14925
+ const bursts = [];
14926
+ const gap = new Int16Array(Math.floor(gapSec * sampleRate));
14927
+ for (let i = 0; i < repeats; i++) {
14928
+ const bodyBits = setAsciiToBits(vtec2);
14929
+ const body = setAFSK(bodyBits, sampleRate);
14930
+ const extendedBodyDuration = Math.round(preMarkSec * sampleRate);
14931
+ const extendedBody = new Int16Array(extendedBodyDuration + gap.length);
14932
+ for (let j2 = 0; j2 < extendedBodyDuration; j2++) {
14933
+ extendedBody[j2] = Math.round(body[j2 % body.length] * 0.2);
15008
14934
  }
14935
+ extendedBody.set(gap, extendedBodyDuration);
14936
+ bursts.push(extendedBody);
14937
+ if (i !== repeats - 1) bursts.push(gap);
15009
14938
  }
15010
- if (!isFinite(minDistance) || closestPoint == null) {
15011
- return { proximity: false, point: [0, 0], distance: null };
14939
+ return getMergedPCM16(bursts);
14940
+ };
14941
+
14942
+ // src/@modules/@eas/eas.setAttentionTone.ts
14943
+ var setAttentionTone = (ms, sampleRate) => {
14944
+ const len = Math.floor(ms * sampleRate);
14945
+ const out = new Int16Array(len);
14946
+ const f1 = 853;
14947
+ const f2 = 960;
14948
+ const twoPi = Math.PI * 2;
14949
+ const amp = 0.1;
14950
+ const fadeLen = Math.floor(sampleRate * 0);
14951
+ for (let i = 0; i < len; i++) {
14952
+ const t = i / sampleRate;
14953
+ const s = Math.sin(twoPi * f1 * t) + Math.sin(twoPi * f2 * t);
14954
+ let gain = 1;
14955
+ if (i < fadeLen) gain = i / fadeLen;
14956
+ else if (i > len - fadeLen) gain = (len - i) / fadeLen;
14957
+ const v = Math.max(-1, Math.min(1, s / 2 * amp * gain));
14958
+ out[i] = Math.round(v * 32767);
15012
14959
  }
15013
- const distanceMiles = minDistance;
15014
- const distanceKm = Number((distanceMiles * 1.609344).toFixed(3));
15015
- const distanceMeters = Math.round(distanceKm * 1e3);
15016
- return { proximity: distanceMiles === 0, point: closestPoint, distance: distanceMiles, distanceKm, distanceMeters };
14960
+ return out;
15017
14961
  };
15018
14962
 
15019
- // src/@building/building.polygon.ts
15020
- var getEventNodes = (event) => __async(null, null, function* () {
15021
- var _a, _b;
15022
- const metadata = { nodes: [], proximity: false, filtered: false };
15023
- const geometry = yield getEventGeometry(event);
15024
- if (!geometry || !geometry.coordinates) {
15025
- return { nodes: [], filtered: false, updated: Date.now() };
14963
+ // src/@modules/@eas/eas.setNoise.ts
14964
+ var setNoise = (int16, noiseLevel = 0.02) => {
14965
+ const x = getPCMToFloat(int16);
14966
+ for (let i = 0; i < x.length; i++) x[i] += (Math.random() * 2 - 1) * noiseLevel;
14967
+ let peak = 0;
14968
+ for (let i = 0; i < x.length; i++) peak = Math.max(peak, Math.abs(x[i]));
14969
+ if (peak > 1) for (let i = 0; i < x.length; i++) x[i] *= 0.98 / peak;
14970
+ return getFloatPCM16(x);
14971
+ };
14972
+
14973
+ // src/@modules/@eas/eas.getPCM16.ts
14974
+ var getPCM16 = (samples, sampleRate) => {
14975
+ let o = 0;
14976
+ const bytesPerSample = 2;
14977
+ const blockAlign = 1 * bytesPerSample;
14978
+ const byteRate = sampleRate * blockAlign;
14979
+ const subchunk2Size = samples.length * bytesPerSample;
14980
+ const chunkSize = 36 + subchunk2Size;
14981
+ const buffer = Buffer.alloc(44 + subchunk2Size);
14982
+ buffer.write("RIFF", o);
14983
+ o += 4;
14984
+ buffer.writeUInt32LE(chunkSize, o);
14985
+ o += 4;
14986
+ buffer.write("WAVE", o);
14987
+ o += 4;
14988
+ buffer.write("fmt ", o);
14989
+ o += 4;
14990
+ buffer.writeUInt32LE(16, o);
14991
+ o += 4;
14992
+ buffer.writeUInt16LE(1, o);
14993
+ o += 2;
14994
+ buffer.writeUInt16LE(1, o);
14995
+ o += 2;
14996
+ buffer.writeUInt32LE(sampleRate, o);
14997
+ o += 4;
14998
+ buffer.writeUInt32LE(byteRate, o);
14999
+ o += 4;
15000
+ buffer.writeUInt16LE(blockAlign, o);
15001
+ o += 2;
15002
+ buffer.writeUInt16LE(16, o);
15003
+ o += 2;
15004
+ buffer.write("data", o);
15005
+ o += 4;
15006
+ buffer.writeUInt32LE(subchunk2Size, o);
15007
+ o += 4;
15008
+ for (let i = 0; i < samples.length; i++, o += 2) {
15009
+ buffer.writeInt16LE(samples[i].value, o);
15026
15010
  }
15027
- const nodes = bootstrap.cache.nodes.features;
15028
- for (const node of nodes) {
15029
- const [longitude, latitude] = node.geometry.coordinates;
15030
- const getPoint = getShapeNearestPoint(geometry.coordinates, [longitude, latitude]);
15031
- const miles = (_a = getPoint.distance) != null ? _a : null;
15032
- const kilometers = Number((miles * 1.609344).toFixed(3));
15033
- const info = {
15034
- id: (_b = node.properties) == null ? void 0 : _b.identifier,
15035
- coordinates: [longitude, latitude],
15036
- nearest: getPoint.point,
15037
- miles,
15038
- kilometers,
15039
- proximity: getPoint.proximity
15040
- };
15041
- metadata.nodes.push(info);
15042
- if (bootstrap.settings.GlobalSettings.EventFiltering.NodeLocationFiltering && miles < bootstrap.settings.GlobalSettings.NodeMinDistance) {
15043
- metadata.proximity = true;
15044
- info.proximity = true;
15011
+ return buffer;
15012
+ };
15013
+
15014
+ // src/@modules/@eas/eas.getTTS.ts
15015
+ var import_os = require("os");
15016
+ var import_fs = require("fs");
15017
+ var import_child_process = require("child_process");
15018
+ var getTTS = (text2, outputPath) => __async(null, null, function* () {
15019
+ const vPlatform = (0, import_os.platform)();
15020
+ switch (vPlatform) {
15021
+ case "win32": {
15022
+ try {
15023
+ const txtPath = outputPath + ".txt";
15024
+ (0, import_fs.writeFileSync)(txtPath, text2, "utf8");
15025
+ const command = [
15026
+ "Add-Type -AssemblyName System.Speech;",
15027
+ `$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;`,
15028
+ `$text = Get-Content -Raw -LiteralPath '${txtPath}';`,
15029
+ `$speak.SetOutputToWaveFile('${outputPath}');`,
15030
+ `$speak.Speak($text);`,
15031
+ `$speak.Dispose();`
15032
+ ].join(" ");
15033
+ (0, import_child_process.execSync)(`powershell -Command "${command}"`, { stdio: "inherit" });
15034
+ } catch (error) {
15035
+ console.error("Error occurred while generating TTS:", error);
15036
+ }
15037
+ break;
15045
15038
  }
15039
+ case "linux":
15040
+ try {
15041
+ (0, import_child_process.execSync)(`espeak -w "${outputPath}" "${text2.replace(/"/g, '\\"')}"`);
15042
+ } catch (e) {
15043
+ }
15044
+ break;
15045
+ default:
15046
+ break;
15046
15047
  }
15047
- return {
15048
- nodes: metadata.nodes,
15049
- filtered: metadata.proximity,
15050
- updated: Date.now()
15051
- };
15052
15048
  });
15053
15049
 
15054
- // src/@manager/manager.updateNodes.ts
15055
- var updateNode = (selectedEvent) => __async(null, null, function* () {
15056
- const events = bootstrap.cache.events.features;
15057
- const ttl = bootstrap.settings.GlobalSettings.NodeTTL * 1e3;
15058
- let total = 0;
15059
- function update(evt) {
15060
- return __async(this, null, function* () {
15061
- var _a, _b, _c;
15062
- const lastUpdate = (_c = (_b = (_a = evt == null ? void 0 : evt.properties) == null ? void 0 : _a.metadata) == null ? void 0 : _b.updated) != null ? _c : null;
15063
- if (lastUpdate != null && Date.now() - lastUpdate < ttl) {
15064
- return evt;
15065
- }
15066
- const node = yield getEventNodes(evt);
15067
- if (node.nodes.length > 0) {
15068
- total++;
15069
- }
15070
- evt.properties.metadata.nodes = node.nodes;
15071
- evt.properties.metadata.filtered_proximity = node.filtered;
15072
- evt.properties.metadata.updated = node.updated;
15050
+ // src/@modules/@eas/eas.getCleanDescription.ts
15051
+ var getCleanDescription = (message) => {
15052
+ const patches = [
15053
+ { regex: /\.{3,}/g, replacement: ". " },
15054
+ { regex: /\bUTC\b/g, replacement: "Coordinated Universal Time" },
15055
+ { regex: /\bGMT\b/g, replacement: "Greenwich Mean Time" },
15056
+ { regex: /\bEST\b(?!\w)/g, replacement: "Eastern Standard Time" },
15057
+ { regex: /\bEDT\b(?!\w)/g, replacement: "Eastern Daylight Time" },
15058
+ { regex: /\bCST\b(?!\w)/g, replacement: "Central Standard Time" },
15059
+ { regex: /\bCDT\b(?!\w)/g, replacement: "Central Daylight Time" },
15060
+ { regex: /\bMST\b(?!\w)/g, replacement: "Mountain Standard Time" },
15061
+ { regex: /\bMDT\b(?!\w)/g, replacement: "Mountain Daylight Time" },
15062
+ { regex: /\bPST\b(?!\w)/g, replacement: "Pacific Standard Time" },
15063
+ { regex: /\bPDT\b(?!\w)/g, replacement: "Pacific Daylight Time" },
15064
+ { regex: /\bAKST\b(?!\w)/g, replacement: "Alaska Standard Time" },
15065
+ { regex: /\bAKDT\b(?!\w)/g, replacement: "Alaska Daylight Time" },
15066
+ { regex: /\bHST\b(?!\w)/g, replacement: "Hawaii Standard Time" },
15067
+ { regex: /\bHDT\b(?!\w)/g, replacement: "Hawaii Daylight Time" },
15068
+ { regex: /\bmph\b(?!\w)/g, replacement: "miles per hour" },
15069
+ { regex: /\bkm\/h\b(?!\w)/g, replacement: "kilometers per hour" },
15070
+ { regex: /\bkmh\b(?!\w)/g, replacement: "kilometers per hour" },
15071
+ { regex: /\bkt\b(?!\w)/g, replacement: "knots" },
15072
+ { regex: /\bNE\b(?!\w)/g, replacement: "northeast" },
15073
+ { regex: /\bNW\b(?!\w)/g, replacement: "northwest" },
15074
+ { regex: /\bSE\b(?!\w)/g, replacement: "southeast" },
15075
+ { regex: /\bSW\b(?!\w)/g, replacement: "southwest" },
15076
+ { regex: /\bNM\b(?!\w)/g, replacement: "nautical miles" },
15077
+ { regex: /\bdeg\b(?!\w)/g, replacement: "degrees" },
15078
+ { regex: /\btstm\b(?!\w)/g, replacement: "thunderstorm" },
15079
+ { regex: /\bmm\b(?!\w)/g, replacement: "millimeters" },
15080
+ { regex: /\bcm\b(?!\w)/g, replacement: "centimeters" },
15081
+ { regex: /\bin.\b(?!\w)/g, replacement: "inches" },
15082
+ { regex: /\bft\b(?!\w)/g, replacement: "feet" },
15083
+ { regex: /\bmi\b(?!\w)/g, replacement: "miles" },
15084
+ { regex: /\bhr\b(?!\w)/g, replacement: "hour" },
15085
+ { regex: /\bhourly\b(?!\w)/g, replacement: "per hour" },
15086
+ { regex: /\bkg\b(?!\w)/g, replacement: "kilograms" },
15087
+ { regex: /\bg\/kg\b(?!\w)/g, replacement: "grams per kilogram" },
15088
+ { regex: /\bmb\b(?!\w)/g, replacement: "millibars" },
15089
+ { regex: /\bhPa\b(?!\w)/g, replacement: "hectopascals" },
15090
+ { regex: /\bPa\b(?!\w)/g, replacement: "pascals" },
15091
+ { regex: /\bKPa\b(?!\w)/g, replacement: "kilopascals" },
15092
+ { regex: /\bC\/hr\b(?!\w)/g, replacement: "degrees Celsius per hour" },
15093
+ { regex: /\bF\/hr\b(?!\w)/g, replacement: "degrees Fahrenheit per hour" },
15094
+ { regex: /\bC\/min\b(?!\w)/g, replacement: "degrees Celsius per minute" },
15095
+ { regex: /\bF\/min\b(?!\w)/g, replacement: "degrees Fahrenheit per minute" },
15096
+ { regex: /\bC\b(?!\w)/g, replacement: "degrees Celsius" },
15097
+ { regex: /\bF\b(?!\w)/g, replacement: "degrees Fahrenheit" }
15098
+ ];
15099
+ const hours = {
15100
+ 0: "twelve",
15101
+ 1: "one",
15102
+ 2: "two",
15103
+ 3: "three",
15104
+ 4: "four",
15105
+ 5: "five",
15106
+ 6: "six",
15107
+ 7: "seven",
15108
+ 8: "eight",
15109
+ 9: "nine",
15110
+ 10: "ten",
15111
+ 11: "eleven",
15112
+ 12: "twelve"
15113
+ };
15114
+ const minWord = (m) => m === 0 ? "o'clock" : m < 10 ? `oh ${m}` : `${m}`;
15115
+ const fmt = (h, m, ap) => `${hours[h % 12]} ${minWord(m)} ${ap}`;
15116
+ for (const { regex, replacement } of patches) {
15117
+ message = message.replace(regex, replacement);
15118
+ }
15119
+ return message.replace(/'/g, "''").replace(/\b(\d{1,2}):(\d{2})\s*(AM|PM)\b/gi, (_, h, m, ap) => fmt(+h, +m, ap.toUpperCase())).replace(/\b(\d{1,2})\s+(\d{2})\s+(AM|PM)\b/gi, (_, h, m, ap) => fmt(+h, +m, ap.toUpperCase())).replace(/\b(\d{2})(\d{2})\s+(AM|PM)\b/gi, (_, hh, mm, ap) => fmt(+hh, +mm, ap.toUpperCase())).replace(/\b(\d{1,2})\s+(AM|PM)\b/gi, (_, h, ap) => fmt(+h, 0, ap.toUpperCase())).replace(/\*+/g, " ").replace(/-/g, " ").replace(/\n/g, " ").trim();
15120
+ };
15121
+
15122
+ // src/@modules/@eas/eas.setEasTone.ts
15123
+ var import_path2 = require("path");
15124
+ var import_fs2 = require("fs");
15125
+ var import_child_process2 = require("child_process");
15126
+ var import_os2 = require("os");
15127
+ var setEasTone = (options) => __async(null, null, function* () {
15128
+ var _a;
15129
+ const settings = bootstrap.settings;
15130
+ const directory = settings.GlobalSettings.ArchiveSettings.EasDirectory;
15131
+ const prefix = settings.GlobalSettings.ArchiveSettings.EasToneout;
15132
+ let message = options.message;
15133
+ let header = options.header;
15134
+ let title = (_a = options.title) != null ? _a : `${Math.random().toString(36).substring(2, 15)}-${header.replace(/[^a-zA-Z0-9]/g, "")}`;
15135
+ if (!message || !header) {
15136
+ setWarning({
15137
+ title: `EAS`,
15138
+ message: `Message and header are required to generate an EAS tone.`
15073
15139
  });
15140
+ return null;
15074
15141
  }
15075
- if (!selectedEvent) {
15076
- yield Promise.all(events.map((evt) => __async(null, null, function* () {
15077
- yield update(evt);
15078
- })));
15142
+ let buffTTS;
15143
+ let buffRadio;
15144
+ let buffFull = [];
15145
+ if (!(0, import_fs2.existsSync)(directory)) {
15146
+ (0, import_fs2.mkdirSync)(directory, { recursive: true });
15079
15147
  }
15080
- if (selectedEvent) {
15081
- yield update(selectedEvent);
15148
+ if (!(0, import_fs2.existsSync)((0, import_path2.join)(directory, `/tts`))) {
15149
+ (0, import_fs2.mkdirSync)((0, import_path2.join)(directory, `/tts`), { recursive: true });
15082
15150
  }
15083
- if (total > 0) {
15084
- setEventEmit({
15085
- event: `onNodeUpdate`,
15086
- metadata: {
15087
- type: `global-update`,
15088
- updated: total
15089
- }
15151
+ if (!(0, import_fs2.existsSync)((0, import_path2.join)(directory, `/encoded`))) {
15152
+ (0, import_fs2.mkdirSync)((0, import_path2.join)(directory, `/encoded`), { recursive: true });
15153
+ }
15154
+ const tmpTTS = (0, import_path2.join)(directory, `/tts/${title}.wav`);
15155
+ const outTTS = (0, import_path2.join)(directory, `/encoded/${title}.wav`);
15156
+ const vPlatform = (0, import_os2.platform)();
15157
+ if (vPlatform === "darwin") {
15158
+ setWarning({
15159
+ title: `EAS`,
15160
+ message: `EAS tone generation is not supported on macOS.`
15090
15161
  });
15162
+ return null;
15091
15163
  }
15092
- });
15093
-
15094
- // src/@manager/manager.mkEvent.ts
15095
- var mkEvent = (event) => __async(null, null, function* () {
15096
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
15097
- const settings = bootstrap.settings;
15098
- const features = bootstrap.cache.events.features;
15099
- const getHash = event.properties.metadata.hash;
15100
- const getTracking = event.properties.metadata.tracking;
15101
- const isEntry = (_a = bootstrap.cache.hashes) == null ? void 0 : _a.find((hash) => hash.tracking === getTracking);
15102
- const isHashed = (_c = (_b = isEntry == null ? void 0 : isEntry.hashes) == null ? void 0 : _b.includes(getHash)) != null ? _c : false;
15103
- const getFeature = features.find((feature) => feature.properties.metadata.tracking === getTracking);
15104
- if (isHashed || event.properties.status_metadata.is_expired) return;
15105
- setHash(event, isEntry);
15106
- const isFilteredLocation = yield updateNode(event).then(() => event.properties.metadata.filtered_proximity);
15107
- if (!isFilteredLocation && settings.GlobalSettings.EventFiltering.NodeLocationFiltering) {
15108
- return;
15109
- }
15110
- setEventEmit({
15111
- event: `onEventStatus`,
15112
- metadata: {
15113
- type: getFeature ? `Updated` : `New`,
15114
- event
15115
- },
15116
- message: `[${getFeature ? "Updated" : "New"}] ${event.properties.event} (${event.properties.status}) (${event.properties.metadata.tracking})`
15164
+ yield new Promise((resolve6, reject) => {
15165
+ const tMsg = getCleanDescription(message);
15166
+ getTTS(tMsg, tmpTTS).then(() => {
15167
+ resolve6();
15168
+ });
15117
15169
  });
15118
- if (settings.GlobalSettings.EventManagement) {
15119
- if (event.properties.status_metadata.is_issued || event.properties.status_metadata.is_updated) {
15120
- if (getFeature) {
15121
- const getIndex = features.indexOf(getFeature);
15122
- const cHistory = (_f = (_e = (_d = getFeature == null ? void 0 : getFeature.properties) == null ? void 0 : _d.metadata) == null ? void 0 : _e.history) != null ? _f : [];
15123
- const cLocations = (_i = (_h = (_g = getFeature == null ? void 0 : getFeature.properties) == null ? void 0 : _g.locations) == null ? void 0 : _h.split(";").map((l) => l.trim())) != null ? _i : [];
15124
- const cUgc = (_l = (_k = (_j = getFeature == null ? void 0 : getFeature.properties) == null ? void 0 : _j.geocode) == null ? void 0 : _k.ugc) != null ? _l : [];
15125
- const iHistory = (_o = (_n = (_m = event.properties) == null ? void 0 : _m.metadata) == null ? void 0 : _n.history) != null ? _o : [];
15126
- const iLocations = (_r = (_q = (_p = event.properties) == null ? void 0 : _p.locations) == null ? void 0 : _q.split(";").map((l) => l.trim())) != null ? _r : [];
15127
- const iUgc = (_u = (_t = (_s = event.properties) == null ? void 0 : _s.geocode) == null ? void 0 : _t.ugc) != null ? _u : [];
15128
- const mHistory = [...cHistory, ...iHistory].filter((v, i, a) => a.indexOf(v) === i).filter((v, i, a) => a.findIndex((h) => h.description === v.description && h.issued === v.issued) === i);
15129
- const mLocations = [...cLocations, ...iLocations].filter((v, i, a) => a.indexOf(v) === i).join("; ");
15130
- const mUgc = [...cUgc, ...iUgc].filter((v, i, a) => a.indexOf(v) === i);
15131
- bootstrap.cache.events.features[getIndex] = __spreadProps(__spreadValues({}, event), {
15132
- properties: __spreadProps(__spreadValues({}, event.properties), {
15133
- metadata: __spreadProps(__spreadValues({}, (_v = event == null ? void 0 : event.properties) == null ? void 0 : _v.metadata), {
15134
- history: mHistory
15135
- }),
15136
- locations: mLocations,
15137
- geocode: __spreadProps(__spreadValues({}, (_w = event == null ? void 0 : event.properties) == null ? void 0 : _w.geocode), {
15138
- ugc: mUgc
15139
- })
15140
- })
15141
- });
15142
- updateWebhooks(bootstrap.cache.events.features[getIndex]);
15143
- } else {
15144
- features.push(event);
15145
- updateWebhooks(event);
15170
+ if (!(0, import_fs2.existsSync)(tmpTTS)) {
15171
+ return null;
15172
+ }
15173
+ buffTTS = (0, import_fs2.readFileSync)(tmpTTS);
15174
+ const vWav = getWavPCM16(buffTTS);
15175
+ const vSamples = getSampledPCM16(vWav.samples, vWav.sampleRate, 8e3);
15176
+ const vRadio = setRadioEffect(vSamples, 8e3);
15177
+ if ((0, import_fs2.existsSync)(prefix)) {
15178
+ let tBuffer = (0, import_fs2.readFileSync)(prefix);
15179
+ let tWav = getWavPCM16(tBuffer);
15180
+ if (tWav == null) {
15181
+ try {
15182
+ const converted = (0, import_path2.join)(directory, `/tts/${title}.converted.wav`);
15183
+ (0, import_child_process2.execSync)(`ffmpeg -y -i "${prefix}" -ar 8000 -ac 1 -sample_fmt s16 "${converted}"`, { stdio: "ignore" });
15184
+ if ((0, import_fs2.existsSync)(converted)) {
15185
+ tBuffer = (0, import_fs2.readFileSync)(converted);
15186
+ tWav = getWavPCM16(tBuffer);
15187
+ try {
15188
+ (0, import_fs2.unlinkSync)(converted);
15189
+ } catch (e) {
15190
+ }
15191
+ }
15192
+ } catch (e) {
15146
15193
  }
15147
15194
  }
15195
+ if (tWav == null) {
15196
+ setWarning({ title: `EAS`, message: `Intro tone isn't a valid .WAV file or isn't in PCM 16-bit format. Converted attempt failed; please convert it then try again.` });
15197
+ return null;
15198
+ }
15199
+ const tSamples = tWav.sampleRate != 8e3 ? getSampledPCM16(tWav.samples, tWav.sampleRate, 8e3) : tWav.samples;
15200
+ buffRadio = setRadioEffect(tSamples, 8e3);
15201
+ }
15202
+ buffFull = buffRadio != null ? [buffRadio, new Int16Array(Math.floor(0.5 * 8e3))] : [];
15203
+ buffFull.push(
15204
+ setSameHeader(header, 3, 8e3, {
15205
+ preMarkSec: 1.1,
15206
+ gapSec: 0.5
15207
+ }),
15208
+ new Int16Array(Math.floor(0.5 * 8e3)),
15209
+ setAttentionTone(8, 8e3),
15210
+ new Int16Array(Math.floor(0.5 * 8e3)),
15211
+ vRadio
15212
+ );
15213
+ for (let i = 0; i < 3; i++) {
15214
+ buffFull.push(setSameHeader(header, 1, 8e3, { preMarkSec: 0.5, gapSec: 0.1 }));
15215
+ buffFull.push(new Int16Array(Math.floor(0.5 * 8e3)));
15216
+ }
15217
+ const aSamples = getMergedPCM16(buffFull);
15218
+ const aFinal = setNoise(aSamples, 2e-3);
15219
+ const aBuffer = getPCM16(Array.from(aFinal).map((v) => ({ value: v })), 8e3);
15220
+ (0, import_fs2.writeFileSync)(outTTS, aBuffer);
15221
+ try {
15222
+ (0, import_fs2.unlinkSync)(tmpTTS);
15223
+ } catch (e) {
15148
15224
  }
15225
+ return outTTS;
15149
15226
  });
15150
15227
 
15151
- // src/@manager/manager.rmEvent.ts
15152
- var rmEvent = (event) => {
15153
- const getEvent = bootstrap.cache.events.features.find((f) => {
15154
- var _a, _b, _c, _d;
15155
- return ((_b = (_a = f == null ? void 0 : f.properties) == null ? void 0 : _a.metadata) == null ? void 0 : _b.tracking) === ((_d = (_c = event == null ? void 0 : event.properties) == null ? void 0 : _c.metadata) == null ? void 0 : _d.tracking);
15156
- });
15157
- const cachedStatus = event.properties.status;
15158
- event.properties.expires = (/* @__PURE__ */ new Date()).toISOString();
15159
- event.properties.status = `Expired`;
15160
- if (getEvent) {
15161
- setEventEmit({
15162
- event: `onEventStatus`,
15163
- metadata: {
15164
- type: `Removed`,
15165
- event
15166
- },
15167
- message: `[Removed] ${event.properties.event} (${event.properties.status}) (${event.properties.metadata.tracking})`
15168
- });
15169
- setEventEmit({ event: `onExpiredProduct`, metadata: event });
15170
- if (cachedStatus != `Statement`) updateWebhooks(event);
15171
- bootstrap.cache.events.features.splice(bootstrap.cache.events.features.indexOf(getEvent), 1);
15172
- bootstrap.cache.hashes = bootstrap.cache.hashes.filter((hash) => hash.tracking !== event.properties.metadata.tracking);
15173
- }
15174
- setEventEmit({
15175
- event: `onEventCache`,
15176
- metadata: bootstrap.cache.events,
15177
- limited: true
15178
- });
15228
+ // src/@parsers/@text/text.getEmbed.ts
15229
+ var getEmebed = (event) => {
15230
+ 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, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua;
15231
+ const line = (label, value, condition = true) => condition && value ? `${label} ${value}` : null;
15232
+ const isStatement = event.properties.status_metadata.is_statement;
15233
+ const isExpired = event.properties.status_metadata.is_expired;
15234
+ return [
15235
+ line(`**Locations:**`, (_b = (_a = event == null ? void 0 : event.properties) == null ? void 0 : _a.locations) == null ? void 0 : _b.slice(0, 100)),
15236
+ line(`**Issued:**`, `<t:${Math.floor(new Date(event.properties.issued).getTime() / 1e3)}:R>`, !isExpired),
15237
+ line(`**Expires:**`, `<t:${Math.floor(new Date(event.properties.expires).getTime() / 1e3)}:R>`, !isStatement),
15238
+ line(`**Damage Threat:**`, (_d = (_c = event == null ? void 0 : event.properties) == null ? void 0 : _c.parameters) == null ? void 0 : _d.damage_threat, !isExpired),
15239
+ line(`**Flood Threat:**`, (_f = (_e = event == null ? void 0 : event.properties) == null ? void 0 : _e.parameters) == null ? void 0 : _f.flood_threat, !isExpired),
15240
+ line(`**Tornado Threat:**`, (_h = (_g = event == null ? void 0 : event.properties) == null ? void 0 : _g.parameters) == null ? void 0 : _h.tornado_threat, !isExpired),
15241
+ line(`**Estimated Wind Gusts:**`, `${(_j = (_i = event == null ? void 0 : event.properties) == null ? void 0 : _i.parameters) == null ? void 0 : _j.estimated_wind_gusts} ${((_l = (_k = event == null ? void 0 : event.properties) == null ? void 0 : _k.parameters) == null ? void 0 : _l.wind_threat) ? ` (${(_n = (_m = event == null ? void 0 : event.properties) == null ? void 0 : _m.parameters) == null ? void 0 : _n.wind_threat})` : ""}`, !isExpired && ((_p = (_o = event == null ? void 0 : event.properties) == null ? void 0 : _o.parameters) == null ? void 0 : _p.estimated_wind_gusts) != null),
15242
+ line(`**Estimated Hail Size:**`, `${(_r = (_q = event == null ? void 0 : event.properties) == null ? void 0 : _q.parameters) == null ? void 0 : _r.estimated_hail_size} ${((_t = (_s = event == null ? void 0 : event.properties) == null ? void 0 : _s.parameters) == null ? void 0 : _t.hail_threat) ? ` (${(_v = (_u = event == null ? void 0 : event.properties) == null ? void 0 : _u.parameters) == null ? void 0 : _v.hail_threat})` : ""}`, !isExpired && ((_x = (_w = event == null ? void 0 : event.properties) == null ? void 0 : _w.parameters) == null ? void 0 : _x.estimated_hail_size) != null),
15243
+ line(`**Discussion:**`, (_z = (_y = event == null ? void 0 : event.properties) == null ? void 0 : _y.discussion_parameters) == null ? void 0 : _z.discussion_number, !isExpired),
15244
+ line(`**Concern:**`, (_B = (_A = event == null ? void 0 : event.properties) == null ? void 0 : _A.discussion_parameters) == null ? void 0 : _B.discussion_concerning, !isExpired),
15245
+ line(`**SPC Max Tornado Threat:**`, (_D = (_C = event == null ? void 0 : event.properties) == null ? void 0 : _C.discussion_parameters) == null ? void 0 : _D.discussion_max_tornado, !isExpired),
15246
+ line(`**SPC Max Hail Threat:**`, (_F = (_E = event == null ? void 0 : event.properties) == null ? void 0 : _E.discussion_parameters) == null ? void 0 : _F.discussion_max_hail, !isExpired),
15247
+ line(`**SPC Max Wind Threat:**`, (_H = (_G = event == null ? void 0 : event.properties) == null ? void 0 : _G.discussion_parameters) == null ? void 0 : _H.discussion_max_wind, !isExpired),
15248
+ line(`**SPC Watch Issuance Probability:**`, ((_J = (_I = event == null ? void 0 : event.properties) == null ? void 0 : _I.discussion_parameters) == null ? void 0 : _J.discussion_watch_issuance) ? `${(_L = (_K = event == null ? void 0 : event.properties) == null ? void 0 : _K.discussion_parameters) == null ? void 0 : _L.discussion_watch_issuance}%` : null, !isExpired),
15249
+ line(`**Watch Number:**`, (_N = (_M = event == null ? void 0 : event.properties) == null ? void 0 : _M.watch_parameters) == null ? void 0 : _N.watch_number, !isExpired),
15250
+ line(`**Strong Tornadoes Probability:**`, ((_P = (_O = event == null ? void 0 : event.properties) == null ? void 0 : _O.watch_parameters) == null ? void 0 : _P.strong_tornadoes_probability) ? `${(_R = (_Q = event == null ? void 0 : event.properties) == null ? void 0 : _Q.watch_parameters) == null ? void 0 : _R.strong_tornadoes_probability}%` : null, !isExpired),
15251
+ line(`**Additional Tornadoes Probability:**`, ((_T = (_S = event == null ? void 0 : event.properties) == null ? void 0 : _S.watch_parameters) == null ? void 0 : _T.additional_tornadoes_probability) ? `${(_V = (_U = event == null ? void 0 : event.properties) == null ? void 0 : _U.watch_parameters) == null ? void 0 : _V.additional_tornadoes_probability}%` : null, !isExpired),
15252
+ line(`**Combined Hail/Wind Probability:**`, ((_X = (_W = event == null ? void 0 : event.properties) == null ? void 0 : _W.watch_parameters) == null ? void 0 : _X.combined_hail_wind_probability) ? `${(_Z = (_Y = event == null ? void 0 : event.properties) == null ? void 0 : _Y.watch_parameters) == null ? void 0 : _Z.combined_hail_wind_probability}%` : null, !isExpired),
15253
+ line(`**Severe Hail Probability:**`, ((_$ = (__ = event == null ? void 0 : event.properties) == null ? void 0 : __.watch_parameters) == null ? void 0 : _$.severe_hail_probability) ? `${(_ba = (_aa = event == null ? void 0 : event.properties) == null ? void 0 : _aa.watch_parameters) == null ? void 0 : _ba.severe_hail_probability}%` : null, !isExpired),
15254
+ line(`**Hail >2in Probability:**`, ((_da = (_ca = event == null ? void 0 : event.properties) == null ? void 0 : _ca.watch_parameters) == null ? void 0 : _da.hail_2in_probability) ? `${(_fa = (_ea = event == null ? void 0 : event.properties) == null ? void 0 : _ea.watch_parameters) == null ? void 0 : _fa.hail_2in_probability}%` : null, !isExpired),
15255
+ line(`**Max Hail Inches:**`, (_ha = (_ga = event == null ? void 0 : event.properties) == null ? void 0 : _ga.watch_parameters) == null ? void 0 : _ha.max_hail_in, !isExpired),
15256
+ line(`**Severe Wind Probability:**`, ((_ja = (_ia = event == null ? void 0 : event.properties) == null ? void 0 : _ia.watch_parameters) == null ? void 0 : _ja.severe_wind_probability) ? `${(_la = (_ka = event == null ? void 0 : event.properties) == null ? void 0 : _ka.watch_parameters) == null ? void 0 : _la.severe_wind_probability}%` : null, !isExpired),
15257
+ line(`**Max Surface Wind:**`, (_na = (_ma = event == null ? void 0 : event.properties) == null ? void 0 : _ma.watch_parameters) == null ? void 0 : _na.max_wind_surface, !isExpired),
15258
+ line(`**Max Tops (x100 feet):**`, (_pa = (_oa = event == null ? void 0 : event.properties) == null ? void 0 : _oa.watch_parameters) == null ? void 0 : _pa.max_tops_x100feet, !isExpired),
15259
+ line(`**Tags:**`, ((_sa = (_ra = (_qa = event == null ? void 0 : event.properties) == null ? void 0 : _qa.parameters) == null ? void 0 : _ra.tags) == null ? void 0 : _sa.length) > 0 ? (_ua = (_ta = event == null ? void 0 : event.properties) == null ? void 0 : _ta.parameters) == null ? void 0 : _ua.tags.join(", ") : null, !isExpired),
15260
+ line(`**Sender:**`, ((_xa = (_wa = (_va = event == null ? void 0 : event.properties) == null ? void 0 : _va.geocode) == null ? void 0 : _wa.office) == null ? void 0 : _xa.name) ? `${(_Aa = (_za = (_ya = event == null ? void 0 : event.properties) == null ? void 0 : _ya.geocode) == null ? void 0 : _za.office) == null ? void 0 : _Aa.name} (${(_Da = (_Ca = (_Ba = event == null ? void 0 : event.properties) == null ? void 0 : _Ba.geocode) == null ? void 0 : _Ca.office) == null ? void 0 : _Da.office})` : (_Ga = (_Fa = (_Ea = event == null ? void 0 : event.properties) == null ? void 0 : _Ea.geocode) == null ? void 0 : _Fa.office) == null ? void 0 : _Ga.office),
15261
+ line(`**Tracking:**`, (_Ia = (_Ha = event == null ? void 0 : event.properties) == null ? void 0 : _Ha.metadata) == null ? void 0 : _Ia.tracking),
15262
+ line(`**Logs:**`, ((_La = (_Ka = (_Ja = event == null ? void 0 : event.properties) == null ? void 0 : _Ja.metadata) == null ? void 0 : _Ka.history) == null ? void 0 : _La.length) > 0 ? (_Na = (_Ma = event == null ? void 0 : event.properties) == null ? void 0 : _Ma.metadata) == null ? void 0 : _Na.history.length : null),
15263
+ line(``, ((_Qa = (_Pa = (_Oa = event == null ? void 0 : event.properties) == null ? void 0 : _Oa.metadata) == null ? void 0 : _Pa.attachments) == null ? void 0 : _Qa.length) > 0 ? `**Attachments:** ${(_Sa = (_Ra = event == null ? void 0 : event.properties) == null ? void 0 : _Ra.metadata) == null ? void 0 : _Sa.attachments.map((attachment) => {
15264
+ var _a2, _b2;
15265
+ return `[Attachment #${((_b2 = (_a2 = event == null ? void 0 : event.properties) == null ? void 0 : _a2.metadata) == null ? void 0 : _b2.attachments.indexOf(attachment)) + 1}](${attachment})`;
15266
+ }).join(" | ")}` : null),
15267
+ line(``, ((_Ta = event == null ? void 0 : event.properties) == null ? void 0 : _Ta.description) ? "```\n" + ((_Ua = event == null ? void 0 : event.properties) == null ? void 0 : _Ua.description.split("\n").map((l) => l.trim()).filter(Boolean).join("\n")) + "\n```" : null, !isExpired)
15268
+ ].filter(Boolean).join("\n");
15179
15269
  };
15180
15270
 
15181
- // src/@building/building.validate.ts
15182
- var validateEvents = (events) => __async(null, null, function* () {
15183
- var _a;
15184
- if (events.length === 0) return;
15185
- const configurations = bootstrap.settings;
15186
- const sets = {};
15187
- const bools = {};
15188
- const megered = __spreadValues(__spreadValues({}, configurations.GlobalSettings), configurations.GlobalSettings.EventFiltering);
15189
- for (const key in megered) {
15190
- const setting = megered[key];
15191
- if (Array.isArray(setting)) {
15192
- sets[key] = new Set(setting.map((item) => item.toLowerCase()));
15193
- }
15194
- if (typeof setting === "boolean") {
15195
- bools[key] = setting;
15196
- }
15197
- }
15198
- const filterd = events.filter((event) => {
15199
- var _a2, _b, _c, _d, _e;
15200
- const define2 = getEventSignature(event);
15201
- const properties2 = define2.properties;
15202
- const zones = properties2.geocode.ugc;
15203
- const icao = properties2.geocode.office.office;
15204
- const enhancedEventName = properties2.event = getEventEnhancedName(event);
15205
- const filteredProperties = JSON.parse(JSON.stringify(properties2));
15206
- if ((filteredProperties == null ? void 0 : filteredProperties.metadata) && "ms" in filteredProperties.metadata) {
15207
- delete filteredProperties.metadata.ms;
15208
- }
15209
- filteredProperties.metadata = (_a2 = filteredProperties.metadata) != null ? _a2 : {};
15210
- properties2.metadata.hash = (0, import_crypto.createHash)("sha256").update(JSON.stringify(filteredProperties)).digest("hex");
15211
- setEventEmit({ event: `onProductType${enhancedEventName.replace(/\s+/g, "")}`, metadata: define2 });
15212
- if (properties2.status_metadata.is_test) {
15213
- setEventEmit({ event: `onTestProduct`, metadata: define2 });
15214
- if (bools == null ? void 0 : bools.IgnoreTestProducts) return false;
15215
- }
15216
- if (properties2.status_metadata.is_expired) {
15217
- setEventEmit({ event: `onExpiredProduct`, metadata: define2 });
15218
- rmEvent(define2);
15219
- return false;
15220
- }
15221
- if ((_c = (_b = properties2.metadata) == null ? void 0 : _b.vtec) == null ? void 0 : _c.is_watch) {
15222
- const isSPC = (_e = (_d = properties2.metadata) == null ? void 0 : _d.vtec) == null ? void 0 : _e.prediction_center;
15223
- setEventEmit({ event: isSPC ? `onStormPredictionWatch` : `onNonStormPredictionWatch`, metadata: define2 });
15224
- if ((bools == null ? void 0 : bools.SPCWatchesOnly) && !isSPC) {
15225
- return false;
15226
- }
15227
- if (!(bools == null ? void 0 : bools.SPCWatchesOnly) && isSPC) {
15228
- return false;
15229
- }
15271
+ // src/@modules/@utilities/utilities.createHttp.ts
15272
+ var import_request = __toESM(require("request"));
15273
+ var createHttp = (options) => __async(null, null, function* () {
15274
+ return new Promise((resolve6, reject) => {
15275
+ var _a, _b, _c, _d, _e;
15276
+ const requestOptions = {
15277
+ url: (_a = options.url) != null ? _a : `https://api.weather.gov/alerts/active`,
15278
+ headers: (_b = options.headers) != null ? _b : {
15279
+ "User-Agent": "AtmosphericX",
15280
+ "Accept": "application/geo+json, text/plain, */*; q=0.9",
15281
+ "Accept-Language": "en-US,en;q=0.9"
15282
+ },
15283
+ method: (_c = options.method) != null ? _c : `GET`,
15284
+ timeout: (_d = options.timeout) != null ? _d : 1e4,
15285
+ proxy: (_e = options.proxy) != null ? _e : null,
15286
+ maxRedirects: 1
15287
+ };
15288
+ if (options.formData) {
15289
+ requestOptions["formData"] = options.formData;
15290
+ } else if (options.body) {
15291
+ requestOptions["body"] = options.body;
15230
15292
  }
15231
- for (const key in sets) {
15232
- const setting = sets[key];
15233
- if (key === "ListeningEvents" && setting.size > 0 && !setting.has(define2.properties.event.toLowerCase())) {
15234
- setEventEmit({
15235
- event: `onFilteredEvent`,
15236
- metadata: define2
15237
- });
15238
- return false;
15239
- }
15240
- if (key === "IgnoredEvents" && setting.size > 0 && setting.has(define2.properties.event.toLowerCase())) {
15241
- setEventEmit({
15242
- event: `onIgnoredEvent`,
15243
- metadata: define2
15293
+ (0, import_request.default)(requestOptions, (error, response2, body) => {
15294
+ var _a2, _b2, _c2, _d2, _e2;
15295
+ if (error) {
15296
+ return resolve6({
15297
+ error: true,
15298
+ options: requestOptions,
15299
+ status: -1,
15300
+ message: (_a2 = error.message) != null ? _a2 : `Unknown Error`
15244
15301
  });
15245
- return false;
15246
15302
  }
15247
- if (key === "ListeningICAO" && setting.size > 0 && icao != null && !setting.has(icao.toLowerCase())) {
15248
- setEventEmit({
15249
- event: `onFilteredICAO`,
15250
- metadata: define2
15303
+ if (response2.statusCode < 200 || response2.statusCode >= 300) {
15304
+ return resolve6({
15305
+ error: true,
15306
+ options: requestOptions,
15307
+ status: (_b2 = response2.statusCode) != null ? _b2 : -1,
15308
+ message: `HTTP Status Code ${(_c2 = response2.statusCode) != null ? _c2 : `Unknown Status Code`} (${body})`
15251
15309
  });
15252
- return false;
15253
15310
  }
15254
- if (key === "IgnoredICAO" && setting.size > 0 && icao != null && setting.has(icao.toLowerCase())) {
15255
- setEventEmit({
15256
- event: `onIgnoredICAO`,
15257
- metadata: define2
15311
+ if (body == void 0 || body == null) {
15312
+ return resolve6({
15313
+ error: true,
15314
+ options: requestOptions,
15315
+ status: (_d2 = response2.statusCode) != null ? _d2 : -1,
15316
+ message: `Empty Response Body`
15258
15317
  });
15259
- return false;
15260
15318
  }
15261
- if (key === "ListeningUGC" && setting.size > 0 && zones.length > 0 && !zones.some((ugc2) => setting.has(ugc2.toLowerCase()))) {
15262
- setEventEmit({
15263
- event: `onFilteredUGC`,
15264
- metadata: define2
15265
- });
15266
- return false;
15319
+ resolve6({
15320
+ error: false,
15321
+ options: requestOptions,
15322
+ status: (_e2 = response2.statusCode) != null ? _e2 : -1,
15323
+ message: body
15324
+ });
15325
+ });
15326
+ });
15327
+ });
15328
+
15329
+ // src/@manager/manager.updateListener.ts
15330
+ var import_fs3 = require("fs");
15331
+ var import_form_data = __toESM(require_form_data());
15332
+ var updateListener = (event) => __async(null, null, function* () {
15333
+ var _a, _b, _c, _d;
15334
+ const settings = bootstrap.settings;
15335
+ const listeners2 = settings.ListenerSettings;
15336
+ const properties2 = event.properties;
15337
+ for (const socket of listeners2) {
15338
+ const events = socket.events;
15339
+ const sWebhook = socket == null ? void 0 : socket.webhook;
15340
+ const sUploads = socket == null ? void 0 : socket.uploads;
15341
+ const matched = events.some((pattern) => {
15342
+ if (!pattern) return false;
15343
+ if (pattern === "*" || pattern === properties2.event) return true;
15344
+ if (pattern.includes("*")) {
15345
+ const regex = "^" + pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*") + "$";
15346
+ return new RegExp(regex).test(properties2.event);
15267
15347
  }
15268
- if (key === "ListeningStates" && setting.size > 0 && zones.length > 0 && !zones.some((ugc2) => setting.has(ugc2.substring(0, 2).toLowerCase()))) {
15269
- setEventEmit({
15270
- event: `onFilteredState`,
15271
- metadata: define2
15348
+ return false;
15349
+ });
15350
+ if ((events == null ? void 0 : events.length) == 0 || matched) {
15351
+ let eas;
15352
+ let file;
15353
+ if (sUploads == null ? void 0 : sUploads.eas) {
15354
+ eas = yield setEasTone({
15355
+ title: `${properties2.event}_${properties2.status}_${properties2.metadata.tracking}`,
15356
+ message: properties2.description,
15357
+ header: properties2.metadata.header
15272
15358
  });
15273
- return false;
15274
15359
  }
15275
- }
15276
- return true;
15277
- });
15278
- if (!((_a = configurations == null ? void 0 : configurations.GlobalSettings) == null ? void 0 : _a.DisableGeometryParsing)) {
15279
- for (const event of filterd) {
15280
- event.geometry = yield getEventGeometry(event);
15281
- }
15282
- }
15283
- if (filterd.length > 0) {
15284
- for (const event of filterd) {
15285
- yield mkEvent(event);
15286
- }
15287
- }
15288
- yield updateNode();
15289
- setEventEmit({
15290
- event: `onEventCache`,
15291
- metadata: bootstrap.cache.events,
15292
- limited: true
15293
- });
15294
- });
15295
-
15296
- // src/@events/events.text.ts
15297
- var text = (stanza) => __async(null, null, function* () {
15298
- var _a, _b, _c;
15299
- let processed = [];
15300
- const getMessages = (_c = (_b = (_a = stanza == null ? void 0 : stanza.message) == null ? void 0 : _a.split(/(?=\$\$)/g)) == null ? void 0 : _b.map((message) => message.trim())) == null ? void 0 : _c.filter((message) => message && message !== "$$");
15301
- if (!getMessages || (getMessages == null ? void 0 : getMessages.length) == 0) return;
15302
- for (const message of getMessages) {
15303
- const tick = performance.now();
15304
- const attributes = stanza == null ? void 0 : stanza.attributes;
15305
- const props = properties({ message, attributes });
15306
- const header = getEventHeader({ properties: props, getType: stanza.getType });
15307
- const issued = new Date(attributes.issue);
15308
- const expires = new Date(issued.getTime() + 12 * 60 * 60 * 1e3);
15309
- let event = Object.keys(eventsMatchText).find((event2) => message.toLowerCase().includes(event2.toLowerCase()));
15310
- let isStatement = false;
15311
- if (!event) {
15312
- event = stanza.getType.type.split(`-`).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(` `);
15313
- isStatement = true;
15314
- }
15315
- processed.push({
15316
- type: `Feature`,
15317
- geometry: {
15318
- type: `Point`,
15319
- coordinates: []
15320
- },
15321
- properties: __spreadProps(__spreadValues({
15322
- event,
15323
- parent: event,
15324
- status: isStatement ? `Statement` : `Issued`,
15325
- issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15326
- expires: isStatement ? new Date(issued.getTime() + 120 * 1e3).toISOString() : !isNaN(expires.getTime()) ? expires.toISOString() : new Date(Date.now() + 60 * 60 * 1e3).toISOString()
15327
- }, props), {
15328
- metadata: {
15329
- ms: performance.now() - tick,
15330
- source: `events.text`,
15331
- tracking: getEventTracking({ type: `RAW`, stanza, attributes, properties: props }),
15332
- header,
15333
- vtec: null,
15334
- hvtec: null,
15335
- history: [
15336
- {
15337
- description: props.description,
15338
- issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15339
- status: `Issued`
15360
+ if (sUploads == null ? void 0 : sUploads.file) {
15361
+ const destination = bootstrap.settings.GlobalSettings.ArchiveSettings.TextDirectory;
15362
+ if (destination) {
15363
+ if (!(0, import_fs3.existsSync)(destination)) {
15364
+ (0, import_fs3.mkdirSync)(destination, { recursive: true });
15365
+ }
15366
+ if ((0, import_fs3.existsSync)(`${destination}/${properties2.event}_${properties2.status}_${properties2.metadata.tracking}.txt`)) {
15367
+ (0, import_fs3.appendFileSync)(`${destination}/${properties2.event}_${properties2.status}_${properties2.metadata.tracking}.txt`, properties2.metadata.raw);
15368
+ } else {
15369
+ (0, import_fs3.writeFileSync)(`${destination}/${properties2.event}_${properties2.status}_${properties2.metadata.tracking}.txt`, properties2.metadata.raw);
15370
+ }
15371
+ }
15372
+ file = properties2.metadata.raw;
15373
+ }
15374
+ if (sWebhook == null ? void 0 : sWebhook.enabled) {
15375
+ const isLimited = setTimeoutAction({ identifier: sWebhook.destination, interval: sWebhook.ratelimit, max: sWebhook.ratelimit, addTime: true });
15376
+ if (!isLimited.limited) {
15377
+ let body = getEmebed(event);
15378
+ if (body.length > 1900) {
15379
+ body = body.substring(0, 1900) + "\n\n[Message truncated due to length]";
15380
+ const blocks = ((_a = body.match(/```/g)) != null ? _a : []).length;
15381
+ if (blocks % 2 !== 0) body += "```";
15382
+ }
15383
+ if (properties2.description.length < 25) {
15384
+ continue;
15385
+ }
15386
+ const form = new import_form_data.default();
15387
+ const embed = {
15388
+ title: `${properties2.event} (${properties2.status})`,
15389
+ description: body,
15390
+ color: 16711680,
15391
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
15392
+ image: {},
15393
+ footer: { text: (_b = sWebhook.title) != null ? _b : `AtmosphericX` }
15394
+ };
15395
+ form.append("payload_json", JSON.stringify({
15396
+ username: (_c = sWebhook.title) != null ? _c : "AtmosphericX",
15397
+ content: (_d = sWebhook.message) != null ? _d : "",
15398
+ embeds: [embed]
15399
+ }));
15400
+ if (sUploads == null ? void 0 : sUploads.file) {
15401
+ form.append("fUpload", Buffer.from(file), { filename: `${properties2.event}_${properties2.status}_${properties2.metadata.tracking}.txt`, contentType: "application/text" });
15402
+ }
15403
+ if (sUploads == null ? void 0 : sUploads.eas) {
15404
+ if (eas) {
15405
+ const file2 = (0, import_fs3.readFileSync)(eas);
15406
+ form.append("fEas", Buffer.from(file2), { filename: `${properties2.event}_${properties2.status}_${properties2.metadata.tracking}_eas.mp3`, contentType: "audio/mpeg" });
15340
15407
  }
15341
- ]
15408
+ }
15409
+ const a = yield createHttp({
15410
+ url: sWebhook.destination,
15411
+ timeout: 5e3,
15412
+ method: `POST`,
15413
+ headers: form.getHeaders(),
15414
+ body: form
15415
+ });
15342
15416
  }
15343
- })
15344
- });
15417
+ }
15418
+ }
15345
15419
  }
15346
- validateEvents(processed);
15347
15420
  });
15348
15421
 
15349
- // src/@parsers/@ugc/ugc.header.ts
15350
- var getUGCHeader = (message) => {
15351
- const start = message.search(regExp.ugc1);
15352
- const sub = message.substring(start);
15353
- const end = sub.search(regExp.ugc2);
15354
- const fin = sub.substring(0, end).replace(/\s+/g, "").slice(0, -1);
15355
- return fin != null ? fin : null;
15356
- };
15357
-
15358
- // src/@parsers/@ugc/ugc.zones.ts
15359
- var getZones = (header) => {
15360
- const splits = header.split("-");
15361
- const zones = [];
15362
- let state = splits[0].substring(0, 2);
15363
- const format = splits[0].substring(2, 3);
15364
- for (const part of splits) {
15365
- if (/^[A-Z]/.test(part)) {
15366
- state = part.substring(0, 2);
15367
- if (part.includes(">")) {
15368
- const [start, end] = part.split(">");
15369
- const startNum = parseInt(start.substring(3), 10);
15370
- const endNum = parseInt(end, 10);
15371
- for (let j2 = startNum; j2 <= endNum; j2++) {
15372
- zones.push(`${state}${format}${j2.toString().padStart(3, "0")}`);
15422
+ // src/@modules/@utilities/utilities.getShapeNearestPoint.ts
15423
+ var getShapeNearestPoint = (coordinates, point) => {
15424
+ if (!coordinates || !point) {
15425
+ return { proximity: false, point: [0, 0], distance: null };
15426
+ }
15427
+ const normalize = (coords) => {
15428
+ if (!Array.isArray(coords)) return [];
15429
+ if (typeof coords[0] === "number" && typeof coords[1] === "number") return [];
15430
+ if (Array.isArray(coords[0]) && typeof coords[0][0] === "number") {
15431
+ return [[coords]];
15432
+ }
15433
+ if (Array.isArray(coords[0]) && Array.isArray(coords[0][0]) && typeof coords[0][0][0] === "number") {
15434
+ return [coords];
15435
+ }
15436
+ if (Array.isArray(coords[0]) && Array.isArray(coords[0][0]) && Array.isArray(coords[0][0][0]) && typeof coords[0][0][0][0] === "number") {
15437
+ return coords;
15438
+ }
15439
+ return [];
15440
+ };
15441
+ const polys = normalize(coordinates);
15442
+ if (polys.length === 0) return { proximity: false, point: [0, 0], distance: null };
15443
+ const lon = point[0];
15444
+ const lat = point[1];
15445
+ const pointInRing = (pt, ring) => {
15446
+ let x = pt[0], y = pt[1];
15447
+ let inside = false;
15448
+ for (let i = 0, j2 = ring.length - 1; i < ring.length; j2 = i++) {
15449
+ const xi = ring[i][0], yi = ring[i][1];
15450
+ const xj = ring[j2][0], yj = ring[j2][1];
15451
+ const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi + 0) + xi;
15452
+ if (intersect) inside = !inside;
15453
+ }
15454
+ return inside;
15455
+ };
15456
+ const toRadians = (deg) => deg * Math.PI / 180;
15457
+ const haversineMiles = (a, b) => {
15458
+ const R = 3958.8;
15459
+ const dLat = toRadians(b[1] - a[1]);
15460
+ const dLon = toRadians(b[0] - a[0]);
15461
+ const lat1 = toRadians(a[1]);
15462
+ const lat2 = toRadians(b[1]);
15463
+ const sinDLat = Math.sin(dLat / 2);
15464
+ const sinDLon = Math.sin(dLon / 2);
15465
+ const c = 2 * Math.asin(Math.sqrt(sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon));
15466
+ return R * c;
15467
+ };
15468
+ let minDistance = Infinity;
15469
+ let closestPoint = null;
15470
+ for (const poly of polys) {
15471
+ const outer = poly[0];
15472
+ const holes = poly.slice(1);
15473
+ if (pointInRing(point, outer)) {
15474
+ let inHole = false;
15475
+ for (const hole of holes) {
15476
+ if (pointInRing(point, hole)) {
15477
+ inHole = true;
15478
+ break;
15373
15479
  }
15374
- } else {
15375
- zones.push(part);
15376
15480
  }
15377
- continue;
15481
+ if (!inHole) {
15482
+ return { proximity: true, point, distance: 0 };
15483
+ }
15378
15484
  }
15379
- if (part.includes(">")) {
15380
- const [start, end] = part.split(">");
15381
- const startNum = parseInt(start, 10);
15382
- const endNum = parseInt(end, 10);
15383
- for (let j2 = startNum; j2 <= endNum; j2++) {
15384
- zones.push(`${state}${format}${j2.toString().padStart(3, "0")}`);
15485
+ for (const ring of poly) {
15486
+ for (let i = 0; i < ring.length - 1; i++) {
15487
+ const start = [ring[i][0], ring[i][1]];
15488
+ const end = [ring[i + 1][0], ring[i + 1][1]];
15489
+ const A = lon - start[0];
15490
+ const B = lat - start[1];
15491
+ const C = end[0] - start[0];
15492
+ const D = end[1] - start[1];
15493
+ const lenSq = C * C + D * D;
15494
+ const t = lenSq === 0 ? 0 : Math.max(0, Math.min(1, (A * C + B * D) / lenSq));
15495
+ const candidate = [start[0] + t * C, start[1] + t * D];
15496
+ const dist = haversineMiles([lon, lat], candidate);
15497
+ if (!isNaN(dist) && dist < minDistance) {
15498
+ minDistance = Number(dist.toFixed(3));
15499
+ closestPoint = candidate;
15500
+ }
15385
15501
  }
15386
- } else {
15387
- zones.push(`${state}${format}${part}`);
15388
15502
  }
15389
15503
  }
15390
- return zones.filter((item) => item !== "");
15391
- };
15392
-
15393
- // src/@parsers/@ugc/ugc.expiry.ts
15394
- var getExpiry = (message) => {
15395
- const match = message.match(/\b(\d{6})-/);
15396
- if (!match) {
15397
- return null;
15504
+ if (!isFinite(minDistance) || closestPoint == null) {
15505
+ return { proximity: false, point: [0, 0], distance: null };
15398
15506
  }
15399
- const date = match == null ? void 0 : match[1];
15400
- const day = parseInt(date == null ? void 0 : date.slice(0, 2), 10);
15401
- const hour = parseInt(date == null ? void 0 : date.slice(2, 4), 10);
15402
- const minute = parseInt(date == null ? void 0 : date.slice(4, 6), 10);
15403
- const now = /* @__PURE__ */ new Date();
15404
- const expires = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), day, hour, minute));
15405
- return expires.toISOString();
15507
+ const distanceMiles = minDistance;
15508
+ const distanceKm = Number((distanceMiles * 1.609344).toFixed(3));
15509
+ const distanceMeters = Math.round(distanceKm * 1e3);
15510
+ return { proximity: distanceMiles === 0, point: closestPoint, distance: distanceMiles, distanceKm, distanceMeters };
15406
15511
  };
15407
15512
 
15408
- // src/@parsers/@ugc/ugc.locations.ts
15409
- var getLocations = (zones) => __async(null, null, function* () {
15410
- const sites = Array.from(new Set(zones));
15411
- const placeholders = sites.map(() => "?").join(",");
15412
- const rows = yield bootstrap.database.prepare(`SELECT id, location FROM shapefiles WHERE id IN (${placeholders})`).all(...sites);
15413
- return rows.map((row) => row.location).sort();
15513
+ // src/@building/building.polygon.ts
15514
+ var getEventNodes = (event) => __async(null, null, function* () {
15515
+ var _a, _b;
15516
+ const metadata = { nodes: [], proximity: false, filtered: false };
15517
+ const geometry = yield getEventGeometry(event);
15518
+ if (!geometry || !geometry.coordinates) {
15519
+ return { nodes: [], filtered: false, updated: Date.now() };
15520
+ }
15521
+ const nodes = bootstrap.cache.nodes.features;
15522
+ for (const node of nodes) {
15523
+ const [longitude, latitude] = node.geometry.coordinates;
15524
+ const getPoint = getShapeNearestPoint(geometry.coordinates, [longitude, latitude]);
15525
+ const miles = (_a = getPoint.distance) != null ? _a : null;
15526
+ const kilometers = Number((miles * 1.609344).toFixed(3));
15527
+ const info = {
15528
+ id: (_b = node.properties) == null ? void 0 : _b.identifier,
15529
+ coordinates: [longitude, latitude],
15530
+ nearest: getPoint.point,
15531
+ miles,
15532
+ kilometers,
15533
+ proximity: getPoint.proximity
15534
+ };
15535
+ metadata.nodes.push(info);
15536
+ if (bootstrap.settings.GlobalSettings.EventFiltering.NodeLocationFiltering && miles < bootstrap.settings.GlobalSettings.NodeMinDistance) {
15537
+ metadata.proximity = true;
15538
+ info.proximity = true;
15539
+ }
15540
+ }
15541
+ return {
15542
+ nodes: metadata.nodes,
15543
+ filtered: metadata.proximity,
15544
+ updated: Date.now()
15545
+ };
15414
15546
  });
15415
15547
 
15416
- // src/@parsers/@ugc/ugc.extract.ts
15417
- var ugcExtract = (message) => __async(null, null, function* () {
15418
- const head = getUGCHeader(message);
15419
- const ugcs = getZones(head);
15420
- const expires = getExpiry(message);
15421
- const areas = yield getLocations(ugcs);
15422
- if (!head || (ugcs == null ? void 0 : ugcs.length) == 0) return;
15423
- return {
15424
- zones: ugcs,
15425
- locations: areas,
15426
- expires
15427
- };
15548
+ // src/@manager/manager.updateNodes.ts
15549
+ var updateNode = (selectedEvent) => __async(null, null, function* () {
15550
+ const events = bootstrap.cache.events.features;
15551
+ const ttl = bootstrap.settings.GlobalSettings.NodeTTL * 1e3;
15552
+ let total = 0;
15553
+ function update(evt) {
15554
+ return __async(this, null, function* () {
15555
+ var _a, _b, _c;
15556
+ const lastUpdate = (_c = (_b = (_a = evt == null ? void 0 : evt.properties) == null ? void 0 : _a.metadata) == null ? void 0 : _b.updated) != null ? _c : null;
15557
+ if (lastUpdate != null && Date.now() - lastUpdate < ttl) {
15558
+ return evt;
15559
+ }
15560
+ const node = yield getEventNodes(evt);
15561
+ if (node.nodes.length > 0) {
15562
+ total++;
15563
+ }
15564
+ evt.properties.metadata.nodes = node.nodes;
15565
+ evt.properties.metadata.filtered_proximity = node.filtered;
15566
+ evt.properties.metadata.updated = node.updated;
15567
+ });
15568
+ }
15569
+ if (!selectedEvent) {
15570
+ yield Promise.all(events.map((evt) => __async(null, null, function* () {
15571
+ yield update(evt);
15572
+ })));
15573
+ }
15574
+ if (selectedEvent) {
15575
+ yield update(selectedEvent);
15576
+ }
15577
+ if (total > 0) {
15578
+ setEventEmit({
15579
+ event: `onNodeUpdate`,
15580
+ metadata: {
15581
+ type: `global-update`,
15582
+ updated: total
15583
+ }
15584
+ });
15585
+ }
15428
15586
  });
15429
15587
 
15430
- // src/@events/events.ugc.ts
15431
- var ugc = (stanza) => __async(null, null, function* () {
15432
- var _a, _b, _c;
15433
- let processed = [];
15434
- const getMessages = (_c = (_b = (_a = stanza == null ? void 0 : stanza.message) == null ? void 0 : _a.split(/(?=\$\$)/g)) == null ? void 0 : _b.map((message) => message.trim())) == null ? void 0 : _c.filter((message) => message && message !== "$$");
15435
- if (!getMessages || (getMessages == null ? void 0 : getMessages.length) == 0) return;
15436
- for (const message of getMessages) {
15437
- const tick = performance.now();
15438
- const attributes = stanza == null ? void 0 : stanza.attributes;
15439
- const ugc2 = yield ugcExtract(message);
15440
- if (ugc2 != null) {
15441
- const props = properties({ message, attributes, ugc: ugc2 });
15442
- const issued = new Date(attributes.issue);
15443
- const expires = new Date(ugc2.expires);
15444
- const header = getEventHeader({ properties: props, getType: stanza.getType });
15445
- let event = Object.keys(eventsMatchText).find((event2) => message.toLowerCase().includes(event2.toLowerCase()));
15446
- let isStatement = false;
15447
- if (!event) {
15448
- event = stanza.getType.type.split(`-`).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(` `);
15449
- isStatement = true;
15588
+ // src/@manager/manager.mkEvent.ts
15589
+ var mkEvent = (event) => __async(null, null, function* () {
15590
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
15591
+ const settings = bootstrap.settings;
15592
+ const features = bootstrap.cache.events.features;
15593
+ const getHash = event.properties.metadata.hash;
15594
+ const getTracking = event.properties.metadata.tracking;
15595
+ const isEntry = (_a = bootstrap.cache.hashes) == null ? void 0 : _a.find((hash) => hash.tracking === getTracking);
15596
+ const isHashed = (_c = (_b = isEntry == null ? void 0 : isEntry.hashes) == null ? void 0 : _b.includes(getHash)) != null ? _c : false;
15597
+ const getFeature = features.find((feature) => feature.properties.metadata.tracking === getTracking);
15598
+ if (isHashed || event.properties.status_metadata.is_expired) return;
15599
+ setHash(event, isEntry);
15600
+ const isFilteredLocation = yield updateNode(event).then(() => event.properties.metadata.filtered_proximity);
15601
+ if (!isFilteredLocation && settings.GlobalSettings.EventFiltering.NodeLocationFiltering) {
15602
+ return;
15603
+ }
15604
+ setEventEmit({
15605
+ event: `onEventStatus`,
15606
+ metadata: {
15607
+ type: getFeature ? `Updated` : `New`,
15608
+ event
15609
+ },
15610
+ message: `[${getFeature ? "Updated" : "New"}] ${event.properties.event} (${event.properties.status}) (${event.properties.metadata.tracking})`
15611
+ });
15612
+ if (settings.GlobalSettings.EventManagement) {
15613
+ if (event.properties.status_metadata.is_issued || event.properties.status_metadata.is_updated) {
15614
+ if (getFeature) {
15615
+ const getIndex = features.indexOf(getFeature);
15616
+ const cHistory = (_f = (_e = (_d = getFeature == null ? void 0 : getFeature.properties) == null ? void 0 : _d.metadata) == null ? void 0 : _e.history) != null ? _f : [];
15617
+ const cLocations = (_i = (_h = (_g = getFeature == null ? void 0 : getFeature.properties) == null ? void 0 : _g.locations) == null ? void 0 : _h.split(";").map((l) => l.trim())) != null ? _i : [];
15618
+ const cUgc = (_l = (_k = (_j = getFeature == null ? void 0 : getFeature.properties) == null ? void 0 : _j.geocode) == null ? void 0 : _k.ugc) != null ? _l : [];
15619
+ const iHistory = (_o = (_n = (_m = event.properties) == null ? void 0 : _m.metadata) == null ? void 0 : _n.history) != null ? _o : [];
15620
+ const iLocations = (_r = (_q = (_p = event.properties) == null ? void 0 : _p.locations) == null ? void 0 : _q.split(";").map((l) => l.trim())) != null ? _r : [];
15621
+ const iUgc = (_u = (_t = (_s = event.properties) == null ? void 0 : _s.geocode) == null ? void 0 : _t.ugc) != null ? _u : [];
15622
+ const mHistory = [...cHistory, ...iHistory].filter((v, i, a) => a.indexOf(v) === i).filter((v, i, a) => a.findIndex((h) => h.description === v.description && h.issued === v.issued) === i);
15623
+ const mLocations = [...cLocations, ...iLocations].filter((v, i, a) => a.indexOf(v) === i).join("; ");
15624
+ const mUgc = [...cUgc, ...iUgc].filter((v, i, a) => a.indexOf(v) === i);
15625
+ bootstrap.cache.events.features[getIndex] = __spreadProps(__spreadValues({}, event), {
15626
+ properties: __spreadProps(__spreadValues({}, event.properties), {
15627
+ metadata: __spreadProps(__spreadValues({}, (_v = event == null ? void 0 : event.properties) == null ? void 0 : _v.metadata), {
15628
+ history: mHistory
15629
+ }),
15630
+ locations: mLocations,
15631
+ geocode: __spreadProps(__spreadValues({}, (_w = event == null ? void 0 : event.properties) == null ? void 0 : _w.geocode), {
15632
+ ugc: mUgc
15633
+ })
15634
+ })
15635
+ });
15636
+ updateListener(bootstrap.cache.events.features[getIndex]);
15637
+ } else {
15638
+ features.push(event);
15639
+ updateListener(event);
15450
15640
  }
15451
- processed.push({
15452
- type: `Feature`,
15453
- geometry: {
15454
- type: `Point`,
15455
- coordinates: []
15456
- },
15457
- properties: __spreadProps(__spreadValues({
15458
- event,
15459
- parent: event,
15460
- status: isStatement ? `Statement` : `Issued`,
15461
- issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15462
- expires: isStatement ? new Date(issued.getTime() + 120 * 1e3).toISOString() : !isNaN(expires.getTime()) ? expires.toISOString() : new Date(Date.now() + 60 * 60 * 1e3).toISOString()
15463
- }, props), {
15464
- metadata: {
15465
- ms: performance.now() - tick,
15466
- source: `events.ugc`,
15467
- tracking: getEventTracking({ type: `RAW`, stanza, attributes, properties: props }),
15468
- header,
15469
- vtec: null,
15470
- hvtec: null,
15471
- history: [
15472
- {
15473
- description: props.description,
15474
- issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15475
- status: `Issued`
15476
- }
15477
- ]
15478
- }
15479
- })
15480
- });
15481
15641
  }
15482
15642
  }
15483
- validateEvents(processed);
15484
15643
  });
15485
15644
 
15486
- // src/@dictionaries/dictionaries.eventTypes.ts
15487
- var eventTypes = {
15488
- "AF": "Ashfall",
15489
- "AS": "Air Stagnation",
15490
- "BH": "Beach Hazard",
15491
- "BW": "Brisk Wind",
15492
- "BZ": "Blizzard",
15493
- "CF": "Coastal Flood",
15494
- "DF": "Debris Flow",
15495
- "DS": "Dust Storm",
15496
- "EC": "Extreme Cold",
15497
- "EH": "Excessive Heat",
15498
- "XH": "Extreme Heat",
15499
- "EW": "Extreme Wind",
15500
- "FA": "Areal Flood",
15501
- "FF": "Flash Flood",
15502
- "FG": "Dense Fog",
15503
- "FL": "Flood",
15504
- "FR": "Frost",
15505
- "FW": "Fire Weather",
15506
- "FZ": "Freeze",
15507
- "GL": "Gale",
15508
- "HF": "Hurricane Force Wind",
15509
- "HT": "Heat",
15510
- "HU": "Hurricane",
15511
- "HW": "High Wind",
15512
- "HY": "Hydrologic",
15513
- "HZ": "Hard Freeze",
15514
- "IS": "Ice Storm",
15515
- "LE": "Lake Effect Snow",
15516
- "LO": "Low Water",
15517
- "LS": "Lakeshore Flood",
15518
- "LW": "Lake Wind",
15519
- "MA": "Special Marine",
15520
- "EQ": "Earthquake",
15521
- "MF": "Dense Fog",
15522
- "MH": "Ashfall",
15523
- "MS": "Dense Smoke",
15524
- "RB": "Small Craft for Rough Bar",
15525
- "RP": "Rip Current Risk",
15526
- "SC": "Small Craft",
15527
- "SE": "Hazardous Seas",
15528
- "SI": "Small Craft for Winds",
15529
- "SM": "Dense Smoke",
15530
- "SQ": "Snow Squall",
15531
- "SR": "Storm",
15532
- "SS": "Storm Surge",
15533
- "SU": "High Surf",
15534
- "SV": "Severe Thunderstorm",
15535
- "SW": "Small Craft for Hazardous Seas",
15536
- "TO": "Tornado",
15537
- "TR": "Tropical Storm",
15538
- "TS": "Tsunami",
15539
- "TY": "Typhoon",
15540
- "SP": "Special Weather",
15541
- "UP": "Heavy Freezing Spray",
15542
- "WC": "Wind Chill",
15543
- "WI": "Wind",
15544
- "WS": "Winter Storm",
15545
- "WW": "Winter Weather",
15546
- "ZF": "Freezing Fog",
15547
- "ZR": "Freezing Rain",
15548
- "ZY": "Freezing Spray"
15645
+ // src/@manager/manager.rmEvent.ts
15646
+ var rmEvent = (event) => {
15647
+ const getEvent = bootstrap.cache.events.features.find((f) => {
15648
+ var _a, _b, _c, _d;
15649
+ return ((_b = (_a = f == null ? void 0 : f.properties) == null ? void 0 : _a.metadata) == null ? void 0 : _b.tracking) === ((_d = (_c = event == null ? void 0 : event.properties) == null ? void 0 : _c.metadata) == null ? void 0 : _d.tracking);
15650
+ });
15651
+ const cachedStatus = event.properties.status;
15652
+ event.properties.expires = (/* @__PURE__ */ new Date()).toISOString();
15653
+ event.properties.status = `Expired`;
15654
+ event.properties.status_metadata.is_expired = true;
15655
+ if (getEvent) {
15656
+ setEventEmit({
15657
+ event: `onEventStatus`,
15658
+ metadata: {
15659
+ type: `Removed`,
15660
+ event
15661
+ },
15662
+ message: `[Removed] ${event.properties.event} (${event.properties.status}) (${event.properties.metadata.tracking})`
15663
+ });
15664
+ setEventEmit({ event: `onExpiredProduct`, metadata: event });
15665
+ if (cachedStatus != `Statement`) updateListener(event);
15666
+ bootstrap.cache.events.features.splice(bootstrap.cache.events.features.indexOf(getEvent), 1);
15667
+ bootstrap.cache.hashes = bootstrap.cache.hashes.filter((hash) => hash.tracking !== event.properties.metadata.tracking);
15668
+ }
15669
+ setEventEmit({
15670
+ event: `onEventCache`,
15671
+ metadata: bootstrap.cache.events,
15672
+ limited: true
15673
+ });
15549
15674
  };
15550
15675
 
15551
- // src/@dictionaries/dictionaries.eventActions.ts
15552
- var eventActions = {
15553
- "W": "Warning",
15554
- "F": "Forecast",
15555
- "A": "Watch",
15556
- "O": "Outlook",
15557
- "Y": "Advisory",
15558
- "N": "Synopsis",
15559
- "S": "Statement"
15676
+ // src/@modules/@utilities/utilities.getLatestIssuance.ts
15677
+ var getLatestIssuance = () => {
15678
+ const now = /* @__PURE__ */ new Date();
15679
+ const current = now.getUTCHours() * 100 + now.getUTCMinutes();
15680
+ const issuances = [100, 600, 1300, 1630, 2e3];
15681
+ let latest = issuances[0];
15682
+ for (const issuance of issuances) {
15683
+ if (current >= issuance) {
15684
+ latest = issuance;
15685
+ }
15686
+ }
15687
+ return latest.toString().padStart(4, "0");
15560
15688
  };
15561
15689
 
15562
- // src/@dictionaries/dictionaries.eventStatus.ts
15563
- var eventStatus = {
15564
- "NEW": "Issued",
15565
- "CON": "Updated",
15566
- "EXT": "Extended",
15567
- "EXA": "Extended",
15568
- "EXB": "Extended",
15569
- "UPG": "Upgraded",
15570
- "COR": "Correction",
15571
- "ROU": "Routine",
15572
- "CAN": "Cancelled",
15573
- "EXP": "Expired"
15690
+ // src/@building/building.attachments.ts
15691
+ var getEventAttachments = (event) => {
15692
+ var _a, _b, _c, _d;
15693
+ const latestTime = getLatestIssuance();
15694
+ const spcNumber = (_b = (_a = event == null ? void 0 : event.properties) == null ? void 0 : _a.discussion_parameters) == null ? void 0 : _b.discussion_number;
15695
+ const watchNumber = (_d = (_c = event == null ? void 0 : event.properties) == null ? void 0 : _c.watch_parameters) == null ? void 0 : _d.watch_number;
15696
+ const validEvents = [
15697
+ { target: "Day 1", attachment: `https://www.spc.noaa.gov/products/outlook/day1otlk_${latestTime}.png` },
15698
+ { target: "Day 2", attachment: `https://www.spc.noaa.gov/products/outlook/day2otlk.png` },
15699
+ { target: "Day 3", attachment: `https://www.spc.noaa.gov/products/outlook/day3otlk.png` },
15700
+ { target: "Mesoscale Discussion", attachment: `https://www.spc.noaa.gov/products/md/mcd${spcNumber}.png` },
15701
+ { target: "Tornado Watch", attachment: `https://www.spc.noaa.gov/products/watch/ww${watchNumber}_radar_big.gif` },
15702
+ { target: "PDS Tornado Watch", attachment: `https://www.spc.noaa.gov/products/watch/ww${watchNumber}_radar_big.gif` },
15703
+ { target: "Severe Thunderstorm Watch", attachment: `https://www.spc.noaa.gov/products/watch/ww${watchNumber}_radar_big.gif` },
15704
+ { target: "PDS Severe Thunderstorm Watch", attachment: `https://www.spc.noaa.gov/products/watch/ww${watchNumber}_radar_big.gif` }
15705
+ ];
15706
+ const isValid = validEvents.find((outlook) => outlook.target == event.properties.event);
15707
+ if (isValid) {
15708
+ return (isValid == null ? void 0 : isValid.attachment) ? [isValid.attachment] : [];
15709
+ }
15710
+ return null;
15574
15711
  };
15575
15712
 
15576
- // src/@parsers/@pvtec/pvtec.expires.ts
15577
- var getExpiry2 = (dates) => {
15578
- if ((dates == null ? void 0 : dates[1]) == `000000T0000Z`) return "Invalid Date Format";
15579
- const expires = `${(/* @__PURE__ */ new Date()).getFullYear().toString().substring(0, 2)}${dates[1].substring(0, 2)}-${dates[1].substring(2, 4)}-${dates[1].substring(4, 6)}T${dates[1].substring(7, 9)}:${dates[1].substring(9, 11)}:00`;
15580
- const local = new Date(new Date(expires).getTime() - 4 * 60 * 6e4);
15581
- const pad = (n) => n.toString().padStart(2, "0");
15582
- return `${local.getFullYear()}-${pad(local.getMonth() + 1)}-${pad(local.getDate())}T${pad(local.getHours())}:${pad(local.getMinutes())}:00.000-04:00`;
15583
- };
15584
-
15585
- // src/@parsers/@pvtec/pvtec.extract.ts
15586
- var pvExtract = (message) => {
15587
- var _a, _b, _c, _d;
15588
- const getVTECs = (_a = message.match(regExp.pvtec)) != null ? _a : [];
15589
- const vtecs = [];
15590
- for (const vtec2 of getVTECs) {
15591
- const sub = vtec2.split(`.`);
15592
- if ((sub == null ? void 0 : sub.length) < 7) continue;
15593
- const dates = (_b = sub[6]) == null ? void 0 : _b.split(`-`);
15594
- vtecs.push({
15595
- vtec: vtec2,
15596
- product: eventProducts[sub[0]],
15597
- tracking: `${sub[2]}.${sub[3]}.${sub[4]}.${sub[5]}`,
15598
- event: `${eventTypes[sub[3]]} ${eventActions[sub[4]]}`,
15599
- status: eventStatus[sub[1]],
15600
- organization: (_d = (_c = message.match(regExp.wmo)) == null ? void 0 : _c[0]) != null ? _d : null,
15601
- expires: getExpiry2(dates),
15602
- is_watch: (sub[4] == `A` || sub[4] == `Y`) && (sub[3] == `TO` || sub[3] == `SV`),
15603
- prediction_center: sub[2] == `KWNS` ? true : false
15604
- });
15605
- }
15606
- return vtecs.length > 0 ? vtecs : null;
15607
- };
15608
-
15609
- // src/@dictionaries/dictionaries.eventCauses.ts
15610
- var eventCauses = {
15611
- "SM": "Snow Melt",
15612
- "RS": "Rain/Snow Melt",
15613
- "ER": "Excessive Rain",
15614
- "DM": "Dam/Levee Failure",
15615
- "IJ": "Ice Jam",
15616
- "GO": "Glacier Lake Outburst",
15617
- "IC": "Ice",
15618
- "FS": "Flash Flood / Storm Surge",
15619
- "FT": "Tidal Effects",
15620
- "ET": "Elevated Upstream Flow",
15621
- "MC": "Other Multiple Causes",
15622
- "WT": "Wind and/or Tidal Effects",
15623
- "DR": "Reservoir Release",
15624
- "UU": "Unknown",
15625
- "OT": "Other Effects"
15626
- };
15627
-
15628
- // src/@dictionaries/dictionaries.eventRecords.ts
15629
- var eventRecords = {
15630
- "NO": "No Record Expected",
15631
- "NR": "Near Record or possible record",
15632
- "UU": "Unknown history of records",
15633
- "OO": "Other"
15634
- };
15635
-
15636
- // src/@dictionaries/dictionaries.eventSeverity.ts
15637
- var eventSeverity = {
15638
- N: "Not Expected",
15639
- 0: "Areal Flood or FF Product",
15640
- 1: "Minor",
15641
- 2: "Moderate",
15642
- 3: "Major",
15643
- U: "Unknown"
15644
- };
15645
-
15646
- // src/@parsers/@hvtec/hvtec.extract.ts
15647
- var hvExtract = (message) => {
15713
+ // src/@building/building.validate.ts
15714
+ var validateEvents = (events) => __async(null, null, function* () {
15648
15715
  var _a;
15649
- const getHVTECs = (_a = message.match(regExp.hvtec)) != null ? _a : [];
15650
- const vtecs = [];
15651
- for (const vtec2 of getHVTECs) {
15652
- const sub = vtec2.split(`.`);
15653
- if (sub.length < 7) continue;
15654
- vtecs.push({
15655
- hvtec: vtec2,
15656
- severity: eventSeverity[sub[1]],
15657
- cause: eventCauses[sub[2]],
15658
- record: eventRecords[sub[6]]
15659
- });
15716
+ if (events.length === 0) return;
15717
+ const configurations = bootstrap.settings;
15718
+ const sets = {};
15719
+ const bools = {};
15720
+ const megered = __spreadValues(__spreadValues({}, configurations.GlobalSettings), configurations.GlobalSettings.EventFiltering);
15721
+ for (const key in megered) {
15722
+ const setting = megered[key];
15723
+ if (Array.isArray(setting)) {
15724
+ sets[key] = new Set(setting.map((item) => item.toLowerCase()));
15725
+ }
15726
+ if (typeof setting === "boolean") {
15727
+ bools[key] = setting;
15728
+ }
15660
15729
  }
15661
- return vtecs.length > 0 ? vtecs : null;
15662
- };
15663
-
15664
- // src/@events/events.vtec.ts
15665
- var vtec = (stanza) => __async(null, null, function* () {
15666
- var _a, _b, _c, _d, _e;
15667
- let processed = [];
15668
- const getMessages = (_c = (_b = (_a = stanza == null ? void 0 : stanza.message) == null ? void 0 : _a.split(/(?=\$\$)/g)) == null ? void 0 : _b.map((message) => message.trim())) == null ? void 0 : _c.filter((message) => message && message !== "$$");
15669
- if (!getMessages || (getMessages == null ? void 0 : getMessages.length) == 0) return;
15670
- for (const message of getMessages) {
15671
- const tick = performance.now();
15672
- const attributes = stanza == null ? void 0 : stanza.attributes;
15673
- const pVtec = pvExtract(message);
15674
- const hVtec = hvExtract(message);
15675
- const ugc2 = yield ugcExtract(message);
15676
- if (pVtec != null && ugc2 != null) {
15677
- for (const pv of pVtec) {
15678
- const vtec2 = pv;
15679
- const props = properties({ message, attributes, ugc: ugc2, pVtec: vtec2 });
15680
- const header = getEventHeader({ properties: props, getType: stanza.getType, vtec: vtec2 });
15681
- const issued = (_d = new Date(attributes.issue)) != null ? _d : /* @__PURE__ */ new Date();
15682
- const expires = new Date(vtec2.expires);
15683
- processed.push({
15684
- type: `Feature`,
15685
- geometry: {
15686
- type: `Point`,
15687
- coordinates: []
15688
- },
15689
- properties: __spreadProps(__spreadValues({
15690
- event: pv.event,
15691
- parent: pv.event,
15692
- status: pv.status,
15693
- issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15694
- expires: !isNaN(expires.getTime()) ? expires.toISOString() : (_e = ugc2.expires) != null ? _e : new Date(issued.getTime() + 60 * 60 * 1e3).toISOString()
15695
- }, props), {
15696
- metadata: {
15697
- ms: performance.now() - tick,
15698
- source: `events.vtec`,
15699
- tracking: getEventTracking({ type: `VTEC`, stanza, attributes, properties: props, vtec: vtec2 }),
15700
- header,
15701
- vtec: pv,
15702
- hvtec: hVtec,
15703
- history: [
15704
- {
15705
- description: props.description,
15706
- issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15707
- status: pv.status
15708
- }
15709
- ]
15710
- }
15711
- })
15730
+ const filterd = events.filter((event) => {
15731
+ var _a2, _b, _c, _d, _e;
15732
+ const define2 = getEventSignature(event);
15733
+ const properties2 = define2.properties;
15734
+ const zones = properties2.geocode.ugc;
15735
+ const icao = properties2.geocode.office.office;
15736
+ const enhancedEventName = properties2.event = getEventEnhancedName(event);
15737
+ const filteredProperties = JSON.parse(JSON.stringify(properties2));
15738
+ if ((filteredProperties == null ? void 0 : filteredProperties.metadata) && "ms" in filteredProperties.metadata) {
15739
+ delete filteredProperties.metadata.ms;
15740
+ }
15741
+ filteredProperties.metadata = (_a2 = filteredProperties.metadata) != null ? _a2 : {};
15742
+ properties2.metadata.hash = (0, import_crypto.createHash)("sha256").update(JSON.stringify(filteredProperties)).digest("hex");
15743
+ properties2.metadata.attachments = getEventAttachments(event);
15744
+ setEventEmit({ event: `onProductType${enhancedEventName.replace(/\s+/g, "")}`, metadata: define2 });
15745
+ if (properties2.status_metadata.is_test) {
15746
+ setEventEmit({ event: `onTestProduct`, metadata: define2 });
15747
+ if (bools == null ? void 0 : bools.IgnoreTestProducts) return false;
15748
+ }
15749
+ if (properties2.status_metadata.is_expired) {
15750
+ setEventEmit({ event: `onExpiredProduct`, metadata: define2 });
15751
+ rmEvent(define2);
15752
+ return false;
15753
+ }
15754
+ if (((_c = (_b = properties2.metadata) == null ? void 0 : _b.vtec) == null ? void 0 : _c.is_watch) && properties2.metadata.source != `events.api`) {
15755
+ const isSPC = (_e = (_d = properties2.metadata) == null ? void 0 : _d.vtec) == null ? void 0 : _e.prediction_center;
15756
+ setEventEmit({ event: isSPC ? `onStormPredictionWatch` : `onNonStormPredictionWatch`, metadata: define2 });
15757
+ if ((bools == null ? void 0 : bools.SPCWatchesOnly) && !isSPC) {
15758
+ return false;
15759
+ }
15760
+ if (!(bools == null ? void 0 : bools.SPCWatchesOnly) && isSPC) {
15761
+ return false;
15762
+ }
15763
+ }
15764
+ for (const key in sets) {
15765
+ const setting = sets[key];
15766
+ if (key === "ListeningEvents" && setting.size > 0 && !setting.has(define2.properties.event.toLowerCase())) {
15767
+ setEventEmit({
15768
+ event: `onFilteredEvent`,
15769
+ metadata: define2
15770
+ });
15771
+ return false;
15772
+ }
15773
+ if (key === "IgnoredEvents" && setting.size > 0 && setting.has(define2.properties.event.toLowerCase())) {
15774
+ setEventEmit({
15775
+ event: `onIgnoredEvent`,
15776
+ metadata: define2
15777
+ });
15778
+ return false;
15779
+ }
15780
+ if (key === "ListeningICAO" && setting.size > 0 && icao != null && !setting.has(icao.toLowerCase())) {
15781
+ setEventEmit({
15782
+ event: `onFilteredICAO`,
15783
+ metadata: define2
15784
+ });
15785
+ return false;
15786
+ }
15787
+ if (key === "IgnoredICAO" && setting.size > 0 && icao != null && setting.has(icao.toLowerCase())) {
15788
+ setEventEmit({
15789
+ event: `onIgnoredICAO`,
15790
+ metadata: define2
15791
+ });
15792
+ return false;
15793
+ }
15794
+ if (key === "ListeningUGC" && setting.size > 0 && zones.length > 0 && !zones.some((ugc2) => setting.has(ugc2.toLowerCase()))) {
15795
+ setEventEmit({
15796
+ event: `onFilteredUGC`,
15797
+ metadata: define2
15712
15798
  });
15799
+ return false;
15800
+ }
15801
+ if (key === "ListeningStates" && setting.size > 0 && zones.length > 0 && !zones.some((ugc2) => setting.has(ugc2.substring(0, 2).toLowerCase()))) {
15802
+ setEventEmit({
15803
+ event: `onFilteredState`,
15804
+ metadata: define2
15805
+ });
15806
+ return false;
15713
15807
  }
15714
15808
  }
15809
+ return true;
15810
+ });
15811
+ if (!((_a = configurations == null ? void 0 : configurations.GlobalSettings) == null ? void 0 : _a.DisableGeometryParsing)) {
15812
+ for (const event of filterd) {
15813
+ event.geometry = yield getEventGeometry(event);
15814
+ }
15715
15815
  }
15716
- validateEvents(processed);
15816
+ if (filterd.length > 0) {
15817
+ for (const event of filterd) {
15818
+ yield mkEvent(event);
15819
+ }
15820
+ }
15821
+ yield updateNode();
15822
+ setEventEmit({
15823
+ event: `onEventCache`,
15824
+ metadata: bootstrap.cache.events,
15825
+ limited: true
15826
+ });
15717
15827
  });
15718
15828
 
15719
- // src/@events/events.api.ts
15720
- var api = (stanza) => __async(null, null, function* () {
15721
- 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, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb;
15829
+ // src/@events/events.text.ts
15830
+ var text = (stanza) => __async(null, null, function* () {
15831
+ var _a, _b, _c;
15722
15832
  let processed = [];
15723
- const messages = Object.values(JSON.parse(stanza.message).features);
15724
- for (const feature of messages) {
15833
+ const getMessages = (_c = (_b = (_a = stanza == null ? void 0 : stanza.message) == null ? void 0 : _a.split(/(?=\$\$)/g)) == null ? void 0 : _b.map((message) => message.trim())) == null ? void 0 : _c.filter((message) => message && message !== "$$");
15834
+ if (!getMessages || (getMessages == null ? void 0 : getMessages.length) == 0) return;
15835
+ for (const message of getMessages) {
15725
15836
  const tick = performance.now();
15726
- const pVtec = (_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;
15837
+ const attributes = stanza == null ? void 0 : stanza.attributes;
15838
+ const props = properties({ message, attributes });
15839
+ const header = getEventHeader({ properties: props, getType: stanza.getType });
15840
+ const issued = new Date(attributes.issue);
15841
+ const expires = new Date(issued.getTime() + 12 * 60 * 60 * 1e3);
15842
+ let event = Object.keys(dict_matches).find((event2) => message.toLowerCase().includes(event2.toLowerCase()));
15843
+ let isStatement = false;
15844
+ if (!event) {
15845
+ event = stanza.getType.type.split(`-`).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(` `);
15846
+ isStatement = true;
15847
+ }
15727
15848
  processed.push({
15728
15849
  type: `Feature`,
15729
15850
  geometry: {
15730
15851
  type: `Point`,
15731
15852
  coordinates: []
15732
15853
  },
15733
- properties: {
15734
- event: (_f = (_e = feature == null ? void 0 : feature.properties) == null ? void 0 : _e.event) != null ? _f : null,
15735
- parent: (_h = (_g = feature == null ? void 0 : feature.properties) == null ? void 0 : _g.event) != null ? _h : null,
15736
- status: (_j = (_i = feature == null ? void 0 : feature.properties) == null ? void 0 : _i.messageType) != null ? _j : null,
15737
- issued: ((_k = feature == null ? void 0 : feature.properties) == null ? void 0 : _k.sent) ? new Date((_l = feature == null ? void 0 : feature.properties) == null ? void 0 : _l.sent).toISOString() : null,
15738
- expires: ((_m = feature == null ? void 0 : feature.properties) == null ? void 0 : _m.expires) ? new Date((_n = feature == null ? void 0 : feature.properties) == null ? void 0 : _n.expires).toISOString() : null,
15739
- locations: (_p = (_o = feature == null ? void 0 : feature.properties) == null ? void 0 : _o.areaDesc) != null ? _p : null,
15740
- description: (_r = (_q = feature == null ? void 0 : feature.properties) == null ? void 0 : _q.description) != null ? _r : null,
15741
- attributes: (_t = (_s = feature == null ? void 0 : feature.properties) == null ? void 0 : _s.attributes) != null ? _t : {},
15742
- geocode: {
15743
- office: {
15744
- office: pVtec ? pVtec.split(`.`)[2] : null,
15745
- name: (_u = officeICAOs[pVtec ? pVtec.split(`.`)[2] : null]) != null ? _u : null
15746
- },
15747
- organization: (_x = (_w = (_v = feature == null ? void 0 : feature.properties) == null ? void 0 : _v.parameters) == null ? void 0 : _w.WMOidentifier) == null ? void 0 : _x[0],
15748
- ugc: (_A = (_z = (_y = feature == null ? void 0 : feature.properties) == null ? void 0 : _y.geocode) == null ? void 0 : _z.UGC) != null ? _A : [],
15749
- polygon: ((_B = feature == null ? void 0 : feature.geometry) == null ? void 0 : _B.coordinates.length) > 0 ? Buffer.from(JSON.stringify([(_C = feature == null ? void 0 : feature.geometry) == null ? void 0 : _C.coordinates[0]])).toString("base64") : null,
15750
- polygon_generated: ((_D = feature == null ? void 0 : feature.geometry) == null ? void 0 : _D.coordinates.length) > 0 ? true : false
15751
- },
15752
- parameters: {
15753
- tags: getEventTags((_E = feature == null ? void 0 : feature.properties) == null ? void 0 : _E.description),
15754
- instructions: (_G = (_F = feature == null ? void 0 : feature.properties) == null ? void 0 : _F.instruction) != null ? _G : null,
15755
- source: (_I = getTextFromProduct({ message: (_H = feature == null ? void 0 : feature.properties) == null ? void 0 : _H.description, find: [`SOURCE...`], removal: [`.`] })) != null ? _I : null,
15756
- hazards: (_K = getTextFromProduct({ message: (_J = feature == null ? void 0 : feature.properties) == null ? void 0 : _J.description, find: [`HAZARD...`], removal: [`.`] })) != null ? _K : null,
15757
- impacts: (_M = getTextFromProduct({ message: (_L = feature == null ? void 0 : feature.properties) == null ? void 0 : _L.description, find: [`IMPACT...`], removal: [`.`] })) != null ? _M : null,
15758
- estimated_hail_size: (_Q = (_P = (_O = (_N = feature == null ? void 0 : feature.properties) == null ? void 0 : _N.parameters) == null ? void 0 : _O.maxHailSize) == null ? void 0 : _P[0]) != null ? _Q : null,
15759
- estimated_wind_gusts: (_U = (_T = (_S = (_R = feature == null ? void 0 : feature.properties) == null ? void 0 : _R.parameters) == null ? void 0 : _S.maxWindGust) == null ? void 0 : _T[0]) != null ? _U : null,
15760
- damage_threat: (_Y = (_X = (_W = (_V = feature == null ? void 0 : feature.properties) == null ? void 0 : _V.parameters) == null ? void 0 : _W.thunderstormDamageThreat) == null ? void 0 : _X[0]) != null ? _Y : null,
15761
- tornado_threat: (_aa = (_$ = (__ = (_Z = feature == null ? void 0 : feature.properties) == null ? void 0 : _Z.parameters) == null ? void 0 : __.tornadoDetection) == null ? void 0 : _$[0]) != null ? _aa : null,
15762
- flood_threat: (_ea = (_da = (_ca = (_ba = feature == null ? void 0 : feature.properties) == null ? void 0 : _ba.parameters) == null ? void 0 : _ca.floodDetection) == null ? void 0 : _da[0]) != null ? _ea : null,
15763
- wind_threat: (_ia = (_ha = (_ga = (_fa = feature == null ? void 0 : feature.properties) == null ? void 0 : _fa.parameters) == null ? void 0 : _ga.windThreat) == null ? void 0 : _ha[0]) != null ? _ia : null,
15764
- hail_threat: (_ma = (_la = (_ka = (_ja = feature == null ? void 0 : feature.properties) == null ? void 0 : _ja.parameters) == null ? void 0 : _ka.hailThreat) == null ? void 0 : _la[0]) != null ? _ma : null
15765
- },
15766
- spc_parameters: {
15767
- spc_max_tornado: (_oa = getTextFromProduct({ message: (_na = feature == null ? void 0 : feature.properties) == null ? void 0 : _na.description, find: [`MOST PROBABLE PEAK TORNADO INTENSITY...`] })) != null ? _oa : null,
15768
- spc_max_hail: (_qa = getTextFromProduct({ message: (_pa = feature == null ? void 0 : feature.properties) == null ? void 0 : _pa.description, find: [`MOST PROBABLE PEAK HAIL SIZE...`] })) != null ? _qa : null,
15769
- spc_max_wind: (_sa = getTextFromProduct({ message: (_ra = feature == null ? void 0 : feature.properties) == null ? void 0 : _ra.description, find: [`MOST PROBABLE PEAK WIND GUST...`] })) != null ? _sa : null,
15770
- spc_watch_issuance: (_ua = getTextFromProduct({ message: (_ta = feature == null ? void 0 : feature.properties) == null ? void 0 : _ta.description, find: [`Probability of Watch Issuance...`], removal: [`percent`] })) != null ? _ua : null
15771
- },
15772
- watch_parameters: {
15773
- watch_number: (_ya = (_xa = (_wa = getTextFromProduct({ message: (_va = feature == null ? void 0 : feature.properties) == null ? void 0 : _va.description, find: [`ITIES FOR`, `UPDATE FOR`, `Watch Number `], removal: [`%`, `<`, `:`] })) == null ? void 0 : _wa.replace(/(WT|WS|)/g, "")) == null ? void 0 : _xa.trim()) != null ? _ya : null,
15774
- watch_type: ((_za = feature == null ? void 0 : feature.properties) == null ? void 0 : _za.description.includes(`TORNADO WATCH`)) ? `Tornado` : ((_Aa = feature == null ? void 0 : feature.properties) == null ? void 0 : _Aa.description.includes(`SEVERE`)) ? `Severe` : null,
15775
- additional_tornadoes_probability: (_Ca = getTextFromProduct({ message: (_Ba = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ba.description, find: [`PROB OF 2 OR MORE TORNADOES`], removal: [`%`, `<`, `:`] })) != null ? _Ca : null,
15776
- strong_tornadoes_probability: (_Ea = getTextFromProduct({ message: (_Da = feature == null ? void 0 : feature.properties) == null ? void 0 : _Da.description, find: [`PROB OF 1 OR MORE STRONG /EF2-EF5/ TORNADOES`], removal: [`%`, `<`, `:`] })) != null ? _Ea : null,
15777
- severe_wind_probability: (_Ga = getTextFromProduct({ message: (_Fa = feature == null ? void 0 : feature.properties) == null ? void 0 : _Fa.description, find: [`PROB OF 10 OR MORE SEVERE WIND EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _Ga : null,
15778
- severe_hail_probability: (_Ia = getTextFromProduct({ message: (_Ha = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ha.description, find: [`PROB OF 10 OR MORE SEVERE HAIL EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _Ia : null,
15779
- hail_2in_probability: (_Ka = getTextFromProduct({ message: (_Ja = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ja.description, find: [`PROB OF 1 OR MORE HAIL EVENTS >= 2 INCHES`], removal: [`%`, `<`, `:`] })) != null ? _Ka : null,
15780
- combined_hail_wind_probability: (_Ma = getTextFromProduct({ message: (_La = feature == null ? void 0 : feature.properties) == null ? void 0 : _La.description, find: [`PROB OF 6 OR MORE COMBINED SEVERE HAIL/WIND EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _Ma : null,
15781
- max_hail_in: (_Oa = getTextFromProduct({ message: (_Na = feature == null ? void 0 : feature.properties) == null ? void 0 : _Na.description, find: [`MAX HAIL /INCHES/`], removal: [`%`, `<`, `:`] })) != null ? _Oa : null,
15782
- max_wind_surface: (_Qa = getTextFromProduct({ message: (_Pa = feature == null ? void 0 : feature.properties) == null ? void 0 : _Pa.description, find: [`MAX WIND GUSTS SURFACE /KNOTS/`], removal: [`%`, `<`, `:`] })) != null ? _Qa : null,
15783
- max_tops_x100feet: (_Sa = getTextFromProduct({ message: (_Ra = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ra.description, find: [`MAX TOPS /X 100 FEET/`], removal: [`%`, `<`, `:`] })) != null ? _Sa : null,
15784
- pds_watch: getTextFromProduct({ message: (_Ta = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ta.description, find: [`PARTICULARLY DANGEROUS SITUATION`], removal: [`%`, `<`, `:`] }) === `YES`
15785
- },
15854
+ properties: __spreadProps(__spreadValues({
15855
+ event,
15856
+ parent: event,
15857
+ status: isStatement ? `Statement` : `Issued`,
15858
+ issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15859
+ expires: isStatement ? new Date(issued.getTime() + 120 * 1e3).toISOString() : !isNaN(expires.getTime()) ? expires.toISOString() : new Date(Date.now() + 60 * 60 * 1e3).toISOString()
15860
+ }, props), {
15786
15861
  metadata: {
15787
15862
  ms: performance.now() - tick,
15788
- source: `events.api`,
15789
- tracking: getEventTracking({ type: `API`, organization: { wmoidentifier: (_Wa = (_Va = (_Ua = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ua.parameters) == null ? void 0 : _Va.WMOidentifier) == null ? void 0 : _Wa[0], featureId: feature == null ? void 0 : feature.id }, vtec: pVtec }),
15790
- header: `ZCZC-ATMOSX-${(_Ya = (_Xa = feature == null ? void 0 : feature.properties) == null ? void 0 : _Xa.parameters) == null ? void 0 : _Ya.WMOidentifier}`,
15791
- vtec: pVtec,
15863
+ source: `events.text`,
15864
+ tracking: getEventTracking({ type: `RAW`, stanza, attributes, properties: props }),
15865
+ header,
15866
+ vtec: null,
15792
15867
  hvtec: null,
15868
+ raw: message,
15793
15869
  history: [
15794
15870
  {
15795
- description: (_Za = feature == null ? void 0 : feature.properties) == null ? void 0 : _Za.description,
15796
- issued: ((__a = feature == null ? void 0 : feature.properties) == null ? void 0 : __a.sent) ? new Date((_$a = feature == null ? void 0 : feature.properties) == null ? void 0 : _$a.sent).toISOString() : null,
15797
- status: (_bb = (_ab = feature == null ? void 0 : feature.properties) == null ? void 0 : _ab.messageType) != null ? _bb : null
15871
+ description: props.description,
15872
+ issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15873
+ status: `Issued`
15798
15874
  }
15799
15875
  ]
15800
15876
  }
15801
- }
15877
+ })
15802
15878
  });
15803
15879
  }
15804
15880
  validateEvents(processed);
15805
15881
  });
15806
15882
 
15807
- // src/@building/building.create.ts
15808
- var createEvent = (stanza) => __async(null, null, function* () {
15809
- const settings = bootstrap.settings;
15810
- const StanzaSettings = settings.NOAAWeatherWireServiceSettings.StanzaSettings;
15811
- const isVtecEvent = stanza.isVTEC && stanza.isUGC;
15812
- const isUgcEvent = !stanza.isVTEC && stanza.isUGC;
15813
- const isTextEvent = !stanza.isVTEC && !stanza.isUGC;
15814
- const isNWWS = stanza.isNWWS;
15815
- if (!isNWWS) return yield api(stanza);
15816
- if (!StanzaSettings.DisableVTEC && isVtecEvent) return yield vtec(stanza);
15817
- if (!StanzaSettings.DisableUGC && isUgcEvent) return yield ugc(stanza);
15818
- if (!StanzaSettings.DisableText && isTextEvent) return yield text(stanza);
15819
- return "nothing picked";
15820
- });
15883
+ // src/@parsers/@ugc/ugc.header.ts
15884
+ var getUGCHeader = (message) => {
15885
+ const start = message.search(dict_expressions.ugc1);
15886
+ const sub = message.substring(start);
15887
+ const end = sub.search(dict_expressions.ugc2);
15888
+ const fin = sub.substring(0, end).replace(/\s+/g, "").slice(0, -1);
15889
+ return fin != null ? fin : null;
15890
+ };
15821
15891
 
15822
- // src/@modules/@database/database.stanza.ts
15823
- var importStanza = (stanza) => __async(null, null, function* () {
15824
- const settings = bootstrap.settings;
15825
- try {
15826
- if (!settings.NOAAWeatherWireServiceSettings.CacheSettings.Enabled) {
15827
- return;
15892
+ // src/@parsers/@ugc/ugc.zones.ts
15893
+ var getZones = (header) => {
15894
+ const splits = header.split("-");
15895
+ const zones = [];
15896
+ let state = splits[0].substring(0, 2);
15897
+ const format = splits[0].substring(2, 3);
15898
+ for (const part of splits) {
15899
+ if (/^[A-Z]/.test(part)) {
15900
+ state = part.substring(0, 2);
15901
+ if (part.includes(">")) {
15902
+ const [start, end] = part.split(">");
15903
+ const startNum = parseInt(start.substring(3), 10);
15904
+ const endNum = parseInt(end, 10);
15905
+ for (let j2 = startNum; j2 <= endNum; j2++) {
15906
+ zones.push(`${state}${format}${j2.toString().padStart(3, "0")}`);
15907
+ }
15908
+ } else {
15909
+ zones.push(part);
15910
+ }
15911
+ continue;
15828
15912
  }
15829
- bootstrap.database.prepare(`INSERT OR IGNORE INTO stanzas (type, stanza, issued) VALUES (?, ?, ?)`).run(stanza.getType.type, JSON.stringify(stanza), stanza.attributes.issue);
15830
- const count = bootstrap.database.prepare(`SELECT COUNT(*) as total FROM stanzas`).get();
15831
- const max = settings.NOAAWeatherWireServiceSettings.CacheSettings.MaxDatabaseHistory;
15832
- if (count.total > max) {
15833
- const toDelete = count.total - max;
15834
- if (toDelete > 0) {
15835
- bootstrap.database.prepare(`DELETE FROM stanzas WHERE id IN (SELECT id FROM stanzas ORDER BY issued ASC LIMIT ?)`).run(toDelete);
15913
+ if (part.includes(">")) {
15914
+ const [start, end] = part.split(">");
15915
+ const startNum = parseInt(start, 10);
15916
+ const endNum = parseInt(end, 10);
15917
+ for (let j2 = startNum; j2 <= endNum; j2++) {
15918
+ zones.push(`${state}${format}${j2.toString().padStart(3, "0")}`);
15836
15919
  }
15920
+ } else {
15921
+ zones.push(`${state}${format}${part}`);
15837
15922
  }
15838
- } catch (error) {
15839
- setWarning({ message: `An error occurred while importing stanza: ${error.message}` });
15840
15923
  }
15924
+ return zones.filter((item) => item !== "");
15925
+ };
15926
+
15927
+ // src/@parsers/@ugc/ugc.expiry.ts
15928
+ var getExpiry = (message) => {
15929
+ const match = message.match(/\b(\d{6})-/);
15930
+ if (!match) {
15931
+ return null;
15932
+ }
15933
+ const date = match == null ? void 0 : match[1];
15934
+ const day = parseInt(date == null ? void 0 : date.slice(0, 2), 10);
15935
+ const hour = parseInt(date == null ? void 0 : date.slice(2, 4), 10);
15936
+ const minute = parseInt(date == null ? void 0 : date.slice(4, 6), 10);
15937
+ const now = /* @__PURE__ */ new Date();
15938
+ const expires = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), day, hour, minute));
15939
+ return expires.toISOString();
15940
+ };
15941
+
15942
+ // src/@parsers/@ugc/ugc.locations.ts
15943
+ var getLocations = (zones) => __async(null, null, function* () {
15944
+ const sites = Array.from(new Set(zones));
15945
+ const placeholders = sites.map(() => "?").join(",");
15946
+ const rows = yield bootstrap.database.prepare(`SELECT id, location FROM shapefiles WHERE id IN (${placeholders})`).all(...sites);
15947
+ return rows.map((row) => row.location).sort();
15841
15948
  });
15842
15949
 
15843
- // src/@modules/@xmpp/xmpp.xStanza.ts
15844
- var xStanza = () => {
15845
- bootstrap.session_xmpp.on(`stanza`, (stanza) => __async(null, null, function* () {
15846
- var _a, _b, _c, _d;
15847
- const msgFrom = (_b = (_a = stanza == null ? void 0 : stanza.attrs) == null ? void 0 : _a.from) != null ? _b : ``;
15848
- const msgType = (_d = (_c = stanza == null ? void 0 : stanza.attrs) == null ? void 0 : _c.type) != null ? _d : ``;
15849
- setEventEmit({
15850
- event: `onServiceStatus`,
15851
- metadata: {
15852
- message: stanza,
15853
- from: msgFrom,
15854
- type: `stanza`
15855
- }
15856
- });
15857
- bootstrap.cache.lastStanza = Date.now();
15858
- if (stanza.is(`message`)) {
15859
- const result = validate({ stanza });
15860
- const isSkippable = result.isIgnored || result.isCapEvent || result.isCapEvent && !result.isCapAreaDescription;
15861
- if (isSkippable) {
15862
- return;
15950
+ // src/@parsers/@ugc/ugc.extract.ts
15951
+ var ugcExtract = (message) => __async(null, null, function* () {
15952
+ const head = getUGCHeader(message);
15953
+ const ugcs = getZones(head);
15954
+ const expires = getExpiry(message);
15955
+ const areas = yield getLocations(ugcs);
15956
+ if (!head || (ugcs == null ? void 0 : ugcs.length) == 0) return;
15957
+ return {
15958
+ zones: ugcs,
15959
+ locations: areas,
15960
+ expires
15961
+ };
15962
+ });
15963
+
15964
+ // src/@events/events.ugc.ts
15965
+ var ugc = (stanza) => __async(null, null, function* () {
15966
+ var _a, _b, _c;
15967
+ let processed = [];
15968
+ const getMessages = (_c = (_b = (_a = stanza == null ? void 0 : stanza.message) == null ? void 0 : _a.split(/(?=\$\$)/g)) == null ? void 0 : _b.map((message) => message.trim())) == null ? void 0 : _c.filter((message) => message && message !== "$$");
15969
+ if (!getMessages || (getMessages == null ? void 0 : getMessages.length) == 0) return;
15970
+ for (const message of getMessages) {
15971
+ const tick = performance.now();
15972
+ const attributes = stanza == null ? void 0 : stanza.attributes;
15973
+ const ugc2 = yield ugcExtract(message);
15974
+ if (ugc2 != null) {
15975
+ const props = properties({ message, attributes, ugc: ugc2 });
15976
+ const issued = new Date(attributes.issue);
15977
+ const expires = new Date(ugc2.expires);
15978
+ const header = getEventHeader({ properties: props, getType: stanza.getType });
15979
+ let event = Object.keys(dict_matches).find((event2) => message.toLowerCase().includes(event2.toLowerCase()));
15980
+ let isStatement = false;
15981
+ if (!event) {
15982
+ event = stanza.getType.type.split(`-`).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(` `);
15983
+ isStatement = true;
15863
15984
  }
15864
- yield createEvent(result);
15865
- yield importStanza(result);
15866
- }
15867
- if (stanza.is(`presence`) && msgFrom.startsWith("nwws@conference.nwws-oi.weather.gov/")) {
15868
- const getOccupant = msgFrom.split(`/`).slice(1).join(`/`);
15869
- const getAvailability = msgType === `unavailable`;
15870
- setEventEmit({
15871
- event: `onServiceStatus`,
15872
- metadata: {
15873
- message: `Occupant ${getOccupant} has ${getAvailability ? `left` : `joined`} the room`,
15874
- data: {},
15875
- type: `occupant`,
15876
- error: false
15877
- }
15985
+ processed.push({
15986
+ type: `Feature`,
15987
+ geometry: {
15988
+ type: `Point`,
15989
+ coordinates: []
15990
+ },
15991
+ properties: __spreadProps(__spreadValues({
15992
+ event,
15993
+ parent: event,
15994
+ status: isStatement ? `Statement` : `Issued`,
15995
+ issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
15996
+ expires: isStatement ? new Date(issued.getTime() + 120 * 1e3).toISOString() : !isNaN(expires.getTime()) ? expires.toISOString() : new Date(Date.now() + 60 * 60 * 1e3).toISOString()
15997
+ }, props), {
15998
+ metadata: {
15999
+ ms: performance.now() - tick,
16000
+ source: `events.ugc`,
16001
+ tracking: getEventTracking({ type: `RAW`, stanza, attributes, properties: props }),
16002
+ header,
16003
+ vtec: null,
16004
+ hvtec: null,
16005
+ raw: message,
16006
+ history: [
16007
+ {
16008
+ description: props.description,
16009
+ issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
16010
+ status: `Issued`
16011
+ }
16012
+ ]
16013
+ }
16014
+ })
15878
16015
  });
15879
16016
  }
15880
- }));
15881
- };
15882
-
15883
- // src/@modules/@xmpp/xmpp.xDeploy.ts
15884
- var xDeploy = () => __async(null, null, function* () {
15885
- var _a, _b;
15886
- let session;
15887
- const settings = bootstrap.settings;
15888
- (_b = (_a = settings.NOAAWeatherWireServiceSettings.CredentialSettings).Nickname) != null ? _b : _a.Nickname = settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username;
15889
- session = bootstrap.session_xmpp = client({
15890
- service: "xmpp://nwws-oi.weather.gov",
15891
- domain: "nwws-oi.weather.gov",
15892
- username: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username,
15893
- password: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Password
15894
- });
15895
- try {
15896
- yield xOffline();
15897
- yield xError();
15898
- yield xStanza();
15899
- yield xOnline();
15900
- yield session.start();
15901
- } catch (error) {
15902
- setEventEmit({
15903
- event: `onServiceStatus`,
15904
- metadata: {
15905
- message: `Error occured while starting XMPP Session: ${error}`,
15906
- data: {},
15907
- type: `error`,
15908
- error: true
15909
- }
15910
- });
15911
16017
  }
16018
+ validateEvents(processed);
15912
16019
  });
15913
16020
 
15914
- // src/@modules/@database/database.init.ts
15915
- var import_fs2 = __toESM(require("fs"));
15916
- var import_better_sqlite3 = __toESM(require("better-sqlite3"));
15917
-
15918
- // src/@modules/@database/database.shapefiles.ts
15919
- var import_fs = __toESM(require("fs"));
15920
- var import_path2 = require("path");
15921
- var import_jszip = require("jszip");
15922
- var import_shapefile = require("shapefile");
15923
-
15924
- // src/@modules/@utilities/utilities.setSleep.ts
15925
- var setSleep = (options) => __async(null, null, function* () {
15926
- return new Promise((resolve6) => {
15927
- setTimeout(() => {
15928
- resolve6();
15929
- }, options.timeout);
15930
- });
15931
- });
15932
-
15933
- // src/@dictionaries/dictionaries.shapefileLinks.ts
15934
- var shapefileLinks = [
15935
- { name: "us_counties", id: "C", link: "https://www.weather.gov/source/gis/Shapefiles/County/c_16ap26.zip" },
15936
- { name: "us_states_territories", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/County/s_16ap26.zip" },
15937
- { name: "fire_weather_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/fz16ap26.zip" },
15938
- { name: "costal_marine_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/mz16ap26.zip" },
15939
- { name: "offshore_marine_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/oz16ap26.zip" },
15940
- { name: "public_forecast_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/z_16ap26.zip" },
15941
- { name: "county_warning_areas", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/w_16ap26.zip" },
15942
- { name: "river_forecast_boundaries", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/Misc/rf05mr24.zip" },
15943
- { name: "high_seas_marine_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/hz17fe26.zip" }
15944
- ];
15945
-
15946
- // src/@modules/@database/database.shapefiles.ts
15947
- var importShapefiles = () => __async(null, null, function* () {
15948
- var _a, _b;
15949
- const settings = bootstrap.settings;
15950
- try {
15951
- const tShapefiles = bootstrap.database.prepare(`SELECT COUNT(*) AS count FROM shapefiles`).get().count;
15952
- if (tShapefiles === 0) {
15953
- yield setSleep({ timeout: 1e3 });
15954
- setWarning({ message: `Shapefiles are currently building, please DO NOT close your terminal. The shapefiles will not finish and will remain incomplete. If you do mess up, you will need to delete ${settings.Database} and restart the application.` });
15955
- for (const shapefile of shapefileLinks) {
15956
- const response2 = yield fetch(shapefile.link);
15957
- const arrayBuff = yield response2.arrayBuffer();
15958
- const content = yield (0, import_jszip.loadAsync)(arrayBuff);
15959
- const directory = (0, import_path2.resolve)(__dirname, `../../shapefiles`);
15960
- if (!import_fs.default.existsSync(directory)) {
15961
- import_fs.default.mkdirSync(directory, { recursive: true });
15962
- }
15963
- for (const file of Object.keys(content.files)) {
15964
- if (file.endsWith(".shp") || file.endsWith(".dbf")) {
15965
- const data = yield content.files[file].async(`nodebuffer`);
15966
- const output = (0, import_path2.resolve)(directory, `${(_a = shapefile == null ? void 0 : shapefile.name) != null ? _a : ``}_${(_b = shapefile == null ? void 0 : shapefile.id) != null ? _b : ``}${(0, import_path2.extname)(file)}`);
15967
- import_fs.default.writeFileSync(output, data);
15968
- }
15969
- }
15970
- const filepath = (0, import_path2.resolve)(__dirname, "../../shapefiles", shapefile.name + "_" + shapefile.id);
15971
- const { features } = yield (0, import_shapefile.read)(
15972
- filepath,
15973
- filepath
15974
- );
15975
- setWarning({ message: `Importing ${features.length} features from ${shapefile.name}_${shapefile.id}` });
15976
- const insert = bootstrap.database.prepare(`INSERT OR REPLACE INTO shapefiles (id, location, geometry) VALUES (?, ?, ?)`);
15977
- const transaction = bootstrap.database.transaction((entries) => {
15978
- var _a2, _b2, _c;
15979
- for (const entry of entries) {
15980
- const { properties: properties2, geometry } = entry;
15981
- let final2, location;
15982
- if (properties2.FIPS) {
15983
- final2 = `${properties2.STATE}${shapefile.id}${properties2.FIPS.substring(2)}`;
15984
- location = `${properties2.COUNTYNAME}, ${properties2.STATE}`;
15985
- } else if (properties2.FULLSTAID) {
15986
- final2 = `${properties2.ST}${shapefile.id}${properties2.WFO}`;
15987
- location = `${properties2.CITY}, ${properties2.STATE}`;
15988
- } else if (properties2.STATE) {
15989
- final2 = `${properties2.STATE}${shapefile.id}${(_a2 = properties2.ZONE) != null ? _a2 : properties2.SITE_ID}`;
15990
- location = `${(_b2 = properties2.NAME) != null ? _b2 : `${properties2.RFC_NAME} ${properties2.RFC_CITY}`}, ${properties2.STATE}`;
15991
- } else {
15992
- final2 = (_c = properties2.ID) != null ? _c : properties2.WFO;
15993
- location = properties2.NAME;
15994
- }
15995
- insert.run(final2, location, JSON.stringify(geometry));
15996
- }
15997
- });
15998
- import_fs.default.unlinkSync(`${filepath}.shp`);
15999
- import_fs.default.unlinkSync(`${filepath}.dbf`);
16000
- setWarning({ message: `Cleaned up temporary files for ${shapefile.name}_${shapefile.id}` });
16001
- transaction(features);
16002
- }
16003
- setWarning({ message: `Shapefiles have finished compiling, you can now continue and close this terminal` });
16004
- import_fs.default.rm((0, import_path2.resolve)(__dirname, "../../shapefiles"), { recursive: true, force: true }, () => {
16005
- });
16006
- }
16007
- } catch (error) {
16008
- setWarning({ message: `An error occurred while compiling shapefiles: ${error.message}` });
16009
- }
16010
- });
16011
-
16012
- // src/@modules/@database/database.init.ts
16013
- var initializeDatabase = () => __async(null, null, function* () {
16014
- const settings = bootstrap.settings;
16015
- try {
16016
- if (!import_fs2.default.existsSync(settings.Database)) {
16017
- import_fs2.default.writeFileSync(settings.Database, "");
16018
- setWarning({ message: `Creating new database at ${settings.Database}` });
16019
- }
16020
- bootstrap.database = new import_better_sqlite3.default(settings.Database);
16021
- bootstrap.database.prepare(`CREATE TABLE IF NOT EXISTS stanzas ( id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, issued TEXT, stanza TEXT )`).run();
16022
- bootstrap.database.prepare(`CREATE TABLE IF NOT EXISTS shapefiles (id TEXT PRIMARY KEY, location TEXT, geometry TEXT)`).run();
16023
- yield importShapefiles();
16024
- } catch (error) {
16025
- setWarning({ message: `An error occurred while initializing the database: ${error.message}` });
16026
- }
16027
- });
16028
-
16029
- // src/@modules/@database/database.cache.ts
16030
- var getCachedEvents = () => __async(null, null, function* () {
16031
- var _a;
16032
- try {
16033
- const settings = bootstrap.settings;
16034
- const tick = performance.now();
16035
- if (settings.NOAAWeatherWireServiceSettings.CacheSettings.Enabled) {
16036
- const max = (_a = settings.NOAAWeatherWireServiceSettings.CacheSettings.MaxRetentionHistory) != null ? _a : 500;
16037
- const get = yield bootstrap.database.prepare(`SELECT * FROM stanzas ORDER BY rowid DESC LIMIT ?`).all(max);
16038
- setWarning({ message: `Fetched ${get.length} cached events from the database in ${Math.floor(performance.now() - tick)} ms` });
16039
- let events = get.map((row) => JSON.parse(row.stanza)).filter((stanza) => {
16040
- if (!stanza) {
16041
- return;
16042
- }
16043
- const isSkippable = stanza.isIgnored || stanza.isCapEvent || stanza.isCapEvent && !stanza.isCapAreaDescription;
16044
- return !isSkippable;
16045
- });
16046
- events = events.sort((a, b) => b.issued - a.issued);
16047
- yield Promise.all(events.map((event) => createEvent(event)));
16048
- setWarning({ message: `Processed ${events.length} cached events in ${Math.floor(performance.now() - tick)} ms` });
16049
- }
16050
- } catch (error) {
16051
- setWarning({ message: `An error occurred while fetching cached events: ${error.message} -> ${error.stack}` });
16052
- }
16053
- });
16054
-
16055
- // src/@modules/@xmpp/xmpp.xReconnect.ts
16056
- var xReconnect = (interval) => __async(null, null, function* () {
16057
- const settings = bootstrap.settings;
16058
- const lastStanza = Date.now() - bootstrap.cache.lastStanza;
16059
- if (interval < 15) {
16060
- setWarning({ message: `Reconnection interval of ${interval} seconds is too low, setting to 15 seconds` });
16061
- interval = 15;
16062
- bootstrap.settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.ReconnectionInterval = 15;
16063
- }
16064
- const reconnectThreshold = interval * 1e3;
16065
- if (!bootstrap.cache.isConnected && !bootstrap.cache.sigHault || !bootstrap.session_xmpp) {
16066
- return;
16067
- }
16068
- if (lastStanza > reconnectThreshold) {
16069
- if (!bootstrap.cache.isReconnecting) {
16070
- bootstrap.cache.isReconnecting = true;
16071
- bootstrap.cache.isConnected = false;
16072
- bootstrap.cache.tReconnects += 1;
16073
- try {
16074
- setEventEmit({
16075
- event: `onServiceStatus`,
16076
- metadata: {
16077
- message: `Attempting to reconnect to XMPP Service (Reconnect Attempt ${bootstrap.cache.tReconnects})`,
16078
- data: {
16079
- last_stanza: lastStanza,
16080
- nickname: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Nickname
16081
- },
16082
- type: `reconnect`,
16083
- error: true
16084
- }
16085
- });
16086
- yield bootstrap.session_xmpp.stop().catch(() => {
16087
- });
16088
- yield bootstrap.session_xmpp.start().catch(() => {
16089
- });
16090
- } catch (error) {
16091
- setWarning({ message: `XMPP Reconnect Failed - ${error.message}` });
16092
- } finally {
16093
- bootstrap.cache.isReconnecting = false;
16094
- }
16095
- }
16096
- }
16097
- });
16098
-
16099
- // src/@modules/@utilities/utilities.setCronSchedule.ts
16100
- var setCronSchedule = () => __async(null, null, function* () {
16101
- const settings = bootstrap.settings;
16102
- if (settings.EnableWireService) {
16103
- if (settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.Enabled) {
16104
- void xReconnect(settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.ReconnectionInterval);
16105
- }
16106
- } else {
16107
- const response2 = yield createHttp({
16108
- url: settings.NationalWeatherServiceSettings.EventsEndpoint,
16109
- headers: {
16110
- "User-Agent": "@atmosx/event-product-parser"
16111
- }
16112
- });
16113
- if (response2.error) {
16114
- return setEventEmit({
16115
- event: `onServiceStatus`,
16116
- metadata: {
16117
- type: "fetch-api",
16118
- message: `Failed to fetch latest events from National Weather Service API - ${response2.message}`,
16119
- data: {},
16120
- error: true
16121
- }
16122
- });
16123
- }
16124
- setEventEmit({
16125
- event: `onServiceStatus`,
16126
- metadata: {
16127
- message: `Fetched latest events from National Weather Service API`,
16128
- data: {},
16129
- type: "fetch-api",
16130
- error: false
16131
- }
16132
- });
16133
- createEvent({ message: response2.message, isNWWS: false });
16134
- }
16135
- });
16136
-
16137
- // src/@manager/manager.updateEvents.ts
16138
- var updateEvents = (selectedEvent) => __async(null, null, function* () {
16139
- const events = bootstrap.cache.events.features;
16140
- function update(evt) {
16141
- return __async(this, null, function* () {
16142
- if (new Date(evt.properties.expires) < /* @__PURE__ */ new Date()) {
16143
- rmEvent(evt);
16144
- }
16145
- });
16146
- }
16147
- if (!selectedEvent) {
16148
- yield Promise.all(events.map((evt) => __async(null, null, function* () {
16149
- yield update(evt);
16150
- })));
16151
- }
16152
- if (selectedEvent) {
16153
- yield update(selectedEvent);
16154
- }
16155
- });
16156
-
16157
- // src/@core/core.start.ts
16158
- var import_croner = require("croner");
16159
- var startService = (configurations) => __async(null, null, function* () {
16160
- if (!bootstrap.isReady) {
16161
- return setWarning({
16162
- message: `You can not create another instance without shutting down the current one first, please make sure to call the stop() method first!`
16163
- });
16164
- }
16165
- const settings = setSettings(configurations);
16166
- bootstrap.isReady = true;
16167
- yield initializeDatabase();
16168
- if (settings.EnableWireService) {
16169
- (() => __async(null, null, function* () {
16170
- yield getCachedEvents();
16171
- yield xDeploy();
16172
- }))();
16173
- }
16174
- yield setCronSchedule();
16175
- let scheduleInterval = !settings.EnableWireService ? settings.NationalWeatherServiceSettings.CallbackInterval : 1;
16176
- if (!settings.EnableWireService && scheduleInterval < 15) {
16177
- setWarning({ message: `Schedule interval of ${scheduleInterval} seconds is too low, setting to 15 seconds` });
16178
- bootstrap.settings.NationalWeatherServiceSettings.CallbackInterval = 15;
16179
- scheduleInterval = 15;
16180
- }
16181
- bootstrap.cron = new import_croner.Cron(`*/${scheduleInterval} * * * * *`, () => __async(null, null, function* () {
16182
- yield setCronSchedule();
16183
- }));
16184
- bootstrap.cron = new import_croner.Cron(`* * * * * *`, () => __async(null, null, function* () {
16185
- yield updateNode();
16186
- yield updateEvents();
16187
- }));
16188
- });
16021
+ // src/@dictionaries/dictionaries.events.ts
16022
+ var dict_events = {
16023
+ "AF": "Ashfall",
16024
+ "AS": "Air Stagnation",
16025
+ "BH": "Beach Hazard",
16026
+ "BW": "Brisk Wind",
16027
+ "BZ": "Blizzard",
16028
+ "CF": "Coastal Flood",
16029
+ "DF": "Debris Flow",
16030
+ "DS": "Dust Storm",
16031
+ "EC": "Extreme Cold",
16032
+ "EH": "Excessive Heat",
16033
+ "XH": "Extreme Heat",
16034
+ "EW": "Extreme Wind",
16035
+ "FA": "Areal Flood",
16036
+ "FF": "Flash Flood",
16037
+ "FG": "Dense Fog",
16038
+ "FL": "Flood",
16039
+ "FR": "Frost",
16040
+ "FW": "Fire Weather",
16041
+ "FZ": "Freeze",
16042
+ "GL": "Gale",
16043
+ "HF": "Hurricane Force Wind",
16044
+ "HT": "Heat",
16045
+ "HU": "Hurricane",
16046
+ "HW": "High Wind",
16047
+ "HY": "Hydrologic",
16048
+ "HZ": "Hard Freeze",
16049
+ "IS": "Ice Storm",
16050
+ "LE": "Lake Effect Snow",
16051
+ "LO": "Low Water",
16052
+ "LS": "Lakeshore Flood",
16053
+ "LW": "Lake Wind",
16054
+ "MA": "Special Marine",
16055
+ "EQ": "Earthquake",
16056
+ "MF": "Dense Fog",
16057
+ "MH": "Ashfall",
16058
+ "MS": "Dense Smoke",
16059
+ "RB": "Small Craft for Rough Bar",
16060
+ "RP": "Rip Current Risk",
16061
+ "SC": "Small Craft",
16062
+ "SE": "Hazardous Seas",
16063
+ "SI": "Small Craft for Winds",
16064
+ "SM": "Dense Smoke",
16065
+ "SQ": "Snow Squall",
16066
+ "SR": "Storm",
16067
+ "SS": "Storm Surge",
16068
+ "SU": "High Surf",
16069
+ "SV": "Severe Thunderstorm",
16070
+ "SW": "Small Craft for Hazardous Seas",
16071
+ "TO": "Tornado",
16072
+ "TR": "Tropical Storm",
16073
+ "TS": "Tsunami",
16074
+ "TY": "Typhoon",
16075
+ "SP": "Special Weather",
16076
+ "UP": "Heavy Freezing Spray",
16077
+ "WC": "Wind Chill",
16078
+ "WI": "Wind",
16079
+ "WS": "Winter Storm",
16080
+ "WW": "Winter Weather",
16081
+ "ZF": "Freezing Fog",
16082
+ "ZR": "Freezing Rain",
16083
+ "ZY": "Freezing Spray"
16084
+ };
16189
16085
 
16190
- // src/@core/core.stop.ts
16191
- var stopService = () => __async(null, null, function* () {
16192
- if (bootstrap.isReady) {
16193
- bootstrap.isReady = false;
16194
- if (bootstrap.session_xmpp) {
16195
- try {
16196
- yield bootstrap.session_xmpp.stop();
16197
- } catch (e) {
16198
- }
16199
- bootstrap.cache.isConnected = false;
16200
- bootstrap.cache.sigHault = true;
16201
- bootstrap.session_xmpp = null;
16202
- }
16203
- }
16204
- });
16086
+ // src/@dictionaries/dictionaries.actions.ts
16087
+ var dict_actions = {
16088
+ "W": "Warning",
16089
+ "F": "Forecast",
16090
+ "A": "Watch",
16091
+ "O": "Outlook",
16092
+ "Y": "Advisory",
16093
+ "N": "Synopsis",
16094
+ "S": "Statement"
16095
+ };
16205
16096
 
16206
- // src/@dictionaries/dictionaries.transcribedMessageReplacements.ts
16207
- var transcribedMessageReplacements = [
16208
- { regex: /\*/g, replacement: "" },
16209
- { regex: /\.{3,}/g, replacement: "" },
16210
- { regex: /\bUTC\b/g, replacement: "Coordinated Universal Time" },
16211
- { regex: /\bGMT\b/g, replacement: "Greenwich Mean Time" },
16212
- { regex: /\bEST\b(?!\w)/g, replacement: "Eastern Standard Time" },
16213
- { regex: /\bEDT\b(?!\w)/g, replacement: "Eastern Daylight Time" },
16214
- { regex: /\bCST\b(?!\w)/g, replacement: "Central Standard Time" },
16215
- { regex: /\bCDT\b(?!\w)/g, replacement: "Central Daylight Time" },
16216
- { regex: /\bMST\b(?!\w)/g, replacement: "Mountain Standard Time" },
16217
- { regex: /\bMDT\b(?!\w)/g, replacement: "Mountain Daylight Time" },
16218
- { regex: /\bPST\b(?!\w)/g, replacement: "Pacific Standard Time" },
16219
- { regex: /\bPDT\b(?!\w)/g, replacement: "Pacific Daylight Time" },
16220
- { regex: /\bAKST\b(?!\w)/g, replacement: "Alaska Standard Time" },
16221
- { regex: /\bAKDT\b(?!\w)/g, replacement: "Alaska Daylight Time" },
16222
- { regex: /\bHST\b(?!\w)/g, replacement: "Hawaii Standard Time" },
16223
- { regex: /\bHDT\b(?!\w)/g, replacement: "Hawaii Daylight Time" },
16224
- { regex: /\bmph\b(?!\w)/g, replacement: "miles per hour" },
16225
- { regex: /\bkm\/h\b(?!\w)/g, replacement: "kilometers per hour" },
16226
- { regex: /\bkmh\b(?!\w)/g, replacement: "kilometers per hour" },
16227
- { regex: /\bkt\b(?!\w)/g, replacement: "knots" },
16228
- { regex: /\bNE\b(?!\w)/g, replacement: "northeast" },
16229
- { regex: /\bNW\b(?!\w)/g, replacement: "northwest" },
16230
- { regex: /\bSE\b(?!\w)/g, replacement: "southeast" },
16231
- { regex: /\bSW\b(?!\w)/g, replacement: "southwest" },
16232
- { regex: /\bNM\b(?!\w)/g, replacement: "nautical miles" },
16233
- { regex: /\bdeg\b(?!\w)/g, replacement: "degrees" },
16234
- { regex: /\btstm\b(?!\w)/g, replacement: "thunderstorm" },
16235
- { regex: /\bmm\b(?!\w)/g, replacement: "millimeters" },
16236
- { regex: /\bcm\b(?!\w)/g, replacement: "centimeters" },
16237
- { regex: /\bin.\b(?!\w)/g, replacement: "inches" },
16238
- { regex: /\bft\b(?!\w)/g, replacement: "feet" },
16239
- { regex: /\bmi\b(?!\w)/g, replacement: "miles" },
16240
- { regex: /\bhr\b(?!\w)/g, replacement: "hour" },
16241
- { regex: /\bhourly\b(?!\w)/g, replacement: "per hour" },
16242
- { regex: /\bkg\b(?!\w)/g, replacement: "kilograms" },
16243
- { regex: /\bg\/kg\b(?!\w)/g, replacement: "grams per kilogram" },
16244
- { regex: /\bmb\b(?!\w)/g, replacement: "millibars" },
16245
- { regex: /\bhPa\b(?!\w)/g, replacement: "hectopascals" },
16246
- { regex: /\bPa\b(?!\w)/g, replacement: "pascals" },
16247
- { regex: /\bKPa\b(?!\w)/g, replacement: "kilopascals" },
16248
- { regex: /\bC\/hr\b(?!\w)/g, replacement: "degrees Celsius per hour" },
16249
- { regex: /\bF\/hr\b(?!\w)/g, replacement: "degrees Fahrenheit per hour" },
16250
- { regex: /\bC\/min\b(?!\w)/g, replacement: "degrees Celsius per minute" },
16251
- { regex: /\bF\/min\b(?!\w)/g, replacement: "degrees Fahrenheit per minute" },
16252
- { regex: /\bC\b(?!\w)/g, replacement: "degrees Celsius" },
16253
- { regex: /\bF\b(?!\w)/g, replacement: "degrees Fahrenheit" }
16254
- ];
16097
+ // src/@dictionaries/dictionaries.status.ts
16098
+ var dict_status = {
16099
+ "NEW": "Issued",
16100
+ "CON": "Updated",
16101
+ "EXT": "Extended",
16102
+ "EXA": "Extended",
16103
+ "EXB": "Extended",
16104
+ "UPG": "Upgraded",
16105
+ "COR": "Correction",
16106
+ "ROU": "Routine",
16107
+ "CAN": "Cancelled",
16108
+ "EXP": "Expired"
16109
+ };
16255
16110
 
16256
- // src/@modules/@eas/eas.getWavPCM16.ts
16257
- var getWavPCM16 = (buffer) => {
16258
- if (buffer.toString("ascii", 0, 4) !== "RIFF" || buffer.toString("ascii", 8, 12) !== "WAVE") {
16259
- return null;
16260
- }
16261
- let fmt = null;
16262
- let data = null;
16263
- let i = 12;
16264
- while (i + 8 <= buffer.length) {
16265
- const id2 = buffer.toString("ascii", i, i + 4);
16266
- const size = buffer.readUInt32LE(i + 4);
16267
- const start = i + 8;
16268
- const end = start + size;
16269
- if (id2 === "fmt ") fmt = buffer.slice(start, end);
16270
- if (id2 === "data") data = buffer.slice(start, end);
16271
- i = end + size % 2;
16272
- }
16273
- if (!fmt || !data) return null;
16274
- const audioFormat = fmt.readUInt16LE(0);
16275
- const channels = fmt.readUInt16LE(2);
16276
- const sampleRate = fmt.readUInt32LE(4);
16277
- const bitsPerSample = fmt.readUInt16LE(14);
16278
- if (audioFormat !== 1 || bitsPerSample !== 16 || channels !== 1) {
16279
- return null;
16280
- }
16281
- const samples = new Int16Array(data.buffer, data.byteOffset, data.length / 2);
16282
- return { samples: new Int16Array(samples), sampleRate, channels, bitsPerSample };
16111
+ // src/@parsers/@pvtec/pvtec.expires.ts
16112
+ var getExpiry2 = (dates) => {
16113
+ if ((dates == null ? void 0 : dates[1]) == `000000T0000Z`) return "Invalid Date Format";
16114
+ const expires = `${(/* @__PURE__ */ new Date()).getFullYear().toString().substring(0, 2)}${dates[1].substring(0, 2)}-${dates[1].substring(2, 4)}-${dates[1].substring(4, 6)}T${dates[1].substring(7, 9)}:${dates[1].substring(9, 11)}:00`;
16115
+ const local = new Date(new Date(expires).getTime() - 4 * 60 * 6e4);
16116
+ const pad = (n) => n.toString().padStart(2, "0");
16117
+ return `${local.getFullYear()}-${pad(local.getMonth() + 1)}-${pad(local.getDate())}T${pad(local.getHours())}:${pad(local.getMinutes())}:00.000-04:00`;
16283
16118
  };
16284
16119
 
16285
- // src/@modules/@eas/eas.getSampledPCM16.ts
16286
- var getSampledPCM16 = (int16, originalRate, targetRate) => {
16287
- if (originalRate === targetRate) return int16;
16288
- const ratio = targetRate / originalRate;
16289
- const outLen = Math.max(1, Math.round(int16.length * ratio));
16290
- const out = new Int16Array(outLen);
16291
- for (let i = 0; i < outLen; i++) {
16292
- const pos = i / ratio;
16293
- const i0 = Math.floor(pos);
16294
- const i1 = Math.min(i0 + 1, int16.length - 1);
16295
- const frac = pos - i0;
16296
- const v = int16[i0] * (1 - frac) + int16[i1] * frac;
16297
- out[i] = Math.round(v);
16120
+ // src/@parsers/@pvtec/pvtec.extract.ts
16121
+ var pvExtract = (message) => {
16122
+ var _a, _b, _c, _d;
16123
+ if (!message) return null;
16124
+ const getVTECs = (_a = message.match(dict_expressions.pvtec)) != null ? _a : [];
16125
+ const vtecs = [];
16126
+ for (const vtec2 of getVTECs) {
16127
+ const sub = vtec2.split(`.`);
16128
+ if ((sub == null ? void 0 : sub.length) < 7) continue;
16129
+ const dates = (_b = sub[6]) == null ? void 0 : _b.split(`-`);
16130
+ vtecs.push({
16131
+ vtec: vtec2,
16132
+ product: dict_products[sub[0]],
16133
+ tracking: `${sub[2]}.${sub[3]}.${sub[4]}.${sub[5]}`,
16134
+ event: `${dict_events[sub[3]]} ${dict_actions[sub[4]]}`,
16135
+ status: dict_status[sub[1]],
16136
+ organization: (_d = (_c = message.match(dict_expressions.wmo)) == null ? void 0 : _c[0]) != null ? _d : null,
16137
+ expires: getExpiry2(dates),
16138
+ is_watch: (sub[4] == `A` || sub[4] == `Y`) && (sub[3] == `TO` || sub[3] == `SV`),
16139
+ prediction_center: sub[2] == `KWNS` ? true : false
16140
+ });
16298
16141
  }
16299
- return out;
16142
+ return vtecs.length > 0 ? vtecs : null;
16300
16143
  };
16301
16144
 
16302
- // src/@modules/@eas/eas.getPCMToFloat.ts
16303
- var getPCMToFloat = (int16) => {
16304
- const out = new Float32Array(int16.length);
16305
- for (let i = 0; i < int16.length; i++) out[i] = int16[i] / 32768;
16306
- return out;
16145
+ // src/@dictionaries/dictionaries.causes.ts
16146
+ var dict_causes = {
16147
+ "SM": "Snow Melt",
16148
+ "RS": "Rain/Snow Melt",
16149
+ "ER": "Excessive Rain",
16150
+ "DM": "Dam/Levee Failure",
16151
+ "IJ": "Ice Jam",
16152
+ "GO": "Glacier Lake Outburst",
16153
+ "IC": "Ice",
16154
+ "FS": "Flash Flood / Storm Surge",
16155
+ "FT": "Tidal Effects",
16156
+ "ET": "Elevated Upstream Flow",
16157
+ "MC": "Other Multiple Causes",
16158
+ "WT": "Wind and/or Tidal Effects",
16159
+ "DR": "Reservoir Release",
16160
+ "UU": "Unknown",
16161
+ "OT": "Other Effects"
16307
16162
  };
16308
16163
 
16309
- // src/@modules/@eas/eas.getFloatPCM16.ts
16310
- var getFloatPCM16 = (float32) => {
16311
- const out = new Int16Array(float32.length);
16312
- for (let i = 0; i < float32.length; i++) {
16313
- let v = Math.max(-1, Math.min(1, float32[i]));
16314
- out[i] = Math.round(v * 32767);
16315
- }
16316
- return out;
16164
+ // src/@dictionaries/dictionaries.records.ts
16165
+ var dict_records = {
16166
+ "NO": "No Record Expected",
16167
+ "NR": "Near Record or possible record",
16168
+ "UU": "Unknown history of records",
16169
+ "OO": "Other"
16317
16170
  };
16318
16171
 
16319
- // src/@modules/@eas/eas.setRadioEffect.ts
16320
- var setRadioEffect = (int16, sampleRate) => {
16321
- const hpCut = 3555;
16322
- const lpCut = 1600;
16323
- const x = getPCMToFloat(int16);
16324
- const dt = 1 / sampleRate;
16325
- const rcHP = 1 / (2 * Math.PI * hpCut);
16326
- const aHP = rcHP / (rcHP + dt);
16327
- let yHP = 0, xPrev = 0;
16328
- for (let i = 0; i < x.length; i++) {
16329
- const xi = x[i];
16330
- yHP = aHP * (yHP + xi - xPrev);
16331
- xPrev = xi;
16332
- x[i] = yHP;
16333
- }
16334
- const rcLP = 1 / (2 * Math.PI * lpCut);
16335
- const aLP = dt / (rcLP + dt);
16336
- let yLP = 0;
16337
- for (let i = 0; i < x.length; i++) {
16338
- yLP = yLP + aLP * (x[i] - yLP);
16339
- x[i] = yLP;
16172
+ // src/@dictionaries/dictionaries.severity.ts
16173
+ var dict_severity = {
16174
+ N: "Not Expected",
16175
+ 0: "Areal Flood or FF Product",
16176
+ 1: "Minor",
16177
+ 2: "Moderate",
16178
+ 3: "Major",
16179
+ U: "Unknown"
16180
+ };
16181
+
16182
+ // src/@parsers/@hvtec/hvtec.extract.ts
16183
+ var hvExtract = (message) => {
16184
+ var _a;
16185
+ const getHVTECs = (_a = message.match(dict_expressions.hvtec)) != null ? _a : [];
16186
+ const vtecs = [];
16187
+ for (const vtec2 of getHVTECs) {
16188
+ const sub = vtec2.split(`.`);
16189
+ if (sub.length < 7) continue;
16190
+ vtecs.push({
16191
+ hvtec: vtec2,
16192
+ severity: dict_severity[sub[1]],
16193
+ cause: dict_causes[sub[2]],
16194
+ record: dict_records[sub[6]]
16195
+ });
16340
16196
  }
16341
- const compGain = 2;
16342
- const norm = Math.tanh(compGain);
16343
- for (let i = 0; i < x.length; i++) x[i] = Math.tanh(x[i] * compGain) / norm;
16344
- return getFloatPCM16(x);
16197
+ return vtecs.length > 0 ? vtecs : null;
16345
16198
  };
16346
16199
 
16347
- // src/@modules/@eas/eas.setAFSK.ts
16348
- var setAFSK = (bits, sampleRate) => {
16349
- const baud = 520.83;
16350
- const markFreq = 2083.3;
16351
- const spaceFreq = 1562.5;
16352
- const amplitude = 0.6;
16353
- const twoPi = Math.PI * 2;
16354
- const result = [];
16355
- let phase = 0;
16356
- let frac = 0;
16357
- for (let b = 0; b < bits.length; b++) {
16358
- const bit = bits[b];
16359
- const freq = bit ? markFreq : spaceFreq;
16360
- const samplesPerBit = sampleRate / baud + frac;
16361
- const n = Math.round(samplesPerBit);
16362
- frac = samplesPerBit - n;
16363
- const inc = twoPi * freq / sampleRate;
16364
- for (let i = 0; i < n; i++) {
16365
- result.push(Math.round(Math.sin(phase) * amplitude * 32767));
16366
- phase += inc;
16367
- if (phase > twoPi) phase -= twoPi;
16200
+ // src/@events/events.vtec.ts
16201
+ var vtec = (stanza) => __async(null, null, function* () {
16202
+ var _a, _b, _c, _d, _e;
16203
+ let processed = [];
16204
+ const getMessages = (_c = (_b = (_a = stanza == null ? void 0 : stanza.message) == null ? void 0 : _a.split(/(?=\$\$)/g)) == null ? void 0 : _b.map((message) => message.trim())) == null ? void 0 : _c.filter((message) => message && message !== "$$");
16205
+ if (!getMessages || (getMessages == null ? void 0 : getMessages.length) == 0) return;
16206
+ for (const message of getMessages) {
16207
+ const tick = performance.now();
16208
+ const attributes = stanza == null ? void 0 : stanza.attributes;
16209
+ const pVtec = pvExtract(message);
16210
+ const hVtec = hvExtract(message);
16211
+ const ugc2 = yield ugcExtract(message);
16212
+ if (pVtec != null && ugc2 != null) {
16213
+ for (const pv of pVtec) {
16214
+ const vtec2 = pv;
16215
+ const props = properties({ message, attributes, ugc: ugc2, pVtec: vtec2 });
16216
+ const header = getEventHeader({ properties: props, getType: stanza.getType, vtec: vtec2 });
16217
+ const issued = (_d = new Date(attributes.issue)) != null ? _d : /* @__PURE__ */ new Date();
16218
+ const expires = new Date(vtec2.expires);
16219
+ processed.push({
16220
+ type: `Feature`,
16221
+ geometry: {
16222
+ type: `Point`,
16223
+ coordinates: []
16224
+ },
16225
+ properties: __spreadProps(__spreadValues({
16226
+ event: pv.event,
16227
+ parent: pv.event,
16228
+ status: pv.status,
16229
+ issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
16230
+ expires: !isNaN(expires.getTime()) ? expires.toISOString() : (_e = ugc2.expires) != null ? _e : new Date(issued.getTime() + 60 * 60 * 1e3).toISOString()
16231
+ }, props), {
16232
+ metadata: {
16233
+ ms: performance.now() - tick,
16234
+ source: `events.vtec`,
16235
+ tracking: getEventTracking({ type: `VTEC`, stanza, attributes, properties: props, vtec: vtec2 }),
16236
+ header,
16237
+ vtec: pv,
16238
+ hvtec: hVtec,
16239
+ raw: message,
16240
+ history: [
16241
+ {
16242
+ description: props.description,
16243
+ issued: !isNaN(issued.getTime()) ? issued.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
16244
+ status: pv.status
16245
+ }
16246
+ ]
16247
+ }
16248
+ })
16249
+ });
16250
+ }
16368
16251
  }
16369
16252
  }
16370
- const fadeSamples = Math.floor(sampleRate * 2e-3);
16371
- for (let i = 0; i < fadeSamples; i++) {
16372
- const gain = i / fadeSamples;
16373
- result[i] = Math.round(result[i] * gain);
16374
- result[result.length - 1 - i] = Math.round(result[result.length - 1 - i] * gain);
16253
+ validateEvents(processed);
16254
+ });
16255
+
16256
+ // src/@events/events.api.ts
16257
+ var api = (stanza) => __async(null, null, function* () {
16258
+ 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, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb;
16259
+ let processed = [];
16260
+ const messages = Object.values(JSON.parse(stanza.message).features);
16261
+ for (const feature of messages) {
16262
+ const tick = performance.now();
16263
+ const pVtec = (_d = pvExtract((_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;
16264
+ processed.push({
16265
+ type: `Feature`,
16266
+ geometry: {
16267
+ type: `Point`,
16268
+ coordinates: []
16269
+ },
16270
+ properties: {
16271
+ event: (_f = (_e = feature == null ? void 0 : feature.properties) == null ? void 0 : _e.event) != null ? _f : null,
16272
+ parent: (_h = (_g = feature == null ? void 0 : feature.properties) == null ? void 0 : _g.event) != null ? _h : null,
16273
+ status: (_j = (_i = feature == null ? void 0 : feature.properties) == null ? void 0 : _i.messageType) != null ? _j : null,
16274
+ issued: ((_k = feature == null ? void 0 : feature.properties) == null ? void 0 : _k.sent) ? new Date((_l = feature == null ? void 0 : feature.properties) == null ? void 0 : _l.sent).toISOString() : null,
16275
+ expires: ((_m = feature == null ? void 0 : feature.properties) == null ? void 0 : _m.expires) ? new Date((_n = feature == null ? void 0 : feature.properties) == null ? void 0 : _n.expires).toISOString() : null,
16276
+ locations: (_p = (_o = feature == null ? void 0 : feature.properties) == null ? void 0 : _o.areaDesc) != null ? _p : null,
16277
+ description: (_r = (_q = feature == null ? void 0 : feature.properties) == null ? void 0 : _q.description) != null ? _r : null,
16278
+ attributes: (_t = (_s = feature == null ? void 0 : feature.properties) == null ? void 0 : _s.attributes) != null ? _t : {},
16279
+ geocode: {
16280
+ office: {
16281
+ office: pVtec ? (_u = pVtec == null ? void 0 : pVtec[0]) == null ? void 0 : _u.tracking.split(`.`)[0] : null,
16282
+ name: (_w = dict_icao[pVtec ? (_v = pVtec == null ? void 0 : pVtec[0]) == null ? void 0 : _v.tracking.split(`.`)[0] : null]) != null ? _w : null
16283
+ },
16284
+ organization: (_z = (_y = (_x = feature == null ? void 0 : feature.properties) == null ? void 0 : _x.parameters) == null ? void 0 : _y.WMOidentifier) == null ? void 0 : _z[0],
16285
+ ugc: (_C = (_B = (_A = feature == null ? void 0 : feature.properties) == null ? void 0 : _A.geocode) == null ? void 0 : _B.UGC) != null ? _C : [],
16286
+ polygon: ((_D = feature == null ? void 0 : feature.geometry) == null ? void 0 : _D.coordinates.length) > 0 ? Buffer.from(JSON.stringify([(_E = feature == null ? void 0 : feature.geometry) == null ? void 0 : _E.coordinates[0]])).toString("base64") : null,
16287
+ polygon_generated: ((_F = feature == null ? void 0 : feature.geometry) == null ? void 0 : _F.coordinates.length) > 0 ? true : false
16288
+ },
16289
+ parameters: {
16290
+ tags: getEventTags((_G = feature == null ? void 0 : feature.properties) == null ? void 0 : _G.description),
16291
+ instructions: (_I = (_H = feature == null ? void 0 : feature.properties) == null ? void 0 : _H.instruction) != null ? _I : null,
16292
+ source: (_K = getTextFromProduct({ message: (_J = feature == null ? void 0 : feature.properties) == null ? void 0 : _J.description, find: [`SOURCE...`], removal: [`.`] })) != null ? _K : null,
16293
+ hazards: (_M = getTextFromProduct({ message: (_L = feature == null ? void 0 : feature.properties) == null ? void 0 : _L.description, find: [`HAZARD...`], removal: [`.`] })) != null ? _M : null,
16294
+ impacts: (_O = getTextFromProduct({ message: (_N = feature == null ? void 0 : feature.properties) == null ? void 0 : _N.description, find: [`IMPACT...`], removal: [`.`] })) != null ? _O : null,
16295
+ estimated_hail_size: (_S = (_R = (_Q = (_P = feature == null ? void 0 : feature.properties) == null ? void 0 : _P.parameters) == null ? void 0 : _Q.maxHailSize) == null ? void 0 : _R[0]) != null ? _S : null,
16296
+ estimated_wind_gusts: (_W = (_V = (_U = (_T = feature == null ? void 0 : feature.properties) == null ? void 0 : _T.parameters) == null ? void 0 : _U.maxWindGust) == null ? void 0 : _V[0]) != null ? _W : null,
16297
+ damage_threat: (__ = (_Z = (_Y = (_X = feature == null ? void 0 : feature.properties) == null ? void 0 : _X.parameters) == null ? void 0 : _Y.thunderstormDamageThreat) == null ? void 0 : _Z[0]) != null ? __ : null,
16298
+ tornado_threat: (_ca = (_ba = (_aa = (_$ = feature == null ? void 0 : feature.properties) == null ? void 0 : _$.parameters) == null ? void 0 : _aa.tornadoDetection) == null ? void 0 : _ba[0]) != null ? _ca : null,
16299
+ flood_threat: (_ga = (_fa = (_ea = (_da = feature == null ? void 0 : feature.properties) == null ? void 0 : _da.parameters) == null ? void 0 : _ea.floodDetection) == null ? void 0 : _fa[0]) != null ? _ga : null,
16300
+ wind_threat: (_ka = (_ja = (_ia = (_ha = feature == null ? void 0 : feature.properties) == null ? void 0 : _ha.parameters) == null ? void 0 : _ia.windThreat) == null ? void 0 : _ja[0]) != null ? _ka : null,
16301
+ hail_threat: (_oa = (_na = (_ma = (_la = feature == null ? void 0 : feature.properties) == null ? void 0 : _la.parameters) == null ? void 0 : _ma.hailThreat) == null ? void 0 : _na[0]) != null ? _oa : null
16302
+ },
16303
+ discussion_parameters: {
16304
+ discussion_number: (_sa = (_ra = (_qa = getTextFromProduct({ message: (_pa = feature == null ? void 0 : feature.properties) == null ? void 0 : _pa.description, find: [`Mesoscale Discussion `], removal: [`Mesoscale Discussion`, `Number`, `...`] })) == null ? void 0 : _qa.toString()) == null ? void 0 : _ra.padStart(4, "0")) != null ? _sa : null,
16305
+ discussion_concerning: (_ua = getTextFromProduct({ message: (_ta = feature == null ? void 0 : feature.properties) == null ? void 0 : _ta.description, find: [`Concerning...`] })) != null ? _ua : null,
16306
+ discussion_max_tornado: (_wa = getTextFromProduct({ message: (_va = feature == null ? void 0 : feature.properties) == null ? void 0 : _va.description, find: [`MOST PROBABLE PEAK TORNADO INTENSITY...`] })) != null ? _wa : null,
16307
+ discussion_max_hail: (_ya = getTextFromProduct({ message: (_xa = feature == null ? void 0 : feature.properties) == null ? void 0 : _xa.description, find: [`MOST PROBABLE PEAK HAIL SIZE...`] })) != null ? _ya : null,
16308
+ discussion_max_wind: (_Aa = getTextFromProduct({ message: (_za = feature == null ? void 0 : feature.properties) == null ? void 0 : _za.description, find: [`MOST PROBABLE PEAK WIND GUST...`] })) != null ? _Aa : null,
16309
+ discussion_watch_issuance: (_Ca = getTextFromProduct({ message: (_Ba = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ba.description, find: [`Probability of Watch Issuance...`], removal: [`percent`] })) != null ? _Ca : null
16310
+ },
16311
+ watch_parameters: {
16312
+ watch_number: ((_Da = pVtec == null ? void 0 : pVtec[0]) == null ? void 0 : _Da.is_watch) && ((_Oa = (_Na = (_Ia = (_Ha = (_Ga = (_Fa = getTextFromProduct({ message: (_Ea = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ea.description, find: [`ITIES FOR`, `UPDATE FOR`, `Watch Number `], removal: [`%`, `<`, `:`] })) == null ? void 0 : _Fa.replace(/(WT|WS|)/g, "")) == null ? void 0 : _Ga.trim()) == null ? void 0 : _Ha.toString()) == null ? void 0 : _Ia.padStart(4, "0")) != null ? _Na : (_Ma = (_La = (_Ka = (_Ja = pVtec == null ? void 0 : pVtec[0]) == null ? void 0 : _Ja.tracking) == null ? void 0 : _Ka.slice(-4)) == null ? void 0 : _La.toString()) == null ? void 0 : _Ma.padStart(4, "0")) != null ? _Oa : null),
16313
+ watch_type: ((_Pa = feature == null ? void 0 : feature.properties) == null ? void 0 : _Pa.description.includes(`TORNADO WATCH`)) ? `Tornado` : ((_Qa = feature == null ? void 0 : feature.properties) == null ? void 0 : _Qa.description.includes(`SEVERE`)) ? `Severe` : null,
16314
+ additional_tornadoes_probability: (_Sa = getTextFromProduct({ message: (_Ra = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ra.description, find: [`PROB OF 2 OR MORE TORNADOES`], removal: [`%`, `<`, `:`] })) != null ? _Sa : null,
16315
+ strong_tornadoes_probability: (_Ua = getTextFromProduct({ message: (_Ta = feature == null ? void 0 : feature.properties) == null ? void 0 : _Ta.description, find: [`PROB OF 1 OR MORE STRONG /EF2-EF5/ TORNADOES`], removal: [`%`, `<`, `:`] })) != null ? _Ua : null,
16316
+ severe_wind_probability: (_Wa = getTextFromProduct({ message: (_Va = feature == null ? void 0 : feature.properties) == null ? void 0 : _Va.description, find: [`PROB OF 10 OR MORE SEVERE WIND EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _Wa : null,
16317
+ severe_hail_probability: (_Ya = getTextFromProduct({ message: (_Xa = feature == null ? void 0 : feature.properties) == null ? void 0 : _Xa.description, find: [`PROB OF 10 OR MORE SEVERE HAIL EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _Ya : null,
16318
+ hail_2in_probability: (__a = getTextFromProduct({ message: (_Za = feature == null ? void 0 : feature.properties) == null ? void 0 : _Za.description, find: [`PROB OF 1 OR MORE HAIL EVENTS >= 2 INCHES`], removal: [`%`, `<`, `:`] })) != null ? __a : null,
16319
+ combined_hail_wind_probability: (_ab = getTextFromProduct({ message: (_$a = feature == null ? void 0 : feature.properties) == null ? void 0 : _$a.description, find: [`PROB OF 6 OR MORE COMBINED SEVERE HAIL/WIND EVENTS`], removal: [`%`, `<`, `:`] })) != null ? _ab : null,
16320
+ max_hail_in: (_cb = getTextFromProduct({ message: (_bb = feature == null ? void 0 : feature.properties) == null ? void 0 : _bb.description, find: [`MAX HAIL /INCHES/`], removal: [`%`, `<`, `:`] })) != null ? _cb : null,
16321
+ max_wind_surface: (_eb = getTextFromProduct({ message: (_db = feature == null ? void 0 : feature.properties) == null ? void 0 : _db.description, find: [`MAX WIND GUSTS SURFACE /KNOTS/`], removal: [`%`, `<`, `:`] })) != null ? _eb : null,
16322
+ max_tops_x100feet: (_gb = getTextFromProduct({ message: (_fb = feature == null ? void 0 : feature.properties) == null ? void 0 : _fb.description, find: [`MAX TOPS /X 100 FEET/`], removal: [`%`, `<`, `:`] })) != null ? _gb : null,
16323
+ pds_watch: getTextFromProduct({ message: (_hb = feature == null ? void 0 : feature.properties) == null ? void 0 : _hb.description, find: [`PARTICULARLY DANGEROUS SITUATION`], removal: [`%`, `<`, `:`] }) === `YES`
16324
+ },
16325
+ metadata: {
16326
+ ms: performance.now() - tick,
16327
+ source: `events.api`,
16328
+ tracking: getEventTracking({ type: `API`, organization: { wmoidentifier: (_kb = (_jb = (_ib = feature == null ? void 0 : feature.properties) == null ? void 0 : _ib.parameters) == null ? void 0 : _jb.WMOidentifier) == null ? void 0 : _kb[0], featureId: feature == null ? void 0 : feature.id }, vtec: pVtec == null ? void 0 : pVtec[0] }),
16329
+ header: `ZCZC-ATMOSX-${(_mb = (_lb = feature == null ? void 0 : feature.properties) == null ? void 0 : _lb.parameters) == null ? void 0 : _mb.WMOidentifier}`,
16330
+ vtec: pVtec == null ? void 0 : pVtec[0],
16331
+ hvtec: null,
16332
+ raw: (_nb = feature == null ? void 0 : feature.properties) == null ? void 0 : _nb.description,
16333
+ history: [
16334
+ {
16335
+ description: (_ob = feature == null ? void 0 : feature.properties) == null ? void 0 : _ob.description,
16336
+ issued: ((_pb = feature == null ? void 0 : feature.properties) == null ? void 0 : _pb.sent) ? new Date((_qb = feature == null ? void 0 : feature.properties) == null ? void 0 : _qb.sent).toISOString() : null,
16337
+ status: (_sb = (_rb = feature == null ? void 0 : feature.properties) == null ? void 0 : _rb.messageType) != null ? _sb : null
16338
+ }
16339
+ ]
16340
+ }
16341
+ }
16342
+ });
16375
16343
  }
16376
- return Int16Array.from(result);
16377
- };
16344
+ validateEvents(processed);
16345
+ });
16378
16346
 
16379
- // src/@modules/@eas/eas.setAsciiToBits.ts
16380
- var setAsciiToBits = (str) => {
16381
- const bits = [];
16382
- for (let i = 0; i < str.length; i++) {
16383
- const c = str.charCodeAt(i) & 255;
16384
- bits.push(0);
16385
- for (let b = 0; b < 8; b++) bits.push(c >> b & 1);
16386
- bits.push(1, 1);
16347
+ // src/@building/building.create.ts
16348
+ var createEvent = (stanza) => __async(null, null, function* () {
16349
+ const settings = bootstrap.settings;
16350
+ const StanzaSettings = settings.NOAAWeatherWireServiceSettings.StanzaSettings;
16351
+ const isVtecEvent = stanza.isVTEC && stanza.isUGC;
16352
+ const isUgcEvent = !stanza.isVTEC && stanza.isUGC;
16353
+ const isTextEvent = !stanza.isVTEC && !stanza.isUGC;
16354
+ const isNWWS = stanza.isNWWS;
16355
+ if (!isNWWS) return yield api(stanza);
16356
+ if (!StanzaSettings.DisableVTEC && isVtecEvent) return yield vtec(stanza);
16357
+ if (!StanzaSettings.DisableUGC && isUgcEvent) return yield ugc(stanza);
16358
+ if (!StanzaSettings.DisableText && isTextEvent) return yield text(stanza);
16359
+ return "nothing picked";
16360
+ });
16361
+
16362
+ // src/@modules/@database/database.stanza.ts
16363
+ var importStanza = (stanza) => __async(null, null, function* () {
16364
+ const settings = bootstrap.settings;
16365
+ try {
16366
+ if (!settings.NOAAWeatherWireServiceSettings.CacheSettings.Enabled) {
16367
+ return;
16368
+ }
16369
+ bootstrap.database.prepare(`INSERT OR IGNORE INTO stanzas (type, stanza, issued) VALUES (?, ?, ?)`).run(stanza.getType.type, JSON.stringify(stanza), stanza.attributes.issue);
16370
+ const count = bootstrap.database.prepare(`SELECT COUNT(*) as total FROM stanzas`).get();
16371
+ const max = settings.NOAAWeatherWireServiceSettings.CacheSettings.MaxDatabaseHistory;
16372
+ if (count.total > max) {
16373
+ const toDelete = count.total - max;
16374
+ if (toDelete > 0) {
16375
+ bootstrap.database.prepare(`DELETE FROM stanzas WHERE id IN (SELECT id FROM stanzas ORDER BY issued ASC LIMIT ?)`).run(toDelete);
16376
+ }
16377
+ }
16378
+ } catch (error) {
16379
+ setWarning({ message: `An error occurred while importing stanza: ${error.message}` });
16387
16380
  }
16388
- return bits;
16389
- };
16381
+ });
16390
16382
 
16391
- // src/@modules/@eas/eas.getMergedPCM16.ts
16392
- var getMergedPCM16 = (arrays) => {
16393
- let total = 0;
16394
- for (const a of arrays) total += a.length;
16395
- const out = new Int16Array(total);
16396
- let o = 0;
16397
- for (const a of arrays) {
16398
- out.set(a, o);
16399
- o += a.length;
16400
- }
16401
- return out;
16383
+ // src/@modules/@xmpp/xmpp.xStanza.ts
16384
+ var xStanza = () => {
16385
+ bootstrap.session_xmpp.on(`stanza`, (stanza) => __async(null, null, function* () {
16386
+ var _a, _b, _c, _d;
16387
+ const msgFrom = (_b = (_a = stanza == null ? void 0 : stanza.attrs) == null ? void 0 : _a.from) != null ? _b : ``;
16388
+ const msgType = (_d = (_c = stanza == null ? void 0 : stanza.attrs) == null ? void 0 : _c.type) != null ? _d : ``;
16389
+ setEventEmit({
16390
+ event: `onServiceStatus`,
16391
+ metadata: {
16392
+ message: stanza,
16393
+ from: msgFrom,
16394
+ type: `stanza`
16395
+ }
16396
+ });
16397
+ bootstrap.cache.lastStanza = Date.now();
16398
+ if (stanza.is(`message`)) {
16399
+ const result = validate({ stanza });
16400
+ const isSkippable = result.isIgnored || result.isCapEvent || result.isCapEvent && !result.isCapAreaDescription;
16401
+ if (isSkippable) {
16402
+ return;
16403
+ }
16404
+ yield createEvent(result);
16405
+ yield importStanza(result);
16406
+ }
16407
+ if (stanza.is(`presence`) && msgFrom.startsWith("nwws@conference.nwws-oi.weather.gov/")) {
16408
+ const getOccupant = msgFrom.split(`/`).slice(1).join(`/`);
16409
+ const getAvailability = msgType === `unavailable`;
16410
+ setEventEmit({
16411
+ event: `onServiceStatus`,
16412
+ metadata: {
16413
+ message: `Occupant ${getOccupant} has ${getAvailability ? `left` : `joined`} the room`,
16414
+ data: {},
16415
+ type: `occupant`,
16416
+ error: false
16417
+ }
16418
+ });
16419
+ }
16420
+ }));
16402
16421
  };
16403
16422
 
16404
- // src/@modules/@eas/eas.setSameHeader.ts
16405
- var setSameHeader = (vtec2, repeats, sampleRate = 8e3, options = {}) => {
16423
+ // src/@modules/@xmpp/xmpp.xDeploy.ts
16424
+ var xDeploy = () => __async(null, null, function* () {
16406
16425
  var _a, _b;
16407
- const preMarkSec = (_a = options.preMarkSec) != null ? _a : 0.3;
16408
- const gapSec = (_b = options.gapSec) != null ? _b : 0.1;
16409
- const bursts = [];
16410
- const gap = new Int16Array(Math.floor(gapSec * sampleRate));
16411
- for (let i = 0; i < repeats; i++) {
16412
- const bodyBits = setAsciiToBits(vtec2);
16413
- const body = setAFSK(bodyBits, sampleRate);
16414
- const extendedBodyDuration = Math.round(preMarkSec * sampleRate);
16415
- const extendedBody = new Int16Array(extendedBodyDuration + gap.length);
16416
- for (let j2 = 0; j2 < extendedBodyDuration; j2++) {
16417
- extendedBody[j2] = Math.round(body[j2 % body.length] * 0.2);
16418
- }
16419
- extendedBody.set(gap, extendedBodyDuration);
16420
- bursts.push(extendedBody);
16421
- if (i !== repeats - 1) bursts.push(gap);
16426
+ let session;
16427
+ const settings = bootstrap.settings;
16428
+ (_b = (_a = settings.NOAAWeatherWireServiceSettings.CredentialSettings).Nickname) != null ? _b : _a.Nickname = settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username;
16429
+ session = bootstrap.session_xmpp = client({
16430
+ service: "xmpp://nwws-oi.weather.gov",
16431
+ domain: "nwws-oi.weather.gov",
16432
+ username: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username,
16433
+ password: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Password
16434
+ });
16435
+ try {
16436
+ yield xOffline();
16437
+ yield xError();
16438
+ yield xStanza();
16439
+ yield xOnline();
16440
+ yield session.start();
16441
+ } catch (error) {
16442
+ setEventEmit({
16443
+ event: `onServiceStatus`,
16444
+ metadata: {
16445
+ message: `Error occured while starting XMPP Session: ${error}`,
16446
+ data: {},
16447
+ type: `error`,
16448
+ error: true
16449
+ }
16450
+ });
16422
16451
  }
16423
- return getMergedPCM16(bursts);
16424
- };
16452
+ });
16425
16453
 
16426
- // src/@modules/@eas/eas.setAttentionTone.ts
16427
- var setAttentionTone = (ms, sampleRate) => {
16428
- const len = Math.floor(ms * sampleRate);
16429
- const out = new Int16Array(len);
16430
- const f1 = 853;
16431
- const f2 = 960;
16432
- const twoPi = Math.PI * 2;
16433
- const amp = 0.1;
16434
- const fadeLen = Math.floor(sampleRate * 0);
16435
- for (let i = 0; i < len; i++) {
16436
- const t = i / sampleRate;
16437
- const s = Math.sin(twoPi * f1 * t) + Math.sin(twoPi * f2 * t);
16438
- let gain = 1;
16439
- if (i < fadeLen) gain = i / fadeLen;
16440
- else if (i > len - fadeLen) gain = (len - i) / fadeLen;
16441
- const v = Math.max(-1, Math.min(1, s / 2 * amp * gain));
16442
- out[i] = Math.round(v * 32767);
16443
- }
16444
- return out;
16445
- };
16454
+ // src/@modules/@database/database.init.ts
16455
+ var import_fs5 = __toESM(require("fs"));
16456
+ var import_better_sqlite3 = __toESM(require("better-sqlite3"));
16446
16457
 
16447
- // src/@modules/@eas/eas.setNoise.ts
16448
- var setNoise = (int16, noiseLevel = 0.02) => {
16449
- const x = getPCMToFloat(int16);
16450
- for (let i = 0; i < x.length; i++) x[i] += (Math.random() * 2 - 1) * noiseLevel;
16451
- let peak = 0;
16452
- for (let i = 0; i < x.length; i++) peak = Math.max(peak, Math.abs(x[i]));
16453
- if (peak > 1) for (let i = 0; i < x.length; i++) x[i] *= 0.98 / peak;
16454
- return getFloatPCM16(x);
16455
- };
16458
+ // src/@modules/@database/database.shapefiles.ts
16459
+ var import_fs4 = __toESM(require("fs"));
16460
+ var import_path3 = require("path");
16461
+ var import_jszip = require("jszip");
16462
+ var import_shapefile = require("shapefile");
16456
16463
 
16457
- // src/@modules/@eas/eas.getPCM16.ts
16458
- var getPCM16 = (samples, sampleRate) => {
16459
- let o = 0;
16460
- const bytesPerSample = 2;
16461
- const blockAlign = 1 * bytesPerSample;
16462
- const byteRate = sampleRate * blockAlign;
16463
- const subchunk2Size = samples.length * bytesPerSample;
16464
- const chunkSize = 36 + subchunk2Size;
16465
- const buffer = Buffer.alloc(44 + subchunk2Size);
16466
- buffer.write("RIFF", o);
16467
- o += 4;
16468
- buffer.writeUInt32LE(chunkSize, o);
16469
- o += 4;
16470
- buffer.write("WAVE", o);
16471
- o += 4;
16472
- buffer.write("fmt ", o);
16473
- o += 4;
16474
- buffer.writeUInt32LE(16, o);
16475
- o += 4;
16476
- buffer.writeUInt16LE(1, o);
16477
- o += 2;
16478
- buffer.writeUInt16LE(1, o);
16479
- o += 2;
16480
- buffer.writeUInt32LE(sampleRate, o);
16481
- o += 4;
16482
- buffer.writeUInt32LE(byteRate, o);
16483
- o += 4;
16484
- buffer.writeUInt16LE(blockAlign, o);
16485
- o += 2;
16486
- buffer.writeUInt16LE(16, o);
16487
- o += 2;
16488
- buffer.write("data", o);
16489
- o += 4;
16490
- buffer.writeUInt32LE(subchunk2Size, o);
16491
- o += 4;
16492
- for (let i = 0; i < samples.length; i++, o += 2) {
16493
- buffer.writeInt16LE(samples[i].value, o);
16464
+ // src/@modules/@utilities/utilities.setSleep.ts
16465
+ var setSleep = (options) => __async(null, null, function* () {
16466
+ return new Promise((resolve6) => {
16467
+ setTimeout(() => {
16468
+ resolve6();
16469
+ }, options.timeout);
16470
+ });
16471
+ });
16472
+
16473
+ // src/@dictionaries/dictionaries.shapefiles.ts
16474
+ var dict_shapefiles = [
16475
+ { name: "us_counties", id: "C", link: "https://www.weather.gov/source/gis/Shapefiles/County/c_16ap26.zip" },
16476
+ { name: "us_states_territories", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/County/s_16ap26.zip" },
16477
+ { name: "fire_weather_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/fz16ap26.zip" },
16478
+ { name: "costal_marine_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/mz16ap26.zip" },
16479
+ { name: "offshore_marine_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/oz16ap26.zip" },
16480
+ { name: "public_forecast_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/z_16ap26.zip" },
16481
+ { name: "county_warning_areas", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/w_16ap26.zip" },
16482
+ { name: "river_forecast_boundaries", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/Misc/rf05mr24.zip" },
16483
+ { name: "high_seas_marine_zones", id: "Z", link: "https://www.weather.gov/source/gis/Shapefiles/WSOM/hz17fe26.zip" }
16484
+ ];
16485
+
16486
+ // src/@modules/@database/database.shapefiles.ts
16487
+ var importShapefiles = () => __async(null, null, function* () {
16488
+ var _a, _b;
16489
+ const settings = bootstrap.settings;
16490
+ try {
16491
+ const tShapefiles = bootstrap.database.prepare(`SELECT COUNT(*) AS count FROM shapefiles`).get().count;
16492
+ if (tShapefiles === 0) {
16493
+ yield setSleep({ timeout: 1e3 });
16494
+ setWarning({ message: `Shapefiles are currently building, please DO NOT close your terminal. The shapefiles will not finish and will remain incomplete. If you do mess up, you will need to delete ${settings.Database} and restart the application.` });
16495
+ for (const shapefile of dict_shapefiles) {
16496
+ const response2 = yield fetch(shapefile.link);
16497
+ const arrayBuff = yield response2.arrayBuffer();
16498
+ const content = yield (0, import_jszip.loadAsync)(arrayBuff);
16499
+ const directory = (0, import_path3.resolve)(__dirname, `../../shapefiles`);
16500
+ if (!import_fs4.default.existsSync(directory)) {
16501
+ import_fs4.default.mkdirSync(directory, { recursive: true });
16502
+ }
16503
+ for (const file of Object.keys(content.files)) {
16504
+ if (file.endsWith(".shp") || file.endsWith(".dbf")) {
16505
+ const data = yield content.files[file].async(`nodebuffer`);
16506
+ const output = (0, import_path3.resolve)(directory, `${(_a = shapefile == null ? void 0 : shapefile.name) != null ? _a : ``}_${(_b = shapefile == null ? void 0 : shapefile.id) != null ? _b : ``}${(0, import_path3.extname)(file)}`);
16507
+ import_fs4.default.writeFileSync(output, data);
16508
+ }
16509
+ }
16510
+ const filepath = (0, import_path3.resolve)(__dirname, "../../shapefiles", shapefile.name + "_" + shapefile.id);
16511
+ const { features } = yield (0, import_shapefile.read)(
16512
+ filepath,
16513
+ filepath
16514
+ );
16515
+ setWarning({ message: `Importing ${features.length} features from ${shapefile.name}_${shapefile.id}` });
16516
+ const insert = bootstrap.database.prepare(`INSERT OR REPLACE INTO shapefiles (id, location, geometry) VALUES (?, ?, ?)`);
16517
+ const transaction = bootstrap.database.transaction((entries) => {
16518
+ var _a2, _b2, _c;
16519
+ for (const entry of entries) {
16520
+ const { properties: properties2, geometry } = entry;
16521
+ let final2, location;
16522
+ if (properties2.FIPS) {
16523
+ final2 = `${properties2.STATE}${shapefile.id}${properties2.FIPS.substring(2)}`;
16524
+ location = `${properties2.COUNTYNAME}, ${properties2.STATE}`;
16525
+ } else if (properties2.FULLSTAID) {
16526
+ final2 = `${properties2.ST}${shapefile.id}${properties2.WFO}`;
16527
+ location = `${properties2.CITY}, ${properties2.STATE}`;
16528
+ } else if (properties2.STATE) {
16529
+ final2 = `${properties2.STATE}${shapefile.id}${(_a2 = properties2.ZONE) != null ? _a2 : properties2.SITE_ID}`;
16530
+ location = `${(_b2 = properties2.NAME) != null ? _b2 : `${properties2.RFC_NAME} ${properties2.RFC_CITY}`}, ${properties2.STATE}`;
16531
+ } else {
16532
+ final2 = (_c = properties2.ID) != null ? _c : properties2.WFO;
16533
+ location = properties2.NAME;
16534
+ }
16535
+ insert.run(final2, location, JSON.stringify(geometry));
16536
+ }
16537
+ });
16538
+ import_fs4.default.unlinkSync(`${filepath}.shp`);
16539
+ import_fs4.default.unlinkSync(`${filepath}.dbf`);
16540
+ setWarning({ message: `Cleaned up temporary files for ${shapefile.name}_${shapefile.id}` });
16541
+ transaction(features);
16542
+ }
16543
+ setWarning({ message: `Shapefiles have finished compiling, you can now continue and close this terminal` });
16544
+ import_fs4.default.rm((0, import_path3.resolve)(__dirname, "../../shapefiles"), { recursive: true, force: true }, () => {
16545
+ });
16546
+ }
16547
+ } catch (error) {
16548
+ setWarning({ message: `An error occurred while compiling shapefiles: ${error.message}` });
16494
16549
  }
16495
- return buffer;
16496
- };
16550
+ });
16497
16551
 
16498
- // src/@modules/@eas/eas.setEasTone.ts
16499
- var import_path3 = require("path");
16500
- var import_fs3 = require("fs");
16501
- var import_child_process = require("child_process");
16502
- var import_os = require("os");
16503
- var import_say = __toESM(require("say"));
16504
- var setEasTone = (options) => __async(null, null, function* () {
16552
+ // src/@modules/@database/database.init.ts
16553
+ var initializeDatabase = () => __async(null, null, function* () {
16505
16554
  const settings = bootstrap.settings;
16506
- const directory = settings.GlobalSettings.EASSettings.ArchiveDirectory;
16507
- const prefix = settings.GlobalSettings.EASSettings.IntroWavFile;
16508
- let message = options.message;
16509
- let header = options.header;
16510
- let buffTTS;
16511
- let buffRadio;
16512
- let buffFull = [];
16513
- const tmpTTS = (0, import_path3.join)(directory, `/temp/${Math.random().toString(36).substring(2, 15)}-${header.replace(/[^a-zA-Z0-9]/g, "")}.wav`);
16514
- const outTTS = (0, import_path3.join)(directory, `/output/${Math.random().toString(36).substring(2, 15)}-${header.replace(/[^a-zA-Z0-9]/g, "")}.wav`);
16515
- const vTTS = process.platform === `win32` ? `Microsoft David Desktop` : `en-US-GuyNerual`;
16516
- const vPlatform = (0, import_os.platform)();
16517
- if (!(0, import_fs3.existsSync)(directory)) {
16518
- (0, import_fs3.mkdirSync)(directory, { recursive: true });
16519
- }
16520
- if (!(0, import_fs3.existsSync)((0, import_path3.join)(directory, `/temp`))) {
16521
- (0, import_fs3.mkdirSync)((0, import_path3.join)(directory, `/temp`), { recursive: true });
16522
- }
16523
- if (!(0, import_fs3.existsSync)((0, import_path3.join)(directory, `/output`))) {
16524
- (0, import_fs3.mkdirSync)((0, import_path3.join)(directory, `/output`), { recursive: true });
16555
+ try {
16556
+ if (!import_fs5.default.existsSync(settings.Database)) {
16557
+ import_fs5.default.writeFileSync(settings.Database, "");
16558
+ setWarning({ message: `Creating new database at ${settings.Database}` });
16559
+ }
16560
+ bootstrap.database = new import_better_sqlite3.default(settings.Database);
16561
+ bootstrap.database.prepare(`CREATE TABLE IF NOT EXISTS stanzas ( id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, issued TEXT, stanza TEXT )`).run();
16562
+ bootstrap.database.prepare(`CREATE TABLE IF NOT EXISTS shapefiles (id TEXT PRIMARY KEY, location TEXT, geometry TEXT)`).run();
16563
+ yield importShapefiles();
16564
+ } catch (error) {
16565
+ setWarning({ message: `An error occurred while initializing the database: ${error.message}` });
16525
16566
  }
16526
- for (const { regex, replacement } of transcribedMessageReplacements) {
16527
- message = message.replace(regex, replacement);
16567
+ });
16568
+
16569
+ // src/@modules/@database/database.cache.ts
16570
+ var getCachedEvents = () => __async(null, null, function* () {
16571
+ var _a;
16572
+ try {
16573
+ const settings = bootstrap.settings;
16574
+ const tick = performance.now();
16575
+ if (settings.NOAAWeatherWireServiceSettings.CacheSettings.Enabled) {
16576
+ const max = (_a = settings.NOAAWeatherWireServiceSettings.CacheSettings.MaxRetentionHistory) != null ? _a : 500;
16577
+ const get = yield bootstrap.database.prepare(`SELECT * FROM stanzas ORDER BY rowid DESC LIMIT ?`).all(max);
16578
+ setWarning({ message: `Fetched ${get.length} cached events from the database in ${Math.floor(performance.now() - tick)} ms` });
16579
+ let events = get.map((row) => JSON.parse(row.stanza)).filter((stanza) => {
16580
+ if (!stanza) {
16581
+ return;
16582
+ }
16583
+ const isSkippable = stanza.isIgnored || stanza.isCapEvent || stanza.isCapEvent && !stanza.isCapAreaDescription;
16584
+ return !isSkippable;
16585
+ });
16586
+ events = events.sort((a, b) => b.issued - a.issued);
16587
+ yield Promise.all(events.map((event) => createEvent(event)));
16588
+ setWarning({ message: `Processed ${events.length} cached events in ${Math.floor(performance.now() - tick)} ms` });
16589
+ }
16590
+ } catch (error) {
16591
+ setWarning({ message: `An error occurred while fetching cached events: ${error.message} -> ${error.stack}` });
16528
16592
  }
16529
- if (vPlatform != `win32`) {
16530
- setWarning({
16531
- title: `EAS`,
16532
- message: `Generation isn't supported with this OS. Please wait for further updates before trying again`
16533
- });
16534
- return null;
16593
+ });
16594
+
16595
+ // src/@modules/@xmpp/xmpp.xReconnect.ts
16596
+ var xReconnect = (interval) => __async(null, null, function* () {
16597
+ const settings = bootstrap.settings;
16598
+ const lastStanza = Date.now() - bootstrap.cache.lastStanza;
16599
+ if (interval < 15) {
16600
+ setWarning({ message: `Reconnection interval of ${interval} seconds is too low, setting to 15 seconds` });
16601
+ interval = 15;
16602
+ bootstrap.settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.ReconnectionInterval = 15;
16535
16603
  }
16536
- import_say.default.export(message, vTTS, 1, tmpTTS);
16537
- while (!(0, import_fs3.existsSync)(tmpTTS) || (buffTTS = (0, import_fs3.readFileSync)(tmpTTS)).length == 0) {
16538
- yield setSleep({ timeout: 25 });
16604
+ const reconnectThreshold = interval * 1e3;
16605
+ if (!bootstrap.cache.isConnected && !bootstrap.cache.sigHault || !bootstrap.session_xmpp) {
16606
+ return;
16539
16607
  }
16540
- const vWav = getWavPCM16(buffTTS);
16541
- const vSamples = getSampledPCM16(vWav.samples, vWav.sampleRate, 8e3);
16542
- const vRadio = setRadioEffect(vSamples, 8e3);
16543
- if ((0, import_fs3.existsSync)(prefix)) {
16544
- let tBuffer = (0, import_fs3.readFileSync)(prefix);
16545
- let tWav = getWavPCM16(tBuffer);
16546
- if (tWav == null) {
16608
+ if (lastStanza > reconnectThreshold) {
16609
+ if (!bootstrap.cache.isReconnecting) {
16610
+ bootstrap.cache.isReconnecting = true;
16611
+ bootstrap.cache.isConnected = false;
16612
+ bootstrap.cache.tReconnects += 1;
16547
16613
  try {
16548
- const converted = (0, import_path3.join)(directory, `/temp/${Math.random().toString(36).substring(2, 15)}.converted.wav`);
16549
- (0, import_child_process.execSync)(`ffmpeg -y -i "${prefix}" -ar 8000 -ac 1 -sample_fmt s16 "${converted}"`, { stdio: "ignore" });
16550
- if ((0, import_fs3.existsSync)(converted)) {
16551
- tBuffer = (0, import_fs3.readFileSync)(converted);
16552
- tWav = getWavPCM16(tBuffer);
16614
+ setEventEmit({
16615
+ event: `onServiceStatus`,
16616
+ metadata: {
16617
+ message: `Attempting to reconnect to XMPP Service (Reconnect Attempt ${bootstrap.cache.tReconnects})`,
16618
+ data: {
16619
+ last_stanza: lastStanza,
16620
+ nickname: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Nickname
16621
+ },
16622
+ type: `reconnect`,
16623
+ error: true
16624
+ }
16625
+ });
16626
+ yield bootstrap.session_xmpp.stop().catch(() => {
16627
+ });
16628
+ yield bootstrap.session_xmpp.start().catch(() => {
16629
+ });
16630
+ } catch (error) {
16631
+ setWarning({ message: `XMPP Reconnect Failed - ${error.message}` });
16632
+ } finally {
16633
+ bootstrap.cache.isReconnecting = false;
16634
+ }
16635
+ }
16636
+ }
16637
+ });
16638
+
16639
+ // src/@modules/@utilities/utilities.setCronSchedule.ts
16640
+ var import_fs6 = require("fs");
16641
+ var import_path4 = require("path");
16642
+ var setCronSchedule = () => __async(null, null, function* () {
16643
+ const settings = bootstrap.settings;
16644
+ const TTL = settings.GlobalSettings.ArchiveSettings.TTL;
16645
+ const TTLCUT = Date.now() - TTL * 1e3;
16646
+ const walk = (dir) => {
16647
+ if ((0, import_fs6.existsSync)(dir)) {
16648
+ const entries = (0, import_fs6.readdirSync)(dir, { withFileTypes: true });
16649
+ for (const entry of entries) {
16650
+ const fullPath = (0, import_path4.join)(dir, entry.name);
16651
+ if (entry.isDirectory()) {
16652
+ walk(fullPath);
16653
+ continue;
16654
+ }
16655
+ const stats = (0, import_fs6.statSync)(fullPath);
16656
+ if (stats.mtime.getTime() < TTLCUT) {
16553
16657
  try {
16554
- (0, import_fs3.unlinkSync)(converted);
16555
- } catch (e) {
16658
+ (0, import_fs6.unlinkSync)(fullPath);
16659
+ } catch (err) {
16660
+ console.error(`Failed to delete ${fullPath}:`, err);
16556
16661
  }
16557
16662
  }
16558
- } catch (e) {
16559
16663
  }
16560
16664
  }
16561
- if (tWav == null) {
16562
- setWarning({ title: `EAS`, message: `Intro tone isn't a valid .WAV file or isn't in PCM 16-bit format. Converted attempt failed; please convert it then try again.` });
16563
- return null;
16665
+ };
16666
+ walk(settings.GlobalSettings.ArchiveSettings.TextDirectory);
16667
+ walk(settings.GlobalSettings.ArchiveSettings.EasDirectory);
16668
+ if (settings.EnableWireService) {
16669
+ if (settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.Enabled) {
16670
+ void xReconnect(settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.ReconnectionInterval);
16564
16671
  }
16565
- const tSamples = tWav.sampleRate != 8e3 ? getSampledPCM16(tWav.samples, tWav.sampleRate, 8e3) : tWav.samples;
16566
- buffRadio = setRadioEffect(tSamples, 8e3);
16672
+ } else {
16673
+ const response2 = yield createHttp({
16674
+ url: settings.NationalWeatherServiceSettings.EventsEndpoint,
16675
+ headers: {
16676
+ "User-Agent": "@atmosx/event-product-parser"
16677
+ }
16678
+ });
16679
+ if (response2.error) {
16680
+ return setEventEmit({
16681
+ event: `onServiceStatus`,
16682
+ metadata: {
16683
+ type: "fetch-api",
16684
+ message: `Failed to fetch latest events from National Weather Service API - ${response2.message}`,
16685
+ data: {},
16686
+ error: true
16687
+ }
16688
+ });
16689
+ }
16690
+ setEventEmit({
16691
+ event: `onServiceStatus`,
16692
+ metadata: {
16693
+ message: `Fetched latest events from National Weather Service API`,
16694
+ data: {},
16695
+ type: "fetch-api",
16696
+ error: false
16697
+ }
16698
+ });
16699
+ createEvent({ message: response2.message, isNWWS: false });
16567
16700
  }
16568
- buffFull = buffRadio != null ? [buffRadio, new Int16Array(Math.floor(0.5 * 8e3))] : [];
16569
- buffFull.push(
16570
- setSameHeader(header, 3, 8e3, {
16571
- preMarkSec: 1.1,
16572
- gapSec: 0.5
16573
- }),
16574
- new Int16Array(Math.floor(0.5 * 8e3)),
16575
- setAttentionTone(8, 8e3),
16576
- new Int16Array(Math.floor(0.5 * 8e3)),
16577
- vRadio
16578
- );
16579
- for (let i = 0; i < 3; i++) {
16580
- buffFull.push(setSameHeader(header, 1, 8e3, { preMarkSec: 0.5, gapSec: 0.1 }));
16581
- buffFull.push(new Int16Array(Math.floor(0.5 * 8e3)));
16701
+ });
16702
+
16703
+ // src/@manager/manager.updateEvents.ts
16704
+ var updateEvents = (selectedEvent) => __async(null, null, function* () {
16705
+ const events = bootstrap.cache.events.features;
16706
+ function update(evt) {
16707
+ return __async(this, null, function* () {
16708
+ if (new Date(evt.properties.expires) < /* @__PURE__ */ new Date()) {
16709
+ rmEvent(evt);
16710
+ }
16711
+ });
16582
16712
  }
16583
- const aSamples = getMergedPCM16(buffFull);
16584
- const aFinal = setNoise(aSamples, 2e-3);
16585
- const aBuffer = getPCM16(Array.from(aFinal).map((v) => ({ value: v })), 8e3);
16586
- (0, import_fs3.writeFileSync)(outTTS, aBuffer);
16587
- try {
16588
- (0, import_fs3.unlinkSync)(tmpTTS);
16589
- } catch (e) {
16713
+ if (!selectedEvent) {
16714
+ yield Promise.all(events.map((evt) => __async(null, null, function* () {
16715
+ yield update(evt);
16716
+ })));
16717
+ }
16718
+ if (selectedEvent) {
16719
+ yield update(selectedEvent);
16720
+ }
16721
+ });
16722
+
16723
+ // src/@core/core.start.ts
16724
+ var import_croner = require("croner");
16725
+ var startService = (configurations) => __async(null, null, function* () {
16726
+ if (!bootstrap.isReady) {
16727
+ return setWarning({
16728
+ message: `You can not create another instance without shutting down the current one first, please make sure to call the stop() method first!`
16729
+ });
16730
+ }
16731
+ const settings = setSettings(configurations);
16732
+ bootstrap.isReady = true;
16733
+ yield initializeDatabase();
16734
+ if (settings.EnableWireService) {
16735
+ (() => __async(null, null, function* () {
16736
+ yield getCachedEvents();
16737
+ yield xDeploy();
16738
+ }))();
16739
+ }
16740
+ yield setCronSchedule();
16741
+ let scheduleInterval = !settings.EnableWireService ? settings.NationalWeatherServiceSettings.CallbackInterval : 1;
16742
+ if (!settings.EnableWireService && scheduleInterval < 15) {
16743
+ setWarning({ message: `Schedule interval of ${scheduleInterval} seconds is too low, setting to 15 seconds` });
16744
+ bootstrap.settings.NationalWeatherServiceSettings.CallbackInterval = 15;
16745
+ scheduleInterval = 15;
16746
+ }
16747
+ bootstrap.cron = new import_croner.Cron(`*/${scheduleInterval} * * * * *`, () => __async(null, null, function* () {
16748
+ yield setCronSchedule();
16749
+ }));
16750
+ bootstrap.cron = new import_croner.Cron(`* * * * * *`, () => __async(null, null, function* () {
16751
+ yield updateNode();
16752
+ yield updateEvents();
16753
+ }));
16754
+ });
16755
+
16756
+ // src/@core/core.stop.ts
16757
+ var stopService = () => __async(null, null, function* () {
16758
+ if (bootstrap.isReady) {
16759
+ bootstrap.isReady = false;
16760
+ if (bootstrap.session_xmpp) {
16761
+ try {
16762
+ yield bootstrap.session_xmpp.stop();
16763
+ } catch (e) {
16764
+ }
16765
+ bootstrap.cache.isConnected = false;
16766
+ bootstrap.cache.sigHault = true;
16767
+ bootstrap.session_xmpp = null;
16768
+ }
16590
16769
  }
16591
- return outTTS;
16592
16770
  });
16593
16771
 
16594
16772
  // src/@core/core.setNode.ts
@@ -16654,6 +16832,59 @@ var getNodes = () => {
16654
16832
  return bootstrap.cache.nodes;
16655
16833
  };
16656
16834
 
16835
+ // src/@core/core.createEvent.ts
16836
+ var createEvent2 = (options) => {
16837
+ var _a;
16838
+ const tick = performance.now();
16839
+ validateEvents([{
16840
+ type: `Feature`,
16841
+ geometry: {
16842
+ type: `Point`,
16843
+ coordinates: options.coordinates
16844
+ },
16845
+ properties: {
16846
+ event: options.event,
16847
+ parent: options.event,
16848
+ status: options.status,
16849
+ issued: options.issued.toISOString(),
16850
+ expires: options.expires.toISOString(),
16851
+ locations: options.locations,
16852
+ description: options.description,
16853
+ geocode: {
16854
+ office: {
16855
+ office: `ATMX`,
16856
+ name: `AtmosphericX Manual Event`
16857
+ },
16858
+ organization: `AtmosphericX`,
16859
+ ugc: [],
16860
+ polygon: options.coordinates.length > 0 ? Buffer.from(JSON.stringify([options.coordinates[0]])).toString("base64") : null,
16861
+ polygon_generated: options.coordinates.length > 0 ? true : false
16862
+ },
16863
+ status_metadata: {
16864
+ is_issued: options.status == `Issued`,
16865
+ is_updated: options.status == `Updated`,
16866
+ is_expired: options.status == `Expired`,
16867
+ is_test: options.status == `Test`,
16868
+ is_statement: options.status == `Statement`
16869
+ },
16870
+ metadata: {
16871
+ ms: performance.now() - tick,
16872
+ source: `events.manual`,
16873
+ tracking: `ATMX-M-W-01`,
16874
+ header: `ZCZC-ATMOSX-ATMX-M-W-01`,
16875
+ raw: options.description,
16876
+ history: [
16877
+ {
16878
+ description: options.description,
16879
+ issued: options.issued.toISOString(),
16880
+ status: (_a = options.status) != null ? _a : null
16881
+ }
16882
+ ]
16883
+ }
16884
+ }
16885
+ }]);
16886
+ };
16887
+
16657
16888
  // src/@core/core.getRandomEvent.ts
16658
16889
  var getRandomEvent = () => {
16659
16890
  return bootstrap.cache.events.features[Math.floor(Math.random() * bootstrap.cache.events.features.length)];
@@ -16714,6 +16945,7 @@ var index_default = Manager;
16714
16945
  0 && (module.exports = {
16715
16946
  Manager,
16716
16947
  clearEvents,
16948
+ createEvent,
16717
16949
  getCleanedEvent,
16718
16950
  getEventGeometry,
16719
16951
  getEvents,