usermaven / usermaven-js

Usermaven provides instant actionable analytics to grow your SaaS business.
MIT License
1 stars 2 forks source link

Next #127

Closed seeratawan01 closed 1 week ago

seeratawan01 commented 1 week ago

PR Type

Tests, Enhancement, Configuration changes


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
helpers.ts
Enhance query string parsing and object validation             

packages/javascript-sdk/src/utils/helpers.ts
  • Improved query string parsing by removing leading '?'.
  • Added check to avoid empty keys in query parameters.
  • Enhanced isObject function to handle null values.
  • +6/-3     
    Tests
    helpers.test.ts
    Add unit tests for helper functions                                           

    packages/javascript-sdk/test/unit/utils/helpers.test.ts
  • Added unit tests for helper functions.
  • Tested generateId, isValidEmail, and debounce.
  • Verified getUtmParams and parseQueryString functionality.
  • Included tests for isString, isObject, and parseLogLevel.
  • +161/-0 
    queue.test.ts
    Implement unit tests for RetryQueue                                           

    packages/javascript-sdk/test/unit/utils/queue.test.ts
  • Added tests for RetryQueue functionality.
  • Tested queue addition and batch processing.
  • Verified retry mechanism and storage loading.
  • Checked offline/online transition handling.
  • +115/-0 
    Configuration changes
    release-candidate.yml
    Add GitHub Actions workflow for release candidates             

    .github/workflows/release-candidate.yml
  • Created a GitHub Actions workflow for release candidates.
  • Configured to trigger on pull request closure to develop.
  • Generates a release candidate version based on latest tag.
  • +52/-0   

    πŸ’‘ PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    github-actions[bot] commented 1 week ago

    PR Reviewer Guide πŸ”

    Here are some key observations to aid the review process:

    πŸ… Score: 85
    πŸ§ͺ PR contains tests
    πŸ”’ No security concerns identified
    ⚑ Recommended focus areas for review

    Error Handling
    Ensure that the parseQueryString function handles cases where decodeURIComponent throws an error due to malformed URI components. Type Checking
    The isObject function should ensure that functions and arrays are not incorrectly identified as plain objects.
    Code feedback:
    relevant filepackages/javascript-sdk/src/utils/helpers.ts
    suggestion       Consider adding error handling for decodeURIComponent to catch exceptions from malformed URI components. This can prevent potential runtime errors. [important]
    relevant lineparams[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');

    relevant filepackages/javascript-sdk/src/utils/helpers.ts
    suggestion       Refine the isObject function to exclude functions and arrays, which are technically objects but not plain objects. You can add checks like `!Array.isArray(value) && !(value instanceof Function)`. [important]
    relevant linereturn value !== null && typeof value === 'object' && value.constructor === Object;

    github-actions[bot] commented 1 week ago

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Ensure robustness by verifying the structure of query string pairs before processing ___ **Add a check to ensure that the pair array has exactly two elements after splitting
    to avoid accessing undefined indices.** [packages/javascript-sdk/src/utils/helpers.ts [48]](https://github.com/usermaven/usermaven-js/pull/127/files#diff-51c6882c0bb5b1ea9ca3fda284cba02f7aa0a927d814f09b7b2f980473d87c90R48-R48) ```diff const pair = queries[i].split('='); +if (pair.length !== 2) continue; ```
    Suggestion importance[1-10]: 9 Why: The suggestion improves the robustness of the code by ensuring that the `pair` array has exactly two elements before accessing them. This prevents potential errors when dealing with malformed query strings and enhances the reliability of the function.
    9
    Prevent potential runtime errors by checking the existence of query parameter values before decoding ___ **Ensure that the pair[1] value is checked for existence before decoding to prevent
    potential runtime errors if the query string is malformed.** [packages/javascript-sdk/src/utils/helpers.ts [50-51]](https://github.com/usermaven/usermaven-js/pull/127/files#diff-51c6882c0bb5b1ea9ca3fda284cba02f7aa0a927d814f09b7b2f980473d87c90R50-R51) ```diff -params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); +if (pair[1]) { + params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); +} else { + params[decodeURIComponent(pair[0])] = ''; +} ```
    Suggestion importance[1-10]: 8 Why: This suggestion addresses a potential runtime error by ensuring that the value of `pair[1]` is checked for existence before decoding. This is crucial for handling malformed query strings gracefully, thereby improving the robustness of the code.
    8
    Enhancement
    Enhance the robustness of object type checking by safely verifying the constructor property ___ **Consider using Object.prototype.hasOwnProperty.call(value, 'constructor') to check
    for the constructor property to avoid potential issues with objects that do not
    inherit from Object.prototype.** [packages/javascript-sdk/src/utils/helpers.ts [62]](https://github.com/usermaven/usermaven-js/pull/127/files#diff-51c6882c0bb5b1ea9ca3fda284cba02f7aa0a927d814f09b7b2f980473d87c90R62-R62) ```diff -return value !== null && typeof value === 'object' && value.constructor === Object; +return value !== null && typeof value === 'object' && Object.prototype.hasOwnProperty.call(value, 'constructor') && value.constructor === Object; ```
    Suggestion importance[1-10]: 7 Why: This suggestion enhances the robustness of the `isObject` function by safely checking the constructor property, which can prevent issues with objects that do not inherit from `Object.prototype`. It is a good practice for more reliable type checking.
    7
    Maintainability
    Improve code readability and maintainability by using Array.prototype.forEach for iteration ___ **Use Array.prototype.forEach for iterating over queries to improve readability and
    leverage functional programming practices.** [packages/javascript-sdk/src/utils/helpers.ts [47-52]](https://github.com/usermaven/usermaven-js/pull/127/files#diff-51c6882c0bb5b1ea9ca3fda284cba02f7aa0a927d814f09b7b2f980473d87c90R47-R52) ```diff -for (let i = 0; i < queries.length; i++) { - const pair = queries[i].split('='); +queries.forEach(query => { + const pair = query.split('='); if (pair[0] !== '') { params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); } -} +}); ```
    Suggestion importance[1-10]: 6 Why: The suggestion to use `Array.prototype.forEach` improves code readability and aligns with functional programming practices. While it doesn't change the functionality, it enhances maintainability and clarity of the code.
    6