list-mapping-programs.ts•2.83 kB
/**
* This file was generated. Do NOT edit this file.
*/
import fetch from 'node-fetch'
import { type ZodRawShape, z } from 'zod'
import { commons_EnvironmentIdSchema, commons_FamilyIdSchema, commons_UserIdSchema } from '../schemas.js'
import type { Tool } from './index.js'
const params = {
pageSize: z.number().int().optional().describe('Number of programs to return in a page (default 10)'),
pageNumber: z.number().int().optional().describe('Based on pageSize, which page of records to return'),
createdBy: commons_UserIdSchema.optional().describe('Filter by creator'),
createdAfter: z.string().optional().describe('Filter by creation time'),
createdBefore: z.string().optional().describe('Filter by creation time'),
environmentId: commons_EnvironmentIdSchema.optional().describe('The ID of the environment'),
familyId: commons_FamilyIdSchema.optional().describe('Filter by family'),
namespace: z.string().optional().describe('Filter by namespace'),
sourceKeys: z.string().optional().describe('Filter by source keys'),
destinationKeys: z.string().optional().describe('Filter by destination keys'),
} as ZodRawShape
export const listMappingPrograms: Tool<typeof params> = {
name: 'listMappingPrograms',
description: 'List mapping programs: List all mapping programs',
params,
cb: async ({
pageSize,
pageNumber,
createdBy,
createdAfter,
createdBefore,
environmentId,
familyId,
namespace,
sourceKeys,
destinationKeys,
}) => {
try {
const searchParams = {
pageSize,
pageNumber,
createdBy,
createdAfter,
createdBefore,
environmentId,
familyId,
namespace,
sourceKeys,
destinationKeys,
}
const searchParamsString = new URLSearchParams(JSON.parse(JSON.stringify(searchParams))).toString()
const baseUrl = process.env.FLATFILE_API_URL || 'https://platform.flatfile.com/api/v1'
const url = `${baseUrl}/mapping${searchParamsString ? `?${searchParamsString}` : ''}`
const response = await fetch(url, {
method: 'GET',
headers: {
'X-Disable-Hooks': 'true',
Authorization: `Bearer ${process.env.FLATFILE_BEARER_TOKEN}`,
'Content-Type': 'application/json',
},
})
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status} - ${response.statusText}`)
}
const data = (await response.json()) as { data: unknown }
return {
content: [
{
type: 'text',
text: JSON.stringify(data.data, null, 2),
},
],
status: 'success',
}
} catch (error) {
return {
content: [{ type: 'text', text: `Error: ${error}` }],
status: 'failed',
}
}
},
}