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 15 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 [email protected] 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
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions functions/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const corsHeaders = {
"Access-Control-Allow-Origin": "*",
koya0 marked this conversation as resolved.
Show resolved Hide resolved
};
60 changes: 60 additions & 0 deletions functions/tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { corsHeaders } from "./helpers";

export async function onRequest(ctx) {
const { request, env } = ctx;

const url = new URL(request.url);

try {
switch (request.method) {
case "POST":
return handleSet(url, env);

case "GET":
if (url.searchParams.has("key")) {
return handleGet(url.searchParams.get("key"), env);
} else {
return handleList(env);
}

default:
return new Response("Method Not Allowed", { headers: corsHeaders, status: 405 });
}
} catch (error) {
console.error("Error processing request:", error);
return new Response("Internal Server Error", { headers: corsHeaders, status: 500 });
}
}

async function handleSet(url, env) {
const key = url.searchParams.get("key");
const value = url.searchParams.get("value");

if (key && value) {
await env.userToReferral.put(key, value);
return new Response(`Key '${key}' added with value '${value}'`, { headers: corsHeaders, status: 200 });
}
return new Response("Missing key or value", { headers: corsHeaders, status: 400 });
}

async function handleGet(key, env) {
const value = await env.userToReferral.get(key);
if (value) {
return new Response(`Value for '${key}': ${value}`, { headers:corsHeaders, status: 200 });
}
return new Response(`No value found for '${key}'`, { headers: corsHeaders, status: 404 });
}

async function handleList(env) {
const keys = await env.userToReferral.list();
const keyValuePairs = {};

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

return new Response(JSON.stringify(keyValuePairs, null, 2), {
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
}

2 changes: 1 addition & 1 deletion src/home/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
25 changes: 17 additions & 8 deletions src/home/devrel-tracker.ts
Original file line number Diff line number Diff line change
@@ -1,22 +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("devRel");
const devRelCode = urlParams.get("ref");
if (devRelCode) {
localStorage.setItem("devRel", devRelCode);
}
}
}
koya0 marked this conversation as resolved.
Show resolved Hide resolved

export function trackDevRelReferral(devGithub: string) {
export async function trackDevRelReferral(devGitHubId: number) {
const devRelCode = localStorage.getItem("devRel");
koya0 marked this conversation as resolved.
Show resolved Hide resolved

// key: user_id (devGitHubId), value: referral_id (devRelCode)
if (devRelCode && devRelCode != "done") {
// @ts-expect-error : using global gtag
gtag("event", "ethSeoul_registration", {
devRel: devRelCode,
devGithub: devGithub,
const url = `${WORKER_URL}/tracker?key=${encodeURIComponent(devGitHubId)}&value=${encodeURIComponent(devRelCode)}`;
koya0 marked this conversation as resolved.
Show resolved Hide resolved

const response = await fetch(url, {
method: 'POST',
});
localStorage.setItem("devRel", "done");

if (response.status === 200) {
localStorage.setItem("devRel", "done");
} else {
console.error(`Failed to set referral. Status: ${response.status}`);
}
}
}
}
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}/tracker?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}/tracker`;

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;
}
}
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
3 changes: 3 additions & 0 deletions worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Env {
myKVNamespace: KVNamespace;
}
Loading
Loading