@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
@@ -0,0 +1,42 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeSettings } from '../../@types/types.settings'
21
+ import { bootstrap } from "../../bootstrap"
22
+
23
+ export const setSettings = (newSettings: TypeSettings): TypeSettings => {
24
+ const settings = bootstrap.settings as Record<string, unknown>;
25
+ const merge = (target: Record<string, unknown>, source: Record<string, unknown>) => {
26
+ for (const key in source) {
27
+ if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
28
+ const srcVal = source[key];
29
+ const tgtVal = target[key];
30
+ if (srcVal && typeof srcVal === 'object' && !Array.isArray(srcVal)) {
31
+ if (!tgtVal || typeof tgtVal !== 'object' || Array.isArray(tgtVal)) {
32
+ target[key] = {};
33
+ }
34
+ merge(target[key] as Record<string, unknown>, srcVal as Record<string, unknown>);
35
+ } else {
36
+ target[key] = srcVal;
37
+ }
38
+ }
39
+ };
40
+ merge(settings, newSettings as Record<string, unknown>);
41
+ return settings as TypeSettings;
42
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+
19
+ */
20
+
21
+ interface SetSleepOptions {
22
+ timeout: number
23
+ }
24
+
25
+ export const setSleep = async (options: SetSleepOptions): Promise<void> => {
26
+ return new Promise((resolve) => {
27
+ setTimeout(() => {
28
+ resolve();
29
+ }, options.timeout);
30
+ });
31
+ }
32
+
33
+
@@ -0,0 +1,59 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { bootstrap } from "../../bootstrap"
21
+
22
+ interface SetTimeoutActionOptions {
23
+ identifier: string
24
+ addTime?: boolean
25
+ max?: number
26
+ interval: number
27
+ }
28
+
29
+ type SetTimeoutActionResponse = {
30
+ limited: boolean
31
+ remaining?: number
32
+ response?: string
33
+ }
34
+
35
+ export const setTimeoutAction = (options: SetTimeoutActionOptions): SetTimeoutActionResponse => {
36
+ let target = bootstrap?.ratelimits?.[options?.identifier];
37
+ if (!target) {
38
+ bootstrap.ratelimits[options?.identifier] = [];
39
+ target = bootstrap.ratelimits[options?.identifier];
40
+ }
41
+ if (target?.length > 0) {
42
+ bootstrap.ratelimits[options?.identifier] = target.filter((ts: number) => Date.now() - ts < options?.interval * 1000);
43
+ target = bootstrap.ratelimits[options?.identifier];
44
+ }
45
+
46
+ const oldestTimestamp = target?.[0];
47
+ const getWait = oldestTimestamp ? Math.ceil((options?.interval * 1000) - (Date.now() - oldestTimestamp)) : 0;
48
+ const max = options?.max || 1;
49
+
50
+ if (target?.length >= max && getWait > 0) {
51
+ return {
52
+ limited: true,
53
+ remaining: getWait,
54
+ response: `You are being rate limited, please wait ${(getWait / 1e3).toFixed(1)} second(s) before performing this action again.`
55
+ }
56
+ }
57
+ bootstrap.ratelimits[options?.identifier].push(Date.now());
58
+ return { limited: false };
59
+ }
@@ -0,0 +1,34 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { bootstrap } from "../../bootstrap"
21
+ import { TypeSettings } from "../../@types/types.settings";
22
+
23
+ interface SetWarningOptions {
24
+ title?: string
25
+ message: string
26
+ }
27
+
28
+ export const setWarning = (options: SetWarningOptions): void => {
29
+ const settings = bootstrap.settings as TypeSettings;
30
+ bootstrap.listener.emit(`log`, `${options.title ?? `[${bootstrap.ansi_colors.YELLOW}ATMOSX-PARSER${bootstrap.ansi_colors.RESET}]`} ${options.message}`)
31
+ if (settings.EnableJournal) {
32
+ console.log(`${options.title ?? `[${bootstrap.ansi_colors.YELLOW}ATMOSX-PARSER${bootstrap.ansi_colors.RESET}]`} ${options.message}`)
33
+ }
34
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { client } from '@xmpp/client';
21
+ import { TypeSettings } from "../../@types/types.settings";
22
+ import { bootstrap } from "../../bootstrap"
23
+ import { setWarning } from "../@utilities/utilities.setWarning";
24
+ import { xOnline } from "./xmpp.xOnline";
25
+ import { xOffline } from "./xmpp.xOffline";
26
+ import { xError } from "./xmpp.xError";
27
+ import { xStanza } from "./xmpp.xStanza";
28
+ import { setEventEmit } from '../@utilities/utilities.setEventEmit';
29
+
30
+ export const xDeploy = async (): Promise<void> => {
31
+ let session;
32
+ const settings = bootstrap.settings as TypeSettings
33
+ settings.NOAAWeatherWireServiceSettings.CredentialSettings.Nickname
34
+ ??= settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username;
35
+ session = bootstrap.session_xmpp = client({
36
+ service: 'xmpp://nwws-oi.weather.gov',
37
+ domain: 'nwws-oi.weather.gov',
38
+ username: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username,
39
+ password: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Password
40
+ })
41
+ try {
42
+ await xOffline();
43
+ await xError();
44
+ await xStanza();
45
+ await xOnline();
46
+ await session.start()
47
+ } catch (error) {
48
+ setEventEmit({
49
+ event: `onServiceStatus`,
50
+ metadata: {
51
+ message: `Error occured while starting XMPP Session: ${error}`,
52
+ data: {},
53
+ type: `error`,
54
+ error: true
55
+ },
56
+ })
57
+ }
58
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { bootstrap } from "../../bootstrap";
21
+ import { setEventEmit } from "../@utilities/utilities.setEventEmit";
22
+ import { setWarning } from "../@utilities/utilities.setWarning";
23
+
24
+ export const xError = () => {
25
+ bootstrap.session_xmpp.on(`error`, async (error: Error) => {
26
+ bootstrap.cache.isConnected = false;
27
+ bootstrap.cache.sigHault = true;
28
+ })
29
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { bootstrap } from "../../bootstrap";
21
+ import { setEventEmit } from "../@utilities/utilities.setEventEmit";
22
+ import { setWarning } from "../@utilities/utilities.setWarning";
23
+
24
+ export const xOffline = () => {
25
+ bootstrap.session_xmpp.on(`offline`, async () => {
26
+ bootstrap.cache.isConnected = false;
27
+ bootstrap.cache.sigHault = true;
28
+ setEventEmit({
29
+ event: `onServiceStatus`,
30
+ metadata: {
31
+ message: `Client has gone offline`,
32
+ data: {},
33
+ type: `offline`,
34
+ error: true
35
+ },
36
+ })
37
+ })
38
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+ import { xml } from '@xmpp/client'
20
+ import { bootstrap } from "../../bootstrap";
21
+ import { setSleep } from "../@utilities/utilities.setSleep";
22
+ import { setEventEmit } from '../@utilities/utilities.setEventEmit';
23
+
24
+ export const xOnline = () => {
25
+ const settings = bootstrap.settings;
26
+ bootstrap.session_xmpp.on(`online`, async (address: string) => {
27
+ bootstrap.cache.sigHault = false;
28
+ bootstrap.cache.isConnected = true;
29
+ bootstrap.cache.tReconnects = 0;
30
+ const nickname = settings.NOAAWeatherWireServiceSettings.CredentialSettings.Nickname;
31
+ bootstrap.session_xmpp.send(xml('presence', {
32
+ to: `nwws@conference.nwws-oi.weather.gov/${nickname}`,
33
+ xmlns: 'http://jabber.org/protocol/muc',
34
+ }))
35
+ setEventEmit({
36
+ event: `onServiceStatus`,
37
+ metadata: {
38
+ message: `Succesfully connected to NOAA Weather Wire Service as "${nickname}"`,
39
+ data: {},
40
+ type: `online`,
41
+ error: false
42
+ },
43
+ })
44
+ })
45
+ }
@@ -0,0 +1,64 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeSettings } from "../../@types/types.settings";
21
+ import { bootstrap } from "../../bootstrap"
22
+ import { setEventEmit } from "../@utilities/utilities.setEventEmit";
23
+ import { setWarning } from "../@utilities/utilities.setWarning";
24
+
25
+ export const xReconnect = async (interval: number): Promise<void> => {
26
+ const settings = bootstrap.settings as TypeSettings;
27
+ const lastStanza = Date.now() - bootstrap.cache.lastStanza
28
+ if (interval < 15) {
29
+ setWarning({ message: `Reconnection Interval of ${interval} seconds is too low, setting to 15 seconds` })
30
+ interval = 15;
31
+ bootstrap.settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.ReconnectionInterval = 15;
32
+ }
33
+ const reconnectThreshold = interval * 1e3
34
+ if ((!bootstrap.cache.isConnected && !bootstrap.cache.sigHault) || !bootstrap.session_xmpp) {
35
+ return;
36
+ }
37
+ if (lastStanza > reconnectThreshold) {
38
+ if (!bootstrap.cache.isReconnecting) {
39
+ bootstrap.cache.isReconnecting = true;
40
+ bootstrap.cache.isConnected = false;
41
+ bootstrap.cache.tReconnects += 1;
42
+ try {
43
+ setEventEmit({
44
+ event: `onServiceStatus`,
45
+ metadata: {
46
+ message: `Attempting to reconnect to XMPP Service (Reconnect Attempt ${bootstrap.cache.tReconnects})`,
47
+ data: {
48
+ last_stanza: lastStanza,
49
+ nickname: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Nickname
50
+ },
51
+ type: `reconnect`,
52
+ error: true
53
+ },
54
+ })
55
+ await bootstrap.session_xmpp.stop().catch(() => {});
56
+ await bootstrap.session_xmpp.start().catch(() => {});
57
+ } catch (error) {
58
+ setWarning({ message: `XMPP Reconnect Failed - ${(error as Error).message}` })
59
+ } finally {
60
+ bootstrap.cache.isReconnecting = false;
61
+ }
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,63 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeStanza } from "../../@types/types.stanza";
21
+ import { bootstrap } from "../../bootstrap";
22
+ import { validate } from "../@stanza/stanza.validate";
23
+ import { createEvent } from "../../@building/building.create";
24
+ import { importStanza } from "../@database/database.stanza";
25
+ import { setEventEmit } from "../@utilities/utilities.setEventEmit";
26
+
27
+ export const xStanza = () => {
28
+ bootstrap.session_xmpp.on(`stanza`, async (stanza: TypeStanza) => {
29
+ const msgFrom = stanza?.attrs?.from ?? ``
30
+ const msgType = stanza?.attrs?.type ?? ``
31
+ setEventEmit({
32
+ event: `onServiceStatus`,
33
+ metadata: {
34
+ message: stanza,
35
+ from: msgFrom,
36
+ type: `stanza`
37
+ },
38
+ })
39
+ bootstrap.cache.lastStanza = Date.now();
40
+ if (stanza.is(`message`)) {
41
+ const result = validate({ stanza });
42
+ const isSkippable = result.isIgnored ||
43
+ (result.isCapEvent) ||
44
+ (result.isCapEvent && !result.isCapAreaDescription)
45
+ if (isSkippable) { return; }
46
+ await createEvent(result);
47
+ await importStanza(result);
48
+ }
49
+ if (stanza.is(`presence`) && msgFrom.startsWith('nwws@conference.nwws-oi.weather.gov/')) {
50
+ const getOccupant = msgFrom.split(`/`).slice(1).join(`/`)
51
+ const getAvailability = msgType === `unavailable`
52
+ setEventEmit({
53
+ event: `onServiceStatus`,
54
+ metadata: {
55
+ message: `Occupant ${getOccupant} has ${getAvailability ? `left` : `joined`} the room`,
56
+ data: {},
57
+ type: `occupant`,
58
+ error: false
59
+ },
60
+ })
61
+ }
62
+ })
63
+ }
@@ -0,0 +1,40 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeHVTEC } from "../../@types/types.hvtec";
21
+ import { eventCauses } from "../../@dictionaries/dictionaries.eventCauses";
22
+ import { eventRecords } from "../../@dictionaries/dictionaries.eventRecords";
23
+ import { regExp } from "../../@dictionaries/dictionaries.regExp";
24
+ import { eventSeverity } from "../../@dictionaries/dictionaries.eventSeverity";
25
+
26
+ export const hvExtract = (message: string): TypeHVTEC[] | null => {
27
+ const getHVTECs = message.match(regExp.hvtec) ?? [];
28
+ const vtecs: TypeHVTEC[] = [];
29
+ for (const vtec of getHVTECs) {
30
+ const sub = vtec.split(`.`);
31
+ if (sub.length < 7) continue;
32
+ vtecs.push({
33
+ hvtec: vtec,
34
+ severity: eventSeverity[sub[1]],
35
+ cause: eventCauses[sub[2]],
36
+ record: eventRecords[sub[6]]
37
+ })
38
+ }
39
+ return vtecs.length > 0 ? vtecs : null;
40
+ }
@@ -0,0 +1,26 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ export const getExpiry = (dates: string[]): string => {
21
+ if (dates?.[1] == `000000T0000Z`) return 'Invalid Date Format'
22
+ const expires = `${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`;
23
+ const local = new Date(new Date(expires).getTime() - 4 * 60 * 60000);
24
+ const pad = (n: number) => n.toString().padStart(2, '0');
25
+ return `${local.getFullYear()}-${pad(local.getMonth() + 1)}-${pad(local.getDate())}T${pad(local.getHours())}:${pad(local.getMinutes())}:00.000-04:00`;
26
+ }
@@ -0,0 +1,49 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypePVTEC } from "../../@types/types.pvtec";
21
+ import { regExp } from "../../@dictionaries/dictionaries.regExp";
22
+ import { eventProducts } from "../../@dictionaries/dictionaries.eventProducts";
23
+ import { eventTypes } from "../../@dictionaries/dictionaries.eventTypes";
24
+ import { eventActions } from "../../@dictionaries/dictionaries.eventActions";
25
+ import { eventStatus } from "../../@dictionaries/dictionaries.eventStatus";
26
+ import { getExpiry } from "./pvtec.expires";
27
+
28
+ export const pvExtract = (message: string): TypePVTEC[] | null => {
29
+ const getVTECs = message.match(regExp.pvtec) ?? [];
30
+ const vtecs: TypePVTEC[] = [];
31
+ for (const vtec of getVTECs) {
32
+ const sub = vtec.split(`.`);
33
+ if (sub?.length < 7) continue;
34
+ const dates = sub[6]?.split(`-`);
35
+ vtecs.push({
36
+ vtec: vtec,
37
+ product: eventProducts[sub[0]],
38
+ tracking: `${sub[2]}-${sub[3]}-${sub[4]}-${sub[5]}`,
39
+ event: `${eventTypes[sub[3]]} ${eventActions[sub[4]]}`,
40
+ status: eventStatus[sub[1]],
41
+ organization: message.match(regExp.wmo)?.[0] ?? null,
42
+ expires: getExpiry(dates),
43
+ is_watch: (sub[4] == `A` || sub[4] == `Y`) && (sub[3] == `TO` || sub[3] == `SV`),
44
+ prediction_center: sub[2] == `KWNS`
45
+ ? true : false
46
+ })
47
+ }
48
+ return vtecs.length > 0 ? vtecs : null;
49
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { regExp } from "../../@dictionaries/dictionaries.regExp";
21
+
22
+ interface GetDescriptionFromProductOptions {
23
+ message: string
24
+ handle?: string
25
+ }
26
+
27
+ export const getDescriptionFromProduct = (options: GetDescriptionFromProductOptions): string => {
28
+ let message = options.message;
29
+ const dates = Array.from(message.matchAll(regExp.dateline));
30
+ if (dates.length) {
31
+ const lastMatch = dates[dates.length - 1][0];
32
+ const sIndx = message.lastIndexOf(lastMatch);
33
+ if (sIndx !== -1) {
34
+ const endIndx = message.indexOf('&&', sIndx);
35
+ message = message.substring(sIndx + lastMatch.length, endIndx !== -1 ? endIndx : undefined).trimStart();
36
+ if (message.startsWith('/')) message = message.slice(1).trimStart();
37
+ if (options.handle && message.includes(options.handle)) {
38
+ const handleIdx = message.indexOf(options.handle);
39
+ message = message.substring(handleIdx + options.handle.length).trimStart();
40
+ if (message.startsWith('/')) message = message.slice(1).trimStart();
41
+ }
42
+ }
43
+ } else if (options.handle) {
44
+ const handleIndx = message.indexOf(options.handle);
45
+ if (handleIndx !== -1) {
46
+ let afterHandle = message.substring(handleIndx + options.handle.length).trimStart();
47
+ if (afterHandle.startsWith('/')) afterHandle = afterHandle.slice(1).trimStart();
48
+ const latEnd = afterHandle.indexOf('&&')
49
+ message = latEnd !== -1 ? afterHandle.substring(0, latEnd).trim() : afterHandle.trim();
50
+ }
51
+ }
52
+ return message.trim();
53
+ }