Skip to content

Commit

Permalink
feat(Mindee Node): Add support for v4 API (#5559)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joffcom committed Mar 9, 2023
1 parent 971d5ae commit e56fbfe
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 5 deletions.
14 changes: 14 additions & 0 deletions packages/nodes-base/nodes/Mindee/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
83 changes: 78 additions & 5 deletions packages/nodes-base/nodes/Mindee/Mindee.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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');
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit e56fbfe

Please sign in to comment.