update-file.ts•2.29 kB
/**
* This file was generated. Do NOT edit this file.
*/
import fetch from 'node-fetch'
import { type ZodRawShape, z } from 'zod'
import {
commons_ActionSchema,
commons_WorkbookIdSchema,
files_ModeSchema,
files_ModelFileStatusEnumSchema,
} from '../schemas.js'
import type { Tool } from './index.js'
const params = {
fileId: z.string().describe('ID of file to update'),
workbookId: commons_WorkbookIdSchema.optional(),
name: z.string().optional().describe('The name of the file'),
mode: files_ModeSchema.optional().describe('The storage mode of file to update'),
status: files_ModelFileStatusEnumSchema.optional(),
actions: z.array(commons_ActionSchema).optional().describe('The actions attached to the file'),
} as ZodRawShape
export const updateFile: Tool<typeof params> = {
name: 'updateFile',
description: 'Update a file: Update a file, to change the workbook id for example',
params,
cb: async ({ fileId, workbookId, name, mode, status, actions }) => {
try {
const searchParams = {}
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}/files/${fileId}${searchParamsString ? `?${searchParamsString}` : ''}`
const response = await fetch(url, {
method: 'PATCH',
headers: {
'X-Disable-Hooks': 'true',
Authorization: `Bearer ${process.env.FLATFILE_BEARER_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
workbookId: workbookId,
name: name,
mode: mode,
status: status,
actions: actions,
}),
})
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',
}
}
},
}