2021-04-03 02:07:21 -07:00
|
|
|
import {
|
2022-07-20 04:50:16 -07:00
|
|
|
IAuthenticateGeneric,
|
|
|
|
ICredentialTestRequest,
|
2021-04-03 02:07:21 -07:00
|
|
|
ICredentialType,
|
2021-06-12 09:39:55 -07:00
|
|
|
INodeProperties,
|
2021-04-03 02:07:21 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class ERPNextApi implements ICredentialType {
|
|
|
|
name = 'erpNextApi';
|
|
|
|
displayName = 'ERPNext API';
|
|
|
|
documentationUrl = 'erpnext';
|
2021-06-12 09:39:55 -07:00
|
|
|
properties: INodeProperties[] = [
|
2021-04-03 02:07:21 -07:00
|
|
|
{
|
|
|
|
displayName: 'API Key',
|
|
|
|
name: 'apiKey',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2021-04-03 02:07:21 -07:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'API Secret',
|
|
|
|
name: 'apiSecret',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2021-04-03 02:07:21 -07:00
|
|
|
default: '',
|
|
|
|
},
|
2021-04-30 11:37:46 -07:00
|
|
|
{
|
|
|
|
displayName: 'Environment',
|
|
|
|
name: 'environment',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'options',
|
2021-04-30 11:37:46 -07:00
|
|
|
default: 'cloudHosted',
|
|
|
|
options: [
|
|
|
|
{
|
2022-04-13 23:32:27 -07:00
|
|
|
name: 'Cloud-Hosted',
|
2021-04-30 11:37:46 -07:00
|
|
|
value: 'cloudHosted',
|
|
|
|
},
|
|
|
|
{
|
2022-04-13 23:32:27 -07:00
|
|
|
name: 'Self-Hosted',
|
2021-04-30 11:37:46 -07:00
|
|
|
value: 'selfHosted',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-04-03 02:07:21 -07:00
|
|
|
{
|
|
|
|
displayName: 'Subdomain',
|
|
|
|
name: 'subdomain',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2021-04-03 02:07:21 -07:00
|
|
|
default: '',
|
|
|
|
placeholder: 'n8n',
|
2022-07-24 08:36:17 -07:00
|
|
|
description:
|
|
|
|
'Subdomain of cloud-hosted ERPNext instance. For example, "n8n" is the subdomain in: <code>https://n8n.erpnext.com</code>',
|
2021-04-30 11:37:46 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-07-24 08:36:17 -07:00
|
|
|
environment: ['cloudHosted'],
|
2021-04-30 11:37:46 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Domain',
|
|
|
|
name: 'domain',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2021-04-30 11:37:46 -07:00
|
|
|
default: '',
|
|
|
|
placeholder: 'https://www.mydomain.com',
|
2022-04-13 23:32:27 -07:00
|
|
|
description: 'Fully qualified domain name of self-hosted ERPNext instance',
|
2021-04-30 11:37:46 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-07-24 08:36:17 -07:00
|
|
|
environment: ['selfHosted'],
|
2021-04-30 11:37:46 -07:00
|
|
|
},
|
|
|
|
},
|
2021-04-03 02:07:21 -07:00
|
|
|
},
|
2022-07-20 04:50:16 -07:00
|
|
|
{
|
|
|
|
displayName: 'Ignore SSL Issues',
|
|
|
|
name: 'allowUnauthorizedCerts',
|
|
|
|
type: 'boolean',
|
|
|
|
description: 'Whether to connect even if SSL certificate validation is not possible',
|
|
|
|
default: false,
|
|
|
|
},
|
2021-04-03 02:07:21 -07:00
|
|
|
];
|
2022-07-20 04:50:16 -07:00
|
|
|
authenticate: IAuthenticateGeneric = {
|
|
|
|
type: 'generic',
|
|
|
|
properties: {
|
|
|
|
headers: {
|
|
|
|
Authorization: '=token {{$credentials.apiKey}}:{{$credentials.apiSecret}}',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
test: ICredentialTestRequest = {
|
|
|
|
request: {
|
|
|
|
baseURL: '={{$credentials.environment === "cloudHosted" ? "https://" + $credentials.subdomain + ".erpnext.com" : $credentials.domain}}',
|
|
|
|
url: '/api/resource/Doctype',
|
|
|
|
skipSslCertificateValidation: '={{ $credentials.allowUnauthorizedCerts }}',
|
|
|
|
},
|
|
|
|
};
|
2021-04-03 02:07:21 -07:00
|
|
|
}
|