-
Notifications
You must be signed in to change notification settings - Fork 3
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
Significant refactor of the library and a partial support for slugs #27
base: 1.0
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.
First, for this library to be taken seriously, its contributors need to act professionally.
Changes made to the login code in this PR are useless as there were never "breaking changes required". The current way of authenticating users with or without "slugs" was already a part of the library. As in you can just add your "slug" to the server url provided to the library (this requirement will be removed in the future). This implementation of user selection would not work regardless, as it does not take into account the different “form keys” between users.
This PR adds extra complexity and confusion to the library, mainly because the changes made were never required to add support for "slugs", which seems to be the point of this PR (?). While it only seems to advance your plans for the library which were already discussed on Discord and rejected.
The structural changes made in this PR are useful. Which is why I recommend making a new pull request just for them. I do not deny the need for some refactoring in the library in its current state (especially in the request wrapper), but “try linting it” won’t be good enough.
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.
There are some great structure changes, but mainly this PR made more confusion than sense.
For roles (or slugs as you called then), they are badly incomplete. I would suggest to let us do the core part of roles, as we have more experience handling with them, assuming by your code for handling slugs. You're free to make further PRs simplifying and improving roles, etc.
"Could not fetch users for this account." | ||
) | ||
} | ||
|
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.
Role parser is missing user account type, and other details that are available in HTML.
@@ -0,0 +1,5 @@ | |||
export interface ListedWilmaUserInfo { |
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.
Can you clarify what is this used for? I cannot understand by its name, so renaming would be nice to something more logical.
{name: "Cookie", value: "Wilma2SID=" + sessionValue} | ||
] | ||
}) | ||
|
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.
If you would like to check if this account requires roles, please do a request to /overview
, without slugs, and check the account type from form key.
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.
Better to rely on more reliable responses than messages, it becomes even more important as it's the authentication mechanism.
@@ -115,6 +115,11 @@ export async function request(method: string, options: RequestOptions): Promise< | |||
if(options.session != null){ | |||
if(options.body.formkey == undefined) options.body.formkey = options.session.formkey | |||
if(options.body.secret == undefined) options.body.secret = options.session.secret | |||
|
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.
If you were doing POST requests, this alone would not work.
Above you can see formkey
and secret
. They are different for the account itself, and all its roles.
formkey
and secret
needs proper handling for roles.
import { ListedWilmaUserInfo } from "../types/userInfo" | ||
|
||
/** A factory class for getting the users of an account. */ | ||
class WilmaAccount { |
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.
If roles are in array, why is first one always returned? Shouldn't there be getUsers and setUser?
@@ -4,7 +4,7 @@ const axios = require("axios") | |||
|
|||
// Typings | |||
import {RequestHeader, RequestOptions, RequestResponse} from "../types/apiRequest" | |||
import Errors from "../utils/error" |
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.
Could you explain what's the reason behind this change?
@@ -1,4 +1,3 @@ | |||
// Starsoft API typings |
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.
Could you explain why did you remove this comment line? Comment lines are useful for explaining ie. usage and purpose of a given code.
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.
Thank you for your contribution! I appreciate your consideration for ease of use and user friendliness.
Please have a look into my comment about referencing the WilmaSession.
session: WilmaSession | ||
|
||
constructor(session: WilmaSession){ | ||
this.session = session |
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.
I have refactored the code base to a direction that will make the it easier to read and study, at least in my opinion. This includes mapping the user classes into "models" and "managers" folders from the little folders they used to be in. I also rewrote some existing code, spending a lot of time reorganizing the if-clauses; however, there is still some work to be done for this library to be taken seriously.
For instance, all of the errors of the library should be exported to the user. Each error related to Wilma API should trivially extend
WAPIError
(I wonder if this should be renamed to a more conciseWilmaError
?), or else error handling won't be nice. Types should also be organized more logically, and in my opinion the request wrapper needs to be heavily refactored (try linting it).Furthermore, I have implemented a partial support for Wilma servers that use slugs. This is a breaking change, but very important as I have not been able to use the library before this. Let's take this piece of code as an example of the slug-enabled library:
This procedure is same for everyone, regardless whether their Wilma instance requires user slugs or not. I think that as the only(?) currently maintained Wilma scripting library openwilma.js should thrive to be as easy to use to be possible, hiding all of the lower-level implementation details from beginners.