feat(Mindee Node): Add support for v4 API (#5559)

This commit is contained in:
Jon 2023-03-09 10:06:03 +00:00 committed by GitHub
parent 971d5ae8f5
commit e56fbfef3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 5 deletions

View file

@ -101,6 +101,20 @@ export function cleanData(document: IDataObject) {
newData.currency = data.currency;
//@ts-ignore
newData.locale = data.value;
} else if (key === 'line_items') {
const lineItems: IDataObject[] = [];
for (const lineItem of data as IDataObject[]) {
lineItems.push({
description: lineItem.description,
product_code: lineItem.product_code,
quantity: lineItem.quantity,
tax_amount: lineItem.tax_amount,
tax_rate: lineItem.tax_rate,
total_amount: lineItem.total_amount,
unit_price: lineItem.unit_price,
});
}
newData[key] = lineItems;
} else {
newData[key] =
//@ts-ignore

View file

@ -15,7 +15,7 @@ export class Mindee implements INodeType {
name: 'mindee',
icon: 'file:mindee.svg',
group: ['input'],
version: [1, 2],
version: [1, 2, 3],
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Mindee API',
defaults: {
@ -63,9 +63,13 @@ export class Mindee implements INodeType {
name: '3',
value: 3,
},
{
name: '4',
value: 4,
},
],
default: 1,
description: 'Whether to return all results or only up to a given limit',
description: 'Which Mindee API Version to use',
},
{
displayName: 'API Version',
@ -86,9 +90,40 @@ export class Mindee implements INodeType {
name: '3',
value: 3,
},
{
name: '4',
value: 4,
},
],
default: 3,
description: 'Whether to return all results or only up to a given limit',
description: 'Which Mindee API Version to use',
},
{
displayName: 'API Version',
name: 'apiVersion',
type: 'options',
isNodeSetting: true,
displayOptions: {
show: {
'@version': [3],
},
},
options: [
{
name: '1',
value: 1,
},
{
name: '3',
value: 3,
},
{
name: '4',
value: 4,
},
],
default: 4,
description: 'Which Mindee API Version to use',
},
{
displayName: 'Resource',
@ -201,13 +236,32 @@ export class Mindee implements INodeType {
},
},
);
} else if (version === 4) {
endpoint = '/expense_receipts/v4/predict';
responseData = await mindeeApiRequest.call(
this,
'POST',
endpoint,
{},
{},
{
formData: {
document: {
value: dataBuffer,
options: {
filename: binaryData.fileName,
},
},
},
},
);
}
if (!rawData) {
if (version === 1) {
responseData = cleanDataPreviousApiVersions(
responseData.predictions as IDataObject[],
);
} else if (version === 3) {
} else if (version === 3 || version === 4) {
responseData = cleanData(responseData.document as IDataObject);
}
}
@ -260,6 +314,25 @@ export class Mindee implements INodeType {
},
},
);
} else if (version === 4) {
endpoint = '/invoices/v4/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');
}
@ -268,7 +341,7 @@ export class Mindee implements INodeType {
responseData = cleanDataPreviousApiVersions(
responseData.predictions as IDataObject[],
);
} else if (version === 3) {
} else if (version === 3 || version === 4) {
responseData = cleanData(responseData.document as IDataObject);
}
}