@aguacerowx/javascript-sdk 0.0.25 → 0.0.27

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/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@aguacerowx/javascript-sdk",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
+ "type": "module",
4
5
  "private": false,
5
6
  "publishConfig": {
6
7
  "access": "public"
@@ -36,6 +37,30 @@
36
37
  "require": "./src/satellite_support.js",
37
38
  "react-native": "./src/satellite_support.js",
38
39
  "default": "./src/satellite_support.js"
40
+ },
41
+ "./nws/NwsWatchesWarningsOverlay.js": {
42
+ "import": "./src/nws/NwsWatchesWarningsOverlay.js",
43
+ "require": "./src/nws/NwsWatchesWarningsOverlay.js",
44
+ "react-native": "./src/nws/NwsWatchesWarningsOverlay.js",
45
+ "default": "./src/nws/NwsWatchesWarningsOverlay.js"
46
+ },
47
+ "./nws/nwsSdkConstants.js": {
48
+ "import": "./src/nws/nwsSdkConstants.js",
49
+ "require": "./src/nws/nwsSdkConstants.js",
50
+ "react-native": "./src/nws/nwsSdkConstants.js",
51
+ "default": "./src/nws/nwsSdkConstants.js"
52
+ },
53
+ "./nws/nwsAlertsSupport.js": {
54
+ "import": "./src/nws/nwsAlertsSupport.js",
55
+ "require": "./src/nws/nwsAlertsSupport.js",
56
+ "react-native": "./src/nws/nwsAlertsSupport.js",
57
+ "default": "./src/nws/nwsAlertsSupport.js"
58
+ },
59
+ "./nws/nwsAlertsFetchSpec.js": {
60
+ "import": "./src/nws/nwsAlertsFetchSpec.js",
61
+ "require": "./src/nws/nwsAlertsFetchSpec.js",
62
+ "react-native": "./src/nws/nwsAlertsFetchSpec.js",
63
+ "default": "./src/nws/nwsAlertsFetchSpec.js"
39
64
  }
40
65
  },
41
66
  "files": [
@@ -43,10 +68,14 @@
43
68
  "src"
44
69
  ],
45
70
  "scripts": {
46
- "build": "babel src -d dist"
71
+ "build": "babel src -d dist",
72
+ "gen:nws-key": "esbuild ../../../aguacero-frontend/src/components/WarningsMenu/nwsWarningCustomizationKey.ts --bundle --format=esm --platform=neutral --outfile=src/nws/nwsWarningCustomizationKey.gen.js"
47
73
  },
48
74
  "author": "Your Name",
49
75
  "license": "MIT",
76
+ "devDependencies": {
77
+ "esbuild": "^0.21.5"
78
+ },
50
79
  "dependencies": {
51
80
  "proj4": "^2.11.0",
52
81
  "fzstd": "^0.1.1"
@@ -8,7 +8,7 @@ import { DICTIONARIES, MODEL_CONFIGS } from './dictionaries.js';
8
8
  import { DEFAULT_COLORMAPS } from './default-colormaps.js';
9
9
  import proj4 from 'proj4';
10
10
  import { processCompressedGrid } from './gridDecodePipeline.js';
11
- import { getBundleId } from './getBundleId';
11
+ import { getBundleId } from './getBundleId.js';
12
12
  import {
13
13
  SATELLITE_FRAMES_URL,
14
14
  buildSatelliteTimelineForSelection,
@@ -115,8 +115,10 @@ export class AguaceroCore extends EventEmitter {
115
115
  super();
116
116
  this.isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
117
117
  this.apiKey = options.apiKey;
118
- /** Passed as CloudFront `userId` for satellite KTX2 URLs (production uses the authenticated account id). */
119
- this.userId = options.userId ?? 'sdk-user';
118
+ /** Base origin for grid HTTP requests (no trailing slash). Node/SSR: sets Origin + Referer so CloudFront can derive a source; browsers usually omit. */
119
+ const siteOriginRaw =
120
+ typeof options.gridRequestSiteOrigin === 'string' ? options.gridRequestSiteOrigin.trim() : '';
121
+ this.gridRequestSiteOrigin = siteOriginRaw ? siteOriginRaw.replace(/\/+$/, '') : null;
120
122
  this.bundleId = getBundleId();
121
123
  this.baseGridUrl = 'https://d3dc62msmxkrd7.cloudfront.net';
122
124
  /** @type {Worker | null} */
@@ -1112,7 +1114,7 @@ export class AguaceroCore extends EventEmitter {
1112
1114
 
1113
1115
  // --- Data and Calculation Methods ---
1114
1116
 
1115
- _ensureGridDecodeWorker() {
1117
+ async _ensureGridDecodeWorker() {
1116
1118
  if (this._gridDecodeWorkerDisabled) {
1117
1119
  return null;
1118
1120
  }
@@ -1124,9 +1126,8 @@ export class AguaceroCore extends EventEmitter {
1124
1126
  return null;
1125
1127
  }
1126
1128
  try {
1127
- this._gridDecodeWorker = new Worker(new URL('./gridDecodeWorker.js', import.meta.url), {
1128
- type: 'module',
1129
- });
1129
+ const { spawnGridDecodeWorker } = await import('./spawnGridDecodeWorker.js');
1130
+ this._gridDecodeWorker = spawnGridDecodeWorker();
1130
1131
  this._gridDecodeWorker.addEventListener('error', () => {
1131
1132
  this._gridDecodeWorkerDisabled = true;
1132
1133
  if (this._gridDecodeWorker) {
@@ -1146,10 +1147,10 @@ export class AguaceroCore extends EventEmitter {
1146
1147
  * {@link processCompressedGrid}. Uses a copy for postMessage transfer so the original `compressedData`
1147
1148
  * stays valid if the Worker path fails.
1148
1149
  */
1149
- _decodeGridPayload(compressedData, encoding) {
1150
- const worker = this._ensureGridDecodeWorker();
1150
+ async _decodeGridPayload(compressedData, encoding) {
1151
+ const worker = await this._ensureGridDecodeWorker();
1151
1152
  if (!worker) {
1152
- return Promise.resolve(processCompressedGrid(compressedData, encoding));
1153
+ return processCompressedGrid(compressedData, encoding);
1153
1154
  }
1154
1155
  const payload = compressedData.slice();
1155
1156
  return new Promise((resolve, reject) => {
@@ -1231,12 +1232,16 @@ export class AguaceroCore extends EventEmitter {
1231
1232
  }
1232
1233
  try {
1233
1234
  const baseUrl = `${this.baseGridUrl}${resourcePath}`;
1234
- const urlWithApiKeyParam = `${baseUrl}?apiKey=${this.apiKey}`;
1235
+ const urlWithApiKeyParam = `${baseUrl}?apiKey=${encodeURIComponent(this.apiKey)}`;
1235
1236
  const headers = { 'x-api-key': this.apiKey };
1236
1237
  if (this.bundleId && this.isReactNative) {
1237
1238
  headers['x-app-identifier'] = this.bundleId;
1238
1239
  }
1239
-
1240
+ if (this.gridRequestSiteOrigin) {
1241
+ headers['Origin'] = this.gridRequestSiteOrigin;
1242
+ headers['Referer'] = `${this.gridRequestSiteOrigin}/`;
1243
+ }
1244
+
1240
1245
  const response = await fetch(urlWithApiKeyParam, {
1241
1246
  headers: headers,
1242
1247
  signal: abortController.signal
@@ -1302,7 +1307,10 @@ export class AguaceroCore extends EventEmitter {
1302
1307
  ? `mrms-${mrmsTimestamp}-${variable}-${effectiveSmoothing}`
1303
1308
  : `${model}-${date}-${run}-${forecastHour}-${variable}-${effectiveSmoothing}`;
1304
1309
 
1305
- const gridDataPromise = this.dataCache.get(dataUrlIdentifier);
1310
+ let gridDataPromise = this.dataCache.get(dataUrlIdentifier);
1311
+ if (!gridDataPromise) {
1312
+ gridDataPromise = await this._loadGridData(this.state);
1313
+ }
1306
1314
  if (!gridDataPromise) return null;
1307
1315
 
1308
1316
  try {
package/src/index.js CHANGED
@@ -40,4 +40,10 @@ export {
40
40
  /** NEXRAD tilt + listing helpers (also importable via subpaths; root re-export fixes Vite/esbuild subpath resolution). */
41
41
  export * from './nexradTilts.js';
42
42
  export * from './nexradTiltCoalesce.js';
43
- export * from './nexrad_support.js';
43
+ export * from './nexrad_support.js';
44
+
45
+ /** NWS watches/warnings (NWWS HTTP + SSE, Mapbox-style paint helpers) — shared by mapsgl and React Native. */
46
+ export { NwsWatchesWarningsOverlay, NWS_DEFAULT_LINE_BEFORE_LAYER_ID } from './nws/NwsWatchesWarningsOverlay.js';
47
+ export * from './nws/nwsSdkConstants.js';
48
+ export * from './nws/nwsAlertsSupport.js';
49
+ export * from './nws/nwsAlertsFetchSpec.js';