indices-records.ts•2.88 kB
/**
* This file was generated. Do NOT edit this file.
*/
import fetch from 'node-fetch'
import { type ZodRawShape, z } from 'zod'
import {
commons_CommitIdSchema,
commons_FilterFieldSchema,
commons_FilterSchema,
commons_RecordIdSchema,
commons_SearchFieldSchema,
commons_SearchValueSchema,
commons_SheetIdSchema,
commons_SortDirectionSchema,
commons_SortFieldSchema,
} from '../schemas.js'
import type { Tool } from './index.js'
const params = {
sheetId: commons_SheetIdSchema.describe('ID of sheet'),
commitId: commons_CommitIdSchema.optional(),
sinceCommitId: commons_CommitIdSchema.optional(),
sortField: commons_SortFieldSchema.optional(),
sortDirection: commons_SortDirectionSchema.optional(),
filter: commons_FilterSchema.optional(),
filterField: commons_FilterFieldSchema.optional().describe('Name of field by which to filter records'),
searchValue: commons_SearchValueSchema.optional(),
searchField: commons_SearchFieldSchema.optional(),
ids: commons_RecordIdSchema.describe('List of record IDs to include in the query. Limit 100.'),
q: z.string().optional().describe('An FFQL query used to filter the result set'),
} as ZodRawShape
export const indicesRecords: Tool<typeof params> = {
name: 'indicesRecords',
description: 'Get record Indices: Returns indices of records from a sheet in a workbook',
params,
cb: async ({
sheetId,
commitId,
sinceCommitId,
sortField,
sortDirection,
filter,
filterField,
searchValue,
searchField,
ids,
q,
}) => {
try {
const searchParams = {
commitId,
sinceCommitId,
sortField,
sortDirection,
filter,
filterField,
searchValue,
searchField,
ids,
q,
}
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}/sheets/${sheetId}/records/indices${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',
}
}
},
}