Skip to content

Commit a6124ed

Browse files
authored
clean & convert location column type to text (#2509)
* fix style * Create 20251105175657_location_text.sql * Update contact.ts * Update MiningTable.vue * Update ContactInformationSidebar.vue * Update ContactInformationSidebar.vue * update backend * Update 20251105175657_location_text.sql * Update 20251105175657_location_text.sql * backend fixes * backend: fix location * Update enrichments.test.ts * Update enricher.test.ts * Update enricher.test.ts * Update enricher.test.ts * Update enricher.test.ts * Update enricher.test.ts * prettier * fix 'clearSyncInterval' was used before it was defined * fix style
1 parent 4f619a5 commit a6124ed

File tree

22 files changed

+275
-71
lines changed

22 files changed

+275
-71
lines changed

backend/src/db/supabase/enrichments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Logger } from 'winston';
21
import { SupabaseClient } from '@supabase/supabase-js';
2+
import { Logger } from 'winston';
33
import { TaskCategory, TaskStatus, TaskType } from '../types';
44

5+
import { TaskEnrich } from '../../services/tasks-manager/types';
56
import Engagements from './engagements';
67
import SupabaseTasks from './tasks';
7-
import { TaskEnrich } from '../../services/tasks-manager/types';
88

99
interface Contact {
1010
id: string;
@@ -14,7 +14,7 @@ interface Contact {
1414
givenName?: string;
1515
familyName?: string;
1616
alternateName?: string[];
17-
location?: string[];
17+
location?: string;
1818
organization?: string;
1919
jobTitle?: string;
2020
sameAs?: string[];
@@ -134,7 +134,7 @@ export default class Enrichments {
134134
family_name: contact.familyName,
135135
works_for: contact.organization,
136136
same_as: contact.sameAs?.join(','),
137-
location: contact.location?.join(','),
137+
location: contact.location,
138138
alternate_name: contact.alternateName?.join(','),
139139
user_id: task.userId
140140
}));

backend/src/db/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface Person {
5555
url?: string;
5656
name?: string;
5757
image?: string;
58-
location?: string[];
58+
location?: string;
5959
jobTitle?: string;
6060
sameAs?: string[];
6161
givenName?: string;
@@ -103,7 +103,7 @@ export interface Contact {
103103
given_name?: string;
104104
family_name?: string;
105105
alternate_name?: string[];
106-
location?: string[];
106+
location?: string;
107107
works_for?: string;
108108
job_title?: string;
109109
same_as?: string[];

backend/src/services/enrichment/Engine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Person {
88
family_name?: string;
99
works_for?: string;
1010
alternate_name?: string[];
11-
location?: string[];
11+
location?: string;
1212
same_as?: string[];
1313
identifiers: string[];
1414
}
@@ -17,7 +17,7 @@ export interface EngineResult {
1717
email: string;
1818
name?: string;
1919
image?: string;
20-
location?: string[];
20+
location?: string;
2121
jobTitle?: string;
2222
organization?: string;
2323
givenName?: string;

backend/src/services/enrichment/enrich-layer/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ export default class EnrichLayer implements Engine {
8181
Boolean(id)
8282
)
8383
),
84-
location: undefinedIfEmpty([
84+
location: undefinedIfFalsy(
8585
[
8686
response?.profile?.city,
8787
response?.profile?.state,
8888
response?.profile?.country_full_name
8989
]
9090
.filter((loc): loc is string => Boolean(loc))
9191
.join(', ')
92-
]),
92+
),
9393
sameAs: undefinedIfEmpty([
9494
response?.linkedin_profile_url,
9595
response?.facebook_profile_url,

backend/src/services/enrichment/thedig/client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export interface EnrichPersonRequest {
2424
identifier?: string[];
2525
nationality?: string[];
2626
description?: string[];
27-
homeLocation?: string[];
28-
workLocation?: string[];
27+
homeLocation?: string;
28+
workLocation?: string;
2929
alternateName?: string[];
3030
knowsLanguage?: string[];
3131
}
@@ -39,8 +39,8 @@ export interface EnrichPersonResponse {
3939
image?: string[];
4040
jobTitle?: string[];
4141
worksFor?: string[];
42-
homeLocation?: string[];
43-
workLocation?: string[];
42+
homeLocation?: string;
43+
workLocation?: string;
4444
sameAs?: string[];
4545
identifier?: string[];
4646
description?: string[];

backend/src/services/enrichment/thedig/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Logger } from 'winston';
2+
import {
3+
undefinedIfEmpty,
4+
undefinedIfFalsy
5+
} from '../../../utils/helpers/validation';
26
import { Engine, EngineResult, Person } from '../Engine';
37
import VoilanorbertApi, {
48
EnrichPersonRequest,
59
EnrichPersonResponse
610
} from './client';
7-
import {
8-
undefinedIfEmpty,
9-
undefinedIfFalsy
10-
} from '../../../utils/helpers/validation';
1111

1212
export default class Thedig implements Engine {
1313
readonly name = 'thedig';
@@ -111,11 +111,11 @@ export default class Thedig implements Engine {
111111
sameAs: undefinedIfEmpty(person.sameAs ?? []),
112112
identifiers: undefinedIfEmpty(person.identifier ?? []),
113113
alternateName: undefinedIfEmpty(person.alternateName ?? []),
114-
location: undefinedIfEmpty(
115-
[
116-
[person.homeLocation].flat().filter(Boolean).join(','),
117-
[person.workLocation].flat().filter(Boolean).join(',')
118-
].flat()
114+
location: undefinedIfFalsy(
115+
[person.homeLocation, person.workLocation]
116+
.flat()
117+
.filter(Boolean)
118+
.join(', ')
119119
)
120120
}))
121121
.filter(

backend/src/services/enrichment/voilanorbert/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class Voilanorbert implements Engine {
7474
name: undefinedIfFalsy(result.fullName),
7575
organization: undefinedIfFalsy(result.organization),
7676
jobTitle: undefinedIfFalsy(result.title),
77-
location: undefinedIfEmpty([result.location]),
77+
location: undefinedIfFalsy(result.location),
7878
sameAs: undefinedIfEmpty([
7979
result.facebook,
8080
result.linkedin,

backend/src/services/extractors/engines/FileImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class CsvXlsxContactEngine {
8383
familyName: undefinedIfFalsy(familyName ?? ''),
8484
jobTitle: undefinedIfFalsy(jobTitle ?? ''),
8585
image: undefinedIfFalsy(image ?? ''),
86-
location: undefinedIfEmpty(location?.split(',') ?? []),
86+
location: undefinedIfFalsy(location ?? ''),
8787
sameAs: undefinedIfEmpty(sameAs?.split(',') ?? []),
8888
worksFor: undefinedIfFalsy(worksFor ?? ''),
8989
alternateName: undefinedIfEmpty(alternateName?.split(',') ?? [])

backend/src/services/signature/llm/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Logger } from 'winston';
21
import assert from 'assert';
3-
import { IRateLimiter } from '../../rate-limiter/RateLimiter';
4-
import { ExtractSignature, PersonLD } from '../types';
2+
import { Logger } from 'winston';
53
import {
6-
undefinedIfFalsy,
7-
undefinedIfEmpty
4+
undefinedIfEmpty,
5+
undefinedIfFalsy
86
} from '../../../utils/helpers/validation';
7+
import { IRateLimiter } from '../../rate-limiter/RateLimiter';
8+
import { ExtractSignature, PersonLD } from '../types';
99
import {
10+
parseLocationString,
1011
parseString,
1112
parseStringArray,
1213
removeFalsePositives,
@@ -254,7 +255,7 @@ export class SignatureLLM implements ExtractSignature {
254255
// name: undefinedIfFalsy(parseString(person.name)),
255256
jobTitle: undefinedIfFalsy(parseString(person.jobTitle)),
256257
worksFor: undefinedIfFalsy(parseString(person.worksFor)),
257-
address: undefinedIfEmpty(parseStringArray(person.address) ?? []),
258+
address: undefinedIfFalsy(parseLocationString(person.address)),
258259
telephone: undefinedIfEmpty(
259260
validatePhones(signature, parseStringArray(person.telephone) ?? [])
260261
),

backend/src/services/signature/llm/output-checkers.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ export function parseStringArray(value: unknown): string[] | undefined {
7373
return cleaned.length ? [...new Set(cleaned)] : undefined;
7474
}
7575

76+
export function parseLocationString(value: unknown): string | undefined {
77+
if (!value) return undefined;
78+
79+
const combined = Array.isArray(value) ? value.join(', ') : String(value);
80+
81+
return (
82+
combined
83+
.replace(/\\n|\n/g, ', ') // replace literal or real newlines with ", "
84+
.replace(/\s*,\s*/g, ', ') // normalize commas and spaces
85+
.replace(/\s{2,}/g, ' ') // collapse multiple spaces
86+
.trim() || undefined
87+
);
88+
}
89+
7690
export function removeFalsePositives(
7791
person: PersonLD,
7892
signature: string,

0 commit comments

Comments
 (0)