import { InitOptions } from '../../core/analytics' import { Plugin } from '../../core/plugin' import { logger } from '../logger' import { version } from './constants' import { load6Sense } from './sources/6sense' import { loadAlbacross } from './sources/albacross' import { loadClearbitV1 } from './sources/clearbitV1' import { loadClearbitV2 } from './sources/clearbitV2' import { loadDealfront } from './sources/dealfront' import { loadDemandbase } from './sources/demandbase' import { loadRollworks } from './sources/rollworks' import { loadSnitcher } from './sources/snitcher' import { loadTriblio } from './sources/triblio' import { loadZoomInfo } from './sources/zoominfo' import { IIntentSource } from './types' import { getMatchingSources, verifyOptions } from './utils' const SOURCES: IIntentSource[] = [ { name: '6sense', load: [load6Sense], }, { name: 'albacross', load: [loadAlbacross], }, { name: 'clearbit', load: [loadClearbitV1], }, { name: 'dealfront', load: [loadDealfront], }, { name: 'demandbase', load: [loadDemandbase], }, { name: 'rollworks', load: [loadRollworks], }, { name: 'snitcher', load: [loadSnitcher], }, { name: 'triblio', load: [loadTriblio], }, { name: 'zoomInfo', load: [loadZoomInfo], }, { name: 'autoGroup', load: [ load6Sense, loadAlbacross, loadDealfront, loadDemandbase, loadRollworks, loadTriblio, loadZoomInfo, loadClearbitV2, ], }, ] export const ddIntentSources = (options: InitOptions): Plugin => { return { name: 'IntentSources', type: 'utility', version, isLoaded: () => true, load: async (ctx, analytics) => { const intentSourcesOptions = options.intentSources || {} if (!verifyOptions(intentSourcesOptions)) { return } logger.debug('Enabling intent sources using options', { intentSourcesOptions, }) const matchingSources = getMatchingSources(SOURCES, intentSourcesOptions) const promises: (void | Promise)[] = [] for (const source of matchingSources) { let sourceOptions = intentSourcesOptions[source.name] if (typeof sourceOptions !== 'object') { sourceOptions = {} } for (const load of source.load) { promises.push(load(analytics, sourceOptions)) } } await Promise.all(promises) return ctx }, } }