n8n/packages/nodes-base/nodes/Zoho/GenericFunctions.ts

423 lines
11 KiB
TypeScript
Raw Normal View History

import { OptionsWithUri } from 'request';
import { IExecuteFunctions, IHookFunctions } from 'n8n-core';
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
import { IDataObject, ILoadOptionsFunctions, NodeApiError, NodeOperationError } from 'n8n-workflow';
2020-02-12 07:04:43 -08:00
import { flow, sortBy } from 'lodash';
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
import {
AllFields,
CamelCaseResource,
DateType,
GetAllFilterOptions,
IdType,
LoadedFields,
LoadedLayouts,
LocationType,
NameType,
ProductDetails,
ResourceItems,
SnakeCaseResource,
ZohoOAuth2ApiCredentials,
} from './types';
export async function zohoApiRequest(
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
method: string,
endpoint: string,
body: IDataObject = {},
qs: IDataObject = {},
uri?: string,
) {
const { oauthTokenData } = (await this.getCredentials(
'zohoOAuth2Api',
)) as ZohoOAuth2ApiCredentials;
2020-02-12 07:04:43 -08:00
const options: OptionsWithUri = {
body: {
data: [body],
2020-02-12 07:04:43 -08:00
},
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
method,
2020-02-12 07:04:43 -08:00
qs,
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
uri: uri ?? `${oauthTokenData.api_domain}/crm/v2${endpoint}`,
2020-10-22 06:46:03 -07:00
json: true,
2020-02-12 07:04:43 -08:00
};
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
if (!Object.keys(body).length) {
delete options.body;
}
if (!Object.keys(qs).length) {
delete options.qs;
}
2020-02-12 07:04:43 -08:00
try {
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
if (responseData === undefined) return [];
throwOnErrorStatus.call(this, responseData);
return responseData;
2020-02-12 07:04:43 -08:00
} catch (error) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeApiError(this.getNode(), error);
2020-02-12 07:04:43 -08:00
}
}
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
/**
* Make an authenticated API request to Zoho CRM API and return all items.
*/
export async function zohoApiRequestAllItems(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
method: string,
endpoint: string,
body: IDataObject = {},
qs: IDataObject = {},
) {
2020-02-12 07:04:43 -08:00
const returnData: IDataObject[] = [];
let responseData;
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
qs.per_page = 200;
qs.page = 1;
2020-02-12 07:04:43 -08:00
do {
responseData = await zohoApiRequest.call(this, method, endpoint, body, qs);
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
if (Array.isArray(responseData) && !responseData.length) return returnData;
returnData.push(...responseData.data);
qs.page++;
} while (responseData.info.more_records !== undefined && responseData.info.more_records === true);
2020-02-12 07:04:43 -08:00
return returnData;
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
}
/**
* Handle a Zoho CRM API listing by returning all items or up to a limit.
*/
export async function handleListing(
this: IExecuteFunctions,
method: string,
endpoint: string,
body: IDataObject = {},
qs: IDataObject = {},
) {
const returnAll = this.getNodeParameter('returnAll', 0);
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
if (returnAll) {
return await zohoApiRequestAllItems.call(this, method, endpoint, body, qs);
}
const responseData = await zohoApiRequestAllItems.call(this, method, endpoint, body, qs);
const limit = this.getNodeParameter('limit', 0);
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
return responseData.slice(0, limit);
}
export function throwOnEmptyUpdate(this: IExecuteFunctions, resource: CamelCaseResource) {
throw new NodeOperationError(
this.getNode(),
`Please enter at least one field to update for the ${resource}.`,
);
}
export function throwOnMissingProducts(
this: IExecuteFunctions,
resource: CamelCaseResource,
productDetails: ProductDetails,
) {
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
if (!productDetails.length) {
throw new NodeOperationError(
this.getNode(),
`Please enter at least one product for the ${resource}.`,
);
}
}
export function throwOnErrorStatus(
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
responseData: { data?: Array<{ status: string; message: string }> },
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
) {
if (responseData?.data?.[0].status === 'error') {
throw new NodeOperationError(this.getNode(), responseData as Error);
}
}
// ----------------------------------------
// required field adjusters
// ----------------------------------------
/**
* Place a product ID at a nested position in a product details field.
*/
export const adjustProductDetails = (productDetails: ProductDetails) => {
return productDetails.map((p) => {
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
return {
...omit('product', p),
product: { id: p.id },
quantity: p.quantity || 1,
};
});
};
// ----------------------------------------
// additional field adjusters
// ----------------------------------------
/**
* Place a product ID at a nested position in a product details field.
*
* Only for updating products from Invoice, Purchase Order, Quote, and Sales Order.
*/
export const adjustProductDetailsOnUpdate = (allFields: AllFields) => {
if (!allFields.Product_Details) return allFields;
return allFields.Product_Details.map((p) => {
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
return {
...omit('product', p),
product: { id: p.id },
quantity: p.quantity || 1,
};
});
};
/**
* Place a location field's contents at the top level of the payload.
*/
const adjustLocationFields = (locationType: LocationType) => (allFields: AllFields) => {
const locationField = allFields[locationType];
if (!locationField) return allFields;
return {
...omit(locationType, allFields),
...locationField.address_fields,
};
};
const adjustAddressFields = adjustLocationFields('Address');
const adjustBillingAddressFields = adjustLocationFields('Billing_Address');
const adjustMailingAddressFields = adjustLocationFields('Mailing_Address');
const adjustShippingAddressFields = adjustLocationFields('Shipping_Address');
const adjustOtherAddressFields = adjustLocationFields('Other_Address');
/**
* Remove from a date field the timestamp set by the datepicker.
*/
const adjustDateField = (dateType: DateType) => (allFields: AllFields) => {
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
const dateField = allFields[dateType];
if (!dateField) return allFields;
allFields[dateType] = dateField.split('T')[0];
return allFields;
};
const adjustDateOfBirthField = adjustDateField('Date_of_Birth');
const adjustClosingDateField = adjustDateField('Closing_Date');
const adjustInvoiceDateField = adjustDateField('Invoice_Date');
const adjustDueDateField = adjustDateField('Due_Date');
const adjustPurchaseOrderDateField = adjustDateField('PO_Date');
const adjustValidTillField = adjustDateField('Valid_Till');
/**
* Place an ID field's value nested inside the payload.
*/
const adjustIdField = (idType: IdType, nameProperty: NameType) => (allFields: AllFields) => {
const idValue = allFields[idType];
if (!idValue) return allFields;
return {
...omit(idType, allFields),
[nameProperty]: { id: idValue },
};
};
const adjustAccountIdField = adjustIdField('accountId', 'Account_Name');
const adjustContactIdField = adjustIdField('contactId', 'Full_Name');
const adjustDealIdField = adjustIdField('dealId', 'Deal_Name');
const adjustCustomFields = (allFields: AllFields) => {
const { customFields, ...rest } = allFields;
if (!customFields?.customFields.length) return allFields;
return customFields.customFields.reduce((acc, cur) => {
acc[cur.fieldId] = cur.value;
return acc;
}, rest);
};
// ----------------------------------------
// payload adjusters
// ----------------------------------------
export const adjustAccountPayload = flow(
adjustBillingAddressFields,
adjustShippingAddressFields,
adjustCustomFields,
);
export const adjustContactPayload = flow(
adjustMailingAddressFields,
adjustOtherAddressFields,
adjustDateOfBirthField,
adjustCustomFields,
);
export const adjustDealPayload = flow(adjustClosingDateField, adjustCustomFields);
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
export const adjustInvoicePayload = flow(
adjustBillingAddressFields,
adjustShippingAddressFields,
adjustInvoiceDateField,
adjustDueDateField,
adjustAccountIdField,
adjustCustomFields,
);
export const adjustInvoicePayloadOnUpdate = flow(
adjustInvoicePayload,
adjustProductDetailsOnUpdate,
);
export const adjustLeadPayload = flow(adjustAddressFields, adjustCustomFields);
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
export const adjustPurchaseOrderPayload = flow(
adjustBillingAddressFields,
adjustShippingAddressFields,
adjustDueDateField,
adjustPurchaseOrderDateField,
adjustCustomFields,
);
export const adjustQuotePayload = flow(
adjustBillingAddressFields,
adjustShippingAddressFields,
adjustValidTillField,
adjustCustomFields,
);
export const adjustSalesOrderPayload = flow(
adjustBillingAddressFields,
adjustShippingAddressFields,
adjustDueDateField,
adjustAccountIdField,
adjustContactIdField,
adjustDealIdField,
adjustCustomFields,
);
export const adjustVendorPayload = flow(adjustAddressFields, adjustCustomFields);
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
export const adjustProductPayload = adjustCustomFields;
// ----------------------------------------
// helpers
// ----------------------------------------
/**
* Create a copy of an object without a specific property.
*/
const omit = (propertyToOmit: string, { [propertyToOmit]: _, ...remainingObject }) =>
remainingObject;
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
/**
* Convert items in a Zoho CRM API response into n8n load options.
*/
export const toLoadOptions = (items: ResourceItems, nameProperty: NameType) =>
items.map((item) => ({ name: item[nameProperty], value: item.id }));
/**
* Retrieve all fields for a resource, sorted alphabetically.
*/
export async function getFields(
this: ILoadOptionsFunctions,
resource: SnakeCaseResource,
{ onlyCustom } = { onlyCustom: false },
) {
const qs = { module: getModuleName(resource) };
let { fields } = (await zohoApiRequest.call(
this,
'GET',
'/settings/fields',
{},
qs,
)) as LoadedFields;
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
if (onlyCustom) {
fields = fields.filter(({ custom_field }) => custom_field);
}
const options = fields.map(({ field_label, api_name }) => ({
name: field_label,
value: api_name,
}));
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
return sortBy(options, (o) => o.name);
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
}
export function getModuleName(resource: string) {
const map: { [key: string]: string } = {
account: 'Accounts',
contact: 'Contacts',
deal: 'Deals',
invoice: 'Invoices',
lead: 'Leads',
product: 'Products',
purchaseOrder: 'Purchase_Orders',
salesOrder: 'Sales_Orders',
vendor: 'Vendors',
quote: 'Quotes',
};
return map[resource];
}
export async function getPicklistOptions(
this: ILoadOptionsFunctions,
resource: string,
targetField: string,
) {
const qs = { module: getModuleName(resource) };
const responseData = (await zohoApiRequest.call(
this,
'GET',
'/settings/layouts',
{},
qs,
)) as LoadedLayouts;
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
const pickListOptions = responseData.layouts[0].sections
.find((section) => section.api_name === getSectionApiName(resource))
?.fields.find((f) => f.api_name === targetField)?.pick_list_values;
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
if (!pickListOptions) return [];
return pickListOptions.map((option) => ({
name: option.display_value,
value: option.actual_value,
}));
:zap: Expand Zoho node (#1763) * :zap: Initial refactor of Zoho node * :zap: Refactor out extra credentials parameter * :fire: Remove unused filters * :zap: Fix date of birth fields * :zap: Fix param casing * :zap: Adjust param types * :zap: Adjust invoice operations * :zap: Refactor types in adjusters * :zap: Add product resource * :zap: Refactor product details field * :zap: Adjust purchase order params * :zap: Adjust quote params * :zap: Adjust sales orders params * :fire: Remove old unused files * :zap: Add vendor resource * :zap: Fix minor details * :zap: Implement continueOnFail * :bug: Fix empty response for getAll * :zap: Simplify response for single item * :fire: Remove unused import * :hammer: Restore old node name * :zap: Prevent request on empty update * :zap: Apply Dali's suggestions * :zap: Improvements * :zap: Add filters for lead:getAll * :zap: Add upsert to all resources * :zap: Add filters to all getAll operations * :hammer: Restore continue on fail * :hammer: Refactor upsert addition * :hammer: Refactor getFields for readability * :zap: Add custom fields to all create-update ops * :zap: Implement custom fields adjuster * :fire: Remove logging * :shirt: Appease linter * :shirt: Refactor type helper for linter * :zap: Fix refactored type * :hammer: Refactor reduce for simplicity * :zap: Fix vendor:getAll filter options * :zap: Fix custom fields for product operations * :zap: Make sort_by into options param * :truck: Rename upsert operation * :pencil2: Add descriptions to upsert * :zap: Deduplicate system-defined check fields * :hammer: Re-order address fields * :pencil2: Generalize references in getAll fields * :fire: Remove extra comma * :zap: Make getFields helper more readable * :pencil2: Touch up description for account ID * :fire: Remove currency from contacts * :hammer: Resort emails and phones for contact * :bug: Fix sales cycle duration param type * :pencil2: Clarify descriptions with percentages * :hammer: Reorder total fields * :pencil2: Clarify percentages for discounts * :pencil2: Clarify percentages for commissions * :hammer: Convert currency to picklist * :pencil2: Add documentation links * :zap: Add resource loaders for picklists * :zap: Fix build * :hammer: Refactor product details * :zap: Add resolve data to all resources * :zap: Change resolve data toggle default * :zap: Restore lead:getFields operation * :fire: Remove upsert descriptions * :hammer: Change casing for upsert operations * :zap: Add operation descriptions * :hammer: Restore makeResolve default value * :hammer: Return nested details * :zap: Reposition Resolve Data toggles * :pencil2: Document breaking changes * Revert "Reposition Resolve Data toggles" This reverts commit 72ac41780b3ebec9cc6a5bf527e154ffe6ed884a. * :zap: Improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2021-07-02 14:34:12 -07:00
}
function getSectionApiName(resource: string) {
if (resource === 'purchaseOrder') return 'Purchase Order Information';
if (resource === 'salesOrder') return 'Sales Order Information';
return `${capitalizeInitial(resource)} Information`;
}
/**
* Add filter options to a query string object.
*/
export const addGetAllFilterOptions = (qs: IDataObject, options: GetAllFilterOptions) => {
if (Object.keys(options).length) {
const { fields, ...rest } = options;
Object.assign(qs, fields && { fields: fields.join(',') }, rest);
}
};
export const capitalizeInitial = (str: string) => str[0].toUpperCase() + str.slice(1);