Skip to content

Commit

Permalink
Revert "SALTO-5481: add reference to support address v2 (#7130)" (#7160)
Browse files Browse the repository at this point in the history
This reverts commit bb728a4.
  • Loading branch information
shayc331 authored Jan 24, 2025
1 parent 32c2912 commit b5c9845
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 38 deletions.
4 changes: 2 additions & 2 deletions packages/zendesk-adapter/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export const DEFAULT_FILTERS = [
organizationsFilter,
tagsFilter,
localeFilter,
// supportAddress should run before referencedIdFieldsFilter
supportAddress,
customStatus,
guideAddBrandToArticleTranslation,
macroFilter,
Expand Down Expand Up @@ -247,8 +249,6 @@ export const DEFAULT_FILTERS = [
// fieldReferencesFilter should be after:
// usersFilter, macroAttachmentsFilter, tagsFilter, guideLocalesFilter, customObjectFilter, customObjectFieldFilter
fieldReferencesFilter,
// supportAddress should run before referencedIdFieldsFilter and after fieldReferencesFilter
supportAddress,
// listValuesMissingReferencesFilter should be after fieldReferencesFilter
listValuesMissingReferencesFilter,
appInstallationsFilter,
Expand Down
43 changes: 7 additions & 36 deletions packages/zendesk-adapter/src/filters/field_references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* CERTAIN THIRD PARTY SOFTWARE MAY BE CONTAINED IN PORTIONS OF THE SOFTWARE. See NOTICE FILE AT https://github.com/salto-io/salto/blob/main/NOTICES
*/
import _ from 'lodash'
import { Element, isInstanceElement, isTemplateExpression } from '@salto-io/adapter-api'
import { Element, isInstanceElement } from '@salto-io/adapter-api'
import { references as referenceUtils } from '@salto-io/adapter-components'
import { GetLookupNameFunc } from '@salto-io/adapter-utils'
import { FilterCreator } from '../filter'
Expand Down Expand Up @@ -39,7 +39,6 @@ import {
BOT_BUILDER_NODE,
BOT_BUILDER_ANSWER,
CONVERSATION_BOT,
SUPPORT_ADDRESS_TYPE_NAME,
BUSINESS_HOUR_SCHEDULE,
} from '../constants'
import { FETCH_CONFIG } from '../config'
Expand All @@ -48,7 +47,6 @@ import {
ZendeskMissingReferenceStrategyName,
} from './references/missing_references'
import { ZendeskUserConfig } from '../user_config'
import { replaceIfReferenceExpression } from './support_address'

const { neighborContextGetter } = referenceUtils

Expand Down Expand Up @@ -169,7 +167,7 @@ const neighborReferenceUserAndOrgFieldLookupFunc: GetLookupNameFunc = async ({ r
const neighborReferenceUserAndOrgFieldLookupType: referenceUtils.ContextValueMapperFunc = val =>
[USER_FIELD_OPTION_TYPE_NAME, ORG_FIELD_OPTION_TYPE_NAME].includes(val) ? val : undefined

type ZendeskReferenceIndexField = 'key' | 'value' | 'locale' | 'email'
type ZendeskReferenceIndexField = 'key' | 'value' | 'locale'
type ZendeskReferenceSerializationStrategyName =
| 'ticketField'
| 'value'
Expand All @@ -184,7 +182,6 @@ type ZendeskReferenceSerializationStrategyName =
| 'idString'
| 'customObjectKey'
| 'customStatusField'
| 'email'

const getSerializationStrategyOfCustomFieldByContainingType = (
prefix: string,
Expand Down Expand Up @@ -238,18 +235,6 @@ const ZendeskReferenceSerializationStrategyLookup: Record<
lookup: val => val,
lookupIndexName: 'value',
},
email: {
serialize: ({ ref }) => {
if (isInstanceElement(ref.value)) {
// the email in the support address is turned to a template expression, we need to serialize this too.
const val = ref.value.value.email
return isTemplateExpression(val) ? val.parts.map(replaceIfReferenceExpression).join('') : val
}
return ref.value
},
lookup: val => val,
lookupIndexName: 'email',
},
localeId: {
serialize: ({ ref }) =>
// locale_id may be missing reference
Expand Down Expand Up @@ -296,8 +281,7 @@ const ZendeskReferenceSerializationStrategyLookup: Record<

export type ReferenceContextStrategyName =
| 'neighborField'
| 'allowListedNeighborField'
| 'allowListedEmailNeighborField'
| 'allowlistedNeighborField'
| 'allowlistedNeighborSubject'
| 'neighborType'
| 'parentSubject'
Expand All @@ -314,11 +298,7 @@ export const contextStrategyLookup: Record<ReferenceContextStrategyName, referen
neighborField: neighborContextFunc({ contextFieldName: 'field', contextValueMapper: getValueLookupType }),
// We use allow lists because there are types we don't support (such as organization or requester)
// and they'll end up being false positives
allowListedNeighborField: neighborContextFunc({ contextFieldName: 'field', contextValueMapper: allowListLookupType }),
allowListedEmailNeighborField: neighborContextFunc({
contextFieldName: 'field',
contextValueMapper: val => (val === 'recipient' ? SUPPORT_ADDRESS_TYPE_NAME : undefined),
}),
allowlistedNeighborField: neighborContextFunc({ contextFieldName: 'field', contextValueMapper: allowListLookupType }),
allowlistedNeighborSubject: neighborContextFunc({
contextFieldName: 'subject',
contextValueMapper: allowListLookupType,
Expand Down Expand Up @@ -659,15 +639,6 @@ const firstIterationFieldNameToTypeMappingDefs: ZendeskFieldReferenceDefinition[
zendeskMissingRefStrategy: 'startsWith',
target: { type: TICKET_FIELD_TYPE_NAME },
},
{
src: {
field: 'value',
parentTypes: ['trigger__conditions__all', 'trigger__conditions__any'],
},
serializationStrategy: 'email',
target: { typeContext: 'allowListedEmailNeighborField' },
zendeskMissingRefStrategy: 'typeAndValue',
},
{
src: {
field: 'subject',
Expand Down Expand Up @@ -994,7 +965,7 @@ const commonFieldNameToTypeMappingDefs: ZendeskFieldReferenceDefinition[] = [
parentTypes: ['trigger__actions'],
},
serializationStrategy: 'idString',
target: { typeContext: 'allowListedNeighborField' },
target: { typeContext: 'allowlistedNeighborField' },
zendeskMissingRefStrategy: 'typeAndValue',
},

Expand Down Expand Up @@ -1047,7 +1018,7 @@ const commonFieldNameToTypeMappingDefs: ZendeskFieldReferenceDefinition[] = [
'queue__definition__any',
],
},
target: { typeContext: 'allowListedNeighborField' },
target: { typeContext: 'allowlistedNeighborField' },
zendeskMissingRefStrategy: 'typeAndValue',
},
{
Expand Down Expand Up @@ -1213,7 +1184,7 @@ export const fieldReferencesOnFetch = async (elements: Element[], config: Zendes
await referenceUtils.addReferences({
elements,
defs: fixedDefs,
fieldsToGroupBy: ['id', 'name', 'key', 'value', 'locale', 'email'],
fieldsToGroupBy: ['id', 'name', 'key', 'value', 'locale'],
contextStrategyLookup,
// since ids and references to ids vary inconsistently between string/number, allow both
fieldReferenceResolverCreator: defs => new ZendeskFieldReferenceResolver(defs),
Expand Down

0 comments on commit b5c9845

Please sign in to comment.