From 862516f25e96fc9639bab07ccf88086f5b9a98ed Mon Sep 17 00:00:00 2001 From: Ankit Gupta <139338151+AnkitSegment@users.noreply.github.com> Date: Tue, 9 Jul 2024 12:20:54 +0530 Subject: [PATCH] [MAIN] [STRATCONN] added depends_on conditions on salesforce actions (#2081) * added depends_on conditions on salesforce actions * updated conditions for depends_on fields * Updated depends on condition for delete operation in salesforce actions * Updated depends on conditions for salesforce actions Contact, lead, opportunity * Added depends on for cases action in salesforce --- .../destinations/salesforce/account/index.ts | 51 ++++++++++++------- .../destinations/salesforce/cases/index.ts | 6 ++- .../destinations/salesforce/contact/index.ts | 30 +++++++---- .../src/destinations/salesforce/lead/index.ts | 30 +++++++---- .../salesforce/opportunity/index.ts | 18 ++++--- .../destinations/salesforce/sf-properties.ts | 20 ++++++-- 6 files changed, 107 insertions(+), 48 deletions(-) diff --git a/packages/destination-actions/src/destinations/salesforce/account/index.ts b/packages/destination-actions/src/destinations/salesforce/account/index.ts index bbb84e11b9..b15579ffb0 100644 --- a/packages/destination-actions/src/destinations/salesforce/account/index.ts +++ b/packages/destination-actions/src/destinations/salesforce/account/index.ts @@ -10,7 +10,8 @@ import { validateLookup, enable_batching, recordMatcherOperator, - batch_size + batch_size, + hideIfDeleteOperation } from '../sf-properties' import type { Payload } from './generated-types' @@ -34,7 +35,8 @@ const action: ActionDefinition = { type: 'string', default: { '@path': '$.traits.name' - } + }, + depends_on: hideIfDeleteOperation }, account_number: { label: 'Account Number', @@ -43,7 +45,8 @@ const action: ActionDefinition = { type: 'string', default: { '@path': '$.groupId' - } + }, + depends_on: hideIfDeleteOperation }, number_of_employees: { label: 'Number of employees', @@ -55,7 +58,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.employees' }, else: { '@path': '$.properties.employees' } } - } + }, + depends_on: hideIfDeleteOperation }, billing_city: { label: 'Billing City', @@ -67,7 +71,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.city' }, else: { '@path': '$.properties.address.city' } } - } + }, + depends_on: hideIfDeleteOperation }, billing_postal_code: { label: 'Billing Postal Code', @@ -79,7 +84,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.postal_code' }, else: { '@path': '$.properties.address.postal_code' } } - } + }, + depends_on: hideIfDeleteOperation }, billing_country: { label: 'Billing Country', @@ -91,7 +97,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.country' }, else: { '@path': '$.properties.address.country' } } - } + }, + depends_on: hideIfDeleteOperation }, billing_street: { label: 'Billing Street', @@ -103,7 +110,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.street' }, else: { '@path': '$.properties.address.street' } } - } + }, + depends_on: hideIfDeleteOperation }, billing_state: { label: 'Billing State', @@ -115,32 +123,38 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.state' }, else: { '@path': '$.properties.address.state' } } - } + }, + depends_on: hideIfDeleteOperation }, shipping_city: { label: 'Shipping City', description: 'City for the shipping address of the account.', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, shipping_postal_code: { label: 'Shipping Postal Code', description: 'Postal code for the shipping address of the account.', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, shipping_country: { label: 'Shipping Country', description: 'Country for the shipping address of the account.', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, shipping_street: { label: 'Shipping Street', description: 'Street address for the shipping address of the account.', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, shipping_state: { label: 'Shipping State', description: 'State for the shipping address of the account.', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, phone: { label: 'Phone', @@ -152,7 +166,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.phone' }, else: { '@path': '$.properties.phone' } } - } + }, + depends_on: hideIfDeleteOperation }, description: { label: 'Description', @@ -164,7 +179,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.description' }, else: { '@path': '$.properties.description' } } - } + }, + depends_on: hideIfDeleteOperation }, website: { label: 'Website', @@ -176,7 +192,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.website' }, else: { '@path': '$.properties.website' } } - } + }, + depends_on: hideIfDeleteOperation }, customFields: customFields }, diff --git a/packages/destination-actions/src/destinations/salesforce/cases/index.ts b/packages/destination-actions/src/destinations/salesforce/cases/index.ts index 599688a95d..f3ab985619 100644 --- a/packages/destination-actions/src/destinations/salesforce/cases/index.ts +++ b/packages/destination-actions/src/destinations/salesforce/cases/index.ts @@ -10,7 +10,8 @@ import { validateLookup, enable_batching, recordMatcherOperator, - batch_size + batch_size, + hideIfDeleteOperation } from '../sf-properties' import Salesforce, { generateSalesforceRequest } from '../sf-operations' @@ -30,7 +31,8 @@ const action: ActionDefinition = { description: { label: 'Description', description: 'A text description of the case.', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, customFields: customFields }, diff --git a/packages/destination-actions/src/destinations/salesforce/contact/index.ts b/packages/destination-actions/src/destinations/salesforce/contact/index.ts index 95df669ca0..f3c1863c78 100644 --- a/packages/destination-actions/src/destinations/salesforce/contact/index.ts +++ b/packages/destination-actions/src/destinations/salesforce/contact/index.ts @@ -10,7 +10,8 @@ import { validateLookup, enable_batching, recordMatcherOperator, - batch_size + batch_size, + hideIfDeleteOperation } from '../sf-properties' import Salesforce, { generateSalesforceRequest } from '../sf-operations' @@ -37,7 +38,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.last_name' }, else: { '@path': '$.properties.last_name' } } - } + }, + depends_on: hideIfDeleteOperation }, first_name: { label: 'First Name', @@ -49,13 +51,15 @@ const action: ActionDefinition = { then: { '@path': '$.traits.first_name' }, else: { '@path': '$.properties.first_name' } } - } + }, + depends_on: hideIfDeleteOperation }, account_id: { label: 'Account ID', description: 'The ID of the account that this contact is associated with. This is the Salesforce-generated ID assigned to the account during creation (i.e. 0018c00002CDThnAAH).', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, email: { label: 'Email', @@ -67,7 +71,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.email' }, else: { '@path': '$.properties.email' } } - } + }, + depends_on: hideIfDeleteOperation }, mailing_city: { label: 'Mailing City', @@ -79,7 +84,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.city' }, else: { '@path': '$.properties.address.city' } } - } + }, + depends_on: hideIfDeleteOperation }, mailing_postal_code: { label: 'Mailing Postal Code', @@ -91,7 +97,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.postal_code' }, else: { '@path': '$.properties.address.postal_code' } } - } + }, + depends_on: hideIfDeleteOperation }, mailing_country: { label: 'Mailing Country', @@ -103,7 +110,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.country' }, else: { '@path': '$.properties.address.country' } } - } + }, + depends_on: hideIfDeleteOperation }, mailing_street: { label: 'Mailing Street', @@ -115,7 +123,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.street' }, else: { '@path': '$.properties.address.street' } } - } + }, + depends_on: hideIfDeleteOperation }, mailing_state: { label: 'Mailing State', @@ -127,7 +136,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.state' }, else: { '@path': '$.properties.address.state' } } - } + }, + depends_on: hideIfDeleteOperation }, customFields: customFields }, diff --git a/packages/destination-actions/src/destinations/salesforce/lead/index.ts b/packages/destination-actions/src/destinations/salesforce/lead/index.ts index be5aff7008..d7dede2ad6 100644 --- a/packages/destination-actions/src/destinations/salesforce/lead/index.ts +++ b/packages/destination-actions/src/destinations/salesforce/lead/index.ts @@ -10,7 +10,8 @@ import { validateLookup, enable_batching, recordMatcherOperator, - batch_size + batch_size, + hideIfDeleteOperation } from '../sf-properties' import Salesforce, { generateSalesforceRequest } from '../sf-operations' @@ -38,7 +39,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.company' }, else: { '@path': '$.properties.company' } } - } + }, + depends_on: hideIfDeleteOperation }, last_name: { label: 'Last Name', @@ -50,7 +52,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.last_name' }, else: { '@path': '$.properties.last_name' } } - } + }, + depends_on: hideIfDeleteOperation }, first_name: { label: 'First Name', @@ -62,7 +65,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.first_name' }, else: { '@path': '$.properties.first_name' } } - } + }, + depends_on: hideIfDeleteOperation }, email: { label: 'Email', @@ -74,7 +78,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.email' }, else: { '@path': '$.properties.email' } } - } + }, + depends_on: hideIfDeleteOperation }, city: { label: 'City', @@ -86,7 +91,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.city' }, else: { '@path': '$.properties.address.city' } } - } + }, + depends_on: hideIfDeleteOperation }, postal_code: { label: 'Postal Code', @@ -98,7 +104,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.postal_code' }, else: { '@path': '$.properties.address.postal_code' } } - } + }, + depends_on: hideIfDeleteOperation }, country: { label: 'Country', @@ -110,7 +117,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.country' }, else: { '@path': '$.properties.address.country' } } - } + }, + depends_on: hideIfDeleteOperation }, street: { label: 'Street', @@ -122,7 +130,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.street' }, else: { '@path': '$.properties.address.street' } } - } + }, + depends_on: hideIfDeleteOperation }, state: { label: 'State', @@ -134,7 +143,8 @@ const action: ActionDefinition = { then: { '@path': '$.traits.address.state' }, else: { '@path': '$.properties.address.state' } } - } + }, + depends_on: hideIfDeleteOperation }, customFields: customFields }, diff --git a/packages/destination-actions/src/destinations/salesforce/opportunity/index.ts b/packages/destination-actions/src/destinations/salesforce/opportunity/index.ts index 9ec852e839..f59855cd1a 100644 --- a/packages/destination-actions/src/destinations/salesforce/opportunity/index.ts +++ b/packages/destination-actions/src/destinations/salesforce/opportunity/index.ts @@ -10,7 +10,8 @@ import { validateLookup, enable_batching, recordMatcherOperator, - batch_size + batch_size, + hideIfDeleteOperation } from '../sf-properties' import type { Payload } from './generated-types' @@ -31,27 +32,32 @@ const action: ActionDefinition = { label: 'Close Date', description: 'Date when the opportunity is expected to close. Use yyyy-MM-dd format. **This is required to create an opportunity.**', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, name: { label: 'Name', description: 'A name for the opportunity. **This is required to create an opportunity.**', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, stage_name: { label: 'Stage Name', description: 'Current stage of the opportunity. **This is required to create an opportunity.**', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, amount: { label: 'Amount', description: 'Estimated total sale amount.', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, description: { label: 'Description', description: 'A text description of the opportunity.', - type: 'string' + type: 'string', + depends_on: hideIfDeleteOperation }, customFields: customFields }, diff --git a/packages/destination-actions/src/destinations/salesforce/sf-properties.ts b/packages/destination-actions/src/destinations/salesforce/sf-properties.ts index 442615b3cb..76094be1a0 100644 --- a/packages/destination-actions/src/destinations/salesforce/sf-properties.ts +++ b/packages/destination-actions/src/destinations/salesforce/sf-properties.ts @@ -1,4 +1,15 @@ import { IntegrationError, InputField } from '@segment/actions-core' +import { DependsOnConditions } from '@segment/actions-core/destination-kit/types' + +export const hideIfDeleteOperation: DependsOnConditions = { + conditions: [ + { + fieldKey: 'operation', + operator: 'is_not', + value: 'delete' + } + ] +} export const operation: InputField = { label: 'Operation', @@ -19,7 +30,8 @@ export const enable_batching: InputField = { description: 'If true, events are sent to [Salesforce’s Bulk API 2.0](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_intro.htm) rather than their streaming REST API. Once enabled, Segment will collect events into batches of 5000 before sending to Salesforce. *Enabling Bulk API is not compatible with the `create` operation*.', type: 'boolean', - default: false + default: false, + depends_on: hideIfDeleteOperation } export const batch_size: InputField = { @@ -28,7 +40,8 @@ export const batch_size: InputField = { type: 'number', required: false, unsafe_hidden: true, - default: 5000 + default: 5000, + depends_on: hideIfDeleteOperation } export const bulkUpsertExternalId: InputField = { @@ -145,7 +158,8 @@ export const customFields: InputField = { `, type: 'object', - defaultObjectUI: 'keyvalue' + defaultObjectUI: 'keyvalue', + depends_on: hideIfDeleteOperation } interface Payload {