Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nicknisi
Copy link
Member

@nicknisi nicknisi commented Nov 6, 2025

Description

This pull request removes the dependency on the external leb and qs packages by introducing an in-house LEB128 encoding/decoding utility and a custom query string serializer. It updates all relevant imports to use these new utilities, ensuring compatibility and maintainability. Comprehensive unit tests for the new LEB128 implementation are also included. This is to improve cross-runtime compatibility support.

Dependency Removal and Internal Utility Replacement:

  • Removed the leb and qs packages from package.json and replaced their usage with internal implementations. (package.json, package.jsonL45-R45)
  • Replaced all imports of leb's encodeUInt32/decodeUInt32 with internal versions in src/vault/vault.ts.
  • Removed the old toQueryString implementation from src/client/utils.ts and updated all imports in src/client/sso.ts and src/client/user-management.ts to use the new internal utility. [1] [2] [3]

New Utility Implementations:

  • Added src/common/utils/leb128.ts: Implements encodeUInt32 and decodeUInt32 for LEB128 encoding/decoding of unsigned 32-bit integers, with input validation and error handling.
  • Added src/common/utils/query-string.ts: Implements toQueryString, matching the old behavior (RFC1738 encoding, key sorting, array/object handling) without external dependencies.

Testing and Compatibility:

  • Added comprehensive unit tests for the new LEB128 implementation in src/common/utils/leb128.spec.ts, including boundary values, invalid input handling, and compatibility with the previous leb package's output.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@nicknisi nicknisi requested a review from a team as a code owner November 6, 2025 17:07
@nicknisi nicknisi requested review from jonatascastro12 and removed request for a team November 6, 2025 17:07
@nicknisi nicknisi changed the title replace leb dep with vanilla implementation replace leb and qs dep with vanilla implementations Nov 6, 2025
@nicknisi nicknisi changed the title replace leb and qs dep with vanilla implementations Replace leb and qs dep with vanilla implementations Nov 6, 2025
@nicknisi nicknisi changed the title Replace leb and qs dep with vanilla implementations Replace leb and qs deps with vanilla implementations Nov 6, 2025
@nicknisi nicknisi requested review from Copilot and hexedpackets and removed request for jonatascastro12 November 6, 2025 17:09
@nicknisi nicknisi changed the title Replace leb and qs deps with vanilla implementations [v8] Replace leb and qs deps with vanilla implementations Nov 6, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR successfully removes external dependencies (leb and qs) by implementing internal replacements for cross-runtime compatibility.

Key Changes:

  • Added src/common/utils/leb128.ts: LEB128 encoding/decoding for uint32 values with proper validation and error handling
  • Added src/common/utils/query-string.ts: Query string serialization matching qs library behavior (RFC1738 format, sorted keys, array/object support)
  • Comprehensive test suite for LEB128 including compatibility verification with original package
  • Updated all imports in vault.ts, sso.ts, and user-management.ts
  • Removed leb and qs from dependencies

Implementation Quality:

  • LEB128 implementation is mathematically correct with proper bitwise operations
  • Extensive test coverage validates boundary cases, round-trips, and wire-format compatibility
  • Existing tests for SSO and user-management confirm query string behavior is preserved
  • Clean separation of concerns with utilities in common/utils

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk after verifying RFC1738 encoding behavior
  • Score reflects solid implementation with comprehensive LEB128 tests and existing SSO/user-management tests validating query string behavior. Minor concern about parentheses encoding in RFC1738 implementation warrants verification but shouldn't block merge
  • Check src/common/utils/query-string.ts - verify RFC1738 parentheses encoding matches expected behavior for your API endpoints

Important Files Changed

File Analysis

Filename Score Overview
src/common/utils/leb128.ts 5/5 new LEB128 implementation with proper validation, encoding/decoding logic appears correct with appropriate error handling
src/common/utils/leb128.spec.ts 5/5 comprehensive test coverage including boundary values, round-trip verification, offset handling, and compatibility tests with original leb package
src/common/utils/query-string.ts 4/5 new query string implementation matches qs library behavior, minor concern about parentheses encoding in RFC1738
src/vault/vault.ts 5/5 updated imports to use internal LEB128 implementation, no logic changes to vault encryption/decryption flow
package.json 5/5 removed leb and qs dependencies as expected, @types/qs remains in devDependencies (acceptable for type checking)

Sequence Diagram

sequenceDiagram
    participant App as Application Code
    participant Vault as Vault Module
    participant LEB128 as LEB128 Utils
    participant QS as Query String Utils
    participant SSO as SSO Client
    participant UM as User Management

    Note over App,UM: Dependency Replacement Flow

    rect rgb(200, 220, 255)
        Note over Vault,LEB128: LEB128 Encoding/Decoding
        App->>Vault: encrypt(data, context)
        Vault->>LEB128: encodeUInt32(keyBlob.length)
        LEB128-->>Vault: Uint8Array (encoded length)
        Vault-->>App: encrypted payload
        
        App->>Vault: decrypt(encryptedData)
        Vault->>LEB128: decodeUInt32(inputData, offset)
        LEB128-->>Vault: {value, nextIndex}
        Vault-->>App: decrypted data
    end

    rect rgb(200, 255, 220)
        Note over SSO,QS: Query String Serialization
        App->>SSO: getAuthorizationUrl(options)
        SSO->>QS: toQueryString(params)
        QS-->>SSO: serialized query string
        SSO-->>App: authorization URL
        
        App->>UM: getAuthorizationUrl(options)
        UM->>QS: toQueryString(params)
        QS-->>UM: serialized query string
        UM-->>App: authorization URL
    end

    Note over App,UM: All external deps (leb, qs) replaced with internal implementations
Loading

9 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes external dependencies (leb and qs packages) by implementing custom utilities for LEB128 encoding and query string generation. The changes replace third-party libraries with internal implementations to reduce bundle size and improve maintainability.

  • Implements a custom LEB128 encoding/decoding utility with comprehensive test coverage
  • Replaces qs library with a custom query string builder that maintains backwards compatibility
  • Updates import paths across multiple files to use the new common utilities

Reviewed Changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/common/utils/leb128.ts New LEB128 encoding/decoding implementation with validation
src/common/utils/leb128.spec.ts Comprehensive test suite for LEB128 with boundary, round-trip, and compatibility tests
src/common/utils/query-string.ts Custom query string builder replacing qs library
src/vault/vault.ts Updated import to use internal LEB128 implementation
src/vault/leb.d.ts Removed type declaration file for external leb package
src/client/utils.ts Removed file containing qs-based query string utility
src/client/user-management.ts Updated import path to new common query string utility
src/client/sso.ts Updated import path to new common query string utility
package.json Removed leb and qs dependencies
package-lock.json Updated lockfile marking qs and its dependencies as dev-only

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nicknisi nicknisi force-pushed the nicknisi/v8-leb-fix branch from 0de3300 to db6f690 Compare November 6, 2025 17:20
@nicknisi nicknisi merged commit e03131b into version-8 Nov 6, 2025
6 checks passed
@nicknisi nicknisi deleted the nicknisi/v8-leb-fix branch November 6, 2025 20:23
nicknisi added a commit that referenced this pull request Nov 24, 2025
## Description

This pull request removes the dependency on the external `leb` and `qs`
packages by introducing an in-house LEB128 encoding/decoding utility and
a custom query string serializer. It updates all relevant imports to use
these new utilities, ensuring compatibility and maintainability.
Comprehensive unit tests for the new LEB128 implementation are also
included. This is to improve cross-runtime compatibility support.

**Dependency Removal and Internal Utility Replacement:**

* Removed the `leb` and `qs` packages from `package.json` and replaced
their usage with internal implementations. (`package.json`,
[package.jsonL45-R45](diffhunk://#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L45-R45))
* Replaced all imports of `leb`'s `encodeUInt32`/`decodeUInt32` with
internal versions in `src/vault/vault.ts`.
* Removed the old `toQueryString` implementation from
`src/client/utils.ts` and updated all imports in `src/client/sso.ts` and
`src/client/user-management.ts` to use the new internal utility.
[[1]](diffhunk://#diff-3973d52ad7d2360214857fd42a183273a2e3904458c1eb573c34b3ec6151ab02L1-L20)
[[2]](diffhunk://#diff-aba556dc64a77e993f9ce2de8ffd20b276128d1f6f4ba69bf2967e05dc1f7676L1-R1)
[[3]](diffhunk://#diff-b5a04503adce4aaadee02b4511ee9bd11ec26a46927bde7c07d85ad31786e4bbL1-R1)

**New Utility Implementations:**

* Added `src/common/utils/leb128.ts`: Implements `encodeUInt32` and
`decodeUInt32` for LEB128 encoding/decoding of unsigned 32-bit integers,
with input validation and error handling.
* Added `src/common/utils/query-string.ts`: Implements `toQueryString`,
matching the old behavior (RFC1738 encoding, key sorting, array/object
handling) without external dependencies.

**Testing and Compatibility:**

* Added comprehensive unit tests for the new LEB128 implementation in
`src/common/utils/leb128.spec.ts`, including boundary values, invalid
input handling, and compatibility with the previous `leb` package's
output.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 2, 2025
## Description

This pull request removes the dependency on the external `leb` and `qs`
packages by introducing an in-house LEB128 encoding/decoding utility and
a custom query string serializer. It updates all relevant imports to use
these new utilities, ensuring compatibility and maintainability.
Comprehensive unit tests for the new LEB128 implementation are also
included. This is to improve cross-runtime compatibility support.

**Dependency Removal and Internal Utility Replacement:**

* Removed the `leb` and `qs` packages from `package.json` and replaced
their usage with internal implementations. (`package.json`,
[package.jsonL45-R45](diffhunk://#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L45-R45))
* Replaced all imports of `leb`'s `encodeUInt32`/`decodeUInt32` with
internal versions in `src/vault/vault.ts`.
* Removed the old `toQueryString` implementation from
`src/client/utils.ts` and updated all imports in `src/client/sso.ts` and
`src/client/user-management.ts` to use the new internal utility.
[[1]](diffhunk://#diff-3973d52ad7d2360214857fd42a183273a2e3904458c1eb573c34b3ec6151ab02L1-L20)
[[2]](diffhunk://#diff-aba556dc64a77e993f9ce2de8ffd20b276128d1f6f4ba69bf2967e05dc1f7676L1-R1)
[[3]](diffhunk://#diff-b5a04503adce4aaadee02b4511ee9bd11ec26a46927bde7c07d85ad31786e4bbL1-R1)

**New Utility Implementations:**

* Added `src/common/utils/leb128.ts`: Implements `encodeUInt32` and
`decodeUInt32` for LEB128 encoding/decoding of unsigned 32-bit integers,
with input validation and error handling.
* Added `src/common/utils/query-string.ts`: Implements `toQueryString`,
matching the old behavior (RFC1738 encoding, key sorting, array/object
handling) without external dependencies.

**Testing and Compatibility:**

* Added comprehensive unit tests for the new LEB128 implementation in
`src/common/utils/leb128.spec.ts`, including boundary values, invalid
input handling, and compatibility with the previous `leb` package's
output.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 4, 2025
## Description

This pull request removes the dependency on the external `leb` and `qs`
packages by introducing an in-house LEB128 encoding/decoding utility and
a custom query string serializer. It updates all relevant imports to use
these new utilities, ensuring compatibility and maintainability.
Comprehensive unit tests for the new LEB128 implementation are also
included. This is to improve cross-runtime compatibility support.

**Dependency Removal and Internal Utility Replacement:**

* Removed the `leb` and `qs` packages from `package.json` and replaced
their usage with internal implementations. (`package.json`,
[package.jsonL45-R45](diffhunk://#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L45-R45))
* Replaced all imports of `leb`'s `encodeUInt32`/`decodeUInt32` with
internal versions in `src/vault/vault.ts`.
* Removed the old `toQueryString` implementation from
`src/client/utils.ts` and updated all imports in `src/client/sso.ts` and
`src/client/user-management.ts` to use the new internal utility.
[[1]](diffhunk://#diff-3973d52ad7d2360214857fd42a183273a2e3904458c1eb573c34b3ec6151ab02L1-L20)
[[2]](diffhunk://#diff-aba556dc64a77e993f9ce2de8ffd20b276128d1f6f4ba69bf2967e05dc1f7676L1-R1)
[[3]](diffhunk://#diff-b5a04503adce4aaadee02b4511ee9bd11ec26a46927bde7c07d85ad31786e4bbL1-R1)

**New Utility Implementations:**

* Added `src/common/utils/leb128.ts`: Implements `encodeUInt32` and
`decodeUInt32` for LEB128 encoding/decoding of unsigned 32-bit integers,
with input validation and error handling.
* Added `src/common/utils/query-string.ts`: Implements `toQueryString`,
matching the old behavior (RFC1738 encoding, key sorting, array/object
handling) without external dependencies.

**Testing and Compatibility:**

* Added comprehensive unit tests for the new LEB128 implementation in
`src/common/utils/leb128.spec.ts`, including boundary values, invalid
input handling, and compatibility with the previous `leb` package's
output.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 4, 2025
## Description

This pull request removes the dependency on the external `leb` and `qs`
packages by introducing an in-house LEB128 encoding/decoding utility and
a custom query string serializer. It updates all relevant imports to use
these new utilities, ensuring compatibility and maintainability.
Comprehensive unit tests for the new LEB128 implementation are also
included. This is to improve cross-runtime compatibility support.

**Dependency Removal and Internal Utility Replacement:**

* Removed the `leb` and `qs` packages from `package.json` and replaced
their usage with internal implementations. (`package.json`,
[package.jsonL45-R45](diffhunk://#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L45-R45))
* Replaced all imports of `leb`'s `encodeUInt32`/`decodeUInt32` with
internal versions in `src/vault/vault.ts`.
* Removed the old `toQueryString` implementation from
`src/client/utils.ts` and updated all imports in `src/client/sso.ts` and
`src/client/user-management.ts` to use the new internal utility.
[[1]](diffhunk://#diff-3973d52ad7d2360214857fd42a183273a2e3904458c1eb573c34b3ec6151ab02L1-L20)
[[2]](diffhunk://#diff-aba556dc64a77e993f9ce2de8ffd20b276128d1f6f4ba69bf2967e05dc1f7676L1-R1)
[[3]](diffhunk://#diff-b5a04503adce4aaadee02b4511ee9bd11ec26a46927bde7c07d85ad31786e4bbL1-R1)

**New Utility Implementations:**

* Added `src/common/utils/leb128.ts`: Implements `encodeUInt32` and
`decodeUInt32` for LEB128 encoding/decoding of unsigned 32-bit integers,
with input validation and error handling.
* Added `src/common/utils/query-string.ts`: Implements `toQueryString`,
matching the old behavior (RFC1738 encoding, key sorting, array/object
handling) without external dependencies.

**Testing and Compatibility:**

* Added comprehensive unit tests for the new LEB128 implementation in
`src/common/utils/leb128.spec.ts`, including boundary values, invalid
input handling, and compatibility with the previous `leb` package's
output.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 16, 2025
## Description

This pull request removes the dependency on the external `leb` and `qs`
packages by introducing an in-house LEB128 encoding/decoding utility and
a custom query string serializer. It updates all relevant imports to use
these new utilities, ensuring compatibility and maintainability.
Comprehensive unit tests for the new LEB128 implementation are also
included. This is to improve cross-runtime compatibility support.

**Dependency Removal and Internal Utility Replacement:**

* Removed the `leb` and `qs` packages from `package.json` and replaced
their usage with internal implementations. (`package.json`,
[package.jsonL45-R45](diffhunk://#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L45-R45))
* Replaced all imports of `leb`'s `encodeUInt32`/`decodeUInt32` with
internal versions in `src/vault/vault.ts`.
* Removed the old `toQueryString` implementation from
`src/client/utils.ts` and updated all imports in `src/client/sso.ts` and
`src/client/user-management.ts` to use the new internal utility.
[[1]](diffhunk://#diff-3973d52ad7d2360214857fd42a183273a2e3904458c1eb573c34b3ec6151ab02L1-L20)
[[2]](diffhunk://#diff-aba556dc64a77e993f9ce2de8ffd20b276128d1f6f4ba69bf2967e05dc1f7676L1-R1)
[[3]](diffhunk://#diff-b5a04503adce4aaadee02b4511ee9bd11ec26a46927bde7c07d85ad31786e4bbL1-R1)

**New Utility Implementations:**

* Added `src/common/utils/leb128.ts`: Implements `encodeUInt32` and
`decodeUInt32` for LEB128 encoding/decoding of unsigned 32-bit integers,
with input validation and error handling.
* Added `src/common/utils/query-string.ts`: Implements `toQueryString`,
matching the old behavior (RFC1738 encoding, key sorting, array/object
handling) without external dependencies.

**Testing and Compatibility:**

* Added comprehensive unit tests for the new LEB128 implementation in
`src/common/utils/leb128.spec.ts`, including boundary values, invalid
input handling, and compatibility with the previous `leb` package's
output.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 22, 2025
## Description

This pull request removes the dependency on the external `leb` and `qs`
packages by introducing an in-house LEB128 encoding/decoding utility and
a custom query string serializer. It updates all relevant imports to use
these new utilities, ensuring compatibility and maintainability.
Comprehensive unit tests for the new LEB128 implementation are also
included. This is to improve cross-runtime compatibility support.

**Dependency Removal and Internal Utility Replacement:**

* Removed the `leb` and `qs` packages from `package.json` and replaced
their usage with internal implementations. (`package.json`,
[package.jsonL45-R45](diffhunk://#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L45-R45))
* Replaced all imports of `leb`'s `encodeUInt32`/`decodeUInt32` with
internal versions in `src/vault/vault.ts`.
* Removed the old `toQueryString` implementation from
`src/client/utils.ts` and updated all imports in `src/client/sso.ts` and
`src/client/user-management.ts` to use the new internal utility.
[[1]](diffhunk://#diff-3973d52ad7d2360214857fd42a183273a2e3904458c1eb573c34b3ec6151ab02L1-L20)
[[2]](diffhunk://#diff-aba556dc64a77e993f9ce2de8ffd20b276128d1f6f4ba69bf2967e05dc1f7676L1-R1)
[[3]](diffhunk://#diff-b5a04503adce4aaadee02b4511ee9bd11ec26a46927bde7c07d85ad31786e4bbL1-R1)

**New Utility Implementations:**

* Added `src/common/utils/leb128.ts`: Implements `encodeUInt32` and
`decodeUInt32` for LEB128 encoding/decoding of unsigned 32-bit integers,
with input validation and error handling.
* Added `src/common/utils/query-string.ts`: Implements `toQueryString`,
matching the old behavior (RFC1738 encoding, key sorting, array/object
handling) without external dependencies.

**Testing and Compatibility:**

* Added comprehensive unit tests for the new LEB128 implementation in
`src/common/utils/leb128.spec.ts`, including boundary values, invalid
input handling, and compatibility with the previous `leb` package's
output.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants