@atmosx/event-product-parser 3.0.6 → 3.0.7

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 (181) hide show
  1. package/.github/docs/docs-functions.md +2 -2
  2. package/.github/docs/docs-general-configurations.md +2 -12
  3. package/.github/docs/docs-integrations.md +4 -3
  4. package/.github/docs/docs-listeners.md +1 -1
  5. package/.github/docs/docs-source-configuration.md +1 -1
  6. package/.github/docs/docs-technical.md +1 -1
  7. package/{.github/README.md → README.md} +15 -9
  8. package/dist/cjs/index.cjs +24073 -7018
  9. package/dist/esm/index.mjs +24035 -6983
  10. package/package.json +56 -47
  11. package/pnpm-workspace.yaml +4 -0
  12. package/src/bootstrap.ts +64 -48
  13. package/src/{@building → building}/CreateEvent.ts +22 -24
  14. package/src/{@building → building}/GetCleanedEvent.ts +2 -2
  15. package/src/{@building → building}/GetEventAttachments.ts +14 -12
  16. package/src/building/GetEventDirection.ts +28 -0
  17. package/src/{@building → building}/GetEventEnhancedName.ts +5 -8
  18. package/src/{@building → building}/GetEventGeometry.ts +19 -13
  19. package/src/{@building → building}/GetEventHeader.ts +13 -13
  20. package/src/{@building → building}/GetEventNodes.ts +21 -19
  21. package/src/{@building → building}/GetEventOffice.ts +13 -13
  22. package/src/building/GetEventProperties.ts +105 -0
  23. package/src/{@building → building}/GetEventSignature.ts +9 -9
  24. package/src/{@building → building}/GetEventTags.ts +3 -3
  25. package/src/building/GetEventTheme.ts +26 -0
  26. package/src/building/GetEventTracking.ts +64 -0
  27. package/src/components/audio/GenerateAudioMessage.ts +149 -0
  28. package/src/{@modules/@eas → components/audio/components}/GetCleanDescription.ts +2 -2
  29. package/src/{@modules/@eas → components/audio/components}/GetFloatPCM16.ts +2 -2
  30. package/src/{@modules/@eas → components/audio/components}/GetMergedPCM16.ts +2 -2
  31. package/src/{@modules/@eas → components/audio/components}/GetPCM16.ts +13 -8
  32. package/src/{@modules/@eas → components/audio/components}/GetPCMToFloat.ts +2 -2
  33. package/src/{@modules/@eas → components/audio/components}/GetSampledPCM16.ts +14 -8
  34. package/src/{@modules/@eas → components/audio/components}/GetTTS.ts +17 -10
  35. package/src/{@modules/@eas → components/audio/components}/GetWavPCM16.ts +7 -7
  36. package/src/{@modules/@eas → components/audio/components}/SetAFSK.ts +13 -8
  37. package/src/{@modules/@eas → components/audio/components}/SetAsciiToBits.ts +2 -2
  38. package/src/{@modules/@eas → components/audio/components}/SetAttentionTone.ts +11 -6
  39. package/src/{@modules/@eas → components/audio/components}/SetNoise.ts +12 -7
  40. package/src/{@modules/@eas → components/audio/components}/SetRadioEffect.ts +12 -7
  41. package/src/{@modules/@eas → components/audio/components}/SetSameHeader.ts +22 -14
  42. package/src/{@modules/@utilities/SetWarning.ts → components/database/CreateQuery.ts} +18 -13
  43. package/src/{@modules/@database → components/database}/GetCachedEvents.ts +18 -15
  44. package/src/components/database/ImportBoundaries.ts +168 -0
  45. package/src/{@modules/@database → components/database}/ImportBroadcastify.ts +14 -24
  46. package/src/components/database/ImportCities.ts +87 -0
  47. package/src/{@modules/@database → components/database}/ImportShapefiles.ts +23 -26
  48. package/src/{@modules/@database → components/database}/ImportStanza.ts +15 -19
  49. package/src/components/database/InitializeDatabase.ts +71 -0
  50. package/src/components/images/GenerateGraphic.ts +234 -0
  51. package/src/components/images/components/CreateRectangle.ts +22 -0
  52. package/src/components/images/components/CreateText.ts +22 -0
  53. package/src/components/images/modules/CreateSVG.ts +37 -0
  54. package/src/components/images/modules/GetGeographicalBoundaries.ts +72 -0
  55. package/src/components/images/modules/GetGeographicalCities.ts +58 -0
  56. package/src/components/images/modules/GetGeographicalEvents.ts +48 -0
  57. package/src/components/images/modules/GetGeometryBounds.ts +82 -0
  58. package/src/components/images/modules/GetParsedBoundary.ts +58 -0
  59. package/src/components/images/modules/GetSVGPath.ts +53 -0
  60. package/src/components/images/modules/NormalizePolygon.ts +57 -0
  61. package/src/{@modules/@stanza → components/stanza}/GetAwipsType.ts +16 -17
  62. package/src/{@modules/@stanza → components/stanza}/ValidateStanza.ts +27 -15
  63. package/src/{@modules/@utilities → components/utilities}/CreateHttp.ts +26 -26
  64. package/src/{@modules/@utilities → components/utilities}/GetFormattedTime.ts +2 -2
  65. package/src/{@modules/@utilities → components/utilities}/GetLatestIssuance.ts +2 -2
  66. package/src/{@modules/@utilities → components/utilities}/GetMatched.ts +10 -5
  67. package/src/{@modules/@utilities → components/utilities}/GetShapeNearestPoint.ts +24 -19
  68. package/src/components/utilities/GetUnionPolygon.ts +36 -0
  69. package/src/components/utilities/QueueManager.ts +70 -0
  70. package/src/{@modules/@utilities → components/utilities}/SetCronSchedule.ts +29 -25
  71. package/src/{@modules/@utilities → components/utilities}/SetDebug.ts +12 -12
  72. package/src/components/utilities/SetEventEmit.ts +42 -0
  73. package/src/{@modules/@utilities → components/utilities}/SetSettings.ts +7 -7
  74. package/src/{@modules/@utilities → components/utilities}/SetSleep.ts +5 -5
  75. package/src/components/utilities/SetTimeoutAction.ts +64 -0
  76. package/src/components/utilities/SetWarning.ts +47 -0
  77. package/src/{@modules/@xmpp → components/xmpp}/DeployXMPP.ts +20 -20
  78. package/src/{@core/CreateListener.ts → components/xmpp/ErrorXMPP.ts} +8 -5
  79. package/src/{@modules/@xmpp → components/xmpp}/OfflineXMPP.ts +13 -13
  80. package/src/{@modules/@xmpp → components/xmpp}/OnlineXMPP.ts +18 -18
  81. package/src/components/xmpp/ReconnectXMPP.ts +64 -0
  82. package/src/{@modules/@xmpp → components/xmpp}/StanzaXMPP.ts +25 -25
  83. package/src/{@core → core}/ClearEvents.ts +9 -9
  84. package/src/{@core → core}/GetEvents.ts +4 -4
  85. package/src/{@core → core}/GetNodes.ts +4 -4
  86. package/src/{@core → core}/GetRandomEvent.ts +4 -4
  87. package/src/{@core → core}/GetVersion.ts +4 -4
  88. package/src/{@core → core}/ManualEvent.ts +23 -24
  89. package/src/{@core → core}/QueryStanza.ts +12 -11
  90. package/src/core/SetNode.ts +87 -0
  91. package/src/{@core → core}/StartService.ts +21 -20
  92. package/src/{@core → core}/StopService.ts +10 -10
  93. package/src/{@enums → enums}/AWIPS.ts +2 -2
  94. package/src/{@enums → enums}/Actions.ts +2 -2
  95. package/src/{@enums → enums}/Cancellation.ts +2 -2
  96. package/src/{@enums → enums}/Causes.ts +2 -2
  97. package/src/{@enums → enums}/Correlations.ts +2 -2
  98. package/src/{@enums → enums}/Enhanced.ts +2 -2
  99. package/src/{@enums → enums}/Events.ts +2 -2
  100. package/src/{@enums → enums}/Expressions.ts +3 -3
  101. package/src/{@enums → enums}/GlobalFilter.ts +2 -2
  102. package/src/{@enums → enums}/Hail.ts +2 -2
  103. package/src/{@enums → enums}/ICAO.ts +2 -2
  104. package/src/{@enums → enums}/Matches.ts +8 -3
  105. package/src/{@enums → enums}/Products.ts +2 -2
  106. package/src/{@enums → enums}/Records.ts +2 -2
  107. package/src/{@enums → enums}/Severity.ts +2 -2
  108. package/src/{@enums → enums}/Shapefiles.ts +2 -2
  109. package/src/{@enums → enums}/States.ts +68 -4
  110. package/src/{@enums → enums}/Status.ts +2 -2
  111. package/src/{@enums → enums}/Strings.ts +2 -2
  112. package/src/{@enums → enums}/Tags.ts +9 -4
  113. package/src/{@enums → enums}/Testing.ts +2 -2
  114. package/src/enums/Themes.ts +70 -0
  115. package/src/events/ParseAPI.ts +129 -0
  116. package/src/{@events → events}/ParseText.ts +24 -22
  117. package/src/{@events → events}/ParseUGC.ts +27 -26
  118. package/src/{@events → events}/ParseVTEC.ts +38 -37
  119. package/src/index.ts +57 -37
  120. package/src/manager/MakeEvents.ts +110 -0
  121. package/src/manager/RemoveEvent.ts +74 -0
  122. package/src/{@manager → manager}/SetHash.ts +18 -13
  123. package/src/{@manager → manager}/UpdateEvents.ts +12 -12
  124. package/src/{@manager → manager}/UpdateNode.ts +14 -14
  125. package/src/{@building → manager}/ValidateEvents.ts +47 -57
  126. package/src/{@parsers/@hvtec → parsers/hvtec}/HVExtract.ts +11 -11
  127. package/src/{@parsers/@text → parsers/text}/GetDescriptionFromProduct.ts +20 -21
  128. package/src/{@parsers/@text → parsers/text}/GetEmbededText.ts +7 -6
  129. package/src/parsers/text/GetPolygonFromProduct.ts +71 -0
  130. package/src/{@parsers/@text → parsers/text}/GetStringText.ts +9 -9
  131. package/src/{@parsers/@text → parsers/text}/GetTextFromProduct.ts +12 -12
  132. package/src/parsers/ugc/GetCache.ts +24 -0
  133. package/src/{@parsers/@ugc → parsers/ugc}/GetExpiry.ts +2 -2
  134. package/src/{@parsers/@ugc/GetUGCHeader.ts → parsers/ugc/GetHeader.ts} +4 -4
  135. package/src/{@parsers/@ugc → parsers/ugc}/GetLocations.ts +10 -10
  136. package/src/parsers/ugc/GetZonePolygon.ts +73 -0
  137. package/src/{@parsers/@ugc → parsers/ugc}/GetZones.ts +3 -3
  138. package/src/{@parsers/@ugc → parsers/ugc}/SetCache.ts +13 -8
  139. package/src/{@parsers/@ugc → parsers/ugc}/UGCExtract.ts +14 -14
  140. package/src/{@parsers/@pvtec → parsers/vtec}/GetExpiry.ts +2 -2
  141. package/src/parsers/vtec/VTECExtract.ts +49 -0
  142. package/src/{@types → static}/Attributes.ts +2 -3
  143. package/src/{@types → static}/Event.ts +8 -7
  144. package/src/{@types → static}/Properties.ts +7 -3
  145. package/src/{@types → static}/Stanza.ts +2 -2
  146. package/src/tasks/CreateTasks.ts +123 -0
  147. package/src/tasks/TaskGenerateJSON.ts +34 -0
  148. package/src/tasks/TaskGenerateText.ts +34 -0
  149. package/src/tasks/TaskSendNTFY.ts +97 -0
  150. package/src/tasks/TaskSendWebhook.ts +107 -0
  151. package/src/{@types → types}/Actions.ts +3 -3
  152. package/src/{@types → types}/HVTEC.ts +6 -6
  153. package/src/{@types → types}/Hash.ts +5 -5
  154. package/src/types/Nodes.ts +29 -0
  155. package/src/{@types → types}/Settings.ts +16 -8
  156. package/src/{@types → types}/StanzaCompiled.ts +15 -15
  157. package/src/{@types → types}/UGC.ts +5 -5
  158. package/src/{@modules/@utilities/GetSettings.ts → types/VTEC.ts} +12 -7
  159. package/tools/build.js +47 -0
  160. package/tsconfig.json +28 -1
  161. package/src/@building/GetEventProperties.ts +0 -96
  162. package/src/@building/GetEventTracking.ts +0 -68
  163. package/src/@core/SetNode.ts +0 -81
  164. package/src/@events/ParseAPI.ts +0 -117
  165. package/src/@manager/CreateActions.ts +0 -213
  166. package/src/@manager/MakeEvent.ts +0 -99
  167. package/src/@manager/RemoveEvent.ts +0 -70
  168. package/src/@modules/@database/InitializeDatabase.ts +0 -59
  169. package/src/@modules/@eas/GenerateEASMessage.ts +0 -144
  170. package/src/@modules/@utilities/SetEventEmit.ts +0 -41
  171. package/src/@modules/@utilities/SetListener.ts +0 -30
  172. package/src/@modules/@utilities/SetTimeoutAction.ts +0 -64
  173. package/src/@modules/@xmpp/ErrorXMPP.ts +0 -27
  174. package/src/@modules/@xmpp/ReconnectXMPP.ts +0 -64
  175. package/src/@parsers/@pvtec/VTECExtract.ts +0 -49
  176. package/src/@parsers/@text/GetPolygonFromProduct.ts +0 -53
  177. package/src/@parsers/@text/GetXML.ts +0 -61
  178. package/src/@parsers/@ugc/GetCache.ts +0 -24
  179. package/src/@parsers/@ugc/GetZonePolygon.ts +0 -111
  180. package/src/@types/VTEC.ts +0 -30
  181. package/tsup.config.ts +0 -16
@@ -11,9 +11,9 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
@@ -11,17 +11,22 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
  */
19
19
 
20
- export const GetMatched = (strings: string[], string: string): boolean => {
21
- const isMatched = strings.some(pattern => {
20
+ interface GetMatchedOptions {
21
+ Strings: string[]
22
+ String: string
23
+ }
24
+
25
+ export const GetMatched = ({ Strings, String }: GetMatchedOptions): boolean => {
26
+ const isMatched = Strings.some(pattern => {
22
27
  if (!pattern) return false;
23
28
  const lowerP = pattern.toLowerCase();
24
- const lowerS = string.toLowerCase()
29
+ const lowerS = String.toLowerCase()
25
30
  if (lowerP === "*" || lowerP === lowerS) return true;
26
31
  if (lowerP.includes("*")) {
27
32
  const regex = "^" + lowerP.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*") + "$";
@@ -11,23 +11,28 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
  */
19
19
 
20
+ interface GetShapeNearestPointOptions {
21
+ Coordinates: number[][]
22
+ Point: [number, number]
23
+ }
24
+
20
25
  interface GetShapeNearestPointResponse {
21
- proximity: boolean
22
- point: [number, number]
23
- distance: number | null
24
- distanceKm?: number | null
25
- distanceMeters?: number | null
26
+ Proximity: boolean
27
+ Point: [number, number]
28
+ Distance: number | null
29
+ DistanceKm?: number | null
30
+ DistanceMeters?: number | null
26
31
  }
27
32
 
28
- export const GetShapeNearestPoint = (coordinates: number[][], point: [number, number]): GetShapeNearestPointResponse => {
29
- if (!coordinates || !point) {
30
- return { proximity: false, point: [0, 0], distance: null }
33
+ export const GetShapeNearestPoint = ({ Coordinates, Point }: GetShapeNearestPointOptions): GetShapeNearestPointResponse => {
34
+ if (!Coordinates || !Point) {
35
+ return { Proximity: false, Point: [0, 0], Distance: null }
31
36
  }
32
37
  const normalize = (coords: any): any[] => {
33
38
  if (!Array.isArray(coords)) return [];
@@ -43,10 +48,10 @@ export const GetShapeNearestPoint = (coordinates: number[][], point: [number, nu
43
48
  }
44
49
  return [];
45
50
  }
46
- const polys = normalize(coordinates);
47
- if (polys.length === 0) return { proximity: false, point: [0, 0], distance: null };
48
- const lon = point[0];
49
- const lat = point[1];
51
+ const polys = normalize(Coordinates);
52
+ if (polys.length === 0) return { Proximity: false, Point: [0, 0], Distance: null };
53
+ const lon = Point[0];
54
+ const lat = Point[1];
50
55
  const pointInRing = (pt: [number, number], ring: number[][]): boolean => {
51
56
  let x = pt[0], y = pt[1];
52
57
  let inside = false;
@@ -76,13 +81,13 @@ export const GetShapeNearestPoint = (coordinates: number[][], point: [number, nu
76
81
  for (const poly of polys) {
77
82
  const outer = poly[0];
78
83
  const holes = poly.slice(1);
79
- if (pointInRing(point, outer)) {
84
+ if (pointInRing(Point, outer)) {
80
85
  let inHole = false;
81
86
  for (const hole of holes) {
82
- if (pointInRing(point, hole)) { inHole = true; break; }
87
+ if (pointInRing(Point, hole)) { inHole = true; break; }
83
88
  }
84
89
  if (!inHole) {
85
- return { proximity: true, point, distance: 0 };
90
+ return { Proximity: true, Point, Distance: 0 };
86
91
  }
87
92
  }
88
93
  for (const ring of poly) {
@@ -105,10 +110,10 @@ export const GetShapeNearestPoint = (coordinates: number[][], point: [number, nu
105
110
  }
106
111
  }
107
112
  if (!isFinite(minDistance) || closestPoint == null) {
108
- return { proximity: false, point: [0,0], distance: null };
113
+ return { Proximity: false, Point: [0,0], Distance: null };
109
114
  }
110
115
  const distanceMiles = minDistance;
111
116
  const distanceKm = Number((distanceMiles * 1.609344).toFixed(3));
112
117
  const distanceMeters = Math.round(distanceKm * 1000);
113
- return { proximity: distanceMiles === 0, point: closestPoint, distance: distanceMiles, distanceKm, distanceMeters };
118
+ return { Proximity: distanceMiles === 0, Point: closestPoint, Distance: distanceMiles, DistanceKm: distanceKm, DistanceMeters: distanceMeters };
114
119
  }
@@ -0,0 +1,36 @@
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: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { union } from "polygon-clipping";
21
+
22
+ interface GetUnionPolygonOptions {
23
+ Polygons: number[][][][] | null;
24
+ }
25
+
26
+ export const GetUnionPolygon = ({ Polygons }: GetUnionPolygonOptions): GeoJSON.MultiPolygon | null => {
27
+ if (!Polygons || Polygons.length === 0) {
28
+ return null;
29
+ }
30
+ const unionFn = union as unknown as (...polygons: number[][][][]) => number[][][][];
31
+ const unioned = unionFn(...Polygons)
32
+ return {
33
+ type: `MultiPolygon`,
34
+ coordinates: unioned
35
+ }
36
+ };
@@ -0,0 +1,70 @@
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: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent Package: @atmosx/event-product-parser
17
+ */
18
+
19
+ export type QueueTask = () => Promise<void>;
20
+
21
+ export interface QueueManagerOptions {
22
+ Concurrency?: number;
23
+ Error?: (error: unknown) => void;
24
+ }
25
+
26
+ export class QueueManager {
27
+ private readonly queue: QueueTask[] = [];
28
+ private readonly concurrency: number;
29
+ private readonly onError: (error: unknown) => void;
30
+
31
+ private running = 0;
32
+ private draining = false;
33
+
34
+ public constructor({ Concurrency, Error }: QueueManagerOptions = {}) {
35
+ this.concurrency = Concurrency ?? 1;
36
+ this.onError = Error ?? ((error) => {
37
+ console.error("[QueueManager] Task failed:", error);
38
+ });
39
+ }
40
+
41
+ public enqueue(task: QueueTask): void {
42
+ this.queue.push(task);
43
+ this.drain();
44
+ }
45
+
46
+ private drain(): void {
47
+ if (this.draining) { return; }
48
+ this.draining = true;
49
+ while (this.running < this.concurrency && this.queue.length > 0) {
50
+ const task = this.queue.shift();
51
+ if (!task) { continue; }
52
+ this.running++;
53
+ void this.execute(task);
54
+ }
55
+ this.draining = false;
56
+ }
57
+
58
+ private async execute(task: QueueTask): Promise<void> {
59
+ try {
60
+ await task();
61
+ } catch (error) {
62
+ try {
63
+ this.onError(error);
64
+ } catch (handlerError) {}
65
+ } finally {
66
+ this.running--;
67
+ this.drain();
68
+ }
69
+ }
70
+ }
@@ -11,34 +11,34 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- import { TypeSettings } from "../../@types/Settings";
22
- import { ReconnectXMPP } from "../@xmpp/ReconnectXMPP"
23
- import { bootstrap } from "../../bootstrap";
24
- import { CreateHttp } from "./CreateHttp";
25
- import { CreateEvent } from "../../@building/CreateEvent";
26
- import { SetEventEmit } from "./SetEventEmit";
27
- import { readdirSync, unlinkSync, statSync, existsSync } from "fs";
28
- import { join } from "path";
21
+ import { TypeSettings } from "Types/Settings"
22
+ import { ReconnectXMPP } from "@XMPP/ReconnectXMPP"
23
+ import { Bootstrap } from "@Bootstrap"
24
+ import { CreateHttp } from "@Utilities/CreateHttp"
25
+ import { SetEventEmit } from "@Utilities/SetEventEmit"
26
+ import { CreateEvent } from "@Building/CreateEvent"
27
+ import { readdirSync, unlinkSync, statSync, rmdirSync, existsSync } from "fs"
28
+ import { join } from "path"
29
29
 
30
30
  export const SetCronSchedule = async (): Promise<void> => {
31
- const settings = bootstrap.settings as TypeSettings;
31
+ const settings = Bootstrap.Settings as TypeSettings;
32
32
 
33
33
  const TTL = settings.GlobalSettings.ArchiveSettings.TTL
34
34
  const TTLCUT = Date.now() - TTL * 1000;
35
35
 
36
- const walk = (dir: string): void => {
36
+ const walk = (dir: string, deleteFolder?: boolean): void => {
37
37
  if (existsSync(dir)) {
38
38
  const entries = readdirSync(dir, { withFileTypes: true });
39
39
  for (const entry of entries) {
40
40
  const fullPath = join(dir, entry.name);
41
- if (entry.isDirectory()) { walk(fullPath); continue; }
41
+ if (entry.isDirectory()) { walk(fullPath, deleteFolder); continue; }
42
42
  const stats = statSync(fullPath);
43
43
  if (stats.mtime.getTime() < TTLCUT) {
44
44
  try {
@@ -47,12 +47,16 @@ export const SetCronSchedule = async (): Promise<void> => {
47
47
  console.error(`Failed to delete ${fullPath}:`, err);
48
48
  }
49
49
  }
50
+ if (deleteFolder && readdirSync(dir).length === 0) {
51
+ rmdirSync(dir);
52
+ }
50
53
  }
51
54
  }
52
55
  };
53
56
  walk(settings.GlobalSettings.ArchiveSettings.TextDirectory)
54
- walk(settings.GlobalSettings.ArchiveSettings.EasDirectory)
57
+ walk(settings.GlobalSettings.ArchiveSettings.AudioDirectory)
55
58
  walk(settings.GlobalSettings.ArchiveSettings.JSONDirectory)
59
+ walk(settings.GlobalSettings.ArchiveSettings.ImageDirectory, true)
56
60
 
57
61
 
58
62
 
@@ -62,15 +66,15 @@ export const SetCronSchedule = async (): Promise<void> => {
62
66
  }
63
67
  } else {
64
68
  const response = await CreateHttp({
65
- url: settings.NationalWeatherServiceSettings.EventsEndpoint,
66
- headers: {
69
+ URL: settings.NationalWeatherServiceSettings.EventsEndpoint,
70
+ Headers: {
67
71
  "User-Agent": "@atmosx/event-product-parser"
68
72
  }
69
73
  })
70
74
  if (response.error) {
71
75
  return SetEventEmit({
72
- event: `onServiceStatus`,
73
- metadata: {
76
+ Event: `onServiceStatus`,
77
+ Metadata: {
74
78
  type: "fetch-api",
75
79
  message: `Failed to fetch latest events from National Weather Service API - ${response.message}`,
76
80
  data: {},
@@ -79,15 +83,15 @@ export const SetCronSchedule = async (): Promise<void> => {
79
83
  })
80
84
  }
81
85
  SetEventEmit({
82
- event: `onServiceStatus`,
83
- metadata: {
84
- message: `Fetched latest events from National Weather Service API`,
85
- data: {},
86
- type: "fetch-api",
87
- error: false
86
+ Event: `onServiceStatus`,
87
+ Metadata: {
88
+ Message: `Fetched latest events from National Weather Service API`,
89
+ Data: {},
90
+ Type: "fetch-api",
91
+ Error: false
88
92
  },
89
93
  })
90
- await CreateEvent({ message: response.message, isNWWS: false })
94
+ await CreateEvent({ Message: response.message, NWWS: false })
91
95
  }
92
96
  }
93
97
 
@@ -11,27 +11,27 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
  */
19
19
 
20
- import { TypeSettings } from "../../@types/Settings";
21
- import { bootstrap } from "../../bootstrap"
20
+ import { TypeSettings } from "Types/Settings"
21
+ import { Bootstrap } from "@Bootstrap"
22
22
 
23
23
  interface SetDebugOptions {
24
- title?: string
25
- message: string
24
+ Title?: string
25
+ Message: string
26
26
  }
27
27
 
28
- export const SetDebug = (options: SetDebugOptions): void => {
29
- const settings = bootstrap.settings as TypeSettings;
30
- bootstrap.listener.emit(`debug`, {
31
- message: options.message,
32
- function: options.title ?? `debug`,
28
+ export const SetDebug = ({ Title, Message }: SetDebugOptions): void => {
29
+ const settings = Bootstrap.Settings as TypeSettings;
30
+ Bootstrap.Listener.emit(`debug`, {
31
+ message: Message,
32
+ function: Title ?? `debug`,
33
33
  })
34
34
  if (settings.EnableDebugging) {
35
- console.log(`[${bootstrap.ansi_colors.BLUE}${options.title ?? `debug`}${bootstrap.ansi_colors.RESET}] ${options.message}`)
35
+ console.log(`[${Bootstrap.Colors.Blue}${Title ?? `debug`}${Bootstrap.Colors.Reset}] ${Message}`)
36
36
  }
37
37
  }
@@ -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: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { Bootstrap } from "@Bootstrap"
21
+ import { SetTimeoutAction } from "@Utilities/SetTimeoutAction"
22
+ import { SetWarning } from "@Utilities/SetWarning"
23
+
24
+ interface SetEventEmitOptions {
25
+ Event: string
26
+ Metadata: any
27
+ Message?: string
28
+ Limited?: boolean
29
+ Tree?: string[]
30
+ }
31
+
32
+ export const SetEventEmit = ({ Event, Metadata, Message, Limited, Tree }: SetEventEmitOptions): void => {
33
+ if (Limited) {
34
+ const isTimeout = SetTimeoutAction({ Identifier: `event.${Event}`, AddTime: true, Max: 1, Interval: 1 })
35
+ if (isTimeout.Limited) return;
36
+ }
37
+ Bootstrap.Listener.emit(Event, Metadata)
38
+ if (Event != `log`) { Bootstrap.Listener.emit(`*`, {event: Event, data: Metadata}) }
39
+ if (Message) {
40
+ SetWarning({ Message: Message, Tree: Tree })
41
+ }
42
+ }
@@ -11,17 +11,17 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
  */
19
19
 
20
- import { TypeSettings } from '../../@types/Settings'
21
- import { bootstrap } from "../../bootstrap"
20
+ import { TypeSettings } from "Types/Settings"
21
+ import { Bootstrap } from "@Bootstrap"
22
22
 
23
- export const SetSettings = (newSettings: TypeSettings): TypeSettings => {
24
- const settings = bootstrap.settings as Record<string, unknown>;
23
+ export const SetSettings = (imported: TypeSettings): TypeSettings => {
24
+ const settings = Bootstrap.Settings as Record<string, unknown>;
25
25
  const merge = (target: Record<string, unknown>, source: Record<string, unknown>) => {
26
26
  for (const key in source) {
27
27
  if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
@@ -37,6 +37,6 @@ export const SetSettings = (newSettings: TypeSettings): TypeSettings => {
37
37
  }
38
38
  }
39
39
  };
40
- merge(settings, newSettings as Record<string, unknown>);
40
+ merge(settings, imported as Record<string, unknown>);
41
41
  return settings as TypeSettings;
42
42
  }
@@ -11,22 +11,22 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
21
  interface SetSleepOptions {
22
- timeout: number
22
+ Timeout: number
23
23
  }
24
24
 
25
- export const SetSleep = async (options: SetSleepOptions): Promise<void> => {
25
+ export const SetSleep = async ({ Timeout }: SetSleepOptions): Promise<void> => {
26
26
  return new Promise((resolve) => {
27
27
  setTimeout(() => {
28
28
  resolve();
29
- }, options.timeout);
29
+ }, Timeout);
30
30
  });
31
31
  }
32
32
 
@@ -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: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent 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
+ Expire?: boolean
28
+ }
29
+
30
+ type SetTimeoutActionResponse = {
31
+ Limited: boolean
32
+ Remaining?: number
33
+ Response?: string
34
+ }
35
+
36
+ export const SetTimeoutAction = ({ Identifier, AddTime, Max, Interval, Expire }: SetTimeoutActionOptions): SetTimeoutActionResponse => {
37
+ let target = Bootstrap?.Ratelimits?.[Identifier];
38
+ if (!target) {
39
+ Bootstrap.Ratelimits[Identifier] = [];
40
+ target = Bootstrap.Ratelimits[Identifier];
41
+ }
42
+ if (Expire) {
43
+ delete Bootstrap.Ratelimits[Identifier];
44
+ return { Limited: false };
45
+ }
46
+ if (target?.length > 0) {
47
+ Bootstrap.Ratelimits[Identifier] = target.filter((ts: number) => Date.now() - ts < Interval * 1000);
48
+ target = Bootstrap.Ratelimits[Identifier];
49
+ }
50
+
51
+ const oldestTimestamp = target?.[0];
52
+ const getWait = oldestTimestamp ? Math.ceil((Interval * 1000) - (Date.now() - oldestTimestamp)) : 0;
53
+ const max = Max ?? 1;
54
+
55
+ if (target?.length >= max && getWait > 0) {
56
+ return {
57
+ Limited: true,
58
+ Remaining: getWait,
59
+ Response: `You are being rate limited, please wait ${(getWait / 1e3).toFixed(1)} second(s) before performing this action again.`
60
+ }
61
+ }
62
+ Bootstrap.Ratelimits[Identifier].push(Date.now());
63
+ return { Limited: false };
64
+ }
@@ -0,0 +1,47 @@
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: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { Bootstrap } from "@Bootstrap"
21
+ import { TypeSettings } from "Types/Settings"
22
+
23
+ interface SetWarningOptions {
24
+ Title?: string
25
+ Message: string
26
+ Tree?: string[]
27
+ }
28
+
29
+ export const SetWarning = ({ Title, Message, Tree }: SetWarningOptions): void => {
30
+ const settings = Bootstrap.Settings as TypeSettings;
31
+ const title = Title ?? (`[${Bootstrap.Colors.Yellow}@atmosx/event-product-parser${Bootstrap.Colors.Reset}]`);
32
+ const log = (message: string): void => {
33
+ Bootstrap.Listener.emit(`log`, message);
34
+ if (settings.EnableJournal) { console.log(message); }
35
+ };
36
+ log(`${title} ${Message}`);
37
+
38
+ if (!Tree?.length) return;
39
+
40
+ const cleanTitle = title.replace(/\x1b\[[0-9;]*m/g, ``);
41
+ const padding = ` `.repeat(cleanTitle.length + 1);
42
+ const entries = Tree.filter((entry): entry is NonNullable<typeof entry> => entry !== undefined && entry !== null);
43
+ entries.forEach((entry, index) => {
44
+ const prefix = index === entries.length - 1 ? `└─` : `├─`;
45
+ log(`${padding}${prefix} ${entry}`);
46
+ });
47
+ };