Skip to content

Commit f48ed78

Browse files
committed
Merge branch 'main' into crowd-linux
2 parents 0aab9a7 + 872f5e0 commit f48ed78

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

backend/src/services/organizationService.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LoggerBase } from '@crowd/logging'
2+
import { websiteNormalizer } from '@crowd/common'
23
import { CLEARBIT_CONFIG, IS_TEST_ENV } from '../conf'
34
import MemberRepository from '../database/repositories/memberRepository'
45
import organizationCacheRepository from '../database/repositories/organizationCacheRepository'
@@ -43,6 +44,11 @@ export default class OrganizationService extends LoggerBase {
4344
transaction,
4445
})
4546

47+
// Normalize the website URL if it exists
48+
if (data.website) {
49+
data.website = websiteNormalizer(data.website)
50+
}
51+
4652
// if cache exists, merge current data with cache data
4753
// if it doesn't exist, create it from incoming data
4854
if (cache) {
@@ -146,6 +152,11 @@ export default class OrganizationService extends LoggerBase {
146152
})
147153
}
148154

155+
// Normalize the website URL if it exists
156+
if (data.website) {
157+
data.website = websiteNormalizer(data.website)
158+
}
159+
149160
const record = await OrganizationRepository.update(id, data, {
150161
...this.options,
151162
transaction,

services/apps/data_sink_worker/src/service/organization.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { OrganizationRepository } from '@/repo/organization.repo'
66
import { DbStore } from '@crowd/database'
77
import { Logger, LoggerBase, getChildLogger } from '@crowd/logging'
88
import { IOrganization, IOrganizationSocial, PlatformType } from '@crowd/types'
9+
import { websiteNormalizer } from '@crowd/common'
910

1011
export class OrganizationService extends LoggerBase {
1112
private readonly repo: OrganizationRepository
@@ -23,6 +24,11 @@ export class OrganizationService extends LoggerBase {
2324
): Promise<string> {
2425
data = this.normalizeSocialFields(data)
2526

27+
// Normalize the website URL if it exists
28+
if (data.website) {
29+
data.website = websiteNormalizer(data.website)
30+
}
31+
2632
// find from cache by name
2733
let cached = await this.repo.findCacheByName(data.name)
2834

services/libs/common/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/libs/common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"dependencies": {
3030
"@crowd/logging": "file:../logging",
3131
"@crowd/types": "file:../types",
32+
"psl": "^1.9.0",
3233
"uuid": "^9.0.0"
3334
}
3435
}

services/libs/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from './requestThrottler'
1111
export * from './rawQueryParser'
1212
export * from './byteLength'
1313
export * from './http'
14+
export * from './websiteNormalizer'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { parse, isValid } from 'psl'
2+
3+
export const websiteNormalizer = (website: string): string => {
4+
// remove http:// or https://
5+
const cleanURL = website.replace(/(^\w+:|^)\/\//, '')
6+
const parsed = parse(cleanURL)
7+
8+
if (!isValid(cleanURL)) {
9+
return null
10+
}
11+
12+
return parsed.domain
13+
}

0 commit comments

Comments
 (0)