warengonzaga / gathertown.js

Simple and lightweight community contributed unofficial JS/TS SDK for Gather Town's HTTPS and WebSocket APIs. 🌏🕹💬
https://gathertown.js.org
MIT License
40 stars 6 forks source link

use optional chaining #21

Closed jofftiquez closed 2 years ago

jofftiquez commented 2 years ago

Use optional chaining for trailing objects for more secure checking

warengonzaga commented 2 years ago

Is it already implemented or not? @jofftiquez?

jofftiquez commented 2 years ago

@WarenGonzaga no, not yet.

warengonzaga commented 2 years ago

@WarenGonzaga no, not yet.

Do you have detailed implementation of this so other contributor can work on it.

warengonzaga commented 2 years ago

Any updates on this @jofftiquez? Can you drop some details on how to achieve this? A reference is a great way to start. I might work on it. I just need to understand. 😅

jofftiquez commented 2 years ago

You can start by searching "Optional chaining in JavaScript". I didn't know this was assigned to me explicitly. Please let me know in the future to avoid confusion. Thanks.

warengonzaga commented 2 years ago

Awesome, thanks for the response! I'll take a look into it. Perhaps I guess @princejoogie can work on it?

princejoogie commented 2 years ago

Awesome, thanks for the response! I'll take a look into it. Perhaps I guess @princejoogie can work on it?

@WarenGonzaga with the conversion of this wrapper from js to typescript, I believe the issue "Use optional chaining for trailing objects for more secure checking" is solved already with interfaces and additional logic to check each request parameters

check out createSpace.ts as an example. https://github.com/WarenGonzaga/gathertown.js/blob/df032e14dfaefdd444a79cd9aa6e4797c54d95c4/src/api/createSpace.ts#L5-L11

the properties map, reason, and sourceSpace are optional so I added additional checking to see if those attributes are present: https://github.com/WarenGonzaga/gathertown.js/blob/df032e14dfaefdd444a79cd9aa6e4797c54d95c4/src/api/createSpace.ts#L20-L33


if we want a super secure way to check the given parameters, we can use validator libraries like yup or joi

i use yup in my projects. example: https://github.com/princejoogie/expressts-typeorm-bp/blob/12f2ad72c2dfd8952335c9a56c600d4bec090798/src/middleware/validators/schema/auth.schema.ts#L14-L21

warengonzaga commented 2 years ago

Thanks for the detailed explanation @princejoogie! What is more secure between yup and joi? Which is easier to implement?

princejoogie commented 2 years ago

Thanks for the detailed explanation @princejoogie!

What is more secure between yup and joi? Which is easier to implement?

im more familiar with yup so i would choose yup

warengonzaga commented 2 years ago

Thanks for the detailed explanation @princejoogie! What is more secure between yup and joi? Which is easier to implement?

im more familiar with yup so i would choose yup

Let's do it! 🤗

warengonzaga commented 2 years ago

@princejoogie update on this?

princejoogie commented 2 years ago

@princejoogie update on this?

ill push a PR next weekend

warengonzaga commented 2 years ago

Awesome, thanks for the update @princejoogie looking forward!

warengonzaga commented 2 years ago

@princejoogie soft follow up on this? thanks!

warengonzaga commented 2 years ago

any update on this @princejoogie?

warengonzaga commented 2 years ago

Thanks @jofftiquez and @princejoogie for the update! Closing this issue now! ⚡