Skip to content

Add better error handling #15

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

BlathanAevon
Copy link

TypeScript Improvements:

Added proper interface definition for key pair results
Made the class methods more strongly typed
Removed default exports in favor of named exports

Error Handling:

Added try-catch blocks to all methods
Included meaningful error messages
Proper error propagation

Performance Optimizations:

Cached TextEncoder as a static class property
Reduced buffer conversions where possible
Used array spread instead of concatenation
Simplified the biscuit token creation with reduce()

Code Organization:

Converted to a proper class structure
Added JSDoc comments for better documentation
Consistent method naming (removed camelCase prefix)
Made methods public for better TypeScript support

Buffer Handling:

Simplified buffer conversions
Removed redundant buffer creation
More efficient byte array handling

General Improvements:

Removed redundant variable declarations
Simplified control flows
More consistent return types
Better separation of concerns

Copy link
Contributor

@chilaraiSxt chilaraiSxt left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Please fix the below errors and merge with main

yarn run build

warning ../../package.json: No license field
$ tsc  && node --experimental-wasm-modules  ./dist/src/index.js
src/authorization/authorization.ts:28:25 - error TS2769: No overload matches this call.
  Overload 1 of 3, '(callbackfn: (previousValue: BiscuitCapabilities, currentValue: BiscuitCapabilities, currentIndex: number, array: BiscuitCapabilities[]) => BiscuitCapabilities, initialValue: BiscuitCapabilities): BiscuitCapabilities', gave the following error.
    Argument of type '(builder: BiscuitBuilder, cap: BiscuitCapabilities) => void' is not assignable to parameter of type '(previousValue: BiscuitCapabilities, currentValue: BiscuitCapabilities, currentIndex: number, array: BiscuitCapabilities[]) => BiscuitCapabilities'.
      Types of parameters 'builder' and 'previousValue' are incompatible.
        Type 'BiscuitCapabilities' is missing the following properties from type 'BiscuitBuilder': free, build, merge, addFact, and 4 more.
  Overload 2 of 3, '(callbackfn: (previousValue: BiscuitBuilder, currentValue: BiscuitCapabilities, currentIndex: number, array: BiscuitCapabilities[]) => BiscuitBuilder, initialValue: BiscuitBuilder): BiscuitBuilder', gave the following error.
    Argument of type '(builder: BiscuitBuilder, cap: BiscuitCapabilities) => void' is not assignable to parameter of type '(previousValue: BiscuitBuilder, currentValue: BiscuitCapabilities, currentIndex: number, array: BiscuitCapabilities[]) => BiscuitBuilder'.
      Type 'void' is not assignable to type 'BiscuitBuilder'.

28                 .reduce((builder, cap) => {
                           ~~~~~~~~~~~~~~~~~~~


src/authorization/authorization.ts:32:18 - error TS2339: Property 'build' does not exist on type 'BiscuitCapabilities'.

32                 .build(PrivateKey.fromString(privKey))
                    ~~~~~

src/authorization/authorization.ts:54:18 - error TS2339: Property 'build' does not exist on type 'void'.

54                 .build(PrivateKey.fromString(privKey))
                    ~~~~~

src/index.ts:2:8 - error TS2613: Module '"/Users/chilarai/Projects/SxT-NodeJS-SDK/src/authorization/authorization"' has no default export. Did you mean to use 'import { Authorization } from "/Users/chilarai/Projects/SxT-NodeJS-SDK/src/authorization/authorization"' instead?

2 import Authorization from "./authorization/authorization.js";
         ~~~~~~~~~~~~~


Found 4 errors in 2 files.

Errors  Files
     3  src/authorization/authorization.ts:28
     1  src/index.ts:2
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Updated error handling
@BlathanAevon
Copy link
Author

Please checkout the latest update

@chilaraiSxt
Copy link
Contributor

Please checkout the latest update

Hey, please fix the errors. Once the errors are fixed please run npm run build or yarn run build to see if it compiles successfully
https://github.com/spaceandtimelabs/SxT-NodeJS-SDK/actions/runs/13307645493/job/37462026286?pr=15

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