-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add chromeStorage, extend testing and add more utility helpers #4
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
Conversation
WalkthroughThe changes involve a restructuring of the codebase, including the consolidation of utility function tests and the introduction of new utility files for functionalities such as Base64 URL encoding, authentication URL generation, and session management. The Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant MainModule as Main
participant Utils as Utilities
participant SessionManager as SessionManager
Client->>Main: Import utilities
Main->>Utilities: Re-export functions
Utilities->>Client: Provide utility functions
Client->>SessionManager: Manage session data
SessionManager->>Utilities: Use utility functions as needed
Tip We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 6
Outside diff range, codebase verification and nitpick comments (2)
lib/utils/generateRandomString.ts (1)
12-14: LGTM!The
dec2hexfunction is correctly implemented and follows best practices.Consider marking the function as
privateto indicate that it's only used within this module:-function dec2hex(dec: number) { +private function dec2hex(dec: number) { return dec.toString(16).padStart(2, "0"); }lib/utils/generateAuthUrl.ts (1)
5-10: Add a description and document the parameters in the JSDoc.The JSDoc comment is missing a description of the function and its parameters. Please add a description and document the parameters, including their types and default values.
Apply this diff to update the JSDoc comment:
/** + * Generates an authentication URL with a state and nonce. + * * @param options + * @param domain - The domain of the authentication server. + * @param type - The type of the authentication flow. Defaults to `IssuerRouteTypes.login`. + * @param options - The options for the authentication flow. See `LoginOptions` for details. * @returns URL to redirect to + * @returns An object containing the generated `url`, `state`, and `nonce`. */
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
package.jsonis excluded by!**/*.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!**/*.yaml
Files selected for processing (19)
- lib/main.test.ts (1 hunks)
- lib/main.ts (1 hunks)
- lib/sessionManager/index.ts (2 hunks)
- lib/sessionManager/stores/chromeStore.test.ts (1 hunks)
- lib/sessionManager/stores/chromeStore.ts (1 hunks)
- lib/sessionManager/stores/memory.ts (1 hunks)
- lib/utils/base64UrlEncode.test.ts (1 hunks)
- lib/utils/base64UrlEncode.ts (1 hunks)
- lib/utils/extractAuthResults.test.ts (1 hunks)
- lib/utils/extractAuthResults.ts (1 hunks)
- lib/utils/generateAuthUrl.test.ts (1 hunks)
- lib/utils/generateAuthUrl.ts (1 hunks)
- lib/utils/generateRandomString.test.ts (1 hunks)
- lib/utils/generateRandomString.ts (1 hunks)
- lib/utils/index.ts (1 hunks)
- lib/utils/mapLoginMethodParamsForUrl.test.ts (1 hunks)
- lib/utils/mapLoginMethodParamsForUrl.ts (1 hunks)
- lib/utils/sanatizeUrl.ts (1 hunks)
- vite.config.ts (1 hunks)
Files skipped from review due to trivial changes (4)
- lib/main.ts
- lib/utils/base64UrlEncode.ts
- lib/utils/index.ts
- lib/utils/sanatizeUrl.ts
Additional context used
Biome
lib/utils/extractAuthResults.test.ts
[error] 5-5: Don't focus the test.
The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Consider removing 'only' to ensure all tests are executed.
Unsafe fix: Remove focus from test.(lint/suspicious/noFocusedTests)
[error] 16-16: Don't focus the test.
The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Consider removing 'only' to ensure all tests are executed.
Unsafe fix: Remove focus from test.(lint/suspicious/noFocusedTests)
lib/main.test.ts
[error] 7-7: Don't focus the test.
The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Consider removing 'only' to ensure all tests are executed.
Unsafe fix: Remove focus from test.(lint/suspicious/noFocusedTests)
Additional comments not posted (41)
lib/utils/extractAuthResults.ts (1)
1-12: LGTM!The
extractAuthResultsfunction is implemented correctly and follows best practices:
- It uses the
URLSearchParamsAPI to parse the search parameters, which is a standard and efficient way to handle URL parameters.- It uses object destructuring to create the result object, which is a clean and readable way to create objects with dynamic keys.
- It converts the
expires_invalue to a number using the+operator, which is a concise way to convert a string to a number.- It handles the case where
expires_inmight be undefined by providing a default value of0.The code changes are approved.
lib/utils/generateRandomString.ts (2)
1-5: LGTM!The JSDoc comment is clear and informative.
6-10: LGTM!The
generateRandomStringfunction is correctly implemented and follows best practices:
- It uses the built-in
cryptomodule to generate cryptographically strong random values.- The default length of 28 is a reasonable choice for a random string.
- The conversion to a hex string is done correctly.
lib/sessionManager/index.ts (2)
Line range hint
3-12: Verify the reason for removing thestorePassworddocumentation.The documentation for the
storePasswordproperty has been removed fromstorageSettings. Please ensure that this removal is intentional and aligns with any changes in how the password is handled or documented.Confirm that the functionality related to
storePasswordis still intact and working as expected, despite the removal of the documentation.Tools
GitHub Check: main (20.x)
[failure] 3-3:
Property 'storePassword' is missing in type '{ keyPrefix: string; maxLength: number; }' but required in type 'StorageSettingsType'.
17-17: LGTM!The new export statement for
ChromeStoreis a valuable addition that expands the available storage options. This change enhances the module's functionality and flexibility by allowing the use of Chrome's storage capabilities alongside the existing memory storage.vite.config.ts (1)
9-9: Approve the change in the entry point.The change in the entry point from
lib/index.tstolib/main.tsis approved.Verify the existence and validity of the
lib/main.tsfile as the new entry point for the library. Run the following script:Verification successful
The
lib/main.tsfile is a valid entry point.The
lib/main.tsfile exists and is correctly set up to serve as the main entry point for the library by re-exporting modules from./types,./utils, and./sessionManager. This confirms that the change in the entry point is valid.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence and validity of the `lib/main.ts` file. # Test: Check if the `lib/main.ts` file exists. Expect: The file exists. if [ -f "lib/main.ts" ]; then echo "The lib/main.ts file exists." else echo "The lib/main.ts file does not exist." exit 1 fi # Test: Check if the `lib/main.ts` file exports the necessary entities. Expect: The file exports the necessary entities. ast-grep --lang typescript --pattern $'export { $$$ }'Length of output: 634
Script:
#!/bin/bash # Display the contents of the `lib/main.ts` file to verify its setup. # Check if the `lib/main.ts` file exists and display its contents. if [ -f "lib/main.ts" ]; then echo "Contents of lib/main.ts:" cat "lib/main.ts" else echo "The lib/main.ts file does not exist." fiLength of output: 185
lib/utils/mapLoginMethodParamsForUrl.ts (1)
4-27: LGTM!The code changes are approved. The function is correctly implemented and follows best practices.
lib/utils/base64UrlEncode.test.ts (5)
5-10: LGTM!The test case is correctly implemented and the expected output matches the actual output.
12-17: LGTM!The test case is correctly implemented and the expected output matches the actual output.
19-24: LGTM!The test case is correctly implemented and the expected output matches the actual output.
26-31: LGTM!The test case is correctly implemented and the expected output matches the actual output.
33-38: LGTM!The test case is correctly implemented and the expected output matches the actual output.
lib/utils/generateRandomString.test.ts (5)
5-9: LGTM!The test case correctly verifies that the generated string has the specified length.
11-19: LGTM!The test case correctly verifies that the generated string contains only valid characters.
21-26: LGTM!The test case correctly verifies that the function generates different strings on subsequent calls.
28-32: LGTM!The test case correctly verifies that the function handles a length of 0 correctly.
34-38: LGTM!The test case correctly verifies that the function handles a large length correctly.
lib/utils/generateAuthUrl.ts (1)
1-42: LGTM!The code changes are approved. The function is well-structured and follows a clear logic flow. It handles various options and generates a random state and nonce for security purposes.
lib/main.test.ts (4)
8-12: LGTM!The test case is correctly implemented and serves its purpose of validating that all exports from the
typesmodule are included in theindexmodule.
14-18: LGTM!The test case is correctly implemented and serves its purpose of validating that all exports from the
utilsmodule are included in theindexmodule.
20-24: LGTM!The test case is correctly implemented and serves its purpose of validating that all exports from the
sessionManagermodule are included in theindexmodule.
26-53: LGTM!The test case is correctly implemented and serves its purpose of validating that the
indexmodule does not export anything extra.lib/sessionManager/stores/memory.ts (1)
31-35: LGTM!The code changes in the
setSessionItemmethod are approved:
- Using
itemKeydirectly for constructing the cache key simplifies the logic and appears to be a correction or enhancement.- Adding an explicit
returnstatement after theforEachloop enhances readability and clarifies the control flow.lib/sessionManager/stores/chromeStore.ts (5)
1-3: LGTM!The code changes are approved.
5-15: LGTM!The code changes are approved.
21-21: LGTM!The code changes are approved.
26-28: LGTM!The code changes are approved.
36-53: LGTM!The code changes are approved.
lib/utils/mapLoginMethodParamsForUrl.test.ts (6)
7-38: LGTM!The test case comprehensively covers the mapping of login method parameters to URL parameters. It provides a good set of input parameters and verifies the expected output.
40-53: LGTM!The test case verifies that the
mapLoginMethodParamsForUrlfunction correctly handles missing optional parameters. It ensures that the function does not include the missing parameters in the output.
55-67: LGTM!The test case verifies that the
mapLoginMethodParamsForUrlfunction uses the default scope when thescopeparameter is not provided. It ensures that the function includes the default scope in the output.
69-81: LGTM!The test case verifies that the
mapLoginMethodParamsForUrlfunction sanitizes the redirect URL by removing any trailing slashes. It ensures that the function correctly handles the redirect URL in the output.
83-97: LGTM!The test case verifies that the
mapLoginMethodParamsForUrlfunction correctly handles boolean values by converting them to string values in the output. It ensures that the function properly maps the boolean parameters.
99-120: LGTM!The test case verifies that the
mapLoginMethodParamsForUrlfunction removes any parameters withundefinedvalues from the output. It ensures that the function correctly handles scenarios where all parameters areundefined.lib/sessionManager/stores/chromeStore.test.ts (2)
9-46: LGTM! Enable the tests once the mocks are implemented.The test suite structure looks good and covers the essential functionality of the
ChromeStoreclass. However, the tests are currently skipped due to missing mocks for chrome storage.As mentioned earlier, please enable the tests once the mocks for chrome storage are implemented.
49-113: LGTM! Enable the tests once the mocks are implemented.The test suite structure looks good and covers the essential functionality of the
ChromeStoreclass, including the handling of extra keys. However, the tests are currently skipped due to missing mocks for chrome storage.As mentioned earlier, please enable the tests once the mocks for chrome storage are implemented.
lib/utils/generateAuthUrl.test.ts (5)
6-29: LGTM!The test case is well-written and covers the required functionality of generating the correct auth URL with the required parameters. It also checks if a nonce is generated and has the correct length.
31-52: LGTM!The test case is well-written and covers the functionality of including the optional parameters in the generated URL if they are provided. It also checks if a nonce is generated and has the correct length.
54-72: LGTM!The test case is well-written and covers the functionality of handling the default
responseTypeif it is not provided. It also checks if a nonce is generated and has the correct length.
74-95: LGTM!The test case is well-written and covers the functionality of handling the default
responseTypeif it is not provided. It also checks if a nonce and state are generated and have the correct lengths.
97-115: Remove the duplicate test case.This test case is a duplicate of the test case at line range 54-72. Both test cases are checking the same functionality of handling the default
responseTypeif it is not provided.Remove this test case to avoid redundancy in the test suite.
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- lib/main.test.ts (1 hunks)
- lib/sessionManager/types.ts (1 hunks)
- lib/utils/extractAuthResults.test.ts (1 hunks)
- lib/utils/generateAuthUrl.test.ts (1 hunks)
- readme.md (2 hunks)
Files skipped from review as they are similar to previous changes (3)
- lib/main.test.ts
- lib/utils/extractAuthResults.test.ts
- lib/utils/generateAuthUrl.test.ts
Additional context used
Markdownlint
readme.md
45-45: Punctuation: '.'
Trailing punctuation in heading(MD026, no-trailing-punctuation)
Additional comments not posted (5)
lib/sessionManager/types.ts (2)
12-12: LGTM!The addition of
statetoStorageKeysenum is a valid change. It indicates thatstateis a new key that will be used for storage management.
15-17: Verify the impact of removingstorePasswordfromStorageSettingsType.The removal of
storePasswordfromStorageSettingsTypeis a breaking change. It indicates a shift in how storage settings are managed, potentially moving away from password storage.Please ensure that:
- The removal of
storePasswordis intentional and documented.- The impact of this change on other parts of the codebase that rely on the
storePasswordproperty is assessed and addressed.Run the following script to verify the usage of
storePassword:Verification successful
Removal of
storePasswordfromStorageSettingsTypeis safe.The search confirmed that
storePasswordis not used elsewhere in the codebase. Therefore, its removal fromStorageSettingsTypedoes not impact other parts of the codebase. This change appears to be safe and does not require further action.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `storePassword` in the codebase. # Test: Search for the usage of `storePassword`. Expect: No occurrences. rg --type typescript $'storePassword'Length of output: 71
Script:
#!/bin/bash # Description: Verify the usage of `storePassword` in the codebase without specifying file type. # Test: Search for the usage of `storePassword`. Expect: No occurrences. rg 'storePassword'Length of output: 18
readme.md (3)
30-31: LGTM!The documentation for the
extractAuthResultsfunction is clear and concise.
32-33: LGTM!The documentation for the
generateRandomStringfunction is clear and concise.
49-50: LGTM!The documentation for the
ChromeStorestorage type is clear and concise.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4 +/- ##
============================================
- Coverage 100.00% 75.41% -24.59%
============================================
Files 7 14 +7
Lines 142 240 +98
Branches 31 36 +5
============================================
+ Hits 142 181 +39
- Misses 0 59 +59
|
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.
Actionable comments posted: 5
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- lib/sessionManager/stores/chromeStore.ts (1 hunks)
Additional context used
GitHub Check: codecov/patch
lib/sessionManager/stores/chromeStore.ts
[warning] 5-15: lib/sessionManager/stores/chromeStore.ts#L5-L15
Added lines #L5 - L15 were not covered by tests
[warning] 27-28: lib/sessionManager/stores/chromeStore.ts#L27-L28
Added lines #L27 - L28 were not covered by tests
[warning] 37-53: lib/sessionManager/stores/chromeStore.ts#L37-L53
Added lines #L37 - L53 were not covered by tests
[warning] 61-72: lib/sessionManager/stores/chromeStore.ts#L61-L72
Added lines #L61 - L72 were not covered by tests
[warning] 74-75: lib/sessionManager/stores/chromeStore.ts#L74-L75
Added lines #L74 - L75 were not covered by tests
[warning] 83-89: lib/sessionManager/stores/chromeStore.ts#L83-L89
Added lines #L83 - L89 were not covered by tests
c5b1c46 to
58324a5
Compare
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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
lib/sessionManager/stores/chromeStore.ts (1)
85-112: Remove theconsole.logstatements.The
console.logstatements at lines 88-93 and 99-105 seem to be used for debugging. Please remove them as they are not needed in production code.Apply this diff to remove the
console.logstatements:async removeSessionItem(itemKey: V | StorageKeys): Promise<void> { // remove items from the chrome.storage let index = 0; - console.log( - `${storageSettings.keyPrefix}${String(itemKey)}${index}`, - await getStorageValue( - `${storageSettings.keyPrefix}${String(itemKey)}${index}`, - ), - ); while ( (await getStorageValue( `${storageSettings.keyPrefix}${String(itemKey)}${index}`, )) !== undefined ) { - console.log( - "removing", - `${storageSettings.keyPrefix}${String(itemKey)}${index}`, - await getStorageValue( - `${storageSettings.keyPrefix}${String(itemKey)}${index}`, - ), - ); await chrome.storage.local.remove( `${storageSettings.keyPrefix}${String(itemKey)}${index}`, ); index++; } }Tools
GitHub Check: codecov/patch
[warning] 87-108: lib/sessionManager/stores/chromeStore.ts#L87-L108
Added lines #L87 - L108 were not covered by tests
[warning] 110-112: lib/sessionManager/stores/chromeStore.ts#L110-L112
Added lines #L110 - L112 were not covered by tests
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- lib/sessionManager/stores/chromeStore.ts (1 hunks)
- lib/sessionManager/stores/memory.ts (1 hunks)
- readme.md (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- lib/sessionManager/stores/memory.ts
- readme.md
Additional context used
GitHub Check: codecov/patch
lib/sessionManager/stores/chromeStore.ts
[warning] 5-15: lib/sessionManager/stores/chromeStore.ts#L5-L15
Added lines #L5 - L15 were not covered by tests
[warning] 27-28: lib/sessionManager/stores/chromeStore.ts#L27-L28
Added lines #L27 - L28 were not covered by tests
[warning] 37-39: lib/sessionManager/stores/chromeStore.ts#L37-L39
Added lines #L37 - L39 were not covered by tests
[warning] 41-41: lib/sessionManager/stores/chromeStore.ts#L41
Added line #L41 was not covered by tests
[warning] 43-56: lib/sessionManager/stores/chromeStore.ts#L43-L56
Added lines #L43 - L56 were not covered by tests
[warning] 64-75: lib/sessionManager/stores/chromeStore.ts#L64-L75
Added lines #L64 - L75 were not covered by tests
[warning] 77-78: lib/sessionManager/stores/chromeStore.ts#L77-L78
Added lines #L77 - L78 were not covered by tests
[warning] 87-108: lib/sessionManager/stores/chromeStore.ts#L87-L108
Added lines #L87 - L108 were not covered by tests
[warning] 110-112: lib/sessionManager/stores/chromeStore.ts#L110-L112
Added lines #L110 - L112 were not covered by tests
58324a5 to
34a7298
Compare
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.
Actionable comments posted: 5
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- lib/sessionManager/stores/chromeStore.ts (1 hunks)
- lib/sessionManager/stores/memory.ts (1 hunks)
- readme.md (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- lib/sessionManager/stores/memory.ts
- readme.md
Additional context used
GitHub Check: codecov/patch
lib/sessionManager/stores/chromeStore.ts
[warning] 5-15: lib/sessionManager/stores/chromeStore.ts#L5-L15
Added lines #L5 - L15 were not covered by tests
[warning] 27-28: lib/sessionManager/stores/chromeStore.ts#L27-L28
Added lines #L27 - L28 were not covered by tests
[warning] 37-39: lib/sessionManager/stores/chromeStore.ts#L37-L39
Added lines #L37 - L39 were not covered by tests
[warning] 41-41: lib/sessionManager/stores/chromeStore.ts#L41
Added line #L41 was not covered by tests
[warning] 43-56: lib/sessionManager/stores/chromeStore.ts#L43-L56
Added lines #L43 - L56 were not covered by tests
[warning] 64-75: lib/sessionManager/stores/chromeStore.ts#L64-L75
Added lines #L64 - L75 were not covered by tests
[warning] 77-78: lib/sessionManager/stores/chromeStore.ts#L77-L78
Added lines #L77 - L78 were not covered by tests
[warning] 87-98: lib/sessionManager/stores/chromeStore.ts#L87-L98
Added lines #L87 - L98 were not covered by tests
Explain your changes
extractAuthResultsgenerateRandomStringgenerateAuthUrl, now return stat, nonce and url in an objectchromeStorewhich userschrome.store.localNote: Drop in test coverage as mocking chrome storage is missing, this will come soon. Tested on a chrome extension application to verify working.
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.