diff --git a/server/src/services/cloud-upstreams.ts b/server/src/services/cloud-upstreams.ts index f18c795ab1f..75d7f4e4910 100644 --- a/server/src/services/cloud-upstreams.ts +++ b/server/src/services/cloud-upstreams.ts @@ -253,9 +253,15 @@ export function cloudUpstreamService(db: Db, options: { instanceId?: string } = } const bundle = await buildBundle(connection, "preview"); + const conflictKeysBySource: Record = {}; + for (const entity of bundle.entities) { + if (!entity.conflictKeys || entity.conflictKeys.length === 0) continue; + conflictKeysBySource[sourceEntityKeyString(entity.record.key)] = [...entity.conflictKeys]; + } const remotePreview = await remotePost(connection, `/api/companies/${encodeURIComponent(connection.targetCompanyId)}/upstream-imports/preview`, { manifest: bundle.manifest, - entities: bundle.entities, + previewShape: "manifest_only", + conflictKeysBySource, }); return { ...basePreview, @@ -1059,6 +1065,12 @@ function shortHash(value: string): string { return crypto.createHash("sha256").update(value).digest("hex").slice(0, 12); } +function sourceEntityKeyString(key: SourceEntityKey): string { + return [key.sourceInstanceId, key.sourceCompanyId, key.sourceEntityType, key.sourceEntityId] + .map((part) => encodeURIComponent(part)) + .join("/"); +} + function titleFromCode(code: string): string { return code .replace(/_/g, " ")