n8n/packages/nodes-base/nodes/SyncroMSP/v1/transport/index.ts

83 lines
2 KiB
TypeScript
Raw Normal View History

import type { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-core';
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
import type {
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
GenericValue,
ICredentialDataDecryptedObject,
ICredentialTestFunctions,
IDataObject,
IHttpRequestOptions,
JsonObject,
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
/**
* Make an API request to Mattermost
*/
export async function apiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD',
endpoint: string,
body: IDataObject | GenericValue | GenericValue[] = {},
query: IDataObject = {},
) {
const credentials = await this.getCredentials('syncroMspApi');
query.api_key = credentials.apiKey;
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
const options: IHttpRequestOptions = {
method,
body,
qs: query,
url: `https://${credentials.subdomain}.syncromsp.com/api/v1/${endpoint}`,
headers: {},
};
try {
return await this.helpers.httpRequest(options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
}
}
export async function apiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD',
endpoint: string,
body: IDataObject = {},
query: IDataObject = {},
) {
let returnData: IDataObject[] = [];
let responseData;
query.page = 1;
do {
responseData = await apiRequest.call(this, method, endpoint, body, query);
query.page++;
returnData = returnData.concat(responseData[endpoint] as IDataObject[]);
} while (responseData[endpoint].length !== 0);
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
return returnData;
}
export async function validateCredentials(
this: ICredentialTestFunctions,
decryptedCredentials: ICredentialDataDecryptedObject,
): Promise<any> {
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
const credentials = decryptedCredentials;
const { subdomain, apiKey } = credentials as {
subdomain: string;
apiKey: string;
:sparkles: Add Syncromsp node (#2477) * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Add customer API * Updates post code review * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * Init Node * Added get customer details api for syncomsp-node * Fixed formatting bug :bug: * Updated description for query params, and removed redundant condition in router * Changed default value for page parameter * :ship: Added tickets API * :ship: Added contacts API * :ship: Added RMM Alerts API * Updates post code review * Add customer API * added create and delete method to customers module * fix liniting issue * Added Update method to customer module * Rename SyncroMspAPI.credentials.ts to SyncroMspApi.credentials.ts * Code Review Changes * :ship: Added CRUD for contacts endpoint * :ship: Added CRUD for RMM Alert endpoint * Added options for status field * :bug: fix linting issues * :ship: Added CRUD for ticket endpoint * :tag: update get customer module * :tag: update get customer module * Minor bug fixes * Changed response for ticket update * :shirt: Fix lint issue * Alphabetically ordered all options * :bug: Fixed build issue * :bug: Fixed Server.ts build issue, rebased from master * :zap: Fix node issues * :zap: Fix more issues * :zap: Fixed all operations with the standard convention * :shirt: Fix lint * Fix reviewed changes * update border color * :zap: minor fixes * minor fixes * Added fallback when port in use * :zap: Minor Fixes * :zap: Hide addtional paramerts when return all is active * :zap: Fix issues with Tickets * :zap: Fix issues with Rmm * :zap: Fix issues with Customer * :shirt: Fix lint * :zap: Fix issues with Contact * :shirt: Fixed formatting issue * :zap: Return 404 in ID not found * :shirt: Fixed formatting issue * :zap: Improvements * :zap: Improvements * :zap: Improvements * :zap: Add credentials verification * :zap: Improvements * :zap: Improvements * :zap: Additional improvements Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-01-07 09:19:24 -08:00
};
const options: IHttpRequestOptions = {
method: 'GET',
qs: {
api_key: apiKey,
},
url: `https://${subdomain}.syncromsp.com/api/v1//me`,
};
return this.helpers.request(options);
}