2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IExecuteFunctions,
|
2022-01-07 09:19:24 -08:00
|
|
|
ICredentialDataDecryptedObject,
|
|
|
|
ICredentialsDecrypted,
|
|
|
|
ICredentialTestFunctions,
|
2022-02-05 13:55:43 -08:00
|
|
|
INodeCredentialTestResult,
|
2022-01-07 09:19:24 -08:00
|
|
|
INodeType,
|
|
|
|
INodeTypeBaseDescription,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import { versionDescription } from './actions/versionDescription';
|
|
|
|
import { loadOptions } from './methods';
|
|
|
|
import { router } from './actions/router';
|
|
|
|
import { validateCredentials } from './transport';
|
|
|
|
|
|
|
|
export class SyncroMspV1 implements INodeType {
|
|
|
|
description: INodeTypeDescription;
|
|
|
|
|
|
|
|
constructor(baseDescription: INodeTypeBaseDescription) {
|
|
|
|
this.description = {
|
|
|
|
...baseDescription,
|
|
|
|
...versionDescription,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions,
|
|
|
|
credentialTest: {
|
2022-08-17 08:50:24 -07:00
|
|
|
async syncroMspApiCredentialTest(
|
|
|
|
this: ICredentialTestFunctions,
|
|
|
|
credential: ICredentialsDecrypted,
|
|
|
|
): Promise<INodeCredentialTestResult> {
|
2022-01-07 09:19:24 -08:00
|
|
|
try {
|
|
|
|
await validateCredentials.call(this, credential.data as ICredentialDataDecryptedObject);
|
|
|
|
} catch (error) {
|
|
|
|
if (error.statusCode === 401) {
|
|
|
|
return {
|
|
|
|
status: 'Error',
|
|
|
|
message: 'The API Key included in the request is invalid',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
status: 'OK',
|
|
|
|
message: 'Connection successful!',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions) {
|
2022-12-02 12:54:28 -08:00
|
|
|
return router.call(this);
|
2022-01-07 09:19:24 -08:00
|
|
|
}
|
|
|
|
}
|