Skip to content

Conversation

@DanielRivers
Copy link
Member

Explain your changes

This adds an implementation of a session manager with configuration.

Currently there is a single manager of memoryStorage, more will be added including cookie and session.

The memory manager keys have a default set of keys of accessToken, idToken and refreshToken, this can be added to by passing in an enum as a generic when setting the storage type

Checklist

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 29, 2024

Walkthrough

The changes introduce a session management system featuring a MemoryStorage class for in-memory session data management, a splitString utility function, and updates to module exports. The generateAuthUrl function in the test suite is modified to include a new state parameter. Documentation updates reflect these new features and configurations, enhancing clarity for users.

Changes

Files Change Summary
lib/index.ts Exported sessionManager instead of types, altering the public API of the module.
lib/main.test.ts Modified generateAuthUrl to include a new state parameter in the options object. Adjusted import statements for clarity.
lib/sessionManager/index.ts Introduced type definitions and constants for session management, including StorageSettingsType and MemoryStorage export.
lib/sessionManager/stores/memory.test.ts Added unit tests for the MemoryStorage class, validating its core functionalities with standard and extra keys.
lib/sessionManager/stores/memory.ts Implemented MemoryStorage class for session management, defining methods for managing session items and ensuring compatibility with the SessionManager interface.
lib/sessionManager/types.ts Created a SessionManager interface and related types for session management, including methods and an enum for storage keys.
lib/sessionManager/utils.test.ts Added unit tests for the splitString function, covering various scenarios for string splitting.
lib/sessionManager/utils.ts Introduced the splitString function to divide strings into segments of specified lengths.
readme.md Updated documentation to include details about storageSettings and MemoryStorage, enhancing user understanding of session management features.

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: 0

Outside diff range, codebase verification and nitpick comments (2)
lib/index.ts (1)

1-1: Potential unresolved references due to removal of export statement for types.

The removal of the export statement in lib/index.ts might lead to unresolved references in the following files that import types directly from ./types:

  • lib/main.test.ts
  • lib/main.ts

Please ensure that all necessary types are still accessible where needed.

Analysis chain

Verify the impact of removing the export statement for types.

The removal of the export statement for types might affect other parts of the codebase that rely on these types. Ensure that all necessary types are still accessible where needed.

Run the following script to verify the usage of the types export:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `types` export.

# Test: Search for the usage of the `types` export. Expect: No unresolved references.
rg --type typescript 'from "./types"'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the usage of the `types` export.

# Test: Search for the usage of the `types` export. Expect: No unresolved references.
rg --type ts 'from "./types"'

Length of output: 232

lib/sessionManager/types.ts (1)

1-5: Fix typographical errors in the comment.

There are minor typographical errors in the comment. Apply this diff to fix them:

- * This interfaces provides the contract that an session management utility must
- * satisfiy in order to work with this SDK, please vist the example provided in the
+ * This interface provides the contract that a session management utility must
+ * satisfy in order to work with this SDK. Please visit the example provided in the
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6300e66 and 149d99c.

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 (9)
  • lib/index.ts (1 hunks)
  • lib/main.test.ts (3 hunks)
  • lib/sessionManager/index.ts (1 hunks)
  • lib/sessionManager/stores/memory.test.ts (1 hunks)
  • lib/sessionManager/stores/memory.ts (1 hunks)
  • lib/sessionManager/types.ts (1 hunks)
  • lib/sessionManager/utils.test.ts (1 hunks)
  • lib/sessionManager/utils.ts (1 hunks)
  • readme.md (1 hunks)
Additional comments not posted (32)
lib/index.ts (1)

3-3: LGTM!

The addition of the export statement for sessionManager makes the session management functionalities available to other parts of the codebase.

The code changes are approved.

lib/sessionManager/utils.ts (1)

1-10: Add type annotation for the result array.

The function is correctly implemented and handles edge cases. Adding a type annotation for the result array would improve readability.

 export function splitString(str: string, length: number): string[] {
   if (length <= 0) {
     return [];
   }
-  const result = [];
+  const result: string[] = [];
   for (let i = 0; i < str.length; i += length) {
     result.push(str.slice(i, i + length));
   }
   return result;
 }
lib/sessionManager/index.ts (4)

1-5: LGTM!

The type declaration for StorageSettingsType is correctly implemented.

The code changes are approved.


7-22: Clarify the usage of the storePassword field.

The constant storageSettings is correctly initialized with default values. However, the storePassword field is specific to cookies, which might be confusing. Add a comment to clarify its usage.

 export const storageSettings: StorageSettingsType = {
   /**
    * The password to encrypt the store. (cookies only)
    */
   storePassword: "",
   /**
    * The prefix to use for the storage keys.
    */
   keyPrefix: "kinde-",
   /**
    * The maximum length of the storage.
    *
    * If the length is exceeded the items will be split into multiple storage items.
    */
   maxLength: 2000,
 };

24-24: LGTM!

The addition of the export statement for MemoryStorage makes the memory storage functionalities available to other parts of the codebase.

The code changes are approved.


25-25: LGTM!

The addition of the export statement for types makes the types available to other parts of the codebase.

The code changes are approved.

readme.md (1)

30-41: LGTM!

The new section on "Session Managers" is well-written and provides clear information about storageSettings and MemoryStorage.

lib/sessionManager/types.ts (3)

8-12: LGTM!

The StorageKeys enum is well-defined and provides a clear set of keys for session management.


14-18: LGTM!

The StorageSettingsType type is well-defined and provides a clear structure for storage settings.


20-50: LGTM!

The SessionManager interface is well-defined and provides a clear contract for session management utilities.

lib/sessionManager/utils.test.ts (2)

1-3: LGTM!

The import statements are correct and necessary for the tests.


5-47: LGTM!

The test suite for the splitString function is comprehensive and covers various scenarios, including edge cases.

lib/sessionManager/stores/memory.ts (5)

1-3: LGTM!

The imports are necessary and correctly included.


12-18: LGTM!

The destroySession method is correctly implemented.


42-64: LGTM!

The getSessionItem method is correctly implemented.


67-79: LGTM!

The removeSessionItem method is correctly implemented.


20-39: LGTM! But verify the handling of non-string values.

The setSessionItem method is correctly implemented. However, ensure that non-string values are handled correctly.

The code changes are approved.

Run the following script to verify the handling of non-string values:

lib/sessionManager/stores/memory.test.ts (10)

1-3: LGTM!

The imports are necessary and correctly included.


16-21: LGTM!

The test for setting and getting an item in session storage is correctly implemented.


23-33: LGTM!

The test for removing an item from session storage is correctly implemented.


35-45: LGTM!

The test for clearing all items from session storage is correctly implemented.


55-60: LGTM!

The test for setting and getting an item in storage: StorageKeys is correctly implemented.


62-72: LGTM!

The test for removing an item from storage: StorageKeys is correctly implemented.


74-84: LGTM!

The test for clearing all items from storage: StorageKeys is correctly implemented.


86-91: LGTM!

The test for setting and getting an item in extra storage is correctly implemented.


93-101: LGTM!

The test for removing an item from extra storage is correctly implemented.


103-111: LGTM!

The test for clearing all items from extra storage is correctly implemented.

lib/main.test.ts (5)

Line range hint 1-8: LGTM!

The imports are necessary and correctly included.


Line range hint 10-13: LGTM!

The test for encoding a string to base64 URL safe format is correctly implemented.


Line range hint 15-25: LGTM!

The tests for removing trailing slashes from URLs and returning the same URL if no trailing slash are correctly implemented.


Line range hint 27-41: LGTM!

The tests for mapping login method params to URL params and handling undefined values in options are correctly implemented.


Line range hint 43-115: LGTM!

The tests for generating the correct auth URL with required parameters, including optional parameters if provided, and handling default responseType if not provided are correctly implemented. The inclusion of the new state parameter is correctly handled.

@codecov
Copy link

codecov bot commented Aug 29, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

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 149d99c and 5eed18f.

Files selected for processing (1)
  • readme.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • readme.md

@DanielRivers DanielRivers changed the title chore: update dependancies feat: Add memory session manager Aug 29, 2024
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 5eed18f and 2d462e4.

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

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.

3 participants