@dangahagan/weather-mcp 1.40.0 → 1.40.2
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.
- package/README.md +3 -3
- package/dist/config/cache.d.ts +1 -0
- package/dist/config/cache.d.ts.map +1 -1
- package/dist/config/cache.js +5 -0
- package/dist/config/cache.js.map +1 -1
- package/dist/handlers/aviationWeatherHandler.d.ts.map +1 -1
- package/dist/handlers/aviationWeatherHandler.js +15 -0
- package/dist/handlers/aviationWeatherHandler.js.map +1 -1
- package/dist/handlers/tropicalCycloneContext.d.ts +32 -0
- package/dist/handlers/tropicalCycloneContext.d.ts.map +1 -0
- package/dist/handlers/tropicalCycloneContext.js +99 -0
- package/dist/handlers/tropicalCycloneContext.js.map +1 -0
- package/dist/services/aviationWeather.d.ts +4 -2
- package/dist/services/aviationWeather.d.ts.map +1 -1
- package/dist/services/aviationWeather.js +7 -3
- package/dist/services/aviationWeather.js.map +1 -1
- package/dist/services/nhc.d.ts +56 -0
- package/dist/services/nhc.d.ts.map +1 -0
- package/dist/services/nhc.js +196 -0
- package/dist/services/nhc.js.map +1 -0
- package/dist/types/nhc.d.ts +74 -0
- package/dist/types/nhc.d.ts.map +1 -0
- package/dist/types/nhc.js +16 -0
- package/dist/types/nhc.js.map +1 -0
- package/dist/utils/jmaParse.js +1 -1
- package/dist/utils/jmaParse.js.map +1 -1
- package/dist/utils/kmz.d.ts +55 -0
- package/dist/utils/kmz.d.ts.map +1 -0
- package/dist/utils/kmz.js +161 -0
- package/dist/utils/kmz.js.map +1 -0
- package/dist/utils/serviceStatusCoverage.d.ts.map +1 -1
- package/dist/utils/serviceStatusCoverage.js +1 -0
- package/dist/utils/serviceStatusCoverage.js.map +1 -1
- package/dist/utils/spcOutlook.js +1 -1
- package/dist/utils/spcOutlook.js.map +1 -1
- package/dist/utils/tafForecast.d.ts +2 -2
- package/dist/utils/tafForecast.js +2 -2
- package/dist/utils/tropicalCyclones.d.ts +123 -0
- package/dist/utils/tropicalCyclones.d.ts.map +1 -0
- package/dist/utils/tropicalCyclones.js +439 -0
- package/dist/utils/tropicalCyclones.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service for the NOAA National Hurricane Center's active-storm feed
|
|
3
|
+
* (`CurrentStorms.json`) and its 5-day forecast-cone KMZ files.
|
|
4
|
+
*
|
|
5
|
+
* Keyless, one host. This is positive-assertion-only garnish: one request per
|
|
6
|
+
* file, no retry, and every failure is a fixed plain `Error` that names
|
|
7
|
+
* neither a URL, a file name nor axios text. Logs carry `{ service, status,
|
|
8
|
+
* code }` only.
|
|
9
|
+
*
|
|
10
|
+
* The feed is cached whole and unfiltered (G6) under the alerts TTL, which
|
|
11
|
+
* matches the file's own `max-age=300`. A cone is cached as parsed rings under
|
|
12
|
+
* `tropicalConeFile`, keyed by its file name, never the URL, which holds `:`
|
|
13
|
+
* (G5). `CACHE_ENABLED` gates every read and every write (G169); same-key
|
|
14
|
+
* concurrent pulls share one request either way (G185). Failures are never
|
|
15
|
+
* cached.
|
|
16
|
+
*
|
|
17
|
+
* A cone URL is upstream data that would become a request, so it must pass the
|
|
18
|
+
* allowlist in `tropicalCyclones.ts` before anything is sent. The request then
|
|
19
|
+
* names only the matched file's path relative to this client's `baseURL`, so
|
|
20
|
+
* the request host is always this file's one host literal.
|
|
21
|
+
*/
|
|
22
|
+
import type { Ring } from '../utils/pointInPolygon.js';
|
|
23
|
+
import { type ParsedCurrentStorms } from '../utils/tropicalCyclones.js';
|
|
24
|
+
export interface NhcServiceConfig {
|
|
25
|
+
timeout?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare class NhcService {
|
|
28
|
+
private client;
|
|
29
|
+
private feedCache;
|
|
30
|
+
private coneCache;
|
|
31
|
+
private feedInFlight;
|
|
32
|
+
private coneInFlight;
|
|
33
|
+
constructor(config?: NhcServiceConfig);
|
|
34
|
+
/** Map a request failure to a fixed message. Never includes a URL, a file name, a body, or axios text. */
|
|
35
|
+
private toNhcError;
|
|
36
|
+
private logFailure;
|
|
37
|
+
/** One GET, no retry. Resolves with the body; rejects with a fixed message. */
|
|
38
|
+
private request;
|
|
39
|
+
/**
|
|
40
|
+
* The whole parsed active-storm feed. An empty `activeStorms` array is a
|
|
41
|
+
* valid quiet answer; any other unusable envelope throws (G4, G111). The
|
|
42
|
+
* parse runs outside the request `catch`, so its refusal keeps its own
|
|
43
|
+
* fixed text, and before `cache.set`, so a refused body is never cached. A
|
|
44
|
+
* feed over the record cap logs one `securityEvent` warn and is cached as
|
|
45
|
+
* trimmed: the cap removes lines only and backs no claim.
|
|
46
|
+
*/
|
|
47
|
+
getActiveStorms(): Promise<ParsedCurrentStorms>;
|
|
48
|
+
/**
|
|
49
|
+
* The rings of one forecast cone. The URL must pass the allowlist before
|
|
50
|
+
* any request; a refusal is a cone failure with no request made. The KMZ is
|
|
51
|
+
* read as bytes, unzipped and parsed; any failure (transport, a body that is
|
|
52
|
+
* not a KMZ, an unreadable KML) rejects and is never read as zero rings.
|
|
53
|
+
*/
|
|
54
|
+
getCone(url: string): Promise<Ring[]>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=nhc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nhc.d.ts","sourceRoot":"","sources":["../../src/services/nhc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAUH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAML,KAAK,mBAAmB,EACzB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA6BD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,YAAY,CAAmD;IACvE,OAAO,CAAC,YAAY,CAAsC;IAE1D,YAAY,MAAM,GAAE,gBAAqB,EAexC;IAED,0GAA0G;IAC1G,OAAO,CAAC,UAAU;IA2BlB,OAAO,CAAC,UAAU;IAUlB,+EAA+E;YACjE,OAAO;IAiBrB;;;;;;;OAOG;IACG,eAAe,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAiCpD;IAED;;;;;OAKG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAmC1C;CACF"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service for the NOAA National Hurricane Center's active-storm feed
|
|
3
|
+
* (`CurrentStorms.json`) and its 5-day forecast-cone KMZ files.
|
|
4
|
+
*
|
|
5
|
+
* Keyless, one host. This is positive-assertion-only garnish: one request per
|
|
6
|
+
* file, no retry, and every failure is a fixed plain `Error` that names
|
|
7
|
+
* neither a URL, a file name nor axios text. Logs carry `{ service, status,
|
|
8
|
+
* code }` only.
|
|
9
|
+
*
|
|
10
|
+
* The feed is cached whole and unfiltered (G6) under the alerts TTL, which
|
|
11
|
+
* matches the file's own `max-age=300`. A cone is cached as parsed rings under
|
|
12
|
+
* `tropicalConeFile`, keyed by its file name, never the URL, which holds `:`
|
|
13
|
+
* (G5). `CACHE_ENABLED` gates every read and every write (G169); same-key
|
|
14
|
+
* concurrent pulls share one request either way (G185). Failures are never
|
|
15
|
+
* cached.
|
|
16
|
+
*
|
|
17
|
+
* A cone URL is upstream data that would become a request, so it must pass the
|
|
18
|
+
* allowlist in `tropicalCyclones.ts` before anything is sent. The request then
|
|
19
|
+
* names only the matched file's path relative to this client's `baseURL`, so
|
|
20
|
+
* the request host is always this file's one host literal.
|
|
21
|
+
*/
|
|
22
|
+
import axios from 'axios';
|
|
23
|
+
import { Cache } from '../utils/cache.js';
|
|
24
|
+
import { CacheConfig } from '../config/cache.js';
|
|
25
|
+
import { logger } from '../utils/logger.js';
|
|
26
|
+
import { VERSION } from '../utils/version.js';
|
|
27
|
+
import { withRequestDeadline } from '../utils/httpDeadline.js';
|
|
28
|
+
import { isConnectionFailureCode } from '../utils/connectionFailure.js';
|
|
29
|
+
import { readFirstKmlEntry } from '../utils/kmz.js';
|
|
30
|
+
import { NHC_MAX_RESPONSE_BYTES, NHC_MAX_STORMS, coneFileName, parseConeKml, parseCurrentStorms } from '../utils/tropicalCyclones.js';
|
|
31
|
+
const NHC_USER_AGENT = `weather-mcp/${VERSION} (+https://github.com/weather-mcp/weather-mcp)`;
|
|
32
|
+
function isAxiosLikeError(error) {
|
|
33
|
+
return typeof error === 'object' && error !== null;
|
|
34
|
+
}
|
|
35
|
+
/** The bytes of an `arraybuffer` response, or `undefined` for any other body. */
|
|
36
|
+
function toBytes(data) {
|
|
37
|
+
if (data instanceof ArrayBuffer) {
|
|
38
|
+
return new Uint8Array(data);
|
|
39
|
+
}
|
|
40
|
+
if (ArrayBuffer.isView(data)) {
|
|
41
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
export class NhcService {
|
|
46
|
+
client;
|
|
47
|
+
feedCache;
|
|
48
|
+
coneCache;
|
|
49
|
+
feedInFlight = new Map();
|
|
50
|
+
coneInFlight = new Map();
|
|
51
|
+
constructor(config = {}) {
|
|
52
|
+
const { timeout = CacheConfig.apiTimeoutMs } = config;
|
|
53
|
+
this.feedCache = new Cache(CacheConfig.maxSize);
|
|
54
|
+
this.coneCache = new Cache(CacheConfig.maxSize);
|
|
55
|
+
this.client = axios.create({
|
|
56
|
+
baseURL: 'https://www.nhc.noaa.gov',
|
|
57
|
+
timeout,
|
|
58
|
+
headers: {
|
|
59
|
+
'User-Agent': NHC_USER_AGENT
|
|
60
|
+
},
|
|
61
|
+
// A 3xx is an error and is never followed.
|
|
62
|
+
maxRedirects: 0,
|
|
63
|
+
maxContentLength: NHC_MAX_RESPONSE_BYTES,
|
|
64
|
+
adapter: withRequestDeadline()
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Map a request failure to a fixed message. Never includes a URL, a file name, a body, or axios text. */
|
|
68
|
+
toNhcError(product, error) {
|
|
69
|
+
if (isAxiosLikeError(error)) {
|
|
70
|
+
// Checked before the `response` branch: an oversize rejection carries no `response`.
|
|
71
|
+
if (error.code === 'ERR_BAD_RESPONSE' && /maxContentLength/.test(error.message ?? '')) {
|
|
72
|
+
return new Error(`${product} response too large`);
|
|
73
|
+
}
|
|
74
|
+
if (error.response) {
|
|
75
|
+
const status = error.response.status;
|
|
76
|
+
if (status >= 300 && status < 400) {
|
|
77
|
+
return new Error(`${product} redirected`);
|
|
78
|
+
}
|
|
79
|
+
return new Error(`${product} is not available`);
|
|
80
|
+
}
|
|
81
|
+
if (error.code === 'ECONNABORTED' ||
|
|
82
|
+
error.code === 'ETIMEDOUT' ||
|
|
83
|
+
error.code === 'ERR_CANCELED') {
|
|
84
|
+
return new Error(`${product} request timed out`);
|
|
85
|
+
}
|
|
86
|
+
if (isConnectionFailureCode(error.code)) {
|
|
87
|
+
return new Error('Unable to connect to the NHC');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return new Error(`${product} is not available`);
|
|
91
|
+
}
|
|
92
|
+
logFailure(error) {
|
|
93
|
+
const failure = isAxiosLikeError(error) ? error : undefined;
|
|
94
|
+
// The Error slot stays empty: an axios error carries the URL and the body.
|
|
95
|
+
logger.error('NHC request failed', undefined, {
|
|
96
|
+
service: 'NHC',
|
|
97
|
+
status: failure?.response?.status,
|
|
98
|
+
code: failure?.code
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/** One GET, no retry. Resolves with the body; rejects with a fixed message. */
|
|
102
|
+
async request(product, path, options) {
|
|
103
|
+
try {
|
|
104
|
+
const response = await this.client.get(path, {
|
|
105
|
+
headers: { Accept: options.accept },
|
|
106
|
+
...(options.responseType ? { responseType: options.responseType } : {})
|
|
107
|
+
});
|
|
108
|
+
return response.data;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
this.logFailure(error);
|
|
112
|
+
throw this.toNhcError(product, error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The whole parsed active-storm feed. An empty `activeStorms` array is a
|
|
117
|
+
* valid quiet answer; any other unusable envelope throws (G4, G111). The
|
|
118
|
+
* parse runs outside the request `catch`, so its refusal keeps its own
|
|
119
|
+
* fixed text, and before `cache.set`, so a refused body is never cached. A
|
|
120
|
+
* feed over the record cap logs one `securityEvent` warn and is cached as
|
|
121
|
+
* trimmed: the cap removes lines only and backs no claim.
|
|
122
|
+
*/
|
|
123
|
+
async getActiveStorms() {
|
|
124
|
+
const cacheKey = Cache.generateKey('nhc', 'storms');
|
|
125
|
+
const cached = CacheConfig.enabled ? this.feedCache.get(cacheKey) : undefined;
|
|
126
|
+
if (cached !== undefined) {
|
|
127
|
+
return cached;
|
|
128
|
+
}
|
|
129
|
+
const existing = this.feedInFlight.get(cacheKey);
|
|
130
|
+
if (existing) {
|
|
131
|
+
return existing;
|
|
132
|
+
}
|
|
133
|
+
const pull = (async () => {
|
|
134
|
+
const body = await this.request('NHC storm feed', '/CurrentStorms.json', {
|
|
135
|
+
accept: 'application/json'
|
|
136
|
+
});
|
|
137
|
+
const parsed = parseCurrentStorms(body);
|
|
138
|
+
if (parsed.trimmed) {
|
|
139
|
+
logger.warn('NHC storm feed trimmed to the record cap', {
|
|
140
|
+
service: 'NHC',
|
|
141
|
+
cap: NHC_MAX_STORMS,
|
|
142
|
+
securityEvent: true
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (CacheConfig.enabled) {
|
|
146
|
+
this.feedCache.set(cacheKey, parsed, CacheConfig.ttl.alerts);
|
|
147
|
+
}
|
|
148
|
+
return parsed;
|
|
149
|
+
})().finally(() => {
|
|
150
|
+
this.feedInFlight.delete(cacheKey);
|
|
151
|
+
});
|
|
152
|
+
this.feedInFlight.set(cacheKey, pull);
|
|
153
|
+
return pull;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The rings of one forecast cone. The URL must pass the allowlist before
|
|
157
|
+
* any request; a refusal is a cone failure with no request made. The KMZ is
|
|
158
|
+
* read as bytes, unzipped and parsed; any failure (transport, a body that is
|
|
159
|
+
* not a KMZ, an unreadable KML) rejects and is never read as zero rings.
|
|
160
|
+
*/
|
|
161
|
+
async getCone(url) {
|
|
162
|
+
const fileName = coneFileName(url);
|
|
163
|
+
if (fileName === undefined) {
|
|
164
|
+
throw new Error('NHC forecast cone URL was refused');
|
|
165
|
+
}
|
|
166
|
+
const cacheKey = Cache.generateKey('nhc', 'cone', fileName);
|
|
167
|
+
const cached = CacheConfig.enabled ? this.coneCache.get(cacheKey) : undefined;
|
|
168
|
+
if (cached !== undefined) {
|
|
169
|
+
return cached;
|
|
170
|
+
}
|
|
171
|
+
const existing = this.coneInFlight.get(cacheKey);
|
|
172
|
+
if (existing) {
|
|
173
|
+
return existing;
|
|
174
|
+
}
|
|
175
|
+
const pull = (async () => {
|
|
176
|
+
const body = await this.request('NHC forecast cone', `/storm_graphics/api/${fileName}`, {
|
|
177
|
+
responseType: 'arraybuffer',
|
|
178
|
+
accept: 'application/vnd.google-earth.kmz, application/zip;q=0.9, */*;q=0.5'
|
|
179
|
+
});
|
|
180
|
+
const bytes = toBytes(body);
|
|
181
|
+
if (bytes === undefined) {
|
|
182
|
+
throw new Error('NHC forecast cone returned an unexpected body');
|
|
183
|
+
}
|
|
184
|
+
const rings = parseConeKml(readFirstKmlEntry(bytes));
|
|
185
|
+
if (CacheConfig.enabled) {
|
|
186
|
+
this.coneCache.set(cacheKey, rings, CacheConfig.ttl.tropicalConeFile);
|
|
187
|
+
}
|
|
188
|
+
return rings;
|
|
189
|
+
})().finally(() => {
|
|
190
|
+
this.coneInFlight.delete(cacheKey);
|
|
191
|
+
});
|
|
192
|
+
this.coneInFlight.set(cacheKey, pull);
|
|
193
|
+
return p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,CAAC;YACH,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACnE,CAAC;YACD,MAAM,KAAK,GAAG,YAAY,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;YACrD,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;gBACxB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;YACxE,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;YAChB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response shapes for the National Hurricane Center's `CurrentStorms.json`
|
|
3
|
+
* (`www.nhc.noaa.gov/CurrentStorms.json`), the active-storm index.
|
|
4
|
+
*
|
|
5
|
+
* Every field of an upstream shape is optional, per the project rule for
|
|
6
|
+
* third-party JSON: the parser's job is to narrow, and a required field here
|
|
7
|
+
* would be a promise about someone else's server.
|
|
8
|
+
*
|
|
9
|
+
* Verified 2026-11-29 against the live (empty) feed, NHC's official 2023 sample
|
|
10
|
+
* (`/productexamples/NHC_JSON_Sample.json`) and a real Wayback capture
|
|
11
|
+
* (20240927130457). `intensity` and `pressure` are **strings** upstream, and
|
|
12
|
+
* `movementSpeed` is in **mph** while `intensity` is in knots, so units mix
|
|
13
|
+
* within one record. The nested products carry URLs only, never geometry.
|
|
14
|
+
*/
|
|
15
|
+
/** The envelope. `activeStorms` is `unknown` until the parser has checked it is an array. */
|
|
16
|
+
export interface NhcCurrentStorms {
|
|
17
|
+
activeStorms?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** A nested advisory product reference. */
|
|
20
|
+
export interface NhcAdvisoryRef {
|
|
21
|
+
advNum?: string;
|
|
22
|
+
issuance?: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The forecast-cone product reference; the whole object is `null` for a post-tropical or potential cyclone. */
|
|
26
|
+
export interface NhcTrackCone {
|
|
27
|
+
advNum?: string;
|
|
28
|
+
issuance?: string;
|
|
29
|
+
kmzFile?: string;
|
|
30
|
+
}
|
|
31
|
+
/** One raw storm record as the feed publishes it. */
|
|
32
|
+
export interface NhcRawStorm {
|
|
33
|
+
id?: string;
|
|
34
|
+
binNumber?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
classification?: string;
|
|
37
|
+
intensity?: string | number;
|
|
38
|
+
pressure?: string | number;
|
|
39
|
+
latitudeNumeric?: number;
|
|
40
|
+
longitudeNumeric?: number;
|
|
41
|
+
movementDir?: string | number;
|
|
42
|
+
movementSpeed?: string | number;
|
|
43
|
+
lastUpdate?: string;
|
|
44
|
+
publicAdvisory?: NhcAdvisoryRef | null;
|
|
45
|
+
trackCone?: NhcTrackCone | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* One storm after parsing: numbers are numbers, an absent or unusable field is
|
|
49
|
+
* `undefined`, and nothing here has been checked for freshness or distance.
|
|
50
|
+
*/
|
|
51
|
+
export interface NhcStorm {
|
|
52
|
+
id: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
classification?: string;
|
|
55
|
+
/** Maximum sustained wind, knots as published. */
|
|
56
|
+
intensityKt?: number;
|
|
57
|
+
/** Minimum central pressure, millibars as published. */
|
|
58
|
+
pressureMb?: number;
|
|
59
|
+
/** Centre latitude, degrees; south negative. */
|
|
60
|
+
latitude: number;
|
|
61
|
+
/** Centre longitude, degrees; west negative. */
|
|
62
|
+
longitude: number;
|
|
63
|
+
/** Direction of movement, degrees. */
|
|
64
|
+
movementDir?: number;
|
|
65
|
+
/** Speed of movement, **mph** as published. */
|
|
66
|
+
movementSpeedMph?: number;
|
|
67
|
+
/** Record time, as published (ISO string; not yet validated). */
|
|
68
|
+
lastUpdate?: string;
|
|
69
|
+
advisoryNumber?: string;
|
|
70
|
+
advisoryIssued?: string;
|
|
71
|
+
/** The cone KMZ URL as published; not yet checked against the allowlist. */
|
|
72
|
+
coneUrl?: string;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=nhc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nhc.d.ts","sourceRoot":"","sources":["../../src/types/nhc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,6FAA6F;AAC7F,MAAM,WAAW,gBAAgB;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,2CAA2C;AAC3C,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,gHAAgH;AAChH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IACvC,SAAS,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response shapes for the National Hurricane Center's `CurrentStorms.json`
|
|
3
|
+
* (`www.nhc.noaa.gov/CurrentStorms.json`), the active-storm index.
|
|
4
|
+
*
|
|
5
|
+
* Every field of an upstream shape is optional, per the project rule for
|
|
6
|
+
* third-party JSON: the parser's job is to narrow, and a required field here
|
|
7
|
+
* would be a promise about someone else's server.
|
|
8
|
+
*
|
|
9
|
+
* Verified 2026-11-29 against the live (empty) feed, NHC's official 2023 sample
|
|
10
|
+
* (`/productexamples/NHC_JSON_Sample.json`) and a real Wayback capture
|
|
11
|
+
* (20240927130457). `intensity` and `pressure` are **strings** upstream, and
|
|
12
|
+
* `movementSpeed` is in **mph** while `intensity` is in knots, so units mix
|
|
13
|
+
* within one record. The nested products carry URLs only, never geometry.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=nhc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nhc.js","sourceRoot":"","sources":["../../src/types/nhc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
package/dist/utils/jmaParse.js
CHANGED
|
@@ -146,7 +146,7 @@ function parseJmaXml(xml, maxBytes, label) {
|
|
|
146
146
|
// 2. Strip a BOM and any CDN-prepended leading whitespace before `<?xml`.
|
|
147
147
|
// XMLValidator rejects an XML declaration that is not the very first
|
|
148
148
|
// thing in the document.
|
|
149
|
-
const stripped = xml.replace(
|
|
149
|
+
const stripped = xml.replace(/^\uFEFF/, '').trimStart();
|
|
150
150
|
// 3. A 200 HTML error page — reported as *shape*, so a caller need not
|
|
151
151
|
// pattern-match on the word "DOCTYPE" to recognise "this was not even
|
|
152
152
|
// trying to be XML".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jmaParse.js","sourceRoot":"","sources":["../../src/utils/jmaParse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAS1D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAE9C,8GAA8G;AAC9G,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAE5C,qFAAqF;AACrF,MAAM,CAA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CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAChE,IAAI,cAAc,KAAK,SAAS;QAAE,QAAQ,CAAC,cAAc,GAAG,cAAc,CAAC;IAC3E,IAAI,gBAAgB,KAAK,SAAS;QAAE,QAAQ,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IACjF,IAAI,KAAK,KAAK,SAAS;QAAE,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;IAChD,IAAI,QAAQ,KAAK,SAAS;QAAE,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACzD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A bounded reader for the one thing this server needs from a KMZ archive:
|
|
3
|
+
* the text of its first KML entry. Built for NHC's forecast-cone KMZs, which
|
|
4
|
+
* are one-entry zips (Deflate) of plain KML, 8–19 KB on the wire.
|
|
5
|
+
*
|
|
6
|
+
* Zero I/O, zero logging, no dependency: bytes in, a string (or a thrown,
|
|
7
|
+
* fixed message) out. The only import is Node's built-in `zlib`; nothing is
|
|
8
|
+
* ever written to disk, so an entry name (`../../evil.kml`) is inert — it is
|
|
9
|
+
* matched by suffix and never used as a path.
|
|
10
|
+
*
|
|
11
|
+
* The archive is untrusted binary input, so every rule here refuses rather
|
|
12
|
+
* than guesses:
|
|
13
|
+
* - Local file headers are walked from offset 0. The central directory is
|
|
14
|
+
* never read; reaching it (or the end-of-central-directory record) simply
|
|
15
|
+
* ends the walk. A split or multi-disk archive starts with a different
|
|
16
|
+
* signature, so it is refused as malformed.
|
|
17
|
+
* - Every header walked must be plain: no encryption (general-purpose bit
|
|
18
|
+
* 0), no trailing data descriptor (bit 3 — the sizes in the header would
|
|
19
|
+
* be zero, so the entry could be neither skipped nor read), no ZIP64
|
|
20
|
+
* sentinel (`0xFFFFFFFF`) in either size, and a method of 0 (stored) or 8
|
|
21
|
+
* (Deflate).
|
|
22
|
+
* - A header, a name, an extra field or a data block that runs past the end
|
|
23
|
+
* of the buffer is malformed.
|
|
24
|
+
* - At most `KMZ_MAX_ENTRIES` headers are scanned; the first entry whose name
|
|
25
|
+
* ends `.kml` (any case) is read and every other entry is skipped by its
|
|
26
|
+
* declared compressed size.
|
|
27
|
+
* - The input is capped at `KMZ_MAX_COMPRESSED_BYTES` (the service's axios
|
|
28
|
+
* cap) and the inflated entry at `KMZ_MAX_INFLATED_BYTES`. The declared
|
|
29
|
+
* size is checked first, and `inflateRawSync`'s `maxOutputLength` enforces
|
|
30
|
+
* the cap during inflation, so a header that lies about its size still
|
|
31
|
+
* cannot make zlib allocate past it.
|
|
32
|
+
* - The inflated length must equal the declared uncompressed size. CRC-32 is
|
|
33
|
+
* not checked (`zlib.crc32` needs Node 22.2; the engines floor is 18); the
|
|
34
|
+
* size check here and the XML validator downstream stand in for it.
|
|
35
|
+
* - The entry must be valid UTF-8.
|
|
36
|
+
*
|
|
37
|
+
* Every thrown message is one of four fixed strings — never a name, a size
|
|
38
|
+
* or a zlib message — so a hostile archive cannot put its own text into a
|
|
39
|
+
* log or a tool result.
|
|
40
|
+
*/
|
|
41
|
+
/** Largest archive accepted, in bytes (equal to the NHC service's response cap). */
|
|
42
|
+
export declare const KMZ_MAX_COMPRESSED_BYTES: number;
|
|
43
|
+
/** Largest inflated KML entry accepted, in bytes. */
|
|
44
|
+
export declare const KMZ_MAX_INFLATED_BYTES: number;
|
|
45
|
+
/** Most local file headers scanned before giving up on finding a KML entry. */
|
|
46
|
+
export declare const KMZ_MAX_ENTRIES = 16;
|
|
47
|
+
/**
|
|
48
|
+
* Return the text of the first `.kml` entry of a KMZ archive.
|
|
49
|
+
*
|
|
50
|
+
* @throws Error with one of four fixed messages: `KMZ archive is malformed`,
|
|
51
|
+
* `KMZ entry uses an unsupported format`, `KMZ entry is too large`, or
|
|
52
|
+
* `KMZ archive has no KML entry`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readFirstKmlEntry(buf: Uint8Array): string;
|
|
55
|
+
//# sourceMappingURL=kmz.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kmz.d.ts","sourceRoot":"","sources":["../../src/utils/kmz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAIH,oFAAoF;AACpF,eAAO,MAAM,wBAAwB,QAAc,CAAC;AAEpD,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,QAAkB,CAAC;AAEtD,+EAA+E;AAC/E,eAAO,MAAM,eAAe,KAAK,CAAC;AAiBlC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CA0DzD"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A bounded reader for the one thing this server needs from a KMZ archive:
|
|
3
|
+
* the text of its first KML entry. Built for NHC's forecast-cone KMZs, which
|
|
4
|
+
* are one-entry zips (Deflate) of plain KML, 8–19 KB on the wire.
|
|
5
|
+
*
|
|
6
|
+
* Zero I/O, zero logging, no dependency: bytes in, a string (or a thrown,
|
|
7
|
+
* fixed message) out. The only import is Node's built-in `zlib`; nothing is
|
|
8
|
+
* ever written to disk, so an entry name (`../../evil.kml`) is inert — it is
|
|
9
|
+
* matched by suffix and never used as a path.
|
|
10
|
+
*
|
|
11
|
+
* The archive is untrusted binary input, so every rule here refuses rather
|
|
12
|
+
* than guesses:
|
|
13
|
+
* - Local file headers are walked from offset 0. The central directory is
|
|
14
|
+
* never read; reaching it (or the end-of-central-directory record) simply
|
|
15
|
+
* ends the walk. A split or multi-disk archive starts with a different
|
|
16
|
+
* signature, so it is refused as malformed.
|
|
17
|
+
* - Every header walked must be plain: no encryption (general-purpose bit
|
|
18
|
+
* 0), no trailing data descriptor (bit 3 — the sizes in the header would
|
|
19
|
+
* be zero, so the entry could be neither skipped nor read), no ZIP64
|
|
20
|
+
* sentinel (`0xFFFFFFFF`) in either size, and a method of 0 (stored) or 8
|
|
21
|
+
* (Deflate).
|
|
22
|
+
* - A header, a name, an extra field or a data block that runs past the end
|
|
23
|
+
* of the buffer is malformed.
|
|
24
|
+
* - At most `KMZ_MAX_ENTRIES` headers are scanned; the first entry whose name
|
|
25
|
+
* ends `.kml` (any case) is read and every other entry is skipped by its
|
|
26
|
+
* declared compressed size.
|
|
27
|
+
* - The input is capped at `KMZ_MAX_COMPRESSED_BYTES` (the service's axios
|
|
28
|
+
* cap) and the inflated entry at `KMZ_MAX_INFLATED_BYTES`. The declared
|
|
29
|
+
* size is checked first, and `inflateRawSync`'s `maxOutputLength` enforces
|
|
30
|
+
* the cap during inflation, so a header that lies about its size still
|
|
31
|
+
* cannot make zlib allocate past it.
|
|
32
|
+
* - The inflated length must equal the declared uncompressed size. CRC-32 is
|
|
33
|
+
* not checked (`zlib.crc32` needs Node 22.2; the engines floor is 18); the
|
|
34
|
+
* size check here and the XML validator downstream stand in for it.
|
|
35
|
+
* - The entry must be valid UTF-8.
|
|
36
|
+
*
|
|
37
|
+
* Every thrown message is one of four fixed strings — never a name, a size
|
|
38
|
+
* or a zlib message — so a hostile archive cannot put its own text into a
|
|
39
|
+
* log or a tool result.
|
|
40
|
+
*/
|
|
41
|
+
import { inflateRawSync } from 'node:zlib';
|
|
42
|
+
/** Largest archive accepted, in bytes (equal to the NHC service's response cap). */
|
|
43
|
+
export const KMZ_MAX_COMPRESSED_BYTES = 1024 * 1024;
|
|
44
|
+
/** Largest inflated KML entry accepted, in bytes. */
|
|
45
|
+
export const KMZ_MAX_INFLATED_BYTES = 4 * 1024 * 1024;
|
|
46
|
+
/** Most local file headers scanned before giving up on finding a KML entry. */
|
|
47
|
+
export const KMZ_MAX_ENTRIES = 16;
|
|
48
|
+
const MALFORMED = 'KMZ archive is malformed';
|
|
49
|
+
const UNSUPPORTED = 'KMZ entry uses an unsupported format';
|
|
50
|
+
const TOO_LARGE = 'KMZ entry is too large';
|
|
51
|
+
const NO_KML = 'KMZ archive has no KML entry';
|
|
52
|
+
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
53
|
+
const CENTRAL_DIRECTORY_SIGNATURE = 0x02014b50;
|
|
54
|
+
const END_OF_CENTRAL_DIRECTORY_SIGNATURE = 0x06054b50;
|
|
55
|
+
const LOCAL_FILE_HEADER_LENGTH = 30;
|
|
56
|
+
const FLAG_ENCRYPTED = 0x0001;
|
|
57
|
+
const FLAG_DATA_DESCRIPTOR = 0x0008;
|
|
58
|
+
const METHOD_STORED = 0;
|
|
59
|
+
const METHOD_DEFLATE = 8;
|
|
60
|
+
const ZIP64_SENTINEL = 0xffffffff;
|
|
61
|
+
/**
|
|
62
|
+
* Return the text of the first `.kml` entry of a KMZ archive.
|
|
63
|
+
*
|
|
64
|
+
* @throws Error with one of four fixed messages: `KMZ archive is malformed`,
|
|
65
|
+
* `KMZ entry uses an unsupported format`, `KMZ entry is too large`, or
|
|
66
|
+
* `KMZ archive has no KML entry`.
|
|
67
|
+
*/
|
|
68
|
+
export function readFirstKmlEntry(buf) {
|
|
69
|
+
if (buf.length > KMZ_MAX_COMPRESSED_BYTES) {
|
|
70
|
+
throw new Error(TOO_LARGE);
|
|
71
|
+
}
|
|
72
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
73
|
+
let offset = 0;
|
|
74
|
+
for (let index = 0; index < KMZ_MAX_ENTRIES; index++) {
|
|
75
|
+
if (offset + 4 > buf.length) {
|
|
76
|
+
throw new Error(MALFORMED);
|
|
77
|
+
}
|
|
78
|
+
const signature = view.getUint32(offset, true);
|
|
79
|
+
if (signature !== LOCAL_FILE_HEADER_SIGNATURE) {
|
|
80
|
+
// The central directory, or the end record of an empty archive, means
|
|
81
|
+
// there are no more entries.
|
|
82
|
+
if (signature === CENTRAL_DIRECTORY_SIGNATURE ||
|
|
83
|
+
signature === END_OF_CENTRAL_DIRECTORY_SIGNATURE) {
|
|
84
|
+
throw new Error(NO_KML);
|
|
85
|
+
}
|
|
86
|
+
throw new Error(MALFORMED);
|
|
87
|
+
}
|
|
88
|
+
if (offset + LOCAL_FILE_HEADER_LENGTH > buf.length) {
|
|
89
|
+
throw new Error(MALFORMED);
|
|
90
|
+
}
|
|
91
|
+
const flags = view.getUint16(offset + 6, true);
|
|
92
|
+
const method = view.getUint16(offset + 8, true);
|
|
93
|
+
const compressedSize = view.getUint32(offset + 18, true);
|
|
94
|
+
const uncompressedSize = view.getUint32(offset + 22, true);
|
|
95
|
+
const nameLength = view.getUint16(offset + 26, true);
|
|
96
|
+
const extraLength = view.getUint16(offset + 28, true);
|
|
97
|
+
if ((flags & FLAG_ENCRYPTED) !== 0 ||
|
|
98
|
+
(flags & FLAG_DATA_DESCRIPTOR) !== 0 ||
|
|
99
|
+
compressedSize === ZIP64_SENTINEL ||
|
|
100
|
+
uncompressedSize === ZIP64_SENTINEL ||
|
|
101
|
+
(method !== METHOD_STORED && method !== METHOD_DEFLATE)) {
|
|
102
|
+
throw new Error(UNSUPPORTED);
|
|
103
|
+
}
|
|
104
|
+
const nameStart = offset + LOCAL_FILE_HEADER_LENGTH;
|
|
105
|
+
const dataStart = nameStart + nameLength + extraLength;
|
|
106
|
+
const dataEnd = dataStart + compressedSize;
|
|
107
|
+
if (dataEnd > buf.length) {
|
|
108
|
+
throw new Error(MALFORMED);
|
|
109
|
+
}
|
|
110
|
+
if (isKmlName(buf.subarray(nameStart, nameStart + nameLength))) {
|
|
111
|
+
return readEntry(buf.subarray(dataStart, dataEnd), method, uncompressedSize);
|
|
112
|
+
}
|
|
113
|
+
offset = dataEnd;
|
|
114
|
+
}
|
|
115
|
+
throw new Error(NO_KML);
|
|
116
|
+
}
|
|
117
|
+
/** True when the raw entry name ends `.kml`, compared case-insensitively. */
|
|
118
|
+
function isKmlName(name) {
|
|
119
|
+
if (name.length < 4) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
// Only the ASCII suffix matters, so the name's own encoding (CP437 or
|
|
123
|
+
// UTF-8, per bit 11) never needs decoding.
|
|
124
|
+
let suffix = '';
|
|
125
|
+
for (let i = name.length - 4; i < name.length; i++) {
|
|
126
|
+
suffix += String.fromCharCode(name[i] ?? 0);
|
|
127
|
+
}
|
|
128
|
+
return suffix.toLowerCase() === '.kml';
|
|
129
|
+
}
|
|
130
|
+
/** Decode one entry's data to text, enforcing the size rules. */
|
|
131
|
+
function readEntry(data, method, uncompressedSize) {
|
|
132
|
+
if (uncompressedSize > KMZ_MAX_INFLATED_BYTES) {
|
|
133
|
+
throw new Error(TOO_LARGE);
|
|
134
|
+
}
|
|
135
|
+
let bytes;
|
|
136
|
+
if (method === METHOD_STORED) {
|
|
137
|
+
bytes = data;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
try {
|
|
141
|
+
bytes = inflateRawSync(data, { maxOutputLength: KMZ_MAX_INFLATED_BYTES });
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error instanceof RangeError &&
|
|
145
|
+
error.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
146
|
+
throw new Error(TOO_LARGE);
|
|
147
|
+
}
|
|
148
|
+
throw new Error(MALFORMED);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (bytes.length !== uncompressedSize) {
|
|
152
|
+
throw new Error(MALFORMED);
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
throw new Error(MALFORMED);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=kmz.js.map
|