mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
feat(Mindee Node): Add support for v4 API (#5559)
This commit is contained in:
parent
971d5ae8f5
commit
e56fbfef3e
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue