pull:初次提交
This commit is contained in:
129
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/GenericFunctions.ts
Executable file
129
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/GenericFunctions.ts
Executable file
@@ -0,0 +1,129 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IDataObject,
|
||||
JsonObject,
|
||||
IHttpRequestMethods,
|
||||
IRequestOptions,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function mindeeApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
path: string,
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
option = {},
|
||||
): Promise<any> {
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
|
||||
let service;
|
||||
|
||||
if (resource === 'receipt') {
|
||||
service = 'mindeeReceiptApi';
|
||||
} else {
|
||||
service = 'mindeeInvoiceApi';
|
||||
}
|
||||
|
||||
const version = this.getNodeParameter('apiVersion', 0) as number;
|
||||
// V1 of mindee is deprecated, we are keeping it for now but now V3 is active
|
||||
const url =
|
||||
version === 1
|
||||
? `https://api.mindee.net/products${path}`
|
||||
: `https://api.mindee.net/v1/products/mindee${path}`;
|
||||
|
||||
const options: IRequestOptions = {
|
||||
headers: {},
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
uri: url,
|
||||
json: true,
|
||||
};
|
||||
try {
|
||||
if (Object.keys(body as IDataObject).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
if (Object.keys(qs).length === 0) {
|
||||
delete options.qs;
|
||||
}
|
||||
if (Object.keys(option).length !== 0) {
|
||||
Object.assign(options, option);
|
||||
}
|
||||
|
||||
return await this.helpers.requestWithAuthentication.call(this, service, options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
export function cleanDataPreviousApiVersions(predictions: IDataObject[]) {
|
||||
const newData: IDataObject = {};
|
||||
|
||||
for (const key of Object.keys(predictions[0])) {
|
||||
const data = predictions[0][key] as IDataObject | IDataObject[];
|
||||
|
||||
if (key === 'taxes' && data.length) {
|
||||
newData[key] = {
|
||||
amount: (data as IDataObject[])[0].amount,
|
||||
rate: (data as IDataObject[])[0].rate,
|
||||
};
|
||||
} else if (key === 'locale') {
|
||||
//@ts-ignore
|
||||
newData.currency = data.currency;
|
||||
//@ts-ignore
|
||||
newData.locale = data.value;
|
||||
} else {
|
||||
newData[key] =
|
||||
//@ts-ignore
|
||||
data.value || data.name || data.raw || data.degrees || data.amount || data.iban;
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
}
|
||||
|
||||
export function cleanData(document: IDataObject) {
|
||||
// @ts-ignore
|
||||
const prediction = document.inference.prediction as IDataObject;
|
||||
const newData: IDataObject = {};
|
||||
newData.id = document.id;
|
||||
newData.name = document.name;
|
||||
newData.number_of_pages = document.n_pages;
|
||||
for (const key of Object.keys(prediction)) {
|
||||
const data = prediction[key] as IDataObject | IDataObject[];
|
||||
|
||||
if (key === 'taxes' && data.length) {
|
||||
newData[key] = {
|
||||
amount: (data as IDataObject[])[0].amount,
|
||||
rate: (data as IDataObject[])[0].rate,
|
||||
};
|
||||
} else if (key === 'locale') {
|
||||
//@ts-ignore
|
||||
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
|
||||
data.value || data.name || data.raw || data.degrees || data.amount || data.iban;
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
}
|
||||
30
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/Mindee.node.json
Executable file
30
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/Mindee.node.json
Executable file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.mindee",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Utility"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/mindee/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.mindee/"
|
||||
}
|
||||
],
|
||||
"generic": [
|
||||
{
|
||||
"label": "Building an expense tracking app in 10 minutes",
|
||||
"icon": "📱",
|
||||
"url": "https://n8n.io/blog/building-an-expense-tracking-app-in-10-minutes/"
|
||||
},
|
||||
{
|
||||
"label": "Learn to Build Powerful API Endpoints Using Webhooks",
|
||||
"icon": "🧰",
|
||||
"url": "https://n8n.io/blog/learn-to-build-powerful-api-endpoints-using-webhooks/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
364
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/Mindee.node.ts
Executable file
364
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/Mindee.node.ts
Executable file
@@ -0,0 +1,364 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { cleanData, cleanDataPreviousApiVersions, mindeeApiRequest } from './GenericFunctions';
|
||||
|
||||
export class Mindee implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Mindee',
|
||||
name: 'mindee',
|
||||
icon: 'file:mindee.svg',
|
||||
group: ['input'],
|
||||
version: [1, 2, 3],
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Mindee API',
|
||||
defaults: {
|
||||
name: 'Mindee',
|
||||
},
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'mindeeReceiptApi',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['receipt'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'mindeeInvoiceApi',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
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,
|
||||
},
|
||||
{
|
||||
name: '4',
|
||||
value: 4,
|
||||
},
|
||||
],
|
||||
default: 1,
|
||||
description: 'Which Mindee API Version to use',
|
||||
},
|
||||
{
|
||||
displayName: 'API Version',
|
||||
name: 'apiVersion',
|
||||
type: 'options',
|
||||
isNodeSetting: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [2],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: '1',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: '3',
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
name: '4',
|
||||
value: 4,
|
||||
},
|
||||
],
|
||||
default: 3,
|
||||
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',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Invoice',
|
||||
value: 'invoice',
|
||||
},
|
||||
{
|
||||
name: 'Receipt',
|
||||
value: 'receipt',
|
||||
},
|
||||
],
|
||||
default: 'receipt',
|
||||
},
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Predict',
|
||||
value: 'predict',
|
||||
},
|
||||
],
|
||||
default: 'predict',
|
||||
},
|
||||
{
|
||||
displayName: 'Input Binary Field',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: 'data',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['predict'],
|
||||
resource: ['receipt', 'invoice'],
|
||||
},
|
||||
},
|
||||
hint: 'The name of the input binary field containing the file to be uploaded',
|
||||
},
|
||||
{
|
||||
displayName: 'RAW Data',
|
||||
name: 'rawData',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return the data exactly in the way it got received from the API',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length;
|
||||
let responseData;
|
||||
const version = this.getNodeParameter('apiVersion', 0) as number;
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
let endpoint;
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
if (resource === 'receipt') {
|
||||
if (operation === 'predict') {
|
||||
const rawData = this.getNodeParameter('rawData', i);
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
||||
|
||||
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
||||
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
} 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 || version === 4) {
|
||||
responseData = cleanData(responseData.document as IDataObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'invoice') {
|
||||
if (operation === 'predict') {
|
||||
const rawData = this.getNodeParameter('rawData', i);
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
||||
|
||||
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
||||
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
||||
|
||||
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 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');
|
||||
}
|
||||
if (!rawData) {
|
||||
if (version === 1) {
|
||||
responseData = cleanDataPreviousApiVersions(
|
||||
responseData.predictions as IDataObject[],
|
||||
);
|
||||
} else if (version === 3 || version === 4) {
|
||||
responseData = cleanData(responseData.document as IDataObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else if (responseData !== undefined) {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
53
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/__schema__/v3.0.0/invoice/predict.json
vendored
Executable file
53
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/__schema__/v3.0.0/invoice/predict.json
vendored
Executable file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"currency": {
|
||||
"type": "string"
|
||||
},
|
||||
"customer_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"date": {
|
||||
"type": "string"
|
||||
},
|
||||
"document_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"due_date": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"invoice_number": {
|
||||
"type": "string"
|
||||
},
|
||||
"line_items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"number_of_pages": {
|
||||
"type": "integer"
|
||||
},
|
||||
"payment_date": {
|
||||
"type": "string"
|
||||
},
|
||||
"supplier_address": {
|
||||
"type": "string"
|
||||
},
|
||||
"supplier_name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
36
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/__schema__/v3.0.0/receipt/predict.json
vendored
Executable file
36
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/__schema__/v3.0.0/receipt/predict.json
vendored
Executable file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"category": {
|
||||
"type": "string"
|
||||
},
|
||||
"currency": {
|
||||
"type": "string"
|
||||
},
|
||||
"date": {
|
||||
"type": "string"
|
||||
},
|
||||
"document_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"number_of_pages": {
|
||||
"type": "integer"
|
||||
},
|
||||
"subcategory": {
|
||||
"type": "string"
|
||||
},
|
||||
"supplier": {
|
||||
"type": "string"
|
||||
},
|
||||
"time": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
1
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/mindee.svg
Executable file
1
n8n-n8n-1.109.2/packages/nodes-base/nodes/Mindee/mindee.svg
Executable file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32"><path fill="#FD3246" fill-rule="evenodd" d="M18.329 0h13.746v32H18.33v-4.57h9.164V4.572H18.33zM4.582 13.714V27.43h9.165V32H0V0h13.747v4.571H4.582zm4.582 0v-4.57h13.747v4.57zm0 9.143v-4.571h4.583v4.571z"/></svg>
|
||||
|
After Width: | Height: | Size: 273 B |
Reference in New Issue
Block a user