Skip to content

Commit 18bdc41

Browse files
package-lock and run from dist
1 parent 0c647b5 commit 18bdc41

30 files changed

+4803
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/yarn-debug.log
66

77
# Build
8-
/dist
8+
#/dist
99
/build
1010

1111
# Environment

dist/handlers/jpl/fireball.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.fireballParamsSchema = void 0;
7+
exports.jplFireballHandler = jplFireballHandler;
8+
const zod_1 = require("zod");
9+
const axios_1 = __importDefault(require("axios"));
10+
// Schema for validating JPL Fireball request parameters
11+
exports.fireballParamsSchema = zod_1.z.object({
12+
date_min: zod_1.z.string().optional(),
13+
date_max: zod_1.z.string().optional(),
14+
energy_min: zod_1.z.number().optional(),
15+
energy_max: zod_1.z.number().optional(),
16+
impact_e_min: zod_1.z.number().optional(),
17+
impact_e_max: zod_1.z.number().optional(),
18+
vel_min: zod_1.z.number().optional(),
19+
vel_max: zod_1.z.number().optional(),
20+
alt_min: zod_1.z.number().optional(),
21+
alt_max: zod_1.z.number().optional(),
22+
req_loc: zod_1.z.boolean().optional().default(false),
23+
req_alt: zod_1.z.boolean().optional().default(false),
24+
req_vel: zod_1.z.boolean().optional().default(false),
25+
req_vel_comp: zod_1.z.boolean().optional().default(false),
26+
req_impact_e: zod_1.z.boolean().optional().default(false),
27+
req_energy: zod_1.z.boolean().optional().default(false),
28+
limit: zod_1.z.number().optional().default(50)
29+
});
30+
/**
31+
* Handle requests for JPL's Fireball Database
32+
*/
33+
async function jplFireballHandler(params) {
34+
try {
35+
// Construct the Fireball API URL
36+
const url = 'https://ssd-api.jpl.nasa.gov/fireball.api';
37+
// Make the request to the Fireball API
38+
const response = await axios_1.default.get(url, { params });
39+
return response.data;
40+
}
41+
catch (error) {
42+
console.error('Error in JPL Fireball handler:', error);
43+
if (error.name === 'ZodError') {
44+
throw new Error(`Invalid request parameters: ${error.message}`);
45+
}
46+
throw new Error(`API error: ${error.message}`);
47+
}
48+
}

dist/handlers/jpl/sbdb.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.sbdbParamsSchema = void 0;
7+
exports.jplSbdbHandler = jplSbdbHandler;
8+
const zod_1 = require("zod");
9+
const axios_1 = __importDefault(require("axios"));
10+
// Schema for validating JPL Small-Body Database request parameters
11+
exports.sbdbParamsSchema = zod_1.z.object({
12+
sstr: zod_1.z.string().min(1),
13+
full_precision: zod_1.z.boolean().optional().default(false),
14+
solution_epoch: zod_1.z.string().optional(),
15+
orbit_class: zod_1.z.boolean().optional().default(false),
16+
body_type: zod_1.z.enum(['ast', 'com', 'all']).optional().default('all'),
17+
phys_par: zod_1.z.boolean().optional().default(false),
18+
close_approach: zod_1.z.boolean().optional().default(false),
19+
ca_time: zod_1.z.enum(['all', 'now', 'fut', 'past']).optional().default('all'),
20+
ca_dist: zod_1.z.enum(['au', 'ld', 'lu']).optional().default('au'),
21+
ca_tbl: zod_1.z.enum(['elem', 'approach']).optional().default('approach'),
22+
format: zod_1.z.enum(['json', 'xml']).optional().default('json')
23+
});
24+
/**
25+
* Handle requests for JPL's Small-Body Database
26+
*/
27+
async function jplSbdbHandler(params) {
28+
try {
29+
const { sstr, full_precision, solution_epoch, orbit_class, body_type, phys_par, close_approach, ca_time, ca_dist, ca_tbl, format } = params;
30+
// Construct the SBDB query URL
31+
const url = 'https://ssd-api.jpl.nasa.gov/sbdb.api';
32+
// Prepare the query parameters
33+
const queryParams = {
34+
sstr
35+
};
36+
// Add optional parameters
37+
if (full_precision)
38+
queryParams.full_precision = full_precision ? 'yes' : 'no';
39+
if (solution_epoch)
40+
queryParams.solution_epoch = solution_epoch;
41+
if (orbit_class)
42+
queryParams.orbit_class = orbit_class ? 'yes' : 'no';
43+
if (body_type !== 'all')
44+
queryParams.body_type = body_type;
45+
if (phys_par)
46+
queryParams.phys_par = phys_par ? 'yes' : 'no';
47+
if (close_approach)
48+
queryParams.close_approach = close_approach ? 'yes' : 'no';
49+
if (ca_time !== 'all')
50+
queryParams.ca_time = ca_time;
51+
if (ca_dist !== 'au')
52+
queryParams.ca_dist = ca_dist;
53+
if (ca_tbl !== 'approach')
54+
queryParams.ca_tbl = ca_tbl;
55+
if (format !== 'json')
56+
queryParams.format = format;
57+
// Make the request to SBDB API
58+
const response = await axios_1.default.get(url, { params: queryParams });
59+
return response.data;
60+
}
61+
catch (error) {
62+
console.error('Error in JPL SBDB handler:', error);
63+
if (error.name === 'ZodError') {
64+
throw new Error(`Invalid request parameters: ${error.message}`);
65+
}
66+
throw new Error(`API error: ${error.message}`);
67+
}
68+
}

dist/handlers/jpl/scout.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.jplScoutHandler = jplScoutHandler;
4+
const api_client_1 = require("../../utils/api-client");
5+
/**
6+
* Handle requests for JPL's Scout API
7+
* Scout is a hazard assessment system that automatically calculates the potential
8+
* for an object to be an impactor based on the available observations.
9+
*/
10+
async function jplScoutHandler(params) {
11+
try {
12+
// By default, get the most recent data if no specific parameters are provided
13+
const endpoint = '/scout.api';
14+
// Call the JPL Scout API
15+
const result = await (0, api_client_1.jplApiRequest)(endpoint, params);
16+
// Return the result
17+
return { result };
18+
}
19+
catch (error) {
20+
console.error('Error in Scout handler:', error);
21+
if (error.name === 'ZodError') {
22+
throw {
23+
error: {
24+
type: 'invalid_request',
25+
message: 'Invalid request parameters',
26+
details: error.errors
27+
}
28+
};
29+
}
30+
throw {
31+
error: {
32+
type: 'server_error',
33+
message: error.message || 'An unexpected error occurred',
34+
details: error.response?.data || null
35+
}
36+
};
37+
}
38+
}

dist/handlers/nasa/apod.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.apodParamsSchema = void 0;
4+
exports.nasaApodHandler = nasaApodHandler;
5+
const zod_1 = require("zod");
6+
const api_client_1 = require("../../utils/api-client");
7+
const index_js_1 = require("../../index.js");
8+
// Schema for validating APOD request parameters
9+
exports.apodParamsSchema = zod_1.z.object({
10+
date: zod_1.z.string().optional(),
11+
hd: zod_1.z.boolean().optional(),
12+
count: zod_1.z.number().int().positive().optional(),
13+
start_date: zod_1.z.string().optional(),
14+
end_date: zod_1.z.string().optional(),
15+
thumbs: zod_1.z.boolean().optional()
16+
});
17+
/**
18+
* Handle requests for NASA's Astronomy Picture of the Day (APOD) API
19+
*/
20+
async function nasaApodHandler(params) {
21+
try {
22+
// Call the NASA APOD API
23+
const result = await (0, api_client_1.nasaApiRequest)('/planetary/apod', params);
24+
// Store results as resources
25+
const processedResult = processApodResult(result);
26+
return {
27+
content: [
28+
{
29+
type: "text",
30+
text: processedResult.summary
31+
},
32+
// Instead of trying to include images directly, include them as text with URLs
33+
...processedResult.images.map(img => ({
34+
type: "text",
35+
text: `![${img.title}](${img.data})`
36+
}))
37+
],
38+
isError: false
39+
};
40+
}
41+
catch (error) {
42+
console.error('Error in APOD handler:', error);
43+
return {
44+
content: [
45+
{
46+
type: "text",
47+
text: `Error retrieving APOD data: ${error.message}`
48+
}
49+
],
50+
isError: true
51+
};
52+
}
53+
}
54+
/**
55+
* Process APOD API result
56+
* Convert to resource and return formatted data
57+
*/
58+
function processApodResult(result) {
59+
// Handle both single result and array of results
60+
const results = Array.isArray(result) ? result : [result];
61+
let summary = '';
62+
const images = [];
63+
results.forEach((apod) => {
64+
// Create a unique ID for this APOD entry
65+
const apodId = `nasa://apod/image?date=${apod.date}`;
66+
// Store as a resource
67+
(0, index_js_1.addResource)(apodId, {
68+
name: `Astronomy Picture of the Day - ${apod.title}`,
69+
mimeType: 'application/json',
70+
text: JSON.stringify(apod, null, 2)
71+
});
72+
// Add to summary text
73+
summary += `## ${apod.title} (${apod.date})\n\n${apod.explanation}\n\n`;
74+
// Add image info if available
75+
if (apod.url) {
76+
summary += `Image URL: ${apod.url}\n\n`;
77+
images.push({
78+
data: apod.url,
79+
title: apod.title
80+
});
81+
}
82+
});
83+
return {
84+
summary,
85+
images
86+
};
87+
}
88+
// Export the handler function directly as default
89+
exports.default = nasaApodHandler;

0 commit comments

Comments
 (0)