Skip to content
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

Server re-build with latest AdonisJS framework & Typescript #47

Merged
merged 87 commits into from
Oct 13, 2023

Conversation

cino
Copy link
Contributor

@cino cino commented Jul 22, 2022

I apologize for the size of this PR but as we discussed earlier on Discord it's impossible to upgrade the dependencies without heavily restructuring the project. For anyone wanting to have a look at the code please open this in an editor or make use of github.dev by pressing the . (dot) on your keyboard.

So for now, this is a WIP Pull request so anyone can contribute and see where we are at the moment.

There are a few rules I've committed to while doing this "v2":

  • No breaking changes in the public interface
  • Everything in Typescript
  • Everything tested

Other improvements:

  • All routes should be pointed at controllers, no direct view response / callbacks from the route file
  • Never using Env() to retrieve environment variables outside the config files, the config files should be retrieving the environment variables and providing these to the application

Routes:

Dashboard (Conditional, only if enabled)

  • Login
  • Logout
  • Forgot password
  • Reset password
  • Account page
  • Export services/workspaces
  • Transfer services/workspaces (importing above export)
  • Delete account
  • Import endpoint (different from transfer)

API:

GitHub

  • Add linter/tests in Github action

General:

  • Copy docker building from the original branch into this one
  • ??

This also closes #70

@mcmxcdev
Copy link
Contributor

Hey @cino, I had some available time and pushed 4 new commits to the server overhaul.

All dependencies are up-to-date now, no more CVEs are reported in prod code, no TS/ESLint issues and made sure that all adonis commands work as expected.

I think this migration is moving to be in a great state, but ofc most of the routes have to be rewritten still.

Let's see, maybe some other Ferdium contributors want to jump in and help as well, this is probably one of the biggest tech debt we have to solve.

@SpecialAro
Copy link
Member

Hi all!

I've been trying to learn a bit of AdonisJS so I can push this PR forward. So far I was able to update the following endpoints:

  • Signup
  • Login
  • Me (GET and PUT)

Tested all 3 with Ferdium and they were all looking fine. Let me know what you think (pushing bellow).

Important security note: I'm using the API token guard of adonis auth for handling API authentication, which is different from the JWT we used to have (now it is not supported natively by adonis). I've set an expiration of 7 days, but let me know what you think about this. For this to work I had to add a new migration to introduce two more columns in the Tokens table.

Tomorrow, hopefully, I'll start with the Service or Workspace endpoints x)

@cino you were tagged on the Login and Signup endpoints - if you could review my work I would really apreciate it :D Thank you!

@SpecialAro
Copy link
Member

Hey again!

I just refactored the code to use JWT (so that we don't have to change anything on the Ferdium Client to accomodate that change - that is something we can do in the future, if needed).

I've also finished porting all the API endpoints!! 😄 But I'll be glad if someone could help me test them so that we can validate what I've done. The majority of them are working properly (tested with Ferdium Client), but some specific ones I havent tested (check the TODOS in the files)

@ferdium/reviewers I'm pinging everyone in hope that someone can review my code, given that this substantialy pushes this PR forward.

@cino, sorry to tag you again, but I'm trying to test the web endpoints and I don't seem to be able to past the initial page (no access to login, or dashboad). All I get is:
image

... or if I click on the button to go to dashboard:
image

CONTRIBUTING.md Outdated Show resolved Hide resolved
.nvmrc Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
Comment on lines +27 to +31
@column()
public name: string;

@column.dateTime()
public expires_at: DateTime;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you add these new fields? How are they going to be backwards compatible?

Copy link
Member

Choose a reason for hiding this comment

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

That is a great question. I'm not entirely sure if it is ok to add them like so or if we need to provide a @default value. I've never used Adonis before so I'm not sure how to handle it.

If you test the auth jwt or even the api you will noticed that this 2 fields were added in the Adonis upgrade.

Generally, we have a bigger problem than this... I've tried to test the db in production and it fails to even initiate migrations (even without this new migration I added). We will probably need to code a script to migrate old databases to the new database schema manually

emailValidated: true,
features: {},
firstname: auth.user.username,
id: '82c1cf9d-ab58-4da2-b55e-aaa41d2142d8',
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same hardcoded id for every user?

Copy link
Member

Choose a reason for hiding this comment

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

Copy-pasted from the previous code.... It was strange to me as well xD

Comment on lines 125 to 171
isPremium: true,
isSubscriptionOwner: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to drop these fields since Ferdium is fully OSS, but probably better to split it off in a PR that would happen after this one.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is here to circunvent the fact that we are OSS. Forcing features that depend on those fields to be set to true on the Ferdium-App

emailValidated: true,
features: {},
firstname: auth.user.username,
id: '82c1cf9d-ab58-4da2-b55e-aaa41d2142d8',
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Member

Choose a reason for hiding this comment

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

Yep, don't know why xD

.length > 0
); // eslint-disable-line no-await-in-loop
// eslint-disable-next-line no-await-in-loop, unicorn/no-await-expression-member
(await Service.query().where('serviceId', serviceId)).length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this code even make sense? It is querying for a service but then the result of the call is not assigned to any variable?

Copy link
Member

Choose a reason for hiding this comment

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

This is inside a while block. so it will run while it is > 0 (don't like it either but lets make improvements after we merge this to codebase)

@SpecialAro SpecialAro self-assigned this Oct 1, 2023
@SpecialAro SpecialAro changed the title WIP: Server re-build with latest AdonisJS framework & Typescript Server re-build with latest AdonisJS framework & Typescript Oct 1, 2023
@mcmxcdev
Copy link
Contributor

mcmxcdev commented Oct 1, 2023

Amazing work! 🎉

I noticed a couple of improvement possiblities:

  • pnpm reformat-files produces 10 files diff when run with latest commit which it shouldn't
    • make sure to disable the lint rules which conflict with prettier formatting
  • pnpm start always errored with "missing env value HOST", although I had HOST defined inside .env
  • pnpm test gave me failed tests for various files
    • add the pnpm test step to the CI so we avoid test failures in the future

@SpecialAro
Copy link
Member

Amazing work! 🎉

I noticed a couple of improvement possiblities:

  • pnpm reformat-files produces 10 files diff when run with latest commit which it shouldn't

    • make sure to disable the lint rules which conflict with prettier formatting
  • pnpm start always errored with "missing env value HOST", although I had HOST defined inside .env

  • pnpm test gave me failed tests for various files

    • add the pnpm test step to the CI so we avoid test failures in the future

Thank you for your comment and review @mcmxcdev. Indeed I haven't focused too much on tests up until now.

I've pushed some commits that fix the majority of the fails but I still have to fix the tests with the transfer endpoint because it seems that the endpoint data is being seen as body json (if you look at the controller) and not so much as file - so those tests are not up to date. I'm commenting them out for now if you agree (later we can improve tests)

@SpecialAro SpecialAro requested a review from a team October 2, 2023 01:48
@SpecialAro SpecialAro linked an issue Oct 12, 2023 that may be closed by this pull request
@SpecialAro SpecialAro merged commit e503468 into ferdium:main Oct 13, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
5 participants