From cb1f22b59cceb706873712b5a3d48ea19c4f9e6e Mon Sep 17 00:00:00 2001 From: Anush Date: Fri, 26 May 2023 18:41:53 +0530 Subject: [PATCH 1/3] feat: opt log out --- npm-shrinkwrap.json | 21 +++++++++++++-------- package.json | 4 ++-- src/constants.ts | 1 + src/pages/profile.tsx | 20 ++++++++++---------- src/pages/start.tsx | 10 ++++------ src/utils/checkAuthentication.ts | 22 +++++++++++++++++++++- src/worker/background.ts | 2 +- 7 files changed, 52 insertions(+), 28 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 32ad2ed6..194ab13e 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -8,8 +8,6 @@ "name": "opensauced-browser-extension", "version": "1.3.0-beta.1", "dependencies": { - "@types/chrome": "^0.0.231", - "@types/node-emoji": "^1.8.2", "date-fns": "^2.30.0", "gpt-tokenizer": "^1.0.5", "node-emoji": "^1.11.0", @@ -21,7 +19,9 @@ }, "devDependencies": { "@crxjs/vite-plugin": "^1.0.14", + "@types/chrome": "^0.0.237", "@types/node": "^20.1.4", + "@types/node-emoji": "^1.8.2", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", "@typescript-eslint/eslint-plugin": "^5.59.1", @@ -741,9 +741,10 @@ } }, "node_modules/@types/chrome": { - "version": "0.0.231", - "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.231.tgz", - "integrity": "sha512-K3dSpeorWAj2UA/1GRUbny34+PARsH/k8bj8dRZQusSqNE323QEGils9ty1LaVyR1DnfLMD9PX8cV5Q+EhwAvQ==", + "version": "0.0.237", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.237.tgz", + "integrity": "sha512-krsRmyfMlck5r+H1EapsrrucDRq6iRm0NAi5fapr93CgnpVMDdK+h2+z4x79GegdW7BNH9Vb//gkptORwwwVIQ==", + "dev": true, "dependencies": { "@types/filesystem": "*", "@types/har-format": "*" @@ -753,6 +754,7 @@ "version": "0.0.32", "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.32.tgz", "integrity": "sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==", + "dev": true, "dependencies": { "@types/filewriter": "*" } @@ -760,12 +762,14 @@ "node_modules/@types/filewriter": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.29.tgz", - "integrity": "sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==" + "integrity": "sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==", + "dev": true }, "node_modules/@types/har-format": { "version": "1.2.10", "resolved": "https://registry.npmjs.org/@types/har-format/-/har-format-1.2.10.tgz", - "integrity": "sha512-o0J30wqycjF5miWDKYKKzzOU1ZTLuA42HZ4HE7/zqTOc/jTLdQ5NhYWvsRQo45Nfi1KHoRdNhteSI4BAxTF1Pg==" + "integrity": "sha512-o0J30wqycjF5miWDKYKKzzOU1ZTLuA42HZ4HE7/zqTOc/jTLdQ5NhYWvsRQo45Nfi1KHoRdNhteSI4BAxTF1Pg==", + "dev": true }, "node_modules/@types/json-schema": { "version": "7.0.11", @@ -788,7 +792,8 @@ "node_modules/@types/node-emoji": { "version": "1.8.2", "resolved": "https://registry.npmjs.org/@types/node-emoji/-/node-emoji-1.8.2.tgz", - "integrity": "sha512-PfF1qL/9veo8BSHLV84C9ORNr3lHSlnWJ6yU8OdNufoftajeWHTLVbGHvp2B7e7DPDS9gMs6cfeSsqo5rqSitg==" + "integrity": "sha512-PfF1qL/9veo8BSHLV84C9ORNr3lHSlnWJ6yU8OdNufoftajeWHTLVbGHvp2B7e7DPDS9gMs6cfeSsqo5rqSitg==", + "dev": true }, "node_modules/@types/prop-types": { "version": "15.7.5", diff --git a/package.json b/package.json index a9799475..00a2805b 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,6 @@ "format": "npm run lint -- --fix" }, "dependencies": { - "@types/chrome": "^0.0.231", - "@types/node-emoji": "^1.8.2", "date-fns": "^2.30.0", "gpt-tokenizer": "^1.0.5", "node-emoji": "^1.11.0", @@ -26,7 +24,9 @@ }, "devDependencies": { "@crxjs/vite-plugin": "^1.0.14", + "@types/chrome": "^0.0.237", "@types/node": "^20.1.4", + "@types/node-emoji": "^1.8.2", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", "@typescript-eslint/eslint-plugin": "^5.59.1", diff --git a/src/constants.ts b/src/constants.ts index 0f345ea0..7328b3da 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,6 +2,7 @@ export const SUPABASE_LOGIN_URL = "https://ibcwmlhcimymasokhgvn.supabase.co/auth/v1/authorize?provider=github&redirect_to=https://insights.opensauced.pizza/"; export const SUPABASE_AUTH_COOKIE_NAME = "supabase-auth-token"; export const OPEN_SAUCED_AUTH_TOKEN_KEY = "os-access-token"; +export const OPEN_SAUCED_OPTED_LOG_OUT_KEY = "opted-log-out"; export const OPEN_SAUCED_INSIGHTS_DOMAIN = "insights.opensauced.pizza"; export const AI_PR_DESCRIPTION_CONFIG_KEY = "ai-pr-description-config"; diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx index 572abe9e..714475ae 100644 --- a/src/pages/profile.tsx +++ b/src/pages/profile.tsx @@ -1,15 +1,17 @@ import { useEffect, useState } from "react"; import { FaBrain, FaChevronLeft, FaRobot } from "react-icons/fa"; import { RiLinkedinFill, RiLinkM, RiTwitterFill } from "react-icons/ri"; -import { AiOutlineReload } from "react-icons/ai"; import { SiC, SiCplusplus, SiCsharp, SiGoland, SiJavascript, SiPhp, SiPython, SiReact, SiRuby, SiRust, SiTypescript } from "react-icons/si"; import { DiJava } from "react-icons/di"; import OpenSaucedLogo from "../assets/opensauced-logo.svg"; import { getUserData, getUserPRData, getUserHighlightsData } from "../utils/fetchOpenSaucedApiData"; import { emojify } from "node-emoji"; -import { goBack } from "react-chrome-extension-router"; +import { goBack, goTo } from "react-chrome-extension-router"; import { getRelativeDays } from "../utils/dateUtils"; import { getUserPRVelocity } from "../utils/getUserPRVelocity"; +import { BiExit } from "react-icons/bi"; +import Start from "./start"; +import { optLogOut } from "../utils/checkAuthentication"; const interestIcon = { python: , @@ -72,16 +74,14 @@ export const Profile = ({ username }: { username: string }) => { diff --git a/src/pages/start.tsx b/src/pages/start.tsx index 553bf5b2..c16ab4ba 100644 --- a/src/pages/start.tsx +++ b/src/pages/start.tsx @@ -1,5 +1,5 @@ import OpenSaucedLogo from "../assets/opensauced-logo.svg"; -import { SUPABASE_LOGIN_URL } from "../constants"; +import { optLogIn } from "../utils/checkAuthentication"; const Start = () => (
@@ -23,15 +23,13 @@ const Start = () => ( browser extension.

- Login - +
); diff --git a/src/utils/checkAuthentication.ts b/src/utils/checkAuthentication.ts index 8f98e4fd..cdf07697 100644 --- a/src/utils/checkAuthentication.ts +++ b/src/utils/checkAuthentication.ts @@ -1,12 +1,18 @@ import { OPEN_SAUCED_AUTH_TOKEN_KEY, + OPEN_SAUCED_OPTED_LOG_OUT_KEY, SUPABASE_AUTH_COOKIE_NAME, OPEN_SAUCED_INSIGHTS_DOMAIN, + SUPABASE_LOGIN_URL, } from "../constants"; import { checkTokenValidity } from "./fetchOpenSaucedApiData"; import setAccessTokenInChromeStorage from "../utils/setAccessToken"; -export const checkAuthentication = () => { +export const checkAuthentication = async () => { + if (await hasOptedLogOut()) { + return chrome.storage.sync.remove(OPEN_SAUCED_AUTH_TOKEN_KEY); + } + chrome.cookies.get( { name: SUPABASE_AUTH_COOKIE_NAME, @@ -36,4 +42,18 @@ export const isLoggedIn = async (): Promise => Object.entries(await chr export const getAuthToken = async (): Promise => (await chrome.storage.sync.get(OPEN_SAUCED_AUTH_TOKEN_KEY))[OPEN_SAUCED_AUTH_TOKEN_KEY]; +export const optLogOut = () => { + void chrome.storage.sync.remove(OPEN_SAUCED_AUTH_TOKEN_KEY); + void chrome.storage.local.set({ [OPEN_SAUCED_OPTED_LOG_OUT_KEY]: true }); +}; + +export const optLogIn = () => { + if (typeof window === "undefined") { + return; + } + void chrome.storage.local.set({ [OPEN_SAUCED_OPTED_LOG_OUT_KEY]: false }); + window.open(SUPABASE_LOGIN_URL, "_blank"); +}; + +const hasOptedLogOut = async (): Promise => (await chrome.storage.local.get(OPEN_SAUCED_OPTED_LOG_OUT_KEY))[OPEN_SAUCED_OPTED_LOG_OUT_KEY] === true; diff --git a/src/worker/background.ts b/src/worker/background.ts index 9fa7bb36..62cd846f 100644 --- a/src/worker/background.ts +++ b/src/worker/background.ts @@ -7,7 +7,7 @@ chrome.cookies.onChanged.addListener(changeInfo => { changeInfo.cookie.name === SUPABASE_AUTH_COOKIE_NAME || changeInfo.cookie.domain === OPEN_SAUCED_INSIGHTS_DOMAIN ) { - checkAuthentication(); + void checkAuthentication(); } }); From 8fe6e0b7991539548d1260c7fd39c3cf79c78375 Mon Sep 17 00:00:00 2001 From: Anush Date: Fri, 26 May 2023 18:42:16 +0530 Subject: [PATCH 2/3] chore: limit extension host permissions --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4b42b6ba..a2fabf9a 100644 --- a/manifest.json +++ b/manifest.json @@ -20,6 +20,6 @@ "48": "src/assets/os-icons/os-icon-48.png", "128": "src/assets/os-icons/os-icon-128.png" }, - "host_permissions": [""], + "host_permissions": ["https://github.com/*", "https://insights.opensauced.pizza/*"], "permissions": ["storage", "tabs", "cookies"] } From f08e2179cee33ef47ac05068c979db49b9bc0fd1 Mon Sep 17 00:00:00 2001 From: Anush Date: Fri, 26 May 2023 18:56:50 +0530 Subject: [PATCH 3/3] chore: set max description len to 500 --- src/pages/aiprdescription.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/aiprdescription.tsx b/src/pages/aiprdescription.tsx index 58c15e9f..e81d436f 100644 --- a/src/pages/aiprdescription.tsx +++ b/src/pages/aiprdescription.tsx @@ -122,7 +122,7 @@ const AIPRDescription = () => { ref={setRefFromKey("length")} className="text-black p-1.5 rounded-md mb-1 w-half accent-orange" id="length" - max="600" + max="500" min="100" name="length" type="range"