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: add expo-secure-store #5

Merged
merged 4 commits into from
Sep 11, 2024
Merged

Conversation

DanielRivers
Copy link
Contributor

@DanielRivers DanielRivers commented Sep 5, 2024

Explain your changes

This adds support for expo-secure-store session store.
- dynamically imports expo-secure-store, not bundled in.

Other small changes
- Correction to JSDocs on chrome store
- Add nonce to StorageKeys

Note: Mocking in place, tests are skipped currently

Checklist

🛟 If you need help, consider asking for advice over in the Kinde community.

Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Walkthrough

The changes introduce a new module, ExpoSecureStore, designed to manage session storage securely using Expo's capabilities. This module is integrated into the session manager, with corresponding tests added to validate its functionality. Additionally, the StorageKeys enum is updated to include a new key, nonce, and the Vite configuration is modified to support React applications by including the React plugin and optimizing build settings.

Changes

Files Change Summary
lib/main.test.ts Added ExpoSecureStore to the expected exports in the test suite.
lib/sessionManager/index.ts Exported ExpoSecureStore from ./stores/expoSecureStore.js.
lib/sessionManager/stores/chromeStore.ts Updated documentation to clarify storage mechanism as chrome.store.local.
lib/sessionManager/stores/expoSecureStore.test.ts Implemented unit tests for ExpoSecureStore, covering standard and extra storage keys.
lib/sessionManager/stores/expoSecureStore.ts Introduced ExpoSecureStore class for session management, implementing SessionManager interface.
lib/sessionManager/types.ts Added nonce to the StorageKeys enum.
vite.config.ts Integrated React plugin into Vite configuration and modified Rollup options for external dependencies.

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Outside diff range, codebase verification and nitpick comments (2)
vite.config.ts (1)

4-4: React version not specified in package.json

The package.json file does not specify a React version in dependencies, devDependencies, or peerDependencies. This absence could lead to compatibility issues with the @vitejs/plugin-react version ^4.3.1. It's recommended to explicitly declare the React version to ensure compatibility and prevent potential issues.

  • Ensure that the React version is specified in package.json to verify compatibility with @vitejs/plugin-react.
Analysis chain

Verify the React plugin configuration and compatibility.

Ensure that the @vitejs/plugin-react is correctly imported and configured in the plugins array. Additionally, verify compatibility with the project's React version to prevent potential issues.

Run the following script to verify the plugin's compatibility:

Also applies to: 25-25

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the project's package.json for React version and plugin compatibility.

# Test: Search for React version and plugin version in package.json. Expect: Compatible versions.
cat package.json | jq '.dependencies.react, .devDependencies["@vitejs/plugin-react"]'

Length of output: 101


Script:

#!/bin/bash
# Description: Check for React version in devDependencies and peerDependencies.

# Test: Search for React version in devDependencies and peerDependencies. Expect: Version present.
cat package.json | jq '.devDependencies.react, .peerDependencies.react'

Length of output: 83

lib/sessionManager/types.ts (1)

13-13: Unused nonce entry in StorageKeys enum.

The nonce entry in the StorageKeys enum is currently not used in the session management code. Consider implementing its usage if it is intended for future security enhancements, or remove it if it is unnecessary to avoid confusion.

  • Location: lib/sessionManager/types.ts, line 13
Analysis chain

Verify the usage and necessity of the new nonce enum entry.

Ensure that the addition of nonce to the StorageKeys enum is necessary and correctly implemented. Verify that it is used appropriately in session management processes to enhance security, such as preventing replay attacks.

Run the following script to verify the usage of nonce in the session management code:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `nonce` in session management processes.

# Test: Search for `nonce` usage in session management code. Expect: Correct implementation and usage.
rg --type ts "nonce" lib/sessionManager

Length of output: 86

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d6b5fe0 and e86dd0f.

Files ignored due to path filters (2)
  • package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
Files selected for processing (7)
  • lib/main.test.ts (1 hunks)
  • lib/sessionManager/index.ts (1 hunks)
  • lib/sessionManager/stores/chromeStore.ts (4 hunks)
  • lib/sessionManager/stores/expoSecureStore.test.ts (1 hunks)
  • lib/sessionManager/stores/expoSecureStore.ts (1 hunks)
  • lib/sessionManager/types.ts (1 hunks)
  • vite.config.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • lib/sessionManager/stores/chromeStore.ts
Additional context used
GitHub Check: main (20.x)
lib/sessionManager/stores/expoSecureStore.ts

[failure] 96-96: sessionManager/stores/expoSecureStore.test.ts > ExpoSecureStore keys: storageKeys > should set and get an item in storage: StorageKeys
TypeError: Cannot read properties of undefined (reading 'getItemAsync')
❯ ExpoSecureStore.removeSessionItem sessionManager/stores/expoSecureStore.ts:96:40
❯ ExpoSecureStore.setSessionItem sessionManager/stores/expoSecureStore.ts:46:16
❯ sessionManager/stores/expoSecureStore.test.ts:56:26


[failure] 96-96: sessionManager/stores/expoSecureStore.test.ts > ExpoSecureStore keys: storageKeys > should remove an item from storage: StorageKeys
TypeError: Cannot read properties of undefined (reading 'getItemAsync')
❯ ExpoSecureStore.removeSessionItem sessionManager/stores/expoSecureStore.ts:96:40
❯ ExpoSecureStore.setSessionItem sessionManager/stores/expoSecureStore.ts:46:16
❯ sessionManager/stores/expoSecureStore.test.ts:63:26


[failure] 96-96: sessionManager/stores/expoSecureStore.test.ts > ExpoSecureStore keys: storageKeys > should clear all items from storage: StorageKeys
TypeError: Cannot read properties of undefined (reading 'getItemAsync')
❯ ExpoSecureStore.removeSessionItem sessionManager/stores/expoSecureStore.ts:96:40
❯ ExpoSecureStore.setSessionItem sessionManager/stores/expoSecureStore.ts:46:16
❯ sessionManager/stores/expoSecureStore.test.ts:75:26


[failure] 96-96: sessionManager/stores/expoSecureStore.test.ts > ExpoSecureStore keys: storageKeys > should set and get an item in extra storage
TypeError: Cannot read properties of undefined (reading 'getItemAsync')
❯ ExpoSecureStore.removeSessionItem sessionManager/stores/expoSecureStore.ts:96:40
❯ ExpoSecureStore.setSessionItem sessionManager/stores/expoSecureStore.ts:46:16
❯ sessionManager/stores/expoSecureStore.test.ts:87:26


[failure] 96-96: sessionManager/stores/expoSecureStore.test.ts > ExpoSecureStore keys: storageKeys > should remove an item from extra storage
TypeError: Cannot read properties of undefined (reading 'getItemAsync')
❯ ExpoSecureStore.removeSessionItem sessionManager/stores/expoSecureStore.ts:96:40
❯ ExpoSecureStore.setSessionItem sessionManager/stores/expoSecureStore.ts:46:16
❯ sessionManager/stores/expoSecureStore.test.ts:94:26


[failure] 96-96: sessionManager/stores/expoSecureStore.test.ts > ExpoSecureStore keys: storageKeys > should clear all items from extra storage
TypeError: Cannot read properties of undefined (reading 'getItemAsync')
❯ ExpoSecureStore.removeSessionItem sessionManager/stores/expoSecureStore.ts:96:40
❯ ExpoSecureStore.setSessionItem sessionManager/stores/expoSecureStore.ts:46:16
❯ sessionManager/stores/expoSecureStore.test.ts:104:26

Additional comments not posted (3)
lib/sessionManager/index.ts (1)

18-18: Verify the existence and correctness of the ExpoSecureStore module.

Ensure that the file expoSecureStore.js exists and contains the expected module. This is crucial as the path is relative and must correctly point to the file.

Run the following script to verify the file existence and content:

vite.config.ts (1)

18-20: Verify the Rollup options configuration.

Ensure that the configuration to treat "react" and "react-native" as external dependencies is correct and beneficial for the build process. This configuration should optimize the build by excluding these libraries from the bundle, but it's important to verify that it does not negatively impact the application's runtime.

Run the following script to verify the build configuration and its impact:

lib/main.test.ts (1)

51-51: Approved: Addition of "ExpoSecureStore" to expected exports.

The addition of "ExpoSecureStore" to the list of expected exports is correctly implemented and aligns with the PR's objectives to enhance the module's functionality.

Comment on lines +5 to +22
let expoSecureStore: typeof import("expo-secure-store") | undefined = undefined;

/**
* Provides a expo local store based session manager implementation for the browser.
* @class ExpoSecureStore
*/
export class ExpoSecureStore<V = StorageKeys> implements SessionManager<V> {
constructor() {
this.loadExpoStore();
}

private async loadExpoStore() {
try {
expoSecureStore = await import("expo-secure-store");
} catch (error) {
console.error("Error loading dependency expo storage:", error);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue: Handling of dynamic import for expo-secure-store.

The dynamic import of expo-secure-store is not consistently resolving, leading to expoSecureStore being undefined in some cases. This issue is evident from the static analysis failures and needs to be addressed to ensure reliable operation.

Consider initializing expoSecureStore in a more robust manner, possibly by ensuring the module is fully loaded before any session management methods are called.

Would you like me to help refactor the initialization process to ensure reliability?

lib/sessionManager/stores/expoSecureStore.ts Show resolved Hide resolved
lib/sessionManager/stores/expoSecureStore.ts Show resolved Hide resolved
lib/sessionManager/stores/expoSecureStore.ts Show resolved Hide resolved
lib/sessionManager/stores/expoSecureStore.test.ts Outdated Show resolved Hide resolved
@DanielRivers DanielRivers changed the title chore: correct js doc for chrome store feat: add expo-secure-store Sep 5, 2024
Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 18.05556% with 59 lines in your changes missing coverage. Please review.

Project coverage is 62.17%. Comparing base (d6b5fe0) to head (ae77939).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
lib/sessionManager/stores/expoSecureStore.ts 16.90% 59 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main       #5       +/-   ##
===========================================
- Coverage   75.41%   62.17%   -13.24%     
===========================================
  Files          14       15        +1     
  Lines         240      312       +72     
  Branches       36       36               
===========================================
+ Hits          181      194       +13     
- Misses         59      118       +59     
Files with missing lines Coverage Δ
lib/sessionManager/index.ts 100.00% <ø> (ø)
lib/sessionManager/stores/chromeStore.ts 12.30% <ø> (ø)
lib/sessionManager/types.ts 100.00% <100.00%> (ø)
lib/sessionManager/stores/expoSecureStore.ts 16.90% <16.90%> (ø)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e86dd0f and ae77939.

Files selected for processing (1)
  • lib/sessionManager/stores/expoSecureStore.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • lib/sessionManager/stores/expoSecureStore.test.ts

@DanielRivers DanielRivers merged commit a177a01 into main Sep 11, 2024
2 of 3 checks passed
@DanielRivers DanielRivers deleted the feat/expo-secure-session-store branch September 11, 2024 06:02
@coderabbitai coderabbitai bot mentioned this pull request Sep 11, 2024
2 tasks
This was referenced Sep 19, 2024
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.

2 participants