|
| 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