feat(Mindee Node): Add support for new version (#3596)
* Added versioning, with new credentials * Fix lint issue * 🔥 Remove old import name * Change function name * 🎨 Simplify name of versions within the node mindee * 🎨 Change version type from string to number * 🔥 Removed Mindee from getting ignored by prettier * 🎨 Ran prettier on Mindee folder * 🔥 Removed unused import * 🎨 Moved exceptions that were not working anymore Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IBinaryData,
|
||||
@@ -12,10 +10,7 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
cleanData,
|
||||
mindeeApiRequest,
|
||||
} from './GenericFunctions';
|
||||
import { cleanData, cleanDataPreviousApiVersions, mindeeApiRequest } from './GenericFunctions';
|
||||
|
||||
export class Mindee implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -23,7 +18,7 @@ export class Mindee implements INodeType {
|
||||
name: 'mindee',
|
||||
icon: 'file:mindee.svg',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
version: [1, 2],
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Mindee API',
|
||||
defaults: {
|
||||
@@ -37,9 +32,7 @@ export class Mindee implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'receipt',
|
||||
],
|
||||
resource: ['receipt'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -48,14 +41,58 @@ export class Mindee implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'invoice',
|
||||
],
|
||||
resource: ['invoice'],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'API Version',
|
||||
name: 'apiVersion',
|
||||
type: 'options',
|
||||
isNodeSetting: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [1],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: '1',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: '3',
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
default: 1,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'API Version',
|
||||
name: 'apiVersion',
|
||||
type: 'options',
|
||||
isNodeSetting: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [2],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: '1',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: '3',
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
default: 3,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
@@ -94,16 +131,12 @@ export class Mindee implements INodeType {
|
||||
default: 'data',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'predict',
|
||||
],
|
||||
resource: [
|
||||
'receipt',
|
||||
'invoice',
|
||||
],
|
||||
operation: ['predict'],
|
||||
resource: ['receipt', 'invoice'],
|
||||
},
|
||||
},
|
||||
description: 'Name of the binary property which containsthe data for the file to be uploaded',
|
||||
description:
|
||||
'Name of the binary property which containsthe data for the file to be uploaded',
|
||||
},
|
||||
{
|
||||
displayName: 'RAW Data',
|
||||
@@ -121,8 +154,10 @@ export class Mindee implements INodeType {
|
||||
const length = items.length;
|
||||
const qs: IDataObject = {};
|
||||
let responseData;
|
||||
const version = this.getNodeParameter('apiVersion', 0) as number;
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
let endpoint;
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
if (resource === 'receipt') {
|
||||
@@ -141,29 +176,55 @@ export class Mindee implements INodeType {
|
||||
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
||||
|
||||
if (binaryData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`No binary data property "${binaryPropertyName}" does not exists on item!`,
|
||||
);
|
||||
}
|
||||
|
||||
responseData = await mindeeApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/expense_receipts/v2/predict`,
|
||||
{},
|
||||
{},
|
||||
{
|
||||
formData: {
|
||||
file: {
|
||||
value: dataBuffer,
|
||||
options: {
|
||||
filename: binaryData.fileName,
|
||||
if (version === 1) {
|
||||
responseData = await mindeeApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/expense_receipts/v2/predict`,
|
||||
{},
|
||||
{},
|
||||
{
|
||||
formData: {
|
||||
file: {
|
||||
value: dataBuffer,
|
||||
options: {
|
||||
filename: binaryData.fileName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
);
|
||||
} else if (version === 3) {
|
||||
endpoint = '/expense_receipts/v3/predict';
|
||||
responseData = await mindeeApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
endpoint,
|
||||
{},
|
||||
{},
|
||||
{
|
||||
formData: {
|
||||
document: {
|
||||
value: dataBuffer,
|
||||
options: {
|
||||
filename: binaryData.fileName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
if (rawData === false) {
|
||||
responseData = cleanData(responseData.predictions);
|
||||
if (version === 1) {
|
||||
responseData = cleanDataPreviousApiVersions(responseData.predictions);
|
||||
} else if (version === 3) {
|
||||
responseData = cleanData(responseData.document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,29 +245,58 @@ export class Mindee implements INodeType {
|
||||
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
||||
|
||||
if (binaryData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`No binary data property "${binaryPropertyName}" does not exists on item!`,
|
||||
);
|
||||
}
|
||||
|
||||
responseData = await mindeeApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/invoices/v1/predict`,
|
||||
{},
|
||||
{},
|
||||
{
|
||||
formData: {
|
||||
file: {
|
||||
value: dataBuffer,
|
||||
options: {
|
||||
filename: binaryData.fileName,
|
||||
if (version === 1) {
|
||||
endpoint = '/invoices/v1/predict';
|
||||
responseData = await mindeeApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
endpoint,
|
||||
{},
|
||||
{},
|
||||
{
|
||||
formData: {
|
||||
file: {
|
||||
value: dataBuffer,
|
||||
options: {
|
||||
filename: binaryData.fileName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
);
|
||||
} else if (version === 3) {
|
||||
endpoint = '/invoices/v3/predict';
|
||||
responseData = await mindeeApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
endpoint,
|
||||
{},
|
||||
{},
|
||||
{
|
||||
formData: {
|
||||
document: {
|
||||
value: dataBuffer,
|
||||
options: {
|
||||
filename: binaryData.fileName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'Invalid API version');
|
||||
}
|
||||
if (rawData === false) {
|
||||
responseData = cleanData(responseData.predictions);
|
||||
if (version === 1) {
|
||||
responseData = cleanDataPreviousApiVersions(responseData.predictions);
|
||||
} else if (version === 3) {
|
||||
responseData = cleanData(responseData.document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user