UNPKG

geonet

Version:

A Node.js API wrapper for GeoNet — Aotearoa's geological hazard monitoring system.

80 lines (79 loc) 3.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NetworkService = void 0; const base_1 = require("../../@types/base"); const BaseService_1 = require("./BaseService"); /** * StrongService class for fetching strong motion information for a specified quake from the GeoNet API. * @extends BaseService * @since 1.0.0 */ class NetworkService extends BaseService_1.BaseService { /** * Fetches network data for a given sensor type. * * @param {NetworkSensorRequest} req - The request object containing the sensor type. * @returns {Promise<NetworkSensorResponse>} - A promise that resolves to the sensor data. * @throws {Error} - Throws an error if the sensor type is not provided, or if the optional parameters are not strings. * @since 1.0.0 */ async getNetworkSensor(req) { if (!req.sensorType) throw new Error("Sensor type not provided."); // Validate optional string parameters if they are defined if (req.startDate !== undefined && typeof req.startDate !== "string") { throw new Error("Start date must be a string."); } if (req.endDate !== undefined && typeof req.endDate !== "string") { throw new Error("End date must be a string."); } if (req.station !== undefined && typeof req.station !== "string") { throw new Error("Station code must be a string."); } const params = new URLSearchParams({ sensorType: req.sensorType.toString(), ...(req.startDate && { startDate: req.startDate }), ...(req.endDate && { endDate: req.endDate }), ...(req.station && { station: req.station }) }); return await this.GET({ endpoint: `/network/sensor?${params}`, format: base_1.JSONFormatTypes.APPLICATION_VND_GEO_JSON_VERSION_2 }); } /** * Fetches network data for a specified GNSS mark. * * @param {string} code - The mark code. * @returns {Promise<NetworkGNSStationResponse>} - A promise that resolves to the sensor details data. * @throws {Error} - Throws an error if the mark code is not provided. * @since 1.0.0 */ async getNetworkGNSSDetails(code) { if (!code || typeof (code) !== "string") throw new Error("GNSS mark code not provided, or was not a string."); return await this.GET({ endpoint: `/network/gnss/mark?code=${code}`, format: base_1.JSONFormatTypes.APPLICATION_JSON_VERSION_2 }); } /** * Fetches network data for a specified GNSS mark. * * @param {NetworkFDSNStationRequest} req - The request object containing the mark code. * @returns {Promise<NetworkFDSNStationResponse>} - A promise that resolves to the sensor details data. * @throws {Error} - Throws an error if the mark code is not provided. * @since 1.0.0 */ async getNetworkFDSNDetails(req) { if (!req.station || typeof (req.station) !== "string") throw new Error("FDSN station code not provided, or was not a string."); if (!req.network || typeof (req.network) !== "string") throw new Error("FDSN network code not provided, or was not a string."); return await this.GET({ endpoint: `/network/fdsn/station?station=${req.station}&network=${req.network}`, format: base_1.JSONFormatTypes.APPLICATION_JSON_VERSION_2 }); } } exports.NetworkService = NetworkService;