Skip to content

Commit 16502f8

Browse files
committed
use base64
1 parent ee2f6f9 commit 16502f8

File tree

8 files changed

+72
-37
lines changed

8 files changed

+72
-37
lines changed

src/authentication.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ export default {
2323
{
2424
computed: false,
2525
key: "connectionName",
26+
label: "Connection Name",
2627
required: true,
2728
type: "string",
28-
helpText: "Name of the connection.",
29+
helpText: "Name of the connection, should be in the format: `MindeeV2-` + your API key's name",
2930
},
3031
{
3132
computed: false,
3233
key: "apiKey",
34+
label: "API Key",
3335
required: true,
3436
type: "password",
3537
helpText:

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import packageJson from "../package.json" with { type: "json" };
22

3-
export const MINDEE_V2_BASE_URL = "https://api-v2.mindee.net";
3+
export const MINDEE_V2_BASE_URL = process.env["MINDEE_V2_BASE_URL"] ?? "https://api-v2.mindee.net";
44

55
export const appVersion = packageJson.version;

src/v2/api/inputFields.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const optionChoices: FieldChoices = [
1414
export const inferenceCreateFields = defineInputFields([
1515
{
1616
key: "modelId",
17-
label: "Model ID",
17+
label: "Model to Use",
1818
required: true,
1919
type: "string",
20-
dynamic: "search_models.id.name",
21-
helpText: "Start typing to search a model by name...",
20+
dynamic: "v2_search_models.id.name",
21+
helpText: "The model to use.",
2222
},
2323
{
2424
key: "file",
@@ -40,44 +40,44 @@ export const inferenceCreateFields = defineInputFields([
4040
choices: optionChoices,
4141
default: optionDefault,
4242
helpText:
43-
"Calculate confidence scores for values, and fill the confidence attribute of fields." +
44-
" Useful for automation.",
43+
"Enable automated workflows by enhancing model accuracy and measuring field confidence.",
4544
},
4645
{
4746
key: "polygon",
48-
label: "Enable Confidence Scores",
47+
label: "Enable Polygons (Bounding Boxes)",
4948
type: "string",
5049
choices: optionChoices,
5150
default: optionDefault,
5251
helpText:
53-
"Calculate bounding box polygons for all fields and fill the `locations` attribute.",
52+
"Add the polygon coordinates of each extracted field to the API response.",
5453
},
5554
{
5655
key: "rag",
57-
label: "Enable Confidence Scores",
56+
label: "Enable RAG (Continuous Learning)",
5857
type: "string",
5958
choices: optionChoices,
6059
default: optionDefault,
6160
helpText:
62-
"Enhance extraction accuracy with Retrieval-Augmented Generation.",
61+
"Enhance extraction accuracy with Retrieval-Augmented Generation using your own documents.",
6362
},
6463
{
6564
key: "rawText",
66-
label: "Enable Confidence Scores",
65+
label: "Enable Raw Text (Full OCR)",
6766
type: "string",
6867
choices: optionChoices,
6968
default: optionDefault,
7069
helpText:
71-
"Extract full document text as strings and fill the `rawText` attribute.",
70+
"Add the full text content of your documents to the API response.",
7271
},
7372
]);
7473

7574
export const pollingFields = defineInputFields([
7675
{
7776
key: "maxPollingTimeOut",
77+
label: "Polling Timeout",
7878
required: true,
7979
default: "180",
8080
type: "number",
81-
helpText: "Maximum polling timeout in seconds."
81+
helpText: "Stop attempting to poll for the result after this number of seconds. Raises an error when reached."
8282
},
8383
]);

src/v2/api/requests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ 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.
8283
form.append("file_base64", bundle.inputData.file);
8384

8485
if (bundle.inputData.alias) {

src/v2/test/creates/enqueue.test.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,30 @@ import fs from "node:fs";
88
const appTester = zapier.createAppTester(App);
99
zapier.tools.env.inject();
1010

11+
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+
};
22+
1123
describe("creates.enqueue", () => {
12-
it("should run", async () => {
13-
const bundle = {
14-
authData: { apiKey: process.env["MINDEE_V2_API_KEY"] },
15-
inputData: {
16-
file: fs.createReadStream(blankPdfPath),
17-
modelId: process.env["MINDEE_V2_FINDOC_MODEL_ID"],
18-
}
19-
};
24+
it("should run with default options", async () => {
25+
delete bundle.inputData["polygon"];
26+
delete bundle.inputData["confidence"];
2027

2128
// @ts-expect-error TBD
22-
const results = await appTester(App.creates["v2_enqueue"].operation.perform, bundle);
23-
expect(results).toBeDefined();
24-
// TODO: add more assertions
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;
2536
}, 6000);
2637
});

src/v2/test/creates/enqueue_and_get_inference.test.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,36 @@ import fs from "node:fs";
88
const appTester = zapier.createAppTester(App);
99
zapier.tools.env.inject();
1010

11+
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-get-inference",
20+
}
21+
};
22+
1123
describe("creates.enqueue_and_get_inference", () => {
1224
it("should run", async () => {
13-
const bundle = {
14-
authData: { apiKey: process.env["MINDEE_V2_API_KEY"] },
15-
inputData: {
16-
file: fs.createReadStream(blankPdfPath),
17-
modelId: process.env["MINDEE_V2_FINDOC_MODEL_ID"],
18-
}
19-
};
25+
delete bundle.inputData["polygon"];
26+
delete bundle.inputData["confidence"];
2027

2128
// @ts-expect-error TBD
22-
const results = await appTester(App.creates["v2_enqueue_and_get_inference"].operation.perform, bundle);
23-
expect(results).toBeDefined();
24-
// TODO: add more assertions
29+
const results: any = await appTester(App.creates["v2_enqueue_and_get_inference"].operation.perform, bundle);
30+
expect(results).toBeInstanceOf(Object);
31+
expect(results.inference).toBeInstanceOf(Object);
32+
expect(results.inference.model.id).toEqual(modelId);
33+
34+
expect(results.inference.active_options).toBeInstanceOf(Object);
35+
expect(results.inference.active_options.rag).toEqual(false);
36+
37+
expect(results.inference.file).toBeInstanceOf(Object);
38+
expect(results.inference.file.mime_type).toEqual("application/pdf");
39+
40+
expect(results.inference.result).toBeInstanceOf(Object);
41+
expect(results.inference.result.fields).toBeInstanceOf(Object);
2542
}, 20000);
2643
});

src/v2/test/searches/inference.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ zapier.tools.env.inject();
1212
describe("searches.inference", () => {
1313
it("Non-existing inference ID – must raise 4xx", async () => {
1414
const bundle = {
15-
authData: { apiKey: process.env["MINDEE_V2_API_KEY"] },
15+
authData: {
16+
apiKey: process.env["MINDEE_V2_API_KEY"],
17+
},
1618
inputData: {
1719
inferenceId: "fc405e37-4ba4-4d03-aeba-533a8d1f0f21",
1820
}

src/v2/test/searches/inference_by_polling.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ zapier.tools.env.inject();
1212
describe("searches.inference", () => {
1313
it("Non-existing job ID – must raise 4xx", async () => {
1414
const bundle = {
15-
authData: { apiKey: process.env["MINDEE_V2_API_KEY"] },
15+
authData: {
16+
apiKey: process.env["MINDEE_V2_API_KEY"],
17+
},
1618
inputData: {
1719
jobId: "fc405e37-4ba4-4d03-aeba-533a8d1f0f21",
1820
}

0 commit comments

Comments
 (0)