Skip to content

Commit d89a5ee

Browse files
committed
fix(test): after rebase + added referrars test and more sites
1 parent 157f2f6 commit d89a5ee

File tree

11 files changed

+351
-2832
lines changed

11 files changed

+351
-2832
lines changed

apps/api/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"testing": "API_PORT=3333 pnpm dev",
77
"start": "node dist/index.js",
88
"build": "rm -rf dist && tsup",
9-
"gen:referrers": "jiti scripts/get-referrers.ts && biome format --write src/referrers/index.ts",
109
"gen:bots": "jiti scripts/get-bots.ts && biome format --write src/bots/bots.ts",
1110
"typecheck": "tsc --noEmit"
1211
},

apps/api/scripts/get-referrers.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

apps/api/src/referrers/index.ts

Lines changed: 0 additions & 2685 deletions
This file was deleted.

apps/api/src/referrers/referrers.readme.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

apps/worker/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"testing": "WORKER_PORT=9999 pnpm dev",
88
"start": "node dist/index.js",
99
"build": "rm -rf dist && tsup",
10-
"typecheck": "tsc --noEmit"
10+
"typecheck": "tsc --noEmit",
11+
"gen:referrers": "jiti scripts/get-referrers.ts && biome format --write ./src/referrers/index.ts"
1112
},
1213
"dependencies": {
1314
"@bull-board/api": "5.21.0",

apps/worker/scripts/get-referrers.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
4+
// extras
5+
const extraReferrers = {
6+
'zoom.us': { type: 'social', name: 'Zoom' },
7+
'apple.com': { type: 'tech', name: 'Apple' },
8+
'adobe.com': { type: 'tech', name: 'Adobe' },
9+
'figma.com': { type: 'tech', name: 'Figma' },
10+
'wix.com': { type: 'commerce', name: 'Wix' },
11+
'gmail.com': { type: 'email', name: 'Gmail' },
12+
'notion.so': { type: 'tech', name: 'Notion' },
13+
'ebay.com': { type: 'commerce', name: 'eBay' },
14+
'github.com': { type: 'tech', name: 'GitHub' },
15+
'gitlab.com': { type: 'tech', name: 'GitLab' },
16+
'slack.com': { type: 'social', name: 'Slack' },
17+
'etsy.com': { type: 'commerce', name: 'Etsy' },
18+
'bsky.app': { type: 'social', name: 'Bluesky' },
19+
'twitch.tv': { type: 'content', name: 'Twitch' },
20+
'dropbox.com': { type: 'tech', name: 'Dropbox' },
21+
'outlook.com': { type: 'email', name: 'Outlook' },
22+
'medium.com': { type: 'content', name: 'Medium' },
23+
'paypal.com': { type: 'commerce', name: 'PayPal' },
24+
'discord.com': { type: 'social', name: 'Discord' },
25+
'stripe.com': { type: 'commerce', name: 'Stripe' },
26+
'spotify.com': { type: 'content', name: 'Spotify' },
27+
'netflix.com': { type: 'content', name: 'Netflix' },
28+
'whatsapp.com': { type: 'social', name: 'WhatsApp' },
29+
'shopify.com': { type: 'commerce', name: 'Shopify' },
30+
'microsoft.com': { type: 'tech', name: 'Microsoft' },
31+
'alibaba.com': { type: 'commerce', name: 'Alibaba' },
32+
'telegram.org': { type: 'social', name: 'Telegram' },
33+
'substack.com': { type: 'content', name: 'Substack' },
34+
'salesforce.com': { type: 'tech', name: 'Salesforce' },
35+
'instagram.com': { type: 'social', name: 'Instagram' },
36+
'wikipedia.org': { type: 'content', name: 'Wikipedia' },
37+
'mastodon.social': { type: 'social', name: 'Mastodon' },
38+
'office.com': { type: 'tech', name: 'Microsoft Office' },
39+
'squarespace.com': { type: 'commerce', name: 'Squarespace' },
40+
'stackoverflow.com': { type: 'tech', name: 'Stack Overflow' },
41+
'teams.microsoft.com': { type: 'social', name: 'Microsoft Teams' },
42+
};
43+
44+
function transform(data: any) {
45+
const obj: Record<string, unknown> = {};
46+
for (const type in data) {
47+
for (const name in data[type]) {
48+
const domains = data[type][name].domains ?? [];
49+
for (const domain of domains) {
50+
obj[domain] = {
51+
type,
52+
name,
53+
};
54+
}
55+
}
56+
}
57+
58+
return obj;
59+
}
60+
61+
async function main() {
62+
// Get document, or throw exception on error
63+
try {
64+
const data = await fetch(
65+
'https://s3-eu-west-1.amazonaws.com/snowplow-hosted-assets/third-party/referer-parser/referers-latest.json',
66+
).then((res) => res.json());
67+
68+
fs.writeFileSync(
69+
path.resolve(__dirname, '../../worker/src/referrers/index.ts'),
70+
[
71+
'// This file is generated by the script get-referrers.ts',
72+
'',
73+
'// The data is fetch from snowplow-referer-parser https://github.com/snowplow-referer-parser/referer-parser',
74+
`// The orginal referers.yml is based on Piwik's SearchEngines.php and Socials.php, copyright 2012 Matthieu Aubry and available under the GNU General Public License v3.`,
75+
'',
76+
`const referrers: Record<string, { type: string, name: string }> = ${JSON.stringify(
77+
{
78+
...transform(data),
79+
...extraReferrers,
80+
},
81+
)} as const;`,
82+
'export default referrers;',
83+
].join('\n'),
84+
'utf-8',
85+
);
86+
} catch (e) {
87+
console.log(e);
88+
}
89+
}
90+
91+
main();

0 commit comments

Comments
 (0)