digimithra-autofill-ai-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "digimithra-autofill-ai-sdk",
3
+ "version": "1.0.0",
4
+ "description": "AI document autofill SDK",
5
+ "main": "src/index.js",
6
+ "author": "Deepesh",
7
+ "license": "MIT"
8
+ }
package/src/index.js ADDED
@@ -0,0 +1,40 @@
1
+ const extract = async ({
2
+ apiKey,
3
+ fields,
4
+ file,
5
+ apiUrl = "http://localhost:5000/api/extract"
6
+ }) => {
7
+
8
+ const formData = new FormData();
9
+
10
+ formData.append("file", file);
11
+ formData.append("fields", JSON.stringify(fields));
12
+
13
+ const res = await fetch(apiUrl,{
14
+ method:"POST",
15
+ headers:{
16
+ "x-api-key":apiKey
17
+ },
18
+ body:formData
19
+ });
20
+
21
+ const data = await res.json();
22
+
23
+ if(!res.ok){
24
+
25
+ // 🔥 structured error
26
+ throw {
27
+ error: data.error || "Request failed",
28
+ errorCode: data.errorCode || "UNKNOWN_ERROR",
29
+ status: res.status
30
+ };
31
+
32
+ }
33
+
34
+ return data;
35
+
36
+ };
37
+
38
+ export default {
39
+ extract
40
+ };