Skip to content

Commit 69aa833

Browse files
committed
fix(apollo): mirror bulk_update guard, preserve update fields in migration, expose account_bulk_create options
1 parent ff98127 commit 69aa833

2 files changed

Lines changed: 45 additions & 17 deletions

File tree

apps/sim/blocks/blocks/apollo.ts

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,21 @@ export const ApolloBlock: BlockConfig<ApolloResponse> = {
461461
id: 'run_dedupe',
462462
title: 'Run Deduplication',
463463
type: 'switch',
464-
condition: { field: 'operation', value: 'contact_bulk_create' },
464+
condition: {
465+
field: 'operation',
466+
value: ['contact_bulk_create', 'account_bulk_create'],
467+
},
465468
mode: 'advanced',
466469
},
467470
{
468471
id: 'append_label_names',
469472
title: 'Append Label Names (JSON Array)',
470473
type: 'code',
471474
placeholder: '["Hot Lead", "Q4 Outreach"]',
472-
condition: { field: 'operation', value: 'contact_bulk_create' },
475+
condition: {
476+
field: 'operation',
477+
value: ['contact_bulk_create', 'account_bulk_create'],
478+
},
473479
mode: 'advanced',
474480
},
475481

@@ -967,29 +973,46 @@ Return ONLY the timestamp string in ISO 8601 format - no explanations, no quotes
967973
throw new Error(`Invalid JSON input: ${message}`)
968974
}
969975

970-
const extractIds = (raw: unknown): string[] | undefined => {
971-
if (!Array.isArray(raw)) return undefined
972-
return raw
973-
.map((item) => {
974-
if (typeof item === 'string') return item
975-
if (item && typeof item === 'object' && 'id' in item) {
976-
const id = (item as { id: unknown }).id
977-
return typeof id === 'string' ? id : undefined
976+
const splitBulkUpdateInput = (
977+
raw: unknown
978+
): { ids?: string[]; attributes?: Array<Record<string, unknown>> } => {
979+
if (!Array.isArray(raw)) return {}
980+
const ids: string[] = []
981+
const attributes: Array<Record<string, unknown>> = []
982+
for (const item of raw) {
983+
if (typeof item === 'string') {
984+
ids.push(item)
985+
continue
986+
}
987+
if (item && typeof item === 'object' && 'id' in item) {
988+
const obj = item as Record<string, unknown>
989+
const id = obj.id
990+
if (typeof id !== 'string') continue
991+
const otherKeys = Object.keys(obj).filter((k) => k !== 'id')
992+
if (otherKeys.length === 0) {
993+
ids.push(id)
994+
} else {
995+
attributes.push(obj)
978996
}
979-
return undefined
980-
})
981-
.filter((id): id is string => Boolean(id))
997+
}
998+
}
999+
return {
1000+
ids: ids.length > 0 ? ids : undefined,
1001+
attributes: attributes.length > 0 ? attributes : undefined,
1002+
}
9821003
}
9831004

9841005
if (params.operation === 'contact_bulk_update') {
985-
const ids = extractIds(parsedParams.contacts)
986-
if (ids) parsedParams.contact_ids = ids
1006+
const { ids, attributes } = splitBulkUpdateInput(parsedParams.contacts)
1007+
if (attributes) parsedParams.contact_attributes = attributes
1008+
if (ids && !attributes) parsedParams.contact_ids = ids
9871009
parsedParams.contacts = undefined
9881010
}
9891011

9901012
if (params.operation === 'account_bulk_update') {
991-
const ids = extractIds(parsedParams.accounts)
992-
if (ids) parsedParams.account_ids = ids
1013+
const { ids, attributes } = splitBulkUpdateInput(parsedParams.accounts)
1014+
if (attributes) parsedParams.account_attributes = attributes
1015+
if (ids && !attributes) parsedParams.account_ids = ids
9931016
parsedParams.accounts = undefined
9941017
if (rest.account_bulk_update_name) {
9951018
parsedParams.name = rest.account_bulk_update_name

apps/sim/tools/apollo/account_bulk_update.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export const apolloAccountBulkUpdateTool: ToolConfig<
9494
'Apollo account bulk update requires account_ids (with name/owner_id) or account_attributes (with embedded ids).'
9595
)
9696
}
97+
if (body.account_attributes && !Array.isArray(body.account_attributes) && !body.account_ids) {
98+
throw new Error(
99+
'Apollo account bulk update with object-form account_attributes requires account_ids to identify which accounts to update.'
100+
)
101+
}
97102
if (params.async !== undefined) body.async = params.async
98103
return body
99104
},

0 commit comments

Comments
 (0)