UNPKG

rocketdata

Version:

**Rocketdata** is a modern, lightweight Node.js wrapper for [NASA's public APIs](). Easily fetch data from the Astronomy Picture of the Day (APOD), Mars Rover imagery, and more — all with clean, promise-based functions.

109 lines 4.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRoverMissionManifest = exports.getMarsRoverPhotosByEarthDate = exports.getMarsRoverPhotosByMartianSol = exports.CAMERAS = void 0; var tslib_1 = require("tslib"); var axios_1 = tslib_1.__importDefault(require("axios")); var util_1 = require("./util"); exports.CAMERAS = [ { abbreviation: 'FHAZ', fullName: 'Front Hazard Avoidance Camera', supportedRovers: ['curiosity', 'opportunity', 'spirit'] }, { abbreviation: 'RHAZ', fullName: 'Rear Hazard Avoidance Camera', supportedRovers: ['curiosity', 'opportunity', 'spirit'] }, { abbreviation: 'MAST', fullName: 'Mast Camera', supportedRovers: ['curiosity'] }, { abbreviation: 'CHEMCAM', fullName: 'Chemistry and Camera Complex', supportedRovers: ['curiosity'] }, { abbreviation: 'MAHLI', fullName: 'Mars Hand Lens Imager', supportedRovers: ['curiosity'] }, { abbreviation: 'MARDI', fullName: 'Mars Descent Imager', supportedRovers: ['curiosity'] }, { abbreviation: 'NAVCAM', fullName: 'Navigation Camera', supportedRovers: ['curiosity', 'opportunity', 'spirit'] }, { abbreviation: 'PANCAM', fullName: 'Panoramic Camera', supportedRovers: ['opportunity', 'spirit'] }, { abbreviation: 'MINITES', fullName: 'Miniature Thermal Emission Spectrometer (Mini-TES)', supportedRovers: ['opportunity', 'spirit'] }, ]; var NASA_API_URL = 'https://api.nasa.gov'; var MARS_ROVER_API = "".concat(NASA_API_URL, "/mars-photos/api/v1"); /** * @function getMarsRoverPhotosByMartianSol * @description Get Mars rover photos by Martian sol. * @async * @version 2.1.2 * @param {SolQueryParams} params - The request parameters. * @returns {Promise<MarsPhotoResponse>} * @fulfill {MarsPhotoResponse} - The Mars rover photos. * @reject {Error} - The error object. * @example * const result = await getMarsRoverPhotosByMartianSol({ * sol: 1000, * camera: 'FHAZ', * page: 1, * api_key: 'DEMO_KEY', * }); */ var getMarsRoverPhotosByMartianSol = function (params) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var query, response; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: query = (0, util_1.buildQueryParams)(params); return [4 /*yield*/, axios_1.default.get("".concat(MARS_ROVER_API, "/rovers/curiosity/photos?").concat(query))]; case 1: response = _a.sent(); return [2 /*return*/, response.data]; } }); }); }; exports.getMarsRoverPhotosByMartianSol = getMarsRoverPhotosByMartianSol; /** * @function getMarsRoverPhotosByEarthDate * @description Get Mars rover photos by earth date. * @async * @version 2.2.2 * @param {EarthDateQueryParams} params - The request parameters. * @returns {Promise<MarsPhotoResponse>} * @fulfill {MarsPhotoResponse} - The Mars rover photos. * @reject {Error} - The error object. * @example * const result = await getMarsRoverPhotosByEarthDate({ * earth_date: '2023-06-25', * camera: 'FHAZ', * page: 1, * api_key: 'DEMO_KEY', * }); */ var getMarsRoverPhotosByEarthDate = function (params) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var query, response; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: query = (0, util_1.buildQueryParams)(params); return [4 /*yield*/, axios_1.default.get("".concat(MARS_ROVER_API, "/rovers/curiosity/photos?").concat(query))]; case 1: response = _a.sent(); return [2 /*return*/, response.data]; } }); }); }; exports.getMarsRoverPhotosByEarthDate = getMarsRoverPhotosByEarthDate; /** * @function getMissionManifest * @description A mission manifest is available for each Rover. This manifest will list details of the Rover's mission to help narrow down photo queries to the API. * @async * @version 2.3.5 * @param {Rover} rover - The name of the rover. Curiosity, Opportunity or Spirit. * @returns {Promise<RoverManifest>} * @fulfill {RoverManifest} - The rover manifest. * @reject {Error} - The error object. * @example * const result = await getMissionManifest('curiosity', 'DEMO_KEY); */ var getRoverMissionManifest = function (rover, api_key) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var URL, response; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: URL = "".concat(MARS_ROVER_API, "/manifests/").concat(rover, "?api_key=").concat(api_key); console.log('Logging URL: ' + URL); return [4 /*yield*/, axios_1.default.get(URL)]; case 1: response = _a.sent(); return [2 /*return*/, response.data]; } }); }); }; exports.getRoverMissionManifest = getRoverMissionManifest; //# sourceMappingURL=rovers.js.map