Skip to content

Commit 91090e9

Browse files
committed
handle various file types
1 parent 16502f8 commit 91090e9

File tree

10 files changed

+96
-47
lines changed

10 files changed

+96
-47
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mindee-ocr",
3-
"version": "4.0.999",
3+
"version": "4.0.0",
44
"description": "Parse your document using the Mindee API.",
55
"scripts": {
66
"clean": "rimraf ./dist ./build",
@@ -18,7 +18,7 @@
1818
"zapier-platform-core": "17.8.0"
1919
},
2020
"devDependencies": {
21-
"@typescript-eslint/eslint-plugin": "^8.46.0",
21+
"@typescript-eslint/eslint-plugin": "~8.46",
2222
"vitest": "~2.1.9",
2323
"mocha": "~11.7.4",
2424
"ts-node": "~10.9.2",

src/authentication.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
label: "Connection Name",
2727
required: true,
2828
type: "string",
29-
helpText: "Name of the connection, should be in the format: `MindeeV2-` + your API key's name",
29+
helpText: "Name of the connection. Suggested format: `MindeeV2 - ` + your API key's name",
3030
},
3131
{
3232
computed: false,
@@ -35,7 +35,7 @@ export default {
3535
required: true,
3636
type: "password",
3737
helpText:
38-
"Mindee V2 API Key. Refer to: https://docs.mindee.com/integrations/api-keys for more information.",
38+
"Your Mindee V2 API Key. [More Information](https://docs.mindee.com/integrations/api-keys).",
3939
},
4040
]
4141
} satisfies Authentication;

src/v2/api/inputFields.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export const inferenceCreateFields = defineInputFields([
4040
choices: optionChoices,
4141
default: optionDefault,
4242
helpText:
43-
"Enable automated workflows by enhancing model accuracy and measuring field confidence.",
43+
"Enable automated workflows by enhancing model accuracy and measuring field confidence." +
44+
"\nNot available on all plans.",
4445
},
4546
{
4647
key: "polygon",
@@ -49,7 +50,8 @@ export const inferenceCreateFields = defineInputFields([
4950
choices: optionChoices,
5051
default: optionDefault,
5152
helpText:
52-
"Add the polygon coordinates of each extracted field to the API response.",
53+
"Add the polygon coordinates of each extracted field to the API response." +
54+
"\nNot available on all plans.",
5355
},
5456
{
5557
key: "rag",
@@ -58,7 +60,8 @@ export const inferenceCreateFields = defineInputFields([
5860
choices: optionChoices,
5961
default: optionDefault,
6062
helpText:
61-
"Enhance extraction accuracy with Retrieval-Augmented Generation using your own documents.",
63+
"Enhance extraction accuracy with Retrieval-Augmented Generation using your own documents." +
64+
"\nRequires at least one training document configured for the model.",
6265
},
6366
{
6467
key: "rawText",

src/v2/api/requests.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,24 @@ export function setupEnqueueForm(bundle: Bundle): FormData {
7979
const form = new FormData();
8080

8181
form.append("model_id", bundle.inputData.modelId);
82-
// Zapier sends the file as a base64 string, so we cannot use the 'file' field.
83-
form.append("file_base64", bundle.inputData.file);
82+
83+
const fileData: any = bundle.inputData.file;
84+
85+
// zapier can send the data in various ways
86+
if (!fileData) {
87+
throw new Error("No file provided");
88+
}
89+
if (typeof fileData === "object" && fileData.url) {
90+
form.append("url", fileData.url);
91+
} else if (typeof fileData === "string") {
92+
if (fileData.startsWith("http")) {
93+
form.append("url", fileData);
94+
} else {
95+
form.append("file_base64", fileData);
96+
}
97+
} else {
98+
form.append("file", fileData);
99+
}
84100

85101
if (bundle.inputData.alias) {
86102
form.append("alias", bundle.inputData.alias);

src/v2/creates/enqueue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export default defineCreate({
3232
key: "v2_enqueue",
3333
noun: "Enqueue",
3434
display: {
35-
label: "Enqueue a File",
36-
description: "Send a file and return the job. " +
37-
"You'll need to poll for the inference using the job ID.",
35+
label: "Send a File to Queue",
36+
description: "Add a file to the processing queue, and return the Job." +
37+
" You'll need to poll for the inference result using the Job ID.",
3838
hidden: false,
3939
},
4040
operation: {

src/v2/creates/enqueue_and_get_inference.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ export default defineCreate({
3434
// see here for a full list of available properties:
3535
// https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#createschema
3636
key: "v2_enqueue_and_get_inference",
37-
noun: "Send File and Get Inference",
38-
37+
noun: "Send and Process",
3938
display: {
40-
label: "Send File and Get Inference",
41-
description: "Send a file and return the inference result when it's ready.",
39+
label: "Process a File",
40+
description: "Send a file, process it, and return the inference result.",
4241
hidden: false,
4342
},
44-
4543
operation: {
4644
perform: perform,
4745
inputFields: inputFields,

src/v2/searches/inference.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ export default defineSearch({
3737
key: "v2_inference",
3838
noun: "Inference",
3939
display: {
40-
label: "Get Inference",
41-
description: "Get an inference by its ID.",
40+
label: "Get Inference Result",
41+
description: "Get a processing result by its inference ID." +
42+
" The file must have already been processed.",
4243
hidden: false,
4344
},
4445
operation: {

src/v2/searches/inference_by_polling.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ export default defineSearch({
4141
key: "v2_inference_by_polling",
4242
noun: "Inference by polling",
4343
display: {
44-
label: "Poll for Inference",
45-
description: "Poll for an inference using a job ID.",
44+
label: "Poll for Result",
45+
description: "Poll for an inference result using a job ID." +
46+
" The file must already have been sent to the queue.",
4647
hidden: false,
4748
},
4849
operation: {
Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "vitest";
2-
import zapier from "zapier-platform-core";
2+
import zapier, { Bundle } from "zapier-platform-core";
33

44
import App from "../../../index.js";
55
import { blankPdfPath } from "../index.js";
@@ -9,29 +9,59 @@ const appTester = zapier.createAppTester(App);
99
zapier.tools.env.inject();
1010

1111
const modelId = process.env["MINDEE_V2_FINDOC_MODEL_ID"];
12-
const bundle: any = {
13-
authData: {
14-
apiKey: process.env["MINDEE_V2_API_KEY"],
15-
},
16-
inputData: {
17-
file: fs.readFileSync(blankPdfPath).toString("base64"),
18-
modelId: modelId,
19-
alias: "zapier-test-enqueue",
20-
}
21-
};
12+
13+
async function assertJobResponse(bundle: Bundle) {
14+
// @ts-expect-error TBD
15+
const response: any = await appTester(App.creates["v2_enqueue"].operation.perform, bundle);
16+
17+
expect(response).toBeInstanceOf(Object);
18+
expect(response.job).toBeInstanceOf(Object);
19+
expect(response.job.status).toEqual("Processing");
20+
expect(response.job.model_id).toEqual(modelId);
21+
expect(response.job.alias).toEqual("zapier-test-enqueue");
22+
expect(response.job.error).toBeNull;
23+
}
2224

2325
describe("creates.enqueue", () => {
24-
it("should run with default options", async () => {
25-
delete bundle.inputData["polygon"];
26-
delete bundle.inputData["confidence"];
27-
28-
// @ts-expect-error TBD
29-
const response: any = await appTester(App.creates["v2_enqueue"].operation.perform, bundle);
30-
expect(response).toBeInstanceOf(Object);
31-
expect(response.job).toBeInstanceOf(Object);
32-
expect(response.job.status).toEqual("Processing");
33-
expect(response.job.model_id).toEqual(modelId);
34-
expect(response.job.alias).toEqual("zapier-test-enqueue");
35-
expect(response.job.error).toBeNull;
26+
it("should send a base64 file", async () => {
27+
const bundle: any = {
28+
authData: {
29+
apiKey: process.env["MINDEE_V2_API_KEY"],
30+
},
31+
inputData: {
32+
file: fs.readFileSync(blankPdfPath).toString("base64"),
33+
modelId: modelId,
34+
alias: "zapier-test-enqueue-base64",
35+
}
36+
};
37+
assertJobResponse(bundle);
38+
}, 6000);
39+
40+
it("should send a file stream", async () => {
41+
const bundle: any = {
42+
authData: {
43+
apiKey: process.env["MINDEE_V2_API_KEY"],
44+
},
45+
inputData: {
46+
file: fs.createReadStream(blankPdfPath),
47+
modelId: modelId,
48+
alias: "zapier-test-enqueue-stream",
49+
}
50+
};
51+
assertJobResponse(bundle);
52+
}, 6000);
53+
54+
it("should send a URL", async () => {
55+
const bundle: any = {
56+
authData: {
57+
apiKey: process.env["MINDEE_V2_API_KEY"],
58+
},
59+
inputData: {
60+
file: "https://raw.githubusercontent.com/mindee/client-lib-test-data/refs/heads/main/file_types/receipt.jpg",
61+
modelId: modelId,
62+
alias: "zapier-test-enqueue-url",
63+
}
64+
};
65+
assertJobResponse(bundle);
3666
}, 6000);
3767
});

0 commit comments

Comments
 (0)