Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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