@aguacerowx/mapsgl 0.0.55 → 0.0.56

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.
@@ -1,114 +0,0 @@
1
- /**
2
- * NWWS `/alerts?hours=` sizing (aguacero-frontend baseline + overlap window parity).
3
- *
4
- * Hours follow the **active** observational mode only: NEXRAD → `nexradDurationValue`,
5
- * MRMS → `mrmsDurationValue`, satellite → `satelliteDurationValue`, otherwise `1` (e.g. model-only).
6
- * Tier cap uses {@link AguaceroCore} `satelliteTier` — the only subscription-style field on core today
7
- * (same values as the frontend board tier: basic / enthusiast / professional).
8
- */
9
-
10
- const MAX_ALERT_HISTORY_HOURS = 8760;
11
-
12
- /** Matches javascript-sdk `satellite_support.js` timeline clamp. */
13
- const TIMELINE_DURATION_MAX_HOURS = 12;
14
-
15
- const LEGACY_DURATION_ALIAS = {
16
- '0.5': '1',
17
- };
18
-
19
- /**
20
- * Same rules as `parseTimelineDurationHours` in `@aguacerowx/javascript-sdk` (inlined so mapsgl
21
- * does not depend on a package subpath that Vite may not resolve).
22
- *
23
- * @param {string | number | null | undefined} value
24
- * @returns {number}
25
- */
26
- function parseTimelineDurationHours(value) {
27
- let s = value == null ? '1' : String(value).trim();
28
- s = LEGACY_DURATION_ALIAS[s] || s;
29
- const n = Number(s);
30
- if (!Number.isFinite(n) || n <= 0) return 1;
31
- if (n > TIMELINE_DURATION_MAX_HOURS) return TIMELINE_DURATION_MAX_HOURS;
32
- return n;
33
- }
34
-
35
- /** Max option span (hours) per tier from frontend `RADAR_DURATION_CONFIG`. */
36
- const TIER_MAX_HOURS = {
37
- professional: 12,
38
- enthusiast: 4,
39
- basic: 1,
40
- };
41
-
42
- /**
43
- * @param {string | undefined} tier
44
- * @returns {'professional'|'enthusiast'|'basic'}
45
- */
46
- export function normalizeNwsSubscriptionTier(tier) {
47
- const t = String(tier || 'basic').toLowerCase();
48
- if (t === 'commercial' || t === 'lifetime' || t === 'partner') return 'professional';
49
- if (t === 'professional' || t === 'enthusiast' || t === 'basic') return t;
50
- return 'basic';
51
- }
52
-
53
- /**
54
- * @param {string | undefined} tier
55
- * @returns {number}
56
- */
57
- export function getMaxRadarHistoryHoursForTier(tier) {
58
- const k = normalizeNwsSubscriptionTier(tier);
59
- return TIER_MAX_HOURS[k] ?? TIER_MAX_HOURS.basic;
60
- }
61
-
62
- /**
63
- * @param {object | null | undefined} state - {@link AguaceroCore} `state`
64
- * @returns {number} integer hours in [1, MAX_ALERT_HISTORY_HOURS]
65
- */
66
- export function computeNwsAlertsFetchHoursFromAguaceroState(state) {
67
- const tierMax = getMaxRadarHistoryHoursForTier(state?.satelliteTier);
68
- let desired = 1;
69
- if (state?.isNexrad) {
70
- desired = parseTimelineDurationHours(state.nexradDurationValue);
71
- } else if (state?.isMRMS) {
72
- desired = parseTimelineDurationHours(state.mrmsDurationValue);
73
- } else if (state?.isSatellite) {
74
- desired = parseTimelineDurationHours(state.satelliteDurationValue);
75
- }
76
- const clamped = Math.min(tierMax, Math.max(1, desired));
77
- return Math.min(MAX_ALERT_HISTORY_HOURS, Math.floor(clamped));
78
- }
79
-
80
- /**
81
- * @param {number} hours
82
- * @returns {string}
83
- */
84
- export function nwsAlertsFetchSpecCacheKey(hours) {
85
- return `h${hours}`;
86
- }
87
-
88
- /**
89
- * Unix window [start, end] for client-side validity overlap (wall-clock end at “now”).
90
- *
91
- * @param {number} hours
92
- * @param {number | null} [anchorSec] - reserved; default now (matches frontend `anchorSec: null`)
93
- * @returns {{ winStartSec: number; winEndSec: number }}
94
- */
95
- export function nwwsAlertsFetchUnixWindow(hours, anchorSec = null) {
96
- const nowSec = Math.floor(Date.now() / 1000);
97
- const winEndSec = anchorSec ?? nowSec;
98
- const winStartSec = winEndSec - hours * 3600;
99
- return { winStartSec, winEndSec };
100
- }
101
-
102
- /**
103
- * @param {string} baseUrl - `/alerts` root (no query)
104
- * @param {number} hours
105
- * @returns {string}
106
- */
107
- export function buildNwwsActiveAlertsUrl(baseUrl, hours) {
108
- const h = Math.max(1, Math.floor(Number(hours) || 1));
109
- const params = new URLSearchParams();
110
- params.set('hours', String(h));
111
- const q = params.toString();
112
- const base = String(baseUrl || '').replace(/\/$/, '');
113
- return q ? `${base}?${q}` : base;
114
- }