Skip to content

feat(#161): refactor string literals to typed enums #216

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
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

naaa760
Copy link

@naaa760 naaa760 commented Jun 14, 2025

#161

Purpose of the PR*

Refactor hardcoded string literals into typed enums to improve type safety and maintainability across the extension.

Priority*

  • High: This PR needs to be merged first, before other tasks.
  • Medium: This PR should be merged quickly to prevent conflicts due to common changes. (default)
  • Low: This PR does not affect other tasks, so it can be merged later.

Changes*

  1. Added new enums in packages/shared/lib/constants/enums/:

    • MessageType, MessageAction
    • CaptureState, CaptureType
    • RecordType, RecordSource, LogMethod
    • Chrome-specific enums
  2. Updated files to use new enums:

    • Background script
    • Interceptors (network, console, storage)
    • Event listeners
    • Screen capture functionality

How to check the feature

  1. Run pnpm run:chrome:local
  2. Test core features: screenshots, console logging, network requests
  3. Verify no TypeScript errors: pnpm type-check

Reference

Improves code quality by replacing string literals with type-safe enums

@naaa760 naaa760 requested a review from ionleu as a code owner June 14, 2025 17:05
@github-actions github-actions bot requested a review from LuminitaL June 14, 2025 17:05
Copy link

Hey @naaa760,
Thanks for another PR! 🚀

Copy link
Contributor

@ionleu ionleu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, @naaa760 !

I have just a few questions, but overall looks great! 🔥

@@ -1,4 +1,4 @@
import type { t as t_dev } from './i18n-dev.js';
import { t as t_dev_or_prod } from './i18n.js';
import { t as t_dev_or_prod } from './i18n-dev.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm 🤔
Do we need this change?

@ionleu ionleu linked an issue Jun 14, 2025 that may be closed by this pull request
@naaa760
Copy link
Author

naaa760 commented Jun 14, 2025

Good job, @naaa760 !

I have just a few questions, but overall looks great! 🔥

Thank you! @ionleu for your appreciation!

): void {
this._requestDetails = {
method,
url: url.toString(),
requestStart: new Date().toISOString(),
requestBody: null,
};
originalOpen.apply(this, [method, url, ...rest]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760, can you please elaborate a bit on this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change refactors the XHR interceptor to use the new enums (RecordType, RecordSource, LogMethod) instead of hardcoded strings like 'network', 'client', and 'error' for better type safety.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I see the username, password has been added, why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1,14 +1,12 @@
import { v4 as uuidv4 } from 'uuid';

import { deepRedactSensitiveInfo } from '@extension/shared';
import { deepRedactSensitiveInfo, RecordType } from '@extension/shared';

const restricted = ['https://api.briehq.com']; // 'extend.iife', 'kbmbnelnoppneadncmmkfikbcgmilbao' Note: it blocks the logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some differences between current changes in develop branch.
Can you pull the latests changes from develop branch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
I still see the issue with missing changes that are not matching the develop branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
can you please pull the latest changes from upstream develop branch?

package.json Outdated
@@ -52,18 +52,19 @@
},
"dependencies": {
"html2canvas": "^1.4.1",
"i18n": "^0.15.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

Also,
it seems that you used to create your branch from main branch.
Please rebase it to match develop branch, since this is our development branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
what was the reason to add i18n package?

We have our own custom i18n package, see: packages/i18n

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
we don't need i18n as of now.

@ionleu ionleu changed the title feat: Refactor string literals to typed enums feat(#161): refactor string literals to typed enums Jun 16, 2025
@ionleu
Copy link
Contributor

ionleu commented Jun 16, 2025

@naaa760,
let me know when you got a minute to resolve the suggestions and the rebase issue (we'll need the develop branch changes).

@naaa760
Copy link
Author

naaa760 commented Jun 16, 2025

@naaa760, let me know when you got a minute to resolve the suggestions and the rebase issue (we'll need the develop branch changes).

please check once again, I have updated it!

@@ -33,3 +35,6 @@ jobs:
--ignore-path ./.prettierignore \
--no-error-on-unmatched-pattern \
'**/*.{js,jsx,ts,tsx,json}'

- name: Fix formatting issues
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
please remove this step changes: Fix formatting issues, since we'll want the workflow to be read only.

Also,
.turbo and manifest are added into the .gitignore

@@ -1,14 +1,12 @@
import { v4 as uuidv4 } from 'uuid';

import { deepRedactSensitiveInfo } from '@extension/shared';
import { deepRedactSensitiveInfo, RecordType } from '@extension/shared';

const restricted = ['https://api.briehq.com']; // 'extend.iife', 'kbmbnelnoppneadncmmkfikbcgmilbao' Note: it blocks the logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
I still see the issue with missing changes that are not matching the develop branch.

package.json Outdated
@@ -52,18 +52,19 @@
},
"dependencies": {
"html2canvas": "^1.4.1",
"i18n": "^0.15.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
what was the reason to add i18n package?

We have our own custom i18n package, see: packages/i18n

): void {
this._requestDetails = {
method,
url: url.toString(),
requestStart: new Date().toISOString(),
requestBody: null,
};
originalOpen.apply(this, [method, url, ...rest]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I see the username, password has been added, why?

nehhhhha6 added 2 commits June 17, 2025 20:13
): void {
this._requestDetails = {
method,
url: url.toString(),
requestStart: new Date().toISOString(),
requestBody: null,
};
originalOpen.apply(this, [method, url, ...rest]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};
});
// Override each console method individually to avoid type issues
console.log = (...args: any[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says that this was implemented due to avoid type issues.

Do we still need then to use any[]?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from any[] to unknown[] for better type safety

package.json Outdated
@@ -52,18 +52,19 @@
},
"dependencies": {
"html2canvas": "^1.4.1",
"i18n": "^0.15.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
we don't need i18n as of now.

@@ -1,14 +1,12 @@
import { v4 as uuidv4 } from 'uuid';

import { deepRedactSensitiveInfo } from '@extension/shared';
import { deepRedactSensitiveInfo, RecordType } from '@extension/shared';

const restricted = ['https://api.briehq.com']; // 'extend.iife', 'kbmbnelnoppneadncmmkfikbcgmilbao' Note: it blocks the logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
can you please pull the latest changes from upstream develop branch?

nehhhhha6 added 2 commits June 19, 2025 20:42
.gitignore Outdated
@@ -8,7 +8,7 @@
**/dist
**/build
**/dist-zip
chrome-extension/manifest.js
chrome-extension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
can we please revert these changes back?

@@ -0,0 +1,4 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
this file will be regenerated at each startup.
So no need to modify it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for that.

Copy link
Author

@naaa760 naaa760 Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i have not modify the .turbo folder at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760,
no need to remove our custom i18n packages.

I asked to remove only the i18n that you added in the package.json as a independent package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-06-19 at 11 25 05 AM
This is the external package that you need to remove

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I already checked in package.json, the i18n is not there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that was removed when you did the rebase. So that's fine.

Remains to revert back our custom i18n package.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

see this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again i will update it

@naaa760
Copy link
Author

naaa760 commented Jun 20, 2025

Hello, @ionleu
Let me know if there are any issues regarding this.

@ionleu
Copy link
Contributor

ionleu commented Jun 20, 2025

Let me know if there are any issues regarding this.

@naaa760,
there are a few pending changes and also conflicts that we'll be great to fix.

@ionleu
Copy link
Contributor

ionleu commented Jun 23, 2025

@naaa760,
Could you please look into the remaining comments and change requested. Once done we can merge it.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ENUMs for uniq actions or/and types
2 participants