listTimezones.ts•2.25 kB
import { z } from 'zod';
import type { MarketstackClient, MarketstackApiParams } from '../../marketstackClient.js';
// Define the input schema shape for the Timezones List tool
const listTimezonesInputSchemaShape = {
limit: z
.number()
.int()
.min(1)
.max(1000)
.optional()
.default(100)
.describe(
'Specify a pagination limit (number of results per page) for your API request. Default limit value is `100`, maximum allowed limit value is `1000`.'
),
offset: z
.number()
.int()
.min(0)
.optional()
.default(0)
.describe(
'Specify a pagination offset value for your API request. Example: An offset value of `100` combined with a limit value of 10 would show results 100-110. Default value is `0`, starting with the first available result.'
),
};
type RawSchemaShape = typeof listTimezonesInputSchemaShape;
type Input = z.infer<z.ZodObject<RawSchemaShape>>;
type Output = any; // TODO: Define a more specific output type based on Marketstack response
// Define the handler function for the Timezones List tool
const listTimezonesHandler = async (input: Input, client: MarketstackClient): Promise<Output> => {
try {
const { limit, offset } = input;
const apiRequestParams: MarketstackApiParams = {
endpoint: 'timezones',
...(limit && { limit }), // Include if limit is provided
...(offset && { offset }), // Include if offset is provided
};
const data = await client.fetchApiData(apiRequestParams);
return data;
} catch (error: unknown) {
console.error('listTimezones tool error:', error);
const message = error instanceof Error ? error.message : 'An unknown error occurred.';
throw new Error(`listTimezones tool failed: ${message}`);
}
};
// Define the tool definition object structure
type MarketstackToolDefinition = {
name: string;
description: string;
inputSchemaShape: RawSchemaShape;
handler: (input: Input, client: MarketstackClient) => Promise<Output>;
};
export const listTimezonesTool: MarketstackToolDefinition = {
name: 'list_timezones',
description: 'Look up information about all supported timezones.',
inputSchemaShape: listTimezonesInputSchemaShape,
handler: listTimezonesHandler,
};