Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement new tracker #123

Merged
merged 47 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d7d7378
chore: add node-fetch
koya0 Oct 12, 2024
a8f4e51
feat: add WORKER_URL to .env
koya0 Oct 12, 2024
a722e83
feat: add WORKER_URL to bundler
koya0 Oct 12, 2024
11860cb
feat: remove gtag.js
koya0 Oct 12, 2024
134db4d
feat: write new referral tracker
koya0 Oct 12, 2024
f4fc997
feat: adapt auth script to use new tracker
koya0 Oct 12, 2024
9fff8f0
feat: new getters for new tracker
koya0 Oct 12, 2024
80a8955
chore: remove node-fetch
koya0 Oct 12, 2024
0e41a0f
feat: create tracking folder
koya0 Oct 12, 2024
0433ba4
feat: create cloudflare worker file
koya0 Oct 12, 2024
c3d5645
chore: update lock file using yarn@3.6.3 to match yarn version of Clo…
koya0 Oct 13, 2024
ba5bfde
chore: bun install
koya0 Oct 13, 2024
2f52bbf
feat: implement Cloudflare Page
koya0 Oct 14, 2024
084200d
feat: changed tracker.ts to .js
koya0 Oct 14, 2024
adf4f16
feat: add CORS headers to tracker.js responses
koya0 Oct 14, 2024
c01ed2a
feat: change .js files to .ts
koya0 Oct 15, 2024
181d00f
style: fixed formatting
koya0 Oct 15, 2024
942ae09
chore: bun install
koya0 Oct 15, 2024
b0e1bef
feat: implement GitHub Auth for tracker
koya0 Oct 16, 2024
a37f0e9
feat: update CORS Headers
koya0 Oct 16, 2024
ae87f15
feat: added CORS Headers to devrel-tracker.ts request and method "OPT…
koya0 Oct 16, 2024
2c7a6a7
feat: remove CORS Headers from devrel-tracker.ts and types.ts
koya0 Oct 16, 2024
4667f12
feat: fixed githubUserId and added providerToken checker
koya0 Oct 16, 2024
c59954d
feat: change GitHubAccessToken to SupabaseSession token
koya0 Oct 16, 2024
691d6c3
feat: removed key and value parameters of POST request and added refe…
koya0 Oct 19, 2024
4f3691c
feat: create wrangler.toml
koya0 Oct 19, 2024
6b53a77
feat: update kv-namespace id
koya0 Oct 19, 2024
47a705b
feat: remove WORKER_URL
koya0 Oct 19, 2024
3a91e50
feat: change CustomRequest to Request from @cloudflare/workers-types
koya0 Oct 19, 2024
acf600c
feat: change Supabase Auth Object to Github Auth Token for tracker auth
koya0 Oct 19, 2024
55889a7
feat: change Github issues json
koya0 Oct 19, 2024
2802d52
feat: change SUPABASE vars
koya0 Oct 19, 2024
929d477
feat: remove ?ref= from URL after auth
koya0 Oct 19, 2024
48741f3
chore: fix fetch-issues-full.ts comment conflict
koya0 Oct 20, 2024
316bfd5
feat: change tracker.ts name to referral-manager
koya0 Oct 23, 2024
825b21a
chore: change vars to secrets
koya0 Oct 23, 2024
6f5fa3e
feat: remove support for old tracker
koya0 Oct 23, 2024
7388232
style: change githubUserId vars for gitHubUserId
koya0 Oct 25, 2024
287e9b5
feat: moved oldRefCode checker to functions
koya0 Oct 25, 2024
d8811d9
Merge branch 'development' of https://github.com/ubiquity/work.ubq.fi…
koya0 Oct 26, 2024
35ff1c4
feat: store refCode in localStorage
koya0 Oct 26, 2024
18f3779
chore: replace @cloudflare/wrangler to wrangler and change start comm…
koya0 Oct 26, 2024
1a6b52e
chore: bun install
koya0 Oct 26, 2024
845a453
chore: remove bun.lockb
koya0 Oct 26, 2024
d1698a6
chore: update yarn.lock to v1.22.22
koya0 Oct 26, 2024
ba0d259
Merge branch 'development' of https://github.com/ubiquity/work.ubq.fi…
koya0 Oct 26, 2024
1831918
chore: add YARN_VERSION to wrangler.toml
koya0 Oct 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
SUPABASE_URL=
SUPABASE_ANON_KEY=
WORKER_URL=
2 changes: 1 addition & 1 deletion build/esbuild-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const esBuildContext: esbuild.BuildOptions = {
".json": "dataurl",
},
outdir: "static/dist",
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], {
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY", "WORKER_URL"], {
SUPABASE_STORAGE_KEY: generateSupabaseStorageKey(),
GIT_REVISION: execSync(`git rev-parse --short HEAD`).toString().trim(),
NODE_ENV: process.env.NODE_ENV || "development",
Expand Down
4 changes: 2 additions & 2 deletions src/home/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trackDevRelReferral } from "./devrel-tracker";
import { trackDevRelReferral } from "./tracking/devrel-tracker";
import { getGitHubAccessToken } from "./getters/get-github-access-token";
import { getGitHubUser } from "./getters/get-github-user";
import { GitHubUser } from "./github-types";
Expand All @@ -13,7 +13,7 @@ export async function authentication() {

const gitHubUser: null | GitHubUser = await getGitHubUser();
if (gitHubUser) {
trackDevRelReferral(gitHubUser.login + "|" + gitHubUser.id);
await trackDevRelReferral(gitHubUser.id);
await displayGitHubUserInformation(gitHubUser);
}
}
22 changes: 0 additions & 22 deletions src/home/devrel-tracker.ts

This file was deleted.

36 changes: 36 additions & 0 deletions src/home/getters/get-github-referrals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
declare const WORKER_URL: string; // @DEV: passed in at build time check build/esbuild-build.ts

export async function getReferralFromUser(devGitHubId: number): Promise<string | null> {
const url = `${WORKER_URL}/get?key=${encodeURIComponent(devGitHubId)}`;

const response = await fetch(url, {
method: 'GET',
});

if (response.status === 200) {
const referralId = await response.text();
return referralId;
} else if (response.status == 404) {
// No referral id found for devGitHubId
return null;
} else {
console.error(`Failed to get key: '${devGitHubId}'. Status: ${response.status}`);
return null;
}
}

export async function getListOfReferrals(): Promise<any> {
const url = `${WORKER_URL}/list`;

const response = await fetch(url, {
method: 'GET',
});

if (response.status === 200) {
const data = await response.json();
return data; // return JSON file of pairs {key, value}
} else {
console.error(`Failed to fetch list. Status: ${response.status}`);
return null;
}
}
2 changes: 1 addition & 1 deletion src/home/home.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { grid } from "../the-grid";
import { authentication } from "./authentication";
import { initiateDevRelTracking } from "./devrel-tracker";
import { initiateDevRelTracking } from "./tracking/devrel-tracker";
import { displayGitHubIssues } from "./fetch-github/fetch-and-display-previews";
import { readyToolbar } from "./ready-toolbar";
import { registerServiceWorker } from "./register-service-worker";
Expand Down
53 changes: 53 additions & 0 deletions src/home/tracking/cloudflare-tracking-worker.js
koya0 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});

const corsHeaders = {
"Access-Control-Allow-Origin": "*",
};

async function handleRequest(request) {
const url = new URL(request.url);

if (url.pathname === '/set') {
const key = url.searchParams.get('key');
const value = url.searchParams.get('value');

if(key && value) {
await userToReferral.put(key, value);

return new Response(`Key '${key}' added with value '${value}'`, { headers: corsHeaders, status: 200 });
} else {
return new Response('Missing key or value in query params', { headers: corsHeaders, status: 400 });
}
}

if (url.pathname === '/get') {
const key = url.searchParams.get('key');

if (key) {
const value = await userToReferral.get(key);

return value ?
new Response(`Value for '${key}': ${value}`, { headers: corsHeaders, status: 200 }) :
new Response(`No value found for '${key}'`, { headers: corsHeaders, status: 404 });
} else {
return new Response('Missing key in query params', { headers: corsHeaders, status: 400 });
}
}

if (url.pathname == '/list') {
const keys = await userToReferral.list(); // get at max 1000 keys
const keyValuePairs = {};

for (const key of keys.keys) {
const value = await userToReferral.get(key.name);
keyValuePairs[key.name] = value;
}

return new Response(JSON.stringify(keyValuePairs, null, 2), {
headers: {...corsHeaders, 'Content-Type': 'application/json' },
});
}
return new Response('Not Found', { headers: corsHeaders, status: 404 });
}
31 changes: 31 additions & 0 deletions src/home/tracking/devrel-tracker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
declare const WORKER_URL: string; // @DEV: passed in at build time check build/esbuild-build.ts

export function initiateDevRelTracking() {
const oldDevRelCode = localStorage.getItem("devRel");
if (!oldDevRelCode) {
const urlParams = new URLSearchParams(window.location.search);
const devRelCode = urlParams.get("ref");
if (devRelCode) {
localStorage.setItem("devRel", devRelCode);
}
}
}

export async function trackDevRelReferral(devGitHubId: number) {
const devRelCode = localStorage.getItem("devRel");

// key: user_id (devGitHubId), value: referral_id (devRelCode)
if (devRelCode && devRelCode != "done") {
const url = `${WORKER_URL}/set?key=${encodeURIComponent(devGitHubId)}&value=${encodeURIComponent(devRelCode)}`;

const response = await fetch(url, {
method: 'POST',
});

if (response.status === 200) {
localStorage.setItem("devRel", "done");
} else {
console.error(`Failed to set referral. Status: ${response.status}`);
}
}
}
12 changes: 0 additions & 12 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@
<meta charset="UTF-8" />
<title>DevPool Directory | Ubiquity DAO</title>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-VZLJ61H1YM"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());

gtag("config", "G-VZLJ61H1YM");
</script>

<link rel="stylesheet" href="style/style.css" />
<link rel="stylesheet" href="style/inverted-style.css" />
<link rel="stylesheet" href="style/special.css" />
Expand Down
Loading
Loading