MCPcopy Create free account
hub / github.com/alanagoyal/docbase / parseSignatureBlock

Function parseSignatureBlock

utils/parse-signature-block.ts:6–48  ·  view source on GitHub ↗
(file: File)

Source from the content-addressed store, hash-verified

4import { clientLogger } from "@/lib/client-logger"
5
6export async function parseSignatureBlock(file: File): Promise<{
7 entity_name?: string
8 name?: string
9 title?: string
10 street?: string
11 city_state_zip?: string
12 state_of_incorporation?: string
13 byline?: string
14 type?: "fund" | "company"
15}> {
16 try {
17 const base64Image = await fileToBase64(file)
18
19 const response = await fetch("/api/parse-signature-block", {
20 method: "POST",
21 headers: {
22 "Content-Type": "application/json",
23 },
24 body: JSON.stringify({ base64Image }),
25 })
26
27 if (!response.ok) {
28 const errorText = await response.text()
29 clientLogger.error('API Error', { status: response.status, errorText })
30 throw new Error(`Failed to parse signature block: ${response.status} ${errorText}`)
31 }
32
33 const data = await response.json()
34
35 // Check if the response contains any of the expected fields
36 if (!data.entity_name && !data.name && !data.title && !data.street && !data.city_state_zip && !data.state_of_incorporation && !data.byline) {
37 toast({
38 description: "Unable to parse signature block",
39 })
40 throw new Error("No expected fields in response")
41 }
42
43 return data
44 } catch (error) {
45 clientLogger.error('Error in parseSignatureBlock', { error })
46 throw error
47 }
48}
49
50async function fileToBase64(file: File): Promise<string> {
51 return new Promise((resolve, reject) => {

Callers 1

onDropFunction · 0.90

Calls 2

toastFunction · 0.90
fileToBase64Function · 0.85

Tested by

no test coverage detected