geonet
Version:
A Node.js API wrapper for GeoNet — Aotearoa's geological hazard monitoring system.
75 lines (74 loc) • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuakeService = void 0;
const base_1 = require("../../@types/base");
const common_1 = require("../../@types/common");
const BaseService_1 = require("./BaseService");
/**
* QuakeService class for fetching quake information from the GeoNet API.
* @extends BaseService
* @since 1.0.0
*/
class QuakeService extends BaseService_1.BaseService {
/**
* Fetches quake data for a given public ID.
*
* @param {string} publicID - The public ID of the earthquake.
* @returns {Promise<QuakeResponse>} - A promise that resolves to the quake data.
* @throws {Error} - Throws an error if the public ID is not provided.
* @since 1.0.0
*/
async getQuake(publicID) {
if (!publicID)
throw new Error("Public ID not provided.");
return await this.GET({
endpoint: `/quake/${publicID}`,
format: base_1.JSONFormatTypes.APPLICATION_VND_GEO_JSON_VERSION_2
});
}
/**
* Fetches location history data for a given public ID. Not all quakes have a location history.
*
* @param {string} publicID - The public ID for the earthquake.
* @returns {Promise<QuakeHistoryResponse>} - A promise that resolves to the quake history data. The features array may be empty!
* @throws {Error} - Throws an error if the public ID is not provided.
* @since 1.0.0
*/
async getQuakeHistory(publicID) {
if (!publicID || typeof (publicID) !== "string")
throw new Error("Public ID not provided, or was not a string.");
return await this.GET({
endpoint: `/quake/history/${publicID}`,
format: base_1.JSONFormatTypes.APPLICATION_VND_GEO_JSON_VERSION_2
});
}
/**
* Fetches quake stats for the past 365 days.
*
* @returns {Promise<QuakeStatsResponse>} - A promise that resolves to the quake stats data.
* @since 1.0.0
*/
async getQuakeStats() {
return await this.GET({
endpoint: "/quake/stats",
format: base_1.JSONFormatTypes.APPLICATION_JSON_VERSION_2
});
}
/**
* Fetches all quakes that have occurred over the past 365 days.
*
* @param {MMI} mmi - The request object containing the MMI.
* @returns {Promise<QuakesResponse>} - A promise that resolves to the quakes data.
* @throws {Error} - Throws an error if the MMI is not provided or is not a valid MMI.
* @since 1.0.0
*/
async getQuakes(mmi) {
if (!mmi || (!Object.values(common_1.MMI).includes(mmi) && mmi !== common_1.MMI.NotFelt))
throw new Error("MMI not provided, or was not a valid MMI.");
return await this.GET({
endpoint: `/quake?MMI=${mmi}`,
format: base_1.JSONFormatTypes.APPLICATION_VND_GEO_JSON_VERSION_2
});
}
}
exports.QuakeService = QuakeService;