2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2022-07-20 04:45:25 -07:00
|
|
|
ICredentialDataDecryptedObject,
|
2020-10-03 05:08:50 -07:00
|
|
|
ICredentialType,
|
2022-07-20 04:45:25 -07:00
|
|
|
IHttpRequestOptions,
|
2021-06-12 09:39:55 -07:00
|
|
|
INodeProperties,
|
2020-10-03 05:08:50 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class MindeeInvoiceApi implements ICredentialType {
|
|
|
|
name = 'mindeeInvoiceApi';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2020-10-03 05:08:50 -07:00
|
|
|
displayName = 'Mindee Invoice API';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2020-10-06 01:23:58 -07:00
|
|
|
documentationUrl = 'mindee';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-06-12 09:39:55 -07:00
|
|
|
properties: INodeProperties[] = [
|
2020-10-03 05:08:50 -07:00
|
|
|
{
|
|
|
|
displayName: 'API Key',
|
|
|
|
name: 'apiKey',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2022-11-01 09:41:45 -07:00
|
|
|
typeOptions: { password: true },
|
2020-10-03 05:08:50 -07:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
];
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2022-07-24 08:36:17 -07:00
|
|
|
async authenticate(
|
|
|
|
credentials: ICredentialDataDecryptedObject,
|
|
|
|
requestOptions: IHttpRequestOptions,
|
|
|
|
): Promise<IHttpRequestOptions> {
|
2022-07-20 04:45:25 -07:00
|
|
|
// @ts-ignore
|
|
|
|
const url = requestOptions.url ? requestOptions.url : requestOptions.uri;
|
2022-07-24 08:36:17 -07:00
|
|
|
if (url.includes('https://api.mindee.net/v1/')) {
|
2022-12-02 12:54:28 -08:00
|
|
|
requestOptions.headers!.Authorization = `Token ${credentials.apiKey}`;
|
2022-07-20 04:45:25 -07:00
|
|
|
} else {
|
|
|
|
requestOptions.headers!['X-Inferuser-Token'] = `${credentials.apiKey}`;
|
|
|
|
}
|
|
|
|
return requestOptions;
|
|
|
|
}
|
2020-10-03 05:08:50 -07:00
|
|
|
}
|