-
Notifications
You must be signed in to change notification settings - Fork 66
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
Please checkout the latest update |
Hey, please fix the errors. Once the errors are fixed please run |
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