@atmosx/event-product-parser 2.0.16 → 3.0.1

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 (136) hide show
  1. package/README.md +248 -187
  2. package/dist/cjs/index.cjs +12218 -3139
  3. package/dist/esm/index.mjs +12401 -3327
  4. package/dist/index.d.mts +235 -0
  5. package/dist/index.d.ts +235 -0
  6. package/package.json +6 -4
  7. package/src/@building/building.clean.ts +30 -0
  8. package/src/@building/building.create.ts +42 -0
  9. package/src/@building/building.enhance.ts +56 -0
  10. package/src/@building/building.geometry.ts +48 -0
  11. package/src/@building/building.headers.ts +37 -0
  12. package/src/@building/building.office.ts +43 -0
  13. package/src/@building/building.polygon.ts +71 -0
  14. package/src/@building/building.properties.ts +89 -0
  15. package/src/@building/building.signature.ts +61 -0
  16. package/src/@building/building.tags.ts +24 -0
  17. package/src/@building/building.tracking.ts +68 -0
  18. package/src/@building/building.validate.ts +147 -0
  19. package/src/@core/core.getEvents.ts +25 -0
  20. package/src/@core/core.getNodes.ts +25 -0
  21. package/src/@core/core.getRandomEvent.ts +25 -0
  22. package/src/@core/core.getVersion.ts +25 -0
  23. package/src/@core/core.listener.ts +24 -0
  24. package/src/@core/core.setNode.ts +81 -0
  25. package/src/@core/core.start.ts +59 -0
  26. package/src/@core/core.stop.ts +32 -0
  27. package/src/@dictionaries/dictionaries.betterEventNames.ts +89 -0
  28. package/src/@dictionaries/dictionaries.eventActions.ts +28 -0
  29. package/src/@dictionaries/{awips.ts → dictionaries.eventAwipAbreviations.ts} +13 -7
  30. package/src/@dictionaries/dictionaries.eventCancelMessages.ts +30 -0
  31. package/src/@dictionaries/dictionaries.eventCauses.ts +36 -0
  32. package/src/@dictionaries/dictionaries.eventProducts.ts +25 -0
  33. package/src/@dictionaries/dictionaries.eventRecords.ts +25 -0
  34. package/src/@dictionaries/dictionaries.eventSeverity.ts +27 -0
  35. package/src/@dictionaries/dictionaries.eventStatus.ts +31 -0
  36. package/src/@dictionaries/{signatures.ts → dictionaries.eventTags.ts} +13 -68
  37. package/src/@dictionaries/dictionaries.eventTypes.ts +82 -0
  38. package/src/@dictionaries/dictionaries.eventsOffshore.ts +31 -0
  39. package/src/@dictionaries/dictionaries.hailStrings.ts +33 -0
  40. package/src/@dictionaries/{icao.ts → dictionaries.officeICAOs.ts} +13 -6
  41. package/src/@dictionaries/dictionaries.regExp.ts +28 -0
  42. package/src/@dictionaries/dictionaries.shapefileLinks.ts +36 -0
  43. package/src/@dictionaries/dictionaries.statusCorrelationText.ts +40 -0
  44. package/src/@dictionaries/dictionaries.testSignatures.ts +24 -0
  45. package/src/@dictionaries/dictionaries.transcribedMessageReplacements.ts +68 -0
  46. package/src/@events/events.api.ts +113 -0
  47. package/src/@events/events.text.ts +79 -0
  48. package/src/@events/events.ugc.ts +83 -0
  49. package/src/@events/events.vtec.ts +87 -0
  50. package/src/@manager/manager.mkEvent.ts +95 -0
  51. package/src/@manager/manager.rmEvent.ts +46 -0
  52. package/src/@manager/manager.setHash.ts +37 -0
  53. package/src/@manager/manager.updateNodes.ts +55 -0
  54. package/src/@manager/manager.updateWebhooks.ts +50 -0
  55. package/src/@modules/@database/database.cache.ts +48 -0
  56. package/src/@modules/@database/database.init.ts +45 -0
  57. package/src/@modules/@database/database.shapefiles.ts +96 -0
  58. package/src/@modules/@database/database.stanza.ts +48 -0
  59. package/src/@modules/@eas/eas.getFloatPCM16.ts +29 -0
  60. package/src/@modules/@eas/eas.getMergedPCM16.ts +32 -0
  61. package/src/@modules/@eas/eas.getPCM16.ts +52 -0
  62. package/src/@modules/@eas/eas.getPCMToFloat.ts +26 -0
  63. package/src/@modules/@eas/eas.getSampledPCM16.ts +36 -0
  64. package/src/@modules/@eas/eas.getWavPCM16.ts +52 -0
  65. package/src/@modules/@eas/eas.setAFSK.ts +52 -0
  66. package/src/@modules/@eas/eas.setAsciiToBits.ts +32 -0
  67. package/src/@modules/@eas/eas.setAttentionTone.ts +40 -0
  68. package/src/@modules/@eas/eas.setEasTone.ts +137 -0
  69. package/src/@modules/@eas/eas.setNoise.ts +31 -0
  70. package/src/@modules/@eas/eas.setRadioEffect.ts +49 -0
  71. package/src/@modules/@eas/eas.setSameHeader.ts +45 -0
  72. package/src/@modules/@stanza/stanza.getAwipsType.ts +46 -0
  73. package/src/@modules/@stanza/stanza.validate.ts +50 -0
  74. package/src/@modules/@utilities/utilities.createHttp.ts +85 -0
  75. package/src/@modules/@utilities/utilities.createWebhook.ts +100 -0
  76. package/src/@modules/@utilities/utilities.getFormattedTime.ts +43 -0
  77. package/src/@modules/@utilities/utilities.getSettings.ts +25 -0
  78. package/src/@modules/@utilities/utilities.getShapeNearestPoint.ts +114 -0
  79. package/src/@modules/@utilities/utilities.setCronSchedule.ts +65 -0
  80. package/src/@modules/@utilities/utilities.setEventEmit.ts +41 -0
  81. package/src/@modules/@utilities/utilities.setListener.ts +30 -0
  82. package/src/@modules/@utilities/utilities.setSettings.ts +42 -0
  83. package/src/@modules/@utilities/utilities.setSleep.ts +33 -0
  84. package/src/@modules/@utilities/utilities.setTimeoutAction.ts +59 -0
  85. package/src/@modules/@utilities/utilities.setWarning.ts +34 -0
  86. package/src/@modules/@xmpp/xmpp.xDeploy.ts +58 -0
  87. package/src/@modules/@xmpp/xmpp.xError.ts +29 -0
  88. package/src/@modules/@xmpp/xmpp.xOffline.ts +38 -0
  89. package/src/@modules/@xmpp/xmpp.xOnline.ts +45 -0
  90. package/src/@modules/@xmpp/xmpp.xReconnect.ts +64 -0
  91. package/src/@modules/@xmpp/xmpp.xStanza.ts +63 -0
  92. package/src/@parsers/@hvtec/hvtec.extract.ts +40 -0
  93. package/src/@parsers/@pvtec/pvtec.expires.ts +26 -0
  94. package/src/@parsers/@pvtec/pvtec.extract.ts +49 -0
  95. package/src/@parsers/@text/text.getDescriptionFromProduct.ts +53 -0
  96. package/src/@parsers/@text/text.getPolygonFromProduct.ts +32 -0
  97. package/src/@parsers/@text/text.getTextFromProduct.ts +43 -0
  98. package/src/@parsers/@text/text.getXML.ts +61 -0
  99. package/src/@parsers/@ugc/ugc.coordinates.ts +110 -0
  100. package/src/@parsers/@ugc/ugc.expiry.ts +32 -0
  101. package/src/@parsers/@ugc/ugc.extract.ts +37 -0
  102. package/src/@parsers/@ugc/ugc.header.ts +30 -0
  103. package/src/@parsers/@ugc/ugc.locations.ts +29 -0
  104. package/src/@parsers/@ugc/ugc.zones.ts +52 -0
  105. package/src/@types/type.event.ts +67 -0
  106. package/src/@types/type.properties.ts +75 -0
  107. package/src/@types/types.attributes.ts +28 -0
  108. package/src/@types/types.compiled.ts +35 -0
  109. package/src/@types/types.hash.ts +24 -0
  110. package/src/@types/types.hvtec.ts +25 -0
  111. package/src/@types/types.pvtec.ts +30 -0
  112. package/src/@types/types.settings.ts +76 -0
  113. package/src/@types/types.stanza.ts +37 -0
  114. package/src/@types/types.ugc.ts +24 -0
  115. package/src/@types/types.webhook.ts +26 -0
  116. package/src/bootstrap.ts +85 -163
  117. package/src/index.ts +47 -216
  118. package/test.js +78 -51
  119. package/tsup.config.ts +1 -0
  120. package/src/@dictionaries/events.ts +0 -168
  121. package/src/@parsers/@events/api.ts +0 -146
  122. package/src/@parsers/@events/cap.ts +0 -123
  123. package/src/@parsers/@events/text.ts +0 -104
  124. package/src/@parsers/@events/ugc.ts +0 -107
  125. package/src/@parsers/@events/vtec.ts +0 -76
  126. package/src/@parsers/events.ts +0 -392
  127. package/src/@parsers/hvtec.ts +0 -46
  128. package/src/@parsers/pvtec.ts +0 -72
  129. package/src/@parsers/stanza.ts +0 -97
  130. package/src/@parsers/text.ts +0 -165
  131. package/src/@parsers/ugc.ts +0 -247
  132. package/src/@submodules/database.ts +0 -201
  133. package/src/@submodules/eas.ts +0 -490
  134. package/src/@submodules/utils.ts +0 -191
  135. package/src/@submodules/xmpp.ts +0 -142
  136. package/src/types.ts +0 -259
@@ -1,142 +0,0 @@
1
- /*
2
- _ _ __ __
3
- /\ | | | | (_) \ \ / /
4
- / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
- / /\ \| __| "_ ` _ \ / _ \/ __| "_ \| "_ \ / _ \ "__| |/ __| > <
6
- / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
- /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
- | |
9
- |_|
10
-
11
- Written by: KiyoWx (k3yomi)
12
- */
13
-
14
- import * as loader from '../bootstrap';
15
- import * as types from '../types';
16
- import Utils from './utils';
17
- import StanzaParser from '../@parsers/stanza';
18
- import Database from '../@submodules/database';
19
- import EventParser from '../@parsers/events';
20
-
21
- export class Xmpp {
22
-
23
- /**
24
- * @function isSessionReconnectionEligible
25
- * @description
26
- * Checks if the XMPP session has been inactive longer than the given interval
27
- * and, if so, attempts a controlled reconnection.
28
- *
29
- * @async
30
- * @static
31
- * @param {number} currentInterval
32
- * @returns {Promise<void>}
33
- */
34
- public static async isSessionReconnectionEligible(currentInterval: number): Promise<void> {
35
- const settings = loader.settings as types.ClientSettingsTypes;
36
- const lastStanzaElapsed = Date.now() - loader.cache.lastStanza;
37
- const threshold = currentInterval * 1000;
38
- if ((!loader.cache.isConnected && !loader.cache.sigHalt) || !loader.cache.session) { return; }
39
- if (lastStanzaElapsed < threshold) { return; }
40
- if (loader.cache.attemptingReconnect) { return; }
41
- loader.cache.attemptingReconnect = true;
42
- loader.cache.isConnected = false;
43
- loader.cache.totalReconnects += 1;
44
- try {
45
- loader.cache.events.emit("onReconnection", {
46
- reconnects: loader.cache.totalReconnects,
47
- lastStanza: lastStanzaElapsed,
48
- lastName: settings.noaa_weather_wire_service_settings.credentials.nickname,
49
- });
50
- await loader.cache.session.stop().catch(() => {});
51
- await loader.cache.session.start().catch(() => {});
52
- } catch (err) {
53
- Utils.warn(`XMPP reconnection failed: ${(err as Error).message}`);
54
- } finally {
55
- loader.cache.attemptingReconnect = false;
56
- }
57
- }
58
-
59
- /**
60
- * @function deploySession
61
- * @description
62
- * Initializes the NOAA Weather Wire Service (NWWS-OI) XMPP client session and
63
- * manages its lifecycle events including connection, disconnection, errors,
64
- * and message handling.
65
- *
66
- * @async
67
- * @static
68
- * @returns {Promise<void>}
69
- */
70
- public static async deploySession(): Promise<void> {
71
- const settings = loader.settings as types.ClientSettingsTypes;
72
- settings.noaa_weather_wire_service_settings.credentials.nickname ??= settings.noaa_weather_wire_service_settings.credentials.username;
73
- loader.cache.session = loader.packages.xmpp.client({
74
- service: 'xmpp://nwws-oi.weather.gov',
75
- domain: 'nwws-oi.weather.gov',
76
- username: settings.noaa_weather_wire_service_settings.credentials.username,
77
- password: settings.noaa_weather_wire_service_settings.credentials.password,
78
- });
79
- loader.cache.session.on('online', async (address: string) => {
80
- const now = Date.now();
81
- if (loader.cache.lastConnect && now - loader.cache.lastConnect < 10_000) {
82
- loader.cache.sigHalt = true;
83
- Utils.warn(loader.definitions.messages.reconnect_too_fast);
84
- await Utils.sleep(2_000);
85
- await loader.cache.session.stop().catch(() => {});
86
- return;
87
- }
88
- loader.cache.isConnected = true;
89
- loader.cache.sigHalt = false;
90
- loader.cache.lastConnect = now;
91
- loader.cache.session.send(loader.packages.xmpp.xml('presence', {
92
- to: `nwws@conference.nwws-oi.weather.gov/${settings.noaa_weather_wire_service_settings.credentials.nickname}`,
93
- xmlns: 'http://jabber.org/protocol/muc',
94
- }));
95
- loader.cache.events.emit('onConnection', settings.noaa_weather_wire_service_settings.credentials.nickname);
96
- if (loader.cache.attemptingReconnect) return;
97
- loader.cache.attemptingReconnect = true;
98
- await Utils.sleep(15_000);
99
- loader.cache.attemptingReconnect = false;
100
- });
101
- loader.cache.session.on('offline', () => {
102
- loader.cache.isConnected = false;
103
- loader.cache.sigHalt = true;
104
- Utils.warn('XMPP connection went offline');
105
- });
106
- loader.cache.session.on('error', (error: Error) => {
107
- loader.cache.isConnected = false;
108
- loader.cache.sigHalt = true;
109
- Utils.warn(`XMPP connection error: ${error.message}`);
110
- });
111
- loader.cache.session.on('stanza', async (stanza: any) => {
112
- try {
113
- loader.cache.lastStanza = Date.now();
114
- if (stanza.is('message')) {
115
- const validate = StanzaParser.validate(stanza);
116
- const skipMessage = validate.ignore ||
117
- (validate.isCap && !settings.noaa_weather_wire_service_settings.preferences.cap_only) ||
118
- (!validate.isCap && settings.noaa_weather_wire_service_settings.preferences.cap_only) ||
119
- (validate.isCap && !validate.isCapDescription);
120
- if (skipMessage) return;
121
- await EventParser.eventHandler(validate);
122
- await Database.stanzaCacheImport(validate);
123
- loader.cache.events.emit('onMessage', validate);
124
- }
125
- if (stanza.is('presence') && stanza.attrs.from?.startsWith('nwws@conference.nwws-oi.weather.gov/')) {
126
- const occupant = stanza.attrs.from.split('/').slice(1).join('/');
127
- loader.cache.events.emit('onOccupant', {
128
- occupant,
129
- type: stanza.attrs.type === 'unavailable' ? 'unavailable' : 'available',
130
- });
131
- }
132
- } catch (err: unknown) {
133
- Utils.warn(`Error processing stanza: ${(err as Error).message}`);
134
- }
135
- });
136
- try { await loader.cache.session.start(); } catch (err: unknown) {
137
- Utils.warn(`Failed to start XMPP session: ${(err as Error).message}`);
138
- }
139
- }
140
- }
141
-
142
- export default Xmpp;
package/src/types.ts DELETED
@@ -1,259 +0,0 @@
1
- /*
2
- _ _ __ __
3
- /\ | | | | (_) \ \ / /
4
- / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
- / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
- / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
- /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
- | |
9
- |_|
10
-
11
- Written by: k3yomi@GitHub
12
- */
13
-
14
- // ----------- Settings ----------- //
15
- interface LocalEasSettings {
16
- directory?: string;
17
- intro_wav?: string;
18
- }
19
-
20
- interface LocalAlertFilteringSettings {
21
- events?: string[];
22
- filtered_icao?: string[];
23
- ignored_icao?: string[];
24
- ugc_filter?: string[];
25
- state_filter?: string[];
26
- ignored_events?: string[];
27
- check_expired?: boolean;
28
- }
29
-
30
- interface LocalGlobalSettings {
31
- parent_events_only?: boolean;
32
- better_event_parsing?: boolean;
33
- shapefile_coordinates?: boolean;
34
- shapefile_skip?: number;
35
- eas_settings?: LocalEasSettings;
36
- filtering?: LocalAlertFilteringSettings;
37
- }
38
-
39
- interface LocalClientReconnectionSettings {
40
- enabled?: boolean;
41
- interval?: number;
42
- }
43
-
44
- interface LocalClientCredentialSettings {
45
- username?: string;
46
- password?: string;
47
- nickname?: string;
48
- }
49
-
50
- interface LocalCacheSettings {
51
- enabled?: boolean;
52
- max_db_history?: number;
53
- use_db_for_cache?: boolean;
54
- max_db_cache_size?: number;
55
- }
56
-
57
- interface LocalAlertPreferenceSettings {
58
- disable_ugc?: boolean;
59
- disable_vtec?: boolean;
60
- disable_text?: boolean;
61
- cap_only?: boolean;
62
- }
63
-
64
- interface LocalNoaaWeatherWireServiceSettings {
65
- reconnection_settings?: LocalClientReconnectionSettings;
66
- credentials?: LocalClientCredentialSettings;
67
- cache?: LocalCacheSettings;
68
- preferences?: LocalAlertPreferenceSettings;
69
- }
70
-
71
- interface LocalNationalWeatherServiceSettings {
72
- interval?: number;
73
- endpoint?: string;
74
- }
75
-
76
- // --- Exports --- //
77
- export interface ClientSettingsTypes {
78
- database?: string;
79
- is_wire?: boolean;
80
- journal?: boolean;
81
- noaa_weather_wire_service_settings?: LocalNoaaWeatherWireServiceSettings;
82
- national_weather_service_settings?: LocalNationalWeatherServiceSettings;
83
- global_settings?: LocalGlobalSettings;
84
- }
85
-
86
-
87
- // ----------- Alert / Events ----------- //
88
-
89
-
90
- interface LocalEventHistory {
91
- description?: string;
92
- issued?: string;
93
- type?: string;
94
- }
95
-
96
-
97
- interface LocalEventParameters {
98
- wmo?: string;
99
- source?: string;
100
- max_hail_size?: string;
101
- max_wind_gust?: string;
102
- damage_threat?: string;
103
- tornado_detection?: string;
104
- flood_detection?: string;
105
- discussion_tornado_intensity?: string;
106
- discussion_wind_intensity?: string;
107
- discussion_hail_intensity?: string;
108
- WMOidentifier?: string[];
109
- VTEC?: string;
110
- maxHailSize?: string;
111
- maxWindGust?: string;
112
- thunderstormDamageThreat?: string[];
113
- tornadoDetection?: string[];
114
- waterspoutDetection?: string[];
115
- floodDetection?: string[];
116
- AWIPSidentifier?: string[];
117
- NWSheadline?: string[];
118
- }
119
-
120
- interface LocalEventProperties {
121
- parent?: string;
122
- event?: string;
123
- locations?: string;
124
- issued?: string;
125
- expires?: string;
126
- geocode?: {
127
- UGC: string[],
128
- generated?: string | null
129
- };
130
- description?: string;
131
- instruction?: string;
132
- sender_name?: string;
133
- sender_icao?: string;
134
- raw?: DefaultAttributesType;
135
- parameters?: LocalEventParameters;
136
- messageType?: string;
137
- sent?: string;
138
- areaDesc?: string;
139
- action_type?: string;
140
- is_updated?: boolean;
141
- is_cancelled?: boolean;
142
- is_issued?: boolean;
143
- is_test?: boolean;
144
- hash?: string;
145
- tags?: string[];
146
- details?: Record<string, any>;
147
- }
148
-
149
- // --- Exports --- //
150
-
151
- export interface StanzaAttributesType {
152
- xmlns?: string;
153
- id?: string;
154
- issue?: string;
155
- ttaaii?: string;
156
- cccc?: string;
157
- awipsid?: string;
158
- }
159
- export interface DefaultAttributesType {
160
- attributes?: {
161
- xmlns?: string;
162
- id?: string;
163
- issue?: string;
164
- ttaaii?: string;
165
- cccc?: string;
166
- awipsid?: string;
167
- }
168
- getAwip?: Record<string, string>;
169
- awipsType?: Record<string, string>;
170
- isCap?: boolean;
171
- raw?: boolean;
172
- }
173
-
174
- export interface StanzaCompiled {
175
- message?: string;
176
- attributes?: DefaultAttributesType;
177
- isCap?: boolean;
178
- isApi?: boolean;
179
- isCapDescription?: boolean;
180
- isPVtec?: boolean;
181
- isUGC?: boolean;
182
- getAwip?: Record<string, string>;
183
- awipsType?: Record<string, string>;
184
- awipsPrefix?: string;
185
- ignore?: boolean;
186
- awipsid?: string;
187
- }
188
-
189
- export interface PVtecEntry {
190
- raw?: string;
191
- type?: string;
192
- tracking?: string;
193
- event?: string;
194
- status?: string;
195
- wmo?: string;
196
- expires?: Date | string;
197
- isKWNS?: boolean;
198
- }
199
-
200
- export interface UGCEntry {
201
- zones?: string[];
202
- locations?: string[];
203
- expiry?: Date | string;
204
- polygon?: [number, number][];
205
- }
206
-
207
- export interface HVtecEntry {
208
- severity?: string,
209
- cause?: string,
210
- record?: string,
211
- raw?: string,
212
- }
213
-
214
- export interface geometry {
215
- type?: string;
216
- coordinates?: [number, number][];
217
- }
218
-
219
-
220
- export interface EventCompiled {
221
- performance?: number;
222
- id?: string;
223
- tracking?: string;
224
- header?: string;
225
- pvtec?: string;
226
- hvtec?: string;
227
- history?: LocalEventHistory[];
228
- properties?: LocalEventProperties
229
- geometry?: { type?: string; coordinates?: [number, number][] } | null;
230
- }
231
-
232
- export type EventProperties = LocalEventProperties;
233
- export type StanzaAttributes = DefaultAttributesType;
234
-
235
-
236
- // ----------- Generic ----------- //
237
-
238
- // --- Exports --- //
239
- export type Coordinates = {
240
- lon: number;
241
- lat: number;
242
- }
243
-
244
- export type HTTPSettings = {
245
- timeout?: number;
246
- headers?: Record<string, string>;
247
- method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
248
- body?: string;
249
- }
250
-
251
- export interface EnhancedEventCondition {
252
- description?: string;
253
- condition?: (value: string) => boolean;
254
- }
255
-
256
- export interface GenericHTTPResponse {
257
- error?: boolean,
258
- message?: { features: Record<string, any>[] } | string,
259
- }