-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor(client, extension, setting): Extension/client communication 로직 추상화 및 연결 공통 상수 패키지 추가 #311
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
Open
constantly-dev
wants to merge
8
commits into
develop
Choose a base branch
from
refactor/#310/client-axios-instance-refactoring
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7c9c744
refactor: reissueToken fetch function 분리
constantly-dev 85480f6
refactor: noAuthNeeded 배열 선언부 분리
constantly-dev f943cc0
refactor: syncAccessToken & clearAuthSessionAndRedirect function 분리
constantly-dev c0a99b7
refactor: add packages contracts (extension-client 통신/계약용 공통 상수 & 타입)
constantly-dev 04d82e2
refactor: client authStorage 추상화 유틸 함수 객체 추가
constantly-dev 822393e
refactor: extension message 로직 extensionBridge에 function 추상화
constantly-dev 4ccead2
refactor: extension EXTENSION_MESSAGE_TYPE 사용하도록 변경
constantly-dev 6ddda83
refactor: apps/client authStorage 사용하도록 로직 변경
constantly-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| const AUTH_STORAGE_KEYS = { | ||
| token: 'token', | ||
| refreshToken: 'refreshToken', | ||
| email: 'email', | ||
| userId: 'userId', | ||
| hasJob: 'hasJob', | ||
| } as const; | ||
|
|
||
| export const authStorage = { | ||
| getAccessToken: () => localStorage.getItem(AUTH_STORAGE_KEYS.token), | ||
| hasAccessToken: () => !!localStorage.getItem(AUTH_STORAGE_KEYS.token), | ||
| setAccessToken: (token: string) => | ||
| localStorage.setItem(AUTH_STORAGE_KEYS.token, token), | ||
| setRefreshToken: (refreshToken: string) => | ||
| localStorage.setItem(AUTH_STORAGE_KEYS.refreshToken, refreshToken), | ||
| setHasJob: (hasJob: boolean) => | ||
| localStorage.setItem(AUTH_STORAGE_KEYS.hasJob, String(hasJob)), | ||
| setUserIdentity: (email: string, userId: string) => { | ||
| localStorage.setItem(AUTH_STORAGE_KEYS.email, email); | ||
| localStorage.setItem(AUTH_STORAGE_KEYS.userId, userId); | ||
| }, | ||
| clearSession: () => { | ||
| Object.values(AUTH_STORAGE_KEYS).forEach((key) => { | ||
| localStorage.removeItem(key); | ||
| }); | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { EXTENSION_MESSAGE_TYPE } from '@pinback/contracts/extension-messages'; | ||
|
|
||
| export const extensionBridge = { | ||
| syncToken: (token: string) => { | ||
| window.postMessage( | ||
| { | ||
| type: EXTENSION_MESSAGE_TYPE.setToken, | ||
| token, | ||
| }, | ||
| window.location.origin | ||
| ); | ||
| }, | ||
| logout: () => { | ||
| window.postMessage( | ||
| { | ||
| type: EXTENSION_MESSAGE_TYPE.logout, | ||
| }, | ||
| window.location.origin | ||
| ); | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,23 @@ | ||
| import { EXTENSION_MESSAGE_TYPE } from '@pinback/contracts/extension-messages'; | ||
|
|
||
| window.addEventListener('message', (event) => { | ||
| if (event.source !== window) return; | ||
| if (event.data.type === 'SET_TOKEN') { | ||
| if (event.data.type === EXTENSION_MESSAGE_TYPE.setToken) { | ||
| chrome.runtime.sendMessage({ | ||
| type: 'SET_TOKEN', | ||
| type: EXTENSION_MESSAGE_TYPE.setToken, | ||
| token: event.data.token, | ||
| }); | ||
| chrome.storage.local.set({ token: event.data.token }, () => { | ||
| console.log('Token saved!'); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| window.addEventListener('message', (event) => { | ||
| if (event.source !== window) return; | ||
| if (event.data.type === 'Extension-Logout') { | ||
| if (event.data.type === EXTENSION_MESSAGE_TYPE.logout) { | ||
| chrome.storage.local.remove('token', () => { | ||
| console.log('Token removed!'); | ||
| }); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "@pinback/contracts", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "exports": { | ||
| "./extension-messages": "./src/extension-messages.ts" | ||
| }, | ||
| "scripts": { | ||
| "check-types": "tsc --noEmit" | ||
| }, | ||
| "devDependencies": { | ||
| "@pinback/typescript-config": "workspace:*", | ||
| "typescript": "5.9.2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export const EXTENSION_MESSAGE_TYPE = { | ||
| setToken: 'SET_TOKEN', | ||
| logout: 'Extension-Logout', | ||
| } as const; | ||
|
|
||
| export type ExtensionMessageType = | ||
| (typeof EXTENSION_MESSAGE_TYPE)[keyof typeof EXTENSION_MESSAGE_TYPE]; | ||
|
|
||
| export type ExtensionMessage = | ||
| | { | ||
| type: typeof EXTENSION_MESSAGE_TYPE.setToken; | ||
| token: string; | ||
| } | ||
| | { | ||
| type: typeof EXTENSION_MESSAGE_TYPE.logout; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "../typescript-config/base.json", | ||
| "compilerOptions": { | ||
| "rootDir": ".", | ||
| "baseUrl": ".", | ||
| "lib": ["ES2022"] | ||
| }, | ||
| "include": ["src"], | ||
| "exclude": ["node_modules", "dist"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메시지 payload를 런타임에서 검증해야 합니다.
MessageEvent.data는null이나 임의의 값일 수 있는데, 여기서는 두 리스너 모두event.data.type을 바로 읽고 있습니다. 그래서 잘못된postMessage하나만 들어와도 예외가 날 수 있고,setToken경로는token이 문자열인지 확인하지 않은 채 그대로 저장/전달합니다.packages/contracts/src/extension-messages.ts의 타입은 컴파일 타임 계약일 뿐이라, 이 경계에서는 별도 가드가 필요합니다.🛡️ 제안 수정
Also applies to: 3-8, 16-18
🤖 Prompt for AI Agents